]> git.openstreetmap.org Git - rails.git/commitdiff
Redirect to newly created diary comment
authorAnton Khorev <tony29@yandex.ru>
Wed, 7 Aug 2024 01:59:09 +0000 (04:59 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 7 Aug 2024 01:59:09 +0000 (04:59 +0300)
app/controllers/diary_comments_controller.rb
test/controllers/diary_comments_controller_test.rb

index a9a7a2641b902bcef70038d186b59eab5b1846d3..35dbbb559cce41b03491eda4258404fda9a6cd47 100644 (file)
@@ -41,7 +41,7 @@ class DiaryCommentsController < ApplicationController
       # Add the commenter to the subscribers if necessary
       @entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
 
-      redirect_to diary_entry_path(@entry.user, @entry)
+      redirect_to diary_entry_path(@entry.user, @entry, :anchor => "comment#{@diary_comment.id}")
     else
       render :action => "new"
     end
index fa978d606baa57ee9871eb1251fbb4f15cd99f44..a06565aa1ca2740a6696aeffe5413062a853297f 100644 (file)
@@ -115,14 +115,14 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
         end
       end
     end
-    assert_redirected_to diary_entry_path(entry.user, entry)
+    comment = DiaryComment.last
+    assert_redirected_to diary_entry_path(entry.user, entry, :anchor => "comment#{comment.id}")
     email = ActionMailer::Base.deliveries.first
     assert_equal [user.email], email.to
     assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
     assert_match(/New comment/, email.text_part.decoded)
     assert_match(/New comment/, email.html_part.decoded)
     ActionMailer::Base.deliveries.clear
-    comment = DiaryComment.order(:id).last
     assert_equal entry.id, comment.diary_entry_id
     assert_equal other_user.id, comment.user_id
     assert_equal "New comment", comment.body
@@ -157,14 +157,14 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
         end
       end
     end
-    assert_redirected_to diary_entry_path(entry.user, entry)
+    comment = DiaryComment.last
+    assert_redirected_to diary_entry_path(entry.user, entry, :anchor => "comment#{comment.id}")
     email = ActionMailer::Base.deliveries.first
     assert_equal [user.email], email.to
     assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
     assert_match %r{http://example.com/spam}, email.text_part.decoded
     assert_match %r{http://example.com/spam}, email.html_part.decoded
     ActionMailer::Base.deliveries.clear
-    comment = DiaryComment.order(:id).last
     assert_equal entry.id, comment.diary_entry_id
     assert_equal other_user.id, comment.user_id
     assert_equal spammy_text, comment.body