From 02001527df228402d294f811844907458250b77e Mon Sep 17 00:00:00 2001 From: fandom Date: Sat, 9 May 2026 16:35:21 -0400 Subject: [PATCH 1/8] base comment redirect on referer not param --- app/controllers/comments_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 05b7ce921a..ceede06266 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -436,7 +436,7 @@ def create elsif @comment.unreviewed? redirect_to_all_comments(@commentable) else - redirect_to_comment(@comment, { view_full_work: (params[:view_full_work] == "true"), page: params[:page] }) + redirect_to_comment(@comment, { page: params[:page] }) end end end @@ -733,6 +733,10 @@ def redirect_to_comment(comment, options = {}) def redirect_to_all_comments(commentable, options = {}) default_options = {anchor: "comments"} options = default_options.merge(options) + # If the user is coming from the chapter view (i.e. referrer is /chapters/:id) + # then stay in chapter view. Otherwise, go to user preference + is_coming_from_chapter_view = request.referer&.match(/chapter/).present? + view_full_work = !is_coming_from_chapter_view || current_user.try(:preference).try(:view_full_work) if commentable.is_a?(Tag) redirect_to comments_path(tag_id: commentable.to_param, @@ -741,16 +745,16 @@ def redirect_to_all_comments(commentable, options = {}) page: options[:page], anchor: options[:anchor]) else - if commentable.is_a?(Chapter) && (options[:view_full_work] || current_user.try(:preference).try(:view_full_works)) + if commentable.is_a?(Chapter) && view_full_work commentable = commentable.work end redirect_to polymorphic_path(commentable, options.slice(:show_comments, :add_comment_reply_id, :delete_comment_id, - :view_full_work, :anchor, - :page)) + :page) + .merge({view_full_work:})) end end From 461f4a6ff2b1bd445495be1a39b18a65be56a83a Mon Sep 17 00:00:00 2001 From: fandom Date: Sat, 9 May 2026 22:47:12 -0400 Subject: [PATCH 2/8] clean up redirect logic and consider comments flow --- app/controllers/comments_controller.rb | 18 ++- .../comments_redirect.feature | 6 +- .../comments/comments_controller_spec.rb | 106 ++++++++++++++++-- 3 files changed, 113 insertions(+), 17 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ceede06266..ad74468251 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -733,10 +733,6 @@ def redirect_to_comment(comment, options = {}) def redirect_to_all_comments(commentable, options = {}) default_options = {anchor: "comments"} options = default_options.merge(options) - # If the user is coming from the chapter view (i.e. referrer is /chapters/:id) - # then stay in chapter view. Otherwise, go to user preference - is_coming_from_chapter_view = request.referer&.match(/chapter/).present? - view_full_work = !is_coming_from_chapter_view || current_user.try(:preference).try(:view_full_work) if commentable.is_a?(Tag) redirect_to comments_path(tag_id: commentable.to_param, @@ -745,6 +741,15 @@ def redirect_to_all_comments(commentable, options = {}) page: options[:page], anchor: options[:anchor]) else + is_coming_from_chapter_view = request.referer&.match(/chapters/).present? + is_not_coming_from_work_view = request.referer&.match(/works/).nil? + view_full_work = if is_coming_from_chapter_view + false + elsif is_not_coming_from_work_view + current_user.try(:preference).try(:view_full_works).present? + else + true + end if commentable.is_a?(Chapter) && view_full_work commentable = commentable.work end @@ -754,7 +759,10 @@ def redirect_to_all_comments(commentable, options = {}) :delete_comment_id, :anchor, :page) - .merge({view_full_work:})) + # we don't actually use params[:view_full_work] within + # the comments controller anymore. + # still pass to the redirect since it is referred to elsewhere + .merge({view_full_work: params[:view_full_work]})) end end diff --git a/features/comments_and_kudos/comments_redirect.feature b/features/comments_and_kudos/comments_redirect.feature index ec20253a7f..3e8cc1e508 100644 --- a/features/comments_and_kudos/comments_redirect.feature +++ b/features/comments_and_kudos/comments_redirect.feature @@ -49,8 +49,7 @@ Scenario: Posting top level comment on a chaptered work, with view full work in And I post a comment "Woohoo" Then I should see "Woohoo" And I should see "Chapter 2" within "div#chapters" - # Once you've commented, it defaults back to your preference - And I should see "Chapter 1" within "div#chapters" + And I should not see "Chapter 1" within "div#chapters" # REPLY COMMENTS @@ -115,5 +114,4 @@ Scenario: Posting top level comment on a middle chapter, while in temporary view When I reply to a comment with "Supercalifragelistic" Then I should see "Supercalifragelistic" And I should see "Chapter 2" within "div#chapters" - # Once you've commented, it defaults back to your preference - And I should see "Chapter 1" within "div#chapters" + And I should not see "Chapter 1" within "div#chapters" diff --git a/spec/controllers/comments/comments_controller_spec.rb b/spec/controllers/comments/comments_controller_spec.rb index c6806b40b8..f51d93f511 100644 --- a/spec/controllers/comments/comments_controller_spec.rb +++ b/spec/controllers/comments/comments_controller_spec.rb @@ -79,10 +79,56 @@ end describe "GET #cancel_comment_delete" do - it "redirects to the comment on the commentable without an error" do - get :cancel_comment_delete, params: { id: comment.id } - expect(flash[:error]).to be_nil - expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + context "when cancelling from chapter by chapter view" do + before do + request.env["HTTP_REFERER"] = "/works/1/chapters/1" + end + + it "redirects to the comment on the chapter view without an error" do + get :cancel_comment_delete, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when cancelling from the work view" do + before do + request.env["HTTP_REFERER"] = "/works/1" + end + + it "redirects to the comment on the work view without an error" do + get :cancel_comment_delete, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when cancelling from comments view" do + before do + request.env["HTTP_REFERER"] = "/comments/1" + end + + context "when user set preference to full work view" do + before do + known_user = create(:user) + known_user.preference.update!(view_full_works: true) + fake_login_known_user(known_user) + end + + it "redirects to the comment on the work view without an error" do + get :cancel_comment_delete, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when user set preference to chapter by chapter view" do + it "redirects to the comment on the chapter view without an error" do + get :cancel_comment_delete, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end end end @@ -91,10 +137,54 @@ before { fake_login_known_user(comment.pseud.user) } context "when the format is html" do - it "redirects to the comment on the commentable without an error" do - get :cancel_comment_edit, params: { id: comment.id } - expect(flash[:error]).to be_nil - expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + context "when user is navigating from chapter view" do + before do + request.env["HTTP_REFERER"] = "/works/1/chapters/1" + end + + it "redirects to the comment on the chapter view without an error" do + get :cancel_comment_edit, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when user is navigating from work view" do + before do + request.env["HTTP_REFERER"] = "/works/1" + end + + it "redirects to the comment on the full work view without error" do + get :cancel_comment_edit, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when user is navigating from comment view" do + before do + request.env["HTTP_REFERER"] = "/comments/1" + end + + context "when user preference is full work view" do + before do + comment.pseud.user.preference.update!(view_full_works: true) + end + + it "redirects to the comment on the full work view without error" do + get :cancel_comment_edit, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end + + context "when user preference is not full work view" do + it "redirects to the comment on the chapter view without error" do + get :cancel_comment_edit, params: { id: comment.id } + expect(flash[:error]).to be_nil + expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + end + end end end From d2c09d1395479be4b0cb13396e7009ec11c5d7f8 Mon Sep 17 00:00:00 2001 From: fandom Date: Sat, 9 May 2026 23:02:00 -0400 Subject: [PATCH 3/8] clean up unnecessary use of variables --- app/controllers/comments_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ad74468251..1d09e414b3 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -614,7 +614,6 @@ def show_comments # so we're being extra-nice and preserving any intention to comment along with the show comments option options = {show_comments: true} options[:add_comment_reply_id] = params[:add_comment_reply_id] if params[:add_comment_reply_id] - options[:view_full_work] = params[:view_full_work] if params[:view_full_work] options[:page] = params[:page] redirect_to_all_comments(@commentable, options) end @@ -644,7 +643,6 @@ def add_comment_reply options[:controller] = @commentable.class.to_s.underscore.pluralize options[:anchor] = "comment_#{params[:id]}" options[:page] = params[:page] - options[:view_full_work] = params[:view_full_work] if @thread_view options[:id] = @thread_root options[:add_comment_reply_id] = params[:id] From e82263c548fc0f1dc29fa87238ce9819c32c0838 Mon Sep 17 00:00:00 2001 From: fandom Date: Sat, 9 May 2026 23:44:19 -0400 Subject: [PATCH 4/8] apply rubocop linting --- app/controllers/comments_controller.rb | 58 +++++++++++++------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1d09e414b3..831acbeb82 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -436,7 +436,7 @@ def create elsif @comment.unreviewed? redirect_to_all_comments(@commentable) else - redirect_to_comment(@comment, { page: params[:page] }) + redirect_to_comment(@comment, { page: params[:page] }) end end end @@ -704,40 +704,40 @@ def cancel_comment_delete # if necessary to display it def redirect_to_comment(comment, options = {}) if comment.depth > ArchiveConfig.COMMENT_THREAD_MAX_DEPTH - if comment.ultimate_parent.is_a?(Tag) - default_options = { - controller: :comments, - action: :show, - id: comment.commentable.id, - tag_id: comment.ultimate_parent.to_param, - anchor: "comment_#{comment.id}" - } - else - default_options = { - controller: comment.commentable.class.to_s.underscore.pluralize, - action: :show, - id: (comment.commentable.is_a?(Tag) ? comment.commentable.to_param : comment.commentable.id), - anchor: "comment_#{comment.id}" - } - end + default_options = if comment.ultimate_parent.is_a?(Tag) + { + controller: :comments, + action: :show, + id: comment.commentable.id, + tag_id: comment.ultimate_parent.to_param, + anchor: "comment_#{comment.id}" + } + else + { + controller: comment.commentable.class.to_s.underscore.pluralize, + action: :show, + id: (comment.commentable.is_a?(Tag) ? comment.commentable.to_param : comment.commentable.id), + anchor: "comment_#{comment.id}" + } + end # display the comment's direct parent (and its associated thread) redirect_to(url_for(default_options.merge(options))) else # need to redirect to the specific chapter; redirect_to_all will then retrieve full work view if applicable - redirect_to_all_comments(comment.parent, options.merge({show_comments: true, anchor: "comment_#{comment.id}"})) + redirect_to_all_comments(comment.parent, options.merge({ show_comments: true, anchor: "comment_#{comment.id}" })) end end def redirect_to_all_comments(commentable, options = {}) - default_options = {anchor: "comments"} + default_options = { anchor: "comments" } options = default_options.merge(options) if commentable.is_a?(Tag) redirect_to comments_path(tag_id: commentable.to_param, - add_comment_reply_id: options[:add_comment_reply_id], - delete_comment_id: options[:delete_comment_id], - page: options[:page], - anchor: options[:anchor]) + add_comment_reply_id: options[:add_comment_reply_id], + delete_comment_id: options[:delete_comment_id], + page: options[:page], + anchor: options[:anchor]) else is_coming_from_chapter_view = request.referer&.match(/chapters/).present? is_not_coming_from_work_view = request.referer&.match(/works/).nil? @@ -748,19 +748,17 @@ def redirect_to_all_comments(commentable, options = {}) else true end - if commentable.is_a?(Chapter) && view_full_work - commentable = commentable.work - end + commentable = commentable.work if commentable.is_a?(Chapter) && view_full_work redirect_to polymorphic_path(commentable, options.slice(:show_comments, :add_comment_reply_id, :delete_comment_id, :anchor, :page) - # we don't actually use params[:view_full_work] within - # the comments controller anymore. - # still pass to the redirect since it is referred to elsewhere - .merge({view_full_work: params[:view_full_work]})) + # we don't actually use params[:view_full_work] within + # the comments controller anymore. + # still pass to the redirect since it is referred to elsewhere + .merge({ view_full_work: params[:view_full_work] })) end end From 04c1e40c444b9a8be61c525db09351b02a310d87 Mon Sep 17 00:00:00 2001 From: fandom Date: Sun, 10 May 2026 18:41:05 -0400 Subject: [PATCH 5/8] follow view full work param when origin is not clear --- app/controllers/comments_controller.rb | 35 ++++-- .../comments/comments_controller_spec.rb | 6 +- .../comments/default_rails_actions_spec.rb | 106 +++++++++++++++++- 3 files changed, 130 insertions(+), 17 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 831acbeb82..fced669a9a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -93,8 +93,10 @@ def rate_limited def check_pseud_ownership return unless params[:comment][:pseud_id] + pseud = Pseud.find(params[:comment][:pseud_id]) return if pseud && current_user && current_user.pseuds.include?(pseud) + flash[:error] = ts("You can't comment with that pseud.") redirect_to root_path end @@ -218,14 +220,17 @@ def check_not_replying_to_spam def check_permission_to_review parent = find_parent return if logged_in_as_admin? || current_user_owns?(parent) + flash[:error] = ts("Sorry, you don't have permission to see those unreviewed comments.") redirect_to logged_in? ? root_path : new_user_session_path(return_to: request.fullpath) end def check_permission_to_access_single_unreviewed return unless @comment.unreviewed? + parent = find_parent return if logged_in_as_admin? || current_user_owns?(parent) || current_user_owns?(@comment) + flash[:error] = ts("Sorry, that comment is currently in moderation.") redirect_to logged_in? ? root_path : new_user_session_path(return_to: request.fullpath) end @@ -337,7 +342,7 @@ def set_page_subtitle def index return raise_not_found if @commentable.blank? - return unless @commentable.class == Comment + return unless @commentable.instance_of?(Comment) # we link to the parent object at the top @commentable = @commentable.ultimate_parent @@ -436,7 +441,7 @@ def create elsif @comment.unreviewed? redirect_to_all_comments(@commentable) else - redirect_to_comment(@comment, { page: params[:page] }) + redirect_to_comment(@comment, { view_full_work: (params[:view_full_work] && params[:view_full_work] == "true"), page: params[:page] }) end end end @@ -452,10 +457,11 @@ def create def update updated_comment_params = comment_params.merge(edited_at: Time.current) if @comment.update(updated_comment_params) - flash[:comment_notice] = ts('Comment was successfully updated.') + flash[:comment_notice] = ts("Comment was successfully updated.") respond_to do |format| format.html do redirect_to comment_path(@comment) and return if @comment.unreviewed? + redirect_to_comment(@comment) end format.js # updating the comment in place @@ -487,7 +493,7 @@ def destroy redirect_to_comment(parent_comment) else flash[:comment_notice] = ts("Comment deleted.") - redirect_to_all_comments(parent, {show_comments: true}) + redirect_to_all_comments(parent, { show_comments: true }) end end @@ -612,9 +618,10 @@ def show_comments format.html do # if non-ajax it could mean sudden javascript failure OR being redirected from login # so we're being extra-nice and preserving any intention to comment along with the show comments option - options = {show_comments: true} + options = { show_comments: true } options[:add_comment_reply_id] = params[:add_comment_reply_id] if params[:add_comment_reply_id] options[:page] = params[:page] + options[:view_full_work] = params[:view_full_work] if params[:view_full_work] redirect_to_all_comments(@commentable, options) end @@ -639,10 +646,11 @@ def add_comment_reply @comment = Comment.new respond_to do |format| format.html do - options = {show_comments: true} + options = { show_comments: true } options[:controller] = @commentable.class.to_s.underscore.pluralize options[:anchor] = "comment_#{params[:id]}" options[:page] = params[:page] + options[:view_full_work] = params[:view_full_work] if params[:view_full_work] if @thread_view options[:id] = @thread_root options[:add_comment_reply_id] = params[:id] @@ -744,7 +752,13 @@ def redirect_to_all_comments(commentable, options = {}) view_full_work = if is_coming_from_chapter_view false elsif is_not_coming_from_work_view - current_user.try(:preference).try(:view_full_works).present? + if params[:view_full_work] == "true" + true + elsif params[:view_full_work] == "false" + false + else + current_user.try(:preference).try(:view_full_works).present? + end else true end @@ -753,12 +767,9 @@ def redirect_to_all_comments(commentable, options = {}) options.slice(:show_comments, :add_comment_reply_id, :delete_comment_id, + :view_full_work, :anchor, - :page) - # we don't actually use params[:view_full_work] within - # the comments controller anymore. - # still pass to the redirect since it is referred to elsewhere - .merge({ view_full_work: params[:view_full_work] })) + :page)) end end diff --git a/spec/controllers/comments/comments_controller_spec.rb b/spec/controllers/comments/comments_controller_spec.rb index f51d93f511..0e0d3145d9 100644 --- a/spec/controllers/comments/comments_controller_spec.rb +++ b/spec/controllers/comments/comments_controller_spec.rb @@ -388,7 +388,8 @@ delete :destroy, params: { id: comment.id } expect(flash[:comment_notice]).to eq "Comment deleted." it_redirects_to_simple(work_path(work, show_comments: true, anchor: :comments)) - expect { comment.reload }.to raise_exception(ActiveRecord::RecordNotFound) + expect { comment.reload } + .to raise_exception(ActiveRecord::RecordNotFound) end it "GET #add_comment_reply redirects to the work with an error" do @@ -472,7 +473,8 @@ delete :destroy, params: { id: comment.id } expect(flash[:comment_notice]).to eq "Comment deleted." it_redirects_to_simple(work_path(work, show_comments: true, anchor: :comments)) - expect { comment.reload }.to raise_exception(ActiveRecord::RecordNotFound) + expect { comment.reload } + .to raise_exception(ActiveRecord::RecordNotFound) end end end diff --git a/spec/controllers/comments/default_rails_actions_spec.rb b/spec/controllers/comments/default_rails_actions_spec.rb index 35d57d398c..2b36e0ef26 100644 --- a/spec/controllers/comments/default_rails_actions_spec.rb +++ b/spec/controllers/comments/default_rails_actions_spec.rb @@ -325,6 +325,106 @@ end end + context "when work is not restricted for a logged in user" do + let(:work) { create(:work) } + let(:user) { create(:user) } + let(:comment_attributes) do + { + pseud_id: user.default_pseud_id, + comment_content: "Hello fellow human!" + } + end + before { fake_login_known_user(user) } + + context "when user is commenting from a work view" do + before do + request.env["HTTP_REFERER"] = "/works/1" + end + + it "redirects to the work view" do + post :create, params: { work_id: work.id, comment: comment_attributes } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + work_path(work.id, show_comments: true, anchor: "comment_#{created_comment.id}"), + "Comment created!" + ) + end + end + + context "when user is commenting from a chapter view" do + before do + request.env["HTTP_REFERER"] = "/works/1/chapters/2" + end + + it "redirects to the chapter view" do + post :create, params: { work_id: work.id, comment: comment_attributes } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + chapter_path(commentable_chapter.id, show_comments: true, anchor: "comment_#{created_comment.id}"), + "Comment created!" + ) + end + end + + context "when user is commenting from neither a work view nor chapter view" do + context "when param view_full_work == true" do + it "redirects to the work view" do + post :create, params: { work_id: work.id, comment: comment_attributes, view_full_work: true } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + work_path(work.id, show_comments: true, anchor: "comment_#{created_comment.id}", view_full_work: true), + "Comment created!" + ) + end + end + + context "when param view_full_work == false" do + it "redirects to the chapter view" do + post :create, params: { work_id: work.id, comment: comment_attributes, view_full_work: false } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + chapter_path(commentable_chapter.id, show_comments: true, anchor: "comment_#{created_comment.id}", view_full_work: false), + "Comment created!" + ) + end + end + + context "when param view_full_work is nil" do + context "when user preference is set to view full work" do + before do + user.preference.update!(view_full_works: true) + end + + it "redirects to the full work view" do + post :create, params: { work_id: work.id, comment: comment_attributes } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + work_path(work.id, show_comments: true, anchor: "comment_#{created_comment.id}"), + "Comment created!" + ) + end + end + + context "when user preference is not set to view full work" do + it "redirects to the chapter view" do + post :create, params: { work_id: work.id, comment: comment_attributes } + commentable_chapter = work.chapters.last + created_comment = user.comments.where(commentable: commentable_chapter).last + it_redirects_to_with_comment_notice( + chapter_path(commentable_chapter.id, show_comments: true, anchor: "comment_#{created_comment.id}"), + "Comment created!" + ) + end + end + end + end + end + context "when the work has all comments disabled" do let(:work) { create(:work, comment_permissions: :disable_all) } @@ -520,7 +620,7 @@ post :create, params: { work_id: work.id, comment: comment_attributes } comment = Comment.last expect(flash[:error]).to be_nil - expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, view_full_work: false, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) end end end @@ -638,7 +738,7 @@ fake_login_known_user(user) post :create, params: { work_id: work.id, comment: comment_attributes } comment = assigns[:comment] - it_redirects_to_with_comment_notice(chapter_path(comment.commentable, show_comments: true, view_full_work: false, anchor: "comment_#{comment.id}"), "Comment created!") + it_redirects_to_with_comment_notice(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}"), "Comment created!") expect(comment.user_agent.length).to eq(500) end end @@ -656,7 +756,7 @@ fake_login_known_user(user) post :create, params: { work_id: work.id, comment: comment_attributes } comment = assigns[:comment] - it_redirects_to_with_comment_notice(chapter_path(comment.commentable, show_comments: true, view_full_work: false, anchor: "comment_#{comment.id}"), "Comment created!") + it_redirects_to_with_comment_notice(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}"), "Comment created!") expect(comment.user_agent).to be_nil end end From c23709497bb7952021309c2546df3f65ce1b57e8 Mon Sep 17 00:00:00 2001 From: fandom Date: Sun, 10 May 2026 18:56:19 -0400 Subject: [PATCH 6/8] apply rubocop for changed row --- app/controllers/comments_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fced669a9a..63f18fd842 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -752,9 +752,10 @@ def redirect_to_all_comments(commentable, options = {}) view_full_work = if is_coming_from_chapter_view false elsif is_not_coming_from_work_view - if params[:view_full_work] == "true" + case params[:view_full_work] + when "true" true - elsif params[:view_full_work] == "false" + when "false" false else current_user.try(:preference).try(:view_full_works).present? From 100bc19f5cef27ab3379b230c4f9477546c37a28 Mon Sep 17 00:00:00 2001 From: fandom Date: Sun, 10 May 2026 18:57:26 -0400 Subject: [PATCH 7/8] remove change in line so I don't trigger rubocop i18n --- app/controllers/comments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 63f18fd842..48b7bdadc2 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -457,7 +457,7 @@ def create def update updated_comment_params = comment_params.merge(edited_at: Time.current) if @comment.update(updated_comment_params) - flash[:comment_notice] = ts("Comment was successfully updated.") + flash[:comment_notice] = ts('Comment was successfully updated.') respond_to do |format| format.html do redirect_to comment_path(@comment) and return if @comment.unreviewed? From 90d41a9017b7599297cd549d705576c71dcb615a Mon Sep 17 00:00:00 2001 From: fandom Date: Sun, 10 May 2026 19:47:21 -0400 Subject: [PATCH 8/8] work path should go to work not chapter --- spec/controllers/comments/comments_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/controllers/comments/comments_controller_spec.rb b/spec/controllers/comments/comments_controller_spec.rb index 0e0d3145d9..4c68059be5 100644 --- a/spec/controllers/comments/comments_controller_spec.rb +++ b/spec/controllers/comments/comments_controller_spec.rb @@ -99,7 +99,7 @@ it "redirects to the comment on the work view without an error" do get :cancel_comment_delete, params: { id: comment.id } expect(flash[:error]).to be_nil - expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(work_path(comment.commentable.work, show_comments: true, anchor: "comment_#{comment.id}")) end end @@ -118,7 +118,7 @@ it "redirects to the comment on the work view without an error" do get :cancel_comment_delete, params: { id: comment.id } expect(flash[:error]).to be_nil - expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(work_path(comment.commentable.work, show_comments: true, anchor: "comment_#{comment.id}")) end end @@ -157,7 +157,7 @@ it "redirects to the comment on the full work view without error" do get :cancel_comment_edit, params: { id: comment.id } expect(flash[:error]).to be_nil - expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(work_path(comment.commentable.work, show_comments: true, anchor: "comment_#{comment.id}")) end end @@ -174,7 +174,7 @@ it "redirects to the comment on the full work view without error" do get :cancel_comment_edit, params: { id: comment.id } expect(flash[:error]).to be_nil - expect(response).to redirect_to(work_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(work_path(comment.commentable.work, show_comments: true, anchor: "comment_#{comment.id}")) end end