Merge remote-tracking branch 'upstream/pull/6452'
[rails.git] / test / controllers / api / notes_controller_test.rb
index f1a0f766c9b23858c4bf9b8d2e646afeb42bb255..d04f3888c22c181343d537d5cf175136521ed5c2 100644 (file)
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require "test_helper"
 
 module Api
@@ -330,8 +332,6 @@ module Api
       assert_equal "commented", js["properties"]["comments"].last["action"]
       assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
       assert_equal third_user.display_name, js["properties"]["comments"].last["user"]
-
-      ActionMailer::Base.deliveries.clear
     end
 
     def test_comment_with_notifications_success
@@ -340,7 +340,7 @@ module Api
       second_user = create(:user)
       third_user = create(:user)
 
-      note_with_comments_by_users = create(:note) do |note|
+      note_with_comments_by_users = create(:note, :author => first_user) do |note|
         create(:note_comment, :note => note, :author => first_user)
         create(:note_comment, :note => note, :author => second_user)
       end
@@ -373,16 +373,8 @@ module Api
       assert_equal third_user, subscription.user
       assert_equal note_with_comments_by_users, subscription.note
 
-      email = ActionMailer::Base.deliveries.find { |e| e.to.first == first_user.email }
-      assert_not_nil email
-      assert_equal 1, email.to.length
-      assert_equal "[OpenStreetMap] #{third_user.display_name} has commented on one of your notes", email.subject
-      assert_equal first_user.email, email.to.first
-
-      email = ActionMailer::Base.deliveries.find { |e| e.to.first == second_user.email }
-      assert_not_nil email
-      assert_equal 1, email.to.length
-      assert_equal "[OpenStreetMap] #{third_user.display_name} has commented on a note you are interested in", email.subject
+      assert_email_received first_user.email, "[OpenStreetMap] #{third_user.display_name} has commented on one of your notes"
+      assert_email_received second_user.email, "[OpenStreetMap] #{third_user.display_name} has commented on a note you are interested in"
 
       get api_note_path(note_with_comments_by_users, :format => "json")
       assert_response :success
@@ -395,8 +387,6 @@ module Api
       assert_equal "commented", js["properties"]["comments"].last["action"]
       assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
       assert_equal third_user.display_name, js["properties"]["comments"].last["user"]
-
-      ActionMailer::Base.deliveries.clear
     end
 
     def test_comment_twice_success