From 5e3cda345a144014148db5e3543f99ae9bd08b5e Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 7 Aug 2024 04:59:09 +0300 Subject: [PATCH] Redirect to newly created diary comment --- app/controllers/diary_comments_controller.rb | 2 +- test/controllers/diary_comments_controller_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/diary_comments_controller.rb b/app/controllers/diary_comments_controller.rb index a9a7a2641..35dbbb559 100644 --- a/app/controllers/diary_comments_controller.rb +++ b/app/controllers/diary_comments_controller.rb @@ -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 diff --git a/test/controllers/diary_comments_controller_test.rb b/test/controllers/diary_comments_controller_test.rb index fa978d606..a06565aa1 100644 --- a/test/controllers/diary_comments_controller_test.rb +++ b/test/controllers/diary_comments_controller_test.rb @@ -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 -- 2.39.5