Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
v0.2.8
Browse files Browse the repository at this point in the history
Merge pull request #22 from TechforgoodCAST/dev
  • Loading branch information
suninthesky authored Feb 15, 2019
2 parents b0e8d72 + 3d81965 commit 84c4c92
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
@comment = @commentable.comments.new(comment_params)

if @comment.save
CommentsMailer.new_comment(@comment).deliver_now
CommentsMailer.new_comment(@comment, @commentable.playback).deliver_now
redirect_to(
playback_path(@commentable.playback, anchor: @commentable.anchor),
notice: 'Comment was successfully created.'
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/playbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class PlaybacksController < ApplicationController
before_action :set_playback, only: %i[show edit update destroy]

def pending
@playbacks = Playback.where(comments_count: params[:comments] || 0)
@playbacks = Playback.query(:comments_count, params[:comments])
.query(:source, params[:source])
.order(:source, :comments_count)
end

def index
Expand Down Expand Up @@ -46,7 +48,7 @@ def set_playback

def playback_params
params.require(:playback).permit(
:organisation_name, :project_name, :author_name, :period, :logo_url,
:organisation_name, :email, :project_name, :author_name, :period, :logo_url,
:description, :notes, :source,
sections_attributes: [
:id, :confidence, :name, :description, :_destroy,
Expand Down
6 changes: 4 additions & 2 deletions app/mailers/comments_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class CommentsMailer < ApplicationMailer
helper :playbacks

def new_comment(comment)
def new_comment(comment, playback)
@comment = comment
@playback = playback

subject = "New comment from #{@comment.author}"
mail(to: 'hello@wearecast.org.uk', subject: subject)
mail(to: @playback.email, bcc: 'designhops@wearecast.org.uk', subject: subject)
end
end
6 changes: 5 additions & 1 deletion app/models/playback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ class Playback < ApplicationRecord
accepts_nested_attributes_for :sections, allow_destroy: true
validates_associated :sections

validates :organisation_name, presence: true
validates :organisation_name, :email, presence: true

def self.query(col, param)
param.blank? ? all : where(col => param)
end
end
1 change: 1 addition & 0 deletions app/views/playbacks/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="flex-col1 mb30 px15">
<%= f.input :logo_url %>
<%= f.input :organisation_name %>
<%= f.input :email %>
<%= f.input :project_name %>
<%= f.input :description %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/playbacks/pending.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="maxw1050 mx-auto px15">
<h1 class="h2 bold my40">Pending Playbacks</h1>

<table>
<table class="mb30">
<thead>
<tr>
<th>Organisation Name</th>
Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

config.action_mailer.perform_caching = false

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
Expand Down
4 changes: 1 addition & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_02_04_161239) do

ActiveRecord::Schema.define(version: 2019_02_06_170022) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,7 +53,6 @@
t.datetime "updated_at", null: false
t.string "source"
t.string "email"

t.integer "comments_count", default: 0, null: false
end

Expand Down
2 changes: 1 addition & 1 deletion test/factories/comments.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :comment do
step { nil }
commentable { Section.new(id: 1, name: 'State your problem') }
author { 'John Doe' }
body { 'What should I work on next?' }
end
Expand Down
1 change: 1 addition & 0 deletions test/factories/playbacks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FactoryBot.define do
factory :playback do
organisation_name { 'ACME' }
email { 'test@wearecast.co.uk' }
end
end
14 changes: 11 additions & 3 deletions test/mailers/comments_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
require 'test_helper'

class CommentsMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
setup do
@playback = create(:playback)
@comment = create(:comment)
end

test 'new_comment' do
mail = CommentsMailer.new_comment(@comment, @playback)
assert_equal('New comment from John Doe', mail.subject)
assert_equal([@playback.email], mail.to)
assert_equal(['designhops@wearecast.org.uk'], mail.from)
end
end
8 changes: 7 additions & 1 deletion test/mailers/previews/comments_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ def new_comment
body: '<div>Is <a href="#">this</a> a good resource</div>',
commentable: Step.new(id: 1, name: 'State your problem')
)
CommentsMailer.new_comment(comment)

playback = Playback.new(
organisation_name: 'Organisation',
project_name: 'Project',
email: 'ian@wearecast.org.uk'
)
CommentsMailer.new_comment(comment, playback)
end
end
15 changes: 15 additions & 0 deletions test/models/playback_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ class PlaybackTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end

test 'try to create playback with email and organisation name' do
playback = Playback.new(organisation_name: "ACME", email: "test@example.com")
assert playback.valid?
end

test 'try to create playback without email' do
playback = Playback.new(organisation_name: "ACME")
refute playback.valid?
end

test 'try to create playback without organisation name' do
playback = Playback.new(email: "test@example.com")
refute playback.valid?
end
end
33 changes: 33 additions & 0 deletions test/system/comments_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'application_system_test_case'

class CommentsTest < ApplicationSystemTestCase

setup do
@user = create(:user)

end

test 'send email when comment created' do
visit new_playback_path
sign_in

fill_in(:playback_organisation_name, with: 'ACME')

click_link('Add Section')
fill_in('Section name', with: 'Discover')

click_button('Create Playback')

click_on 'Ask for help'

fill_in('Author', with: 'Author')
find('trix-editor').click.set('Test')

click_on 'Comment'

assert(ActionMailer::Base.deliveries.count == 1)

end


end
3 changes: 0 additions & 3 deletions test/system/webhooks_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'application_system_test_case'

class WebhooksTest < ApplicationSystemTestCase
# playback sucessfully created
# playback not sucessfully created (e.g. missing org name)
# playback not sucessfully created (e.g. no Airtable id)

setup do
@body = {
Expand Down

0 comments on commit 84c4c92

Please sign in to comment.