From 3eee34462357d4e3aabb39dd5f5198aca1a02ee5 Mon Sep 17 00:00:00 2001 From: Ian Edwards Date: Wed, 13 Feb 2019 14:27:34 +0000 Subject: [PATCH 1/6] add email field to playback form --- app/controllers/playbacks_controller.rb | 2 +- app/views/playbacks/_form.html.erb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/playbacks_controller.rb b/app/controllers/playbacks_controller.rb index b660712..c1fa1f5 100644 --- a/app/controllers/playbacks_controller.rb +++ b/app/controllers/playbacks_controller.rb @@ -46,7 +46,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, diff --git a/app/views/playbacks/_form.html.erb b/app/views/playbacks/_form.html.erb index 4894753..22cd571 100644 --- a/app/views/playbacks/_form.html.erb +++ b/app/views/playbacks/_form.html.erb @@ -3,6 +3,7 @@
<%= f.input :logo_url %> <%= f.input :organisation_name %> + <%= f.input :email %> <%= f.input :project_name %> <%= f.input :description %>
From 9777270330465c89350e30556586e2a221e283ad Mon Sep 17 00:00:00 2001 From: Ian Edwards Date: Wed, 13 Feb 2019 15:07:35 +0000 Subject: [PATCH 2/6] send comment notification email to playback owner --- app/controllers/comments_controller.rb | 2 +- app/mailers/comments_mailer.rb | 6 ++++-- test/mailers/previews/comments_mailer_preview.rb | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 3c55eac..f5ffec5 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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.' diff --git a/app/mailers/comments_mailer.rb b/app/mailers/comments_mailer.rb index 919e10f..15d31d7 100644 --- a/app/mailers/comments_mailer.rb +++ b/app/mailers/comments_mailer.rb @@ -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: 'hello@wearecast.org.uk', subject: subject) end end diff --git a/test/mailers/previews/comments_mailer_preview.rb b/test/mailers/previews/comments_mailer_preview.rb index be246bc..b87b037 100644 --- a/test/mailers/previews/comments_mailer_preview.rb +++ b/test/mailers/previews/comments_mailer_preview.rb @@ -6,6 +6,12 @@ def new_comment body: '
Is this a good resource
', 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 From 0bab5a13bac2078362f70ad2e4037c0e8e9831cd Mon Sep 17 00:00:00 2001 From: Ian Edwards Date: Wed, 13 Feb 2019 16:25:00 +0000 Subject: [PATCH 3/6] basic mailer test for new comment --- app/mailers/comments_mailer.rb | 2 +- config/environments/test.rb | 2 ++ db/schema.rb | 4 +--- test/factories/comments.rb | 2 +- test/factories/playbacks.rb | 1 + test/mailers/comments_mailer_test.rb | 14 +++++++++++--- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/mailers/comments_mailer.rb b/app/mailers/comments_mailer.rb index 15d31d7..75ec36b 100644 --- a/app/mailers/comments_mailer.rb +++ b/app/mailers/comments_mailer.rb @@ -6,6 +6,6 @@ def new_comment(comment, playback) @playback = playback subject = "New comment from #{@comment.author}" - mail(to: @playback.email, bcc: 'hello@wearecast.org.uk', subject: subject) + mail(to: @playback.email, bcc: 'designhops@wearecast.org.uk', subject: subject) end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 0a38fd3..305d11a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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. diff --git a/db/schema.rb b/db/schema.rb index aa0067d..9ec7fe0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/test/factories/comments.rb b/test/factories/comments.rb index 037d369..d2b54c4 100644 --- a/test/factories/comments.rb +++ b/test/factories/comments.rb @@ -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 diff --git a/test/factories/playbacks.rb b/test/factories/playbacks.rb index 32c26d4..2f305f1 100644 --- a/test/factories/playbacks.rb +++ b/test/factories/playbacks.rb @@ -1,5 +1,6 @@ FactoryBot.define do factory :playback do organisation_name { 'ACME' } + email { 'test@wearecast.co.uk' } end end diff --git a/test/mailers/comments_mailer_test.rb b/test/mailers/comments_mailer_test.rb index 9a189ef..9a83fe1 100644 --- a/test/mailers/comments_mailer_test.rb +++ b/test/mailers/comments_mailer_test.rb @@ -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 From 85ef23c35eab989c3121d038661a81c9bdff51c5 Mon Sep 17 00:00:00 2001 From: Ian Edwards Date: Wed, 13 Feb 2019 17:21:47 +0000 Subject: [PATCH 4/6] basic system test for comment mailer --- test/system/comments_test.rb | 33 +++++++++++++++++++++++++++++++++ test/system/webhooks_test.rb | 3 --- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/system/comments_test.rb diff --git a/test/system/comments_test.rb b/test/system/comments_test.rb new file mode 100644 index 0000000..c191920 --- /dev/null +++ b/test/system/comments_test.rb @@ -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 diff --git a/test/system/webhooks_test.rb b/test/system/webhooks_test.rb index 9b8d0a2..cfa4a27 100644 --- a/test/system/webhooks_test.rb +++ b/test/system/webhooks_test.rb @@ -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 = { From f60d960514c874e632ca8d97835c2a20ee3f5787 Mon Sep 17 00:00:00 2001 From: Ian Edwards Date: Thu, 14 Feb 2019 14:16:00 +0000 Subject: [PATCH 5/6] require email for playback and tests --- app/models/playback.rb | 2 +- test/models/playback_test.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/playback.rb b/app/models/playback.rb index 9aa1def..66ef3e4 100644 --- a/app/models/playback.rb +++ b/app/models/playback.rb @@ -5,5 +5,5 @@ 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 end diff --git a/test/models/playback_test.rb b/test/models/playback_test.rb index 445ceec..f546436 100644 --- a/test/models/playback_test.rb +++ b/test/models/playback_test.rb @@ -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 From 3d819650c303a3f31024af38a38581f98ce718d5 Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Fri, 15 Feb 2019 10:56:41 +0000 Subject: [PATCH 6/6] Can filter pending playbacks by source --- app/controllers/playbacks_controller.rb | 4 +++- app/models/playback.rb | 4 ++++ app/views/playbacks/pending.html.erb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/playbacks_controller.rb b/app/controllers/playbacks_controller.rb index c1fa1f5..1a960f6 100644 --- a/app/controllers/playbacks_controller.rb +++ b/app/controllers/playbacks_controller.rb @@ -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 diff --git a/app/models/playback.rb b/app/models/playback.rb index 66ef3e4..ed8040e 100644 --- a/app/models/playback.rb +++ b/app/models/playback.rb @@ -6,4 +6,8 @@ class Playback < ApplicationRecord validates_associated :sections validates :organisation_name, :email, presence: true + + def self.query(col, param) + param.blank? ? all : where(col => param) + end end diff --git a/app/views/playbacks/pending.html.erb b/app/views/playbacks/pending.html.erb index cbaf1d7..bd15802 100644 --- a/app/views/playbacks/pending.html.erb +++ b/app/views/playbacks/pending.html.erb @@ -1,7 +1,7 @@

Pending Playbacks

- +
Organisation Name