Skip to content

Commit

Permalink
refine comment mailer functional tests (#9321)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jywarren authored Mar 16, 2021
1 parent c9349ca commit 0908bfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions test/functional/comment_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -304,22 +308,34 @@ 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
end

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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0908bfd

Please sign in to comment.