From 0908bfda7ef2462e6b6b61fd8c4654d60f3c3ada Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Tue, 16 Mar 2021 18:31:31 -0400 Subject: [PATCH] refine comment mailer functional tests (#9321) * refine comment mailer functional tests * Update comment_controller_test.rb * adjust order in test "search question at /search/questions/question" do test * Update search_controller_test.rb --- test/functional/comment_controller_test.rb | 37 ++++++++++++++++------ test/functional/search_controller_test.rb | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb index a3511882dd..ab3f150b5c 100644 --- a/test/functional/comment_controller_test.rb +++ b/test/functional/comment_controller_test.rb @@ -290,7 +290,11 @@ def teardown test 'should send mail to moderator if comment has status 4' do UserSession.create(users(:moderator)) - post :create, params: { id: nodes(:one).nid, body: 'example', status: 4 }, xhr: true + perform_enqueued_jobs do + assert_changes 'ActionMailer::Base.deliveries.size' do + post :create, params: { id: nodes(:one).nid, body: 'example', status: 4 }, xhr: true + end + end assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:moderator).email]) end @@ -304,14 +308,22 @@ def teardown test 'should send mail to tag followers in the comment' do UserSession.create(users(:jeff)) - post :create, params: { id: nodes(:question).nid, body: 'Question #awesome', type: 'question' }, xhr: true + perform_enqueued_jobs do + assert_changes 'ActionMailer::Base.deliveries.size' do + post :create, params: { id: nodes(:question).nid, body: 'Question #awesome', type: 'question' }, xhr: true + end + end assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:bob).email]) # tag followers can be found in tag_selection.yml end test 'should send mail to multiple tag followers in the comment' do UserSession.create(users(:jeff)) - post :create, params: { id: nodes(:question).nid, body: 'Question #everything #awesome', type: 'question' }, xhr: true + perform_enqueued_jobs do + assert_changes 'ActionMailer::Base.deliveries.size' do + post :create, params: { id: nodes(:question).nid, body: 'Question #everything #awesome', type: 'question' }, xhr: true + end + end assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:bob).email]) assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:moderator).email]) # tag followers can be found in tag_selection.yml @@ -319,7 +331,11 @@ def teardown test 'should send notification email upon a new wiki comment' do UserSession.create(users(:jeff)) - post :create, params: { id: nodes(:wiki_page).nid, body: 'A comment by Jeff on a wiki page of author bob', type: 'page' }, xhr: true + perform_enqueued_jobs do + assert_difference 'ActionMailer::Base.deliveries.size', 1 do + post :create, params: { id: nodes(:wiki_page).nid, body: 'A comment by Jeff on a wiki page of author bob', type: 'page' }, xhr: true + end + end assert ActionMailer::Base.deliveries.collect(&:subject).include?("New comment on Wiki page title (#11) - #c#{Comment.last.id}") end @@ -368,11 +384,14 @@ def teardown test 'should not send notification email to author if notify-comment-direct:false usertag is present' do UserSession.create(users(:jeff)) - post :create, params: { - id: nodes(:activity).nid, - body: 'A comment by Jeff on note of author test_user' - }, xhr: true - + perform_enqueued_jobs do + assert_difference 'ActionMailer::Base.deliveries.size', 0 do + post :create, params: { + id: nodes(:activity).nid, + body: 'A comment by Jeff on note of author test_user' + }, xhr: true + end + end assert_not ActionMailer::Base.deliveries.collect(&:subject).include?("New comment on #{nodes(:activity).title} (##{nodes(:activity).nid}) ") assert_not ActionMailer::Base.deliveries.collect(&:to).include?([users(:test_user).email]) end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index dc873d7f44..43ac36bbff 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -48,7 +48,7 @@ class SearchControllerTest < ActionController::TestCase test "search question at /search/questions/question" do get :questions, params: { query: 'question' } assert_response :success - assert_equal nodes(:question).nid, assigns(:questions).first.nid + assert assigns(:questions).include?(nodes(:question)) end test "search places page at /search/places/map" do