From 2c09c37d2c2fd0745a6d2ebd419fc185dae102e9 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 18:39:21 +0100 Subject: [PATCH 01/17] AO3-6503 Add guest comment off option --- app/controllers/comments_controller.rb | 9 +++++++ app/policies/admin_setting_policy.rb | 1 + app/views/admin/settings/index.html.erb | 3 +++ app/views/comments/_commentable.html.erb | 6 ++++- config/locales/views/en.yml | 2 ++ ...add_guest_comment_off_to_admin_settings.rb | 5 ++++ db/schema.rb | 1 + db/structure.sql | 1 + features/admins/admin_settings.feature | 17 +++++++++++++ features/step_definitions/admin_steps.rb | 14 +++++++++++ .../admin/settings_controller_spec.rb | 5 +++- spec/models/comment_spec.rb | 24 +++++++++++++++++++ test/fixtures/admin_settings.yml | 1 + 13 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230408145819_add_guest_comment_off_to_admin_settings.rb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1492d974df7..65a03712842 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -19,6 +19,7 @@ class CommentsController < ApplicationController before_action :check_permission_to_edit, only: [:edit, :update ] before_action :check_permission_to_delete, only: [:delete_comment, :destroy] before_action :check_parent_comment_permissions, only: [:new, :create, :add_comment_reply] + before_action :check_guest_comment_permissions, only: [:new, :create, :add_comment_reply] before_action :check_unreviewed, only: [:add_comment_reply] before_action :check_frozen, only: [:new, :create, :add_comment_reply] before_action :check_hidden_by_admin, only: [:new, :create, :add_comment_reply] @@ -130,6 +131,14 @@ def check_parent_comment_permissions end end + def check_guest_comment_permissions + admin_settings = AdminSetting.current + if admin_settings.guest_comments_off? && !logged_in? + flash[:error] = t("comments.commentable.guest_comments_disabled") + redirect_back(fallback_location: root_path) + end + end + def check_unreviewed return unless @commentable.respond_to?(:unreviewed?) && @commentable.unreviewed? diff --git a/app/policies/admin_setting_policy.rb b/app/policies/admin_setting_policy.rb index 7be90806217..30c206c2831 100644 --- a/app/policies/admin_setting_policy.rb +++ b/app/policies/admin_setting_policy.rb @@ -19,6 +19,7 @@ class AdminSettingPolicy < ApplicationPolicy downloads_enabled enable_test_caching hide_spam + guest_comments_off invite_from_queue_enabled invite_from_queue_frequency invite_from_queue_number diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 15d6321a062..c4538e5d438 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -67,6 +67,9 @@
<%= admin_setting_checkbox(f, :hide_spam) %>
<%= f.label :hide_spam, t(".fields.hide_spam") %>
+ +
<%= admin_setting_checkbox(f, :guest_comments_off) %>
+
<%= f.label :guest_comments_off, t(".fields.guest_comments_off") %>
diff --git a/app/views/comments/_commentable.html.erb b/app/views/comments/_commentable.html.erb index 9c5df2df134..0eb5bdc9ebe 100644 --- a/app/views/comments/_commentable.html.erb +++ b/app/views/comments/_commentable.html.erb @@ -75,7 +75,11 @@ <%= flash_div :comment_error, :comment_notice %> <% commentable_parent = find_parent(commentable) %> - <% if commentable_parent.is_a?(AdminPost) && commentable_parent.disable_all_comments? %> + <% if @admin_settings.guest_comments_off? && !logged_in? %> +

+ <%= t(".guest_comments_disabled") %> +

+ <% elsif commentable_parent.is_a?(AdminPost) && commentable_parent.disable_all_comments? %>

<%= t(".permissions.admin_post.disable_all") %>

diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 9a4c3d4facb..b6fd0e854da 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -92,6 +92,7 @@ en: downloads_enabled: "Allow downloads" enable_test_caching: "Turn on caching (currently experimental)" hide_spam: "Automatically hide spam works" + guest_comments_off: "Turn off guest comments across the site" invite_from_queue_enabled: "Invite from queue enabled (People can add themselves to the queue and invitations are sent out automatically)" invite_from_queue_frequency: "How often (in days) should we invite people from the queue" invite_from_queue_number: "Number of people to invite from the queue at once" @@ -163,6 +164,7 @@ en: hidden: "Sorry, you can't add or edit comments on a hidden work." unrevealed: "Sorry, you can't add or edit comments on an unrevealed work." blocked: "Sorry, you have been blocked by one or more of this work's creators." + guest_comments_disabled: "Sorry, the Archive doesn't allow guests to comment right now." invite_to_collections_link: "Invite To Collections" layouts: proxy_notice: diff --git a/db/migrate/20230408145819_add_guest_comment_off_to_admin_settings.rb b/db/migrate/20230408145819_add_guest_comment_off_to_admin_settings.rb new file mode 100644 index 00000000000..8211b4c5cfe --- /dev/null +++ b/db/migrate/20230408145819_add_guest_comment_off_to_admin_settings.rb @@ -0,0 +1,5 @@ +class AddGuestCommentOffToAdminSettings < ActiveRecord::Migration[6.1] + def change + add_column :admin_settings, :guest_comments_off, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 93293954335..e43cd7a4764 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -100,6 +100,7 @@ t.boolean "creation_requires_invite", default: false, null: false t.boolean "downloads_enabled", default: true t.boolean "hide_spam", default: false, null: false + t.boolean "guest_comments_off", default: false, null: false t.boolean "disable_support_form", default: false, null: false t.text "disabled_support_form_text" t.integer "disabled_support_form_text_sanitizer_version", limit: 2, default: 0, null: false diff --git a/db/structure.sql b/db/structure.sql index c5f17edadb7..1a96f25fffa 100755 --- a/db/structure.sql +++ b/db/structure.sql @@ -147,6 +147,7 @@ CREATE TABLE `admin_settings` ( `creation_requires_invite` tinyint(1) NOT NULL DEFAULT '0', `downloads_enabled` tinyint(1) DEFAULT '1', `hide_spam` tinyint(1) NOT NULL DEFAULT '0', + `guest_comments_off` tinyint(1) NOT NULL DEFAULT '0', `disable_support_form` tinyint(1) NOT NULL DEFAULT '0', `disabled_support_form_text` text COLLATE utf8mb4_unicode_ci, `disabled_support_form_text_sanitizer_version` smallint(6) NOT NULL DEFAULT '0', diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 43048267711..9cdbfe8fcb0 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -36,3 +36,20 @@ Feature: Admin Settings Page When I am logged in as a random user And I go to the support page Then I should see "We can answer Support inquiries in" + + Scenario: Turn on guest comments + Given guest comments are on + And I am logged out + And the work "Generic Work" + And I view the work "Generic Work" + When I fill in "Comment" with "Guest comment" + And I fill in "Email" with "guest@example.com" + And I press "Comment" + Then I should see "Comment created!" + + Scenario: Turn off guest comments + Given guest comments are off + And I am logged out + And the work "Generic Work" + When I view the work "Generic Work" + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." \ No newline at end of file diff --git a/features/step_definitions/admin_steps.rb b/features/step_definitions/admin_steps.rb index 4b68ff19a2e..57a325009f4 100644 --- a/features/step_definitions/admin_steps.rb +++ b/features/step_definitions/admin_steps.rb @@ -88,6 +88,20 @@ click_button("Update") end +Given /^guest comments are on$/ do + step("I am logged in as a super admin") + visit(admin_settings_path) + uncheck("Turn off guest comments across the site") + click_button("Update") +end + +Given /^guest comments are off$/ do + step("I am logged in as a super admin") + visit(admin_settings_path) + check("Turn off guest comments across the site") + click_button("Update") +end + Given /^I have posted known issues$/ do step %{I am logged in as an admin} step %{I follow "Admin Posts"} diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index af00748b8b7..148b9e13dba 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -64,7 +64,8 @@ downloads_enabled: "1", enable_test_caching: "0", cache_expiration: "10", - hide_spam: "1" + hide_spam: "1", + guest_comments_off: "1" } } @@ -107,6 +108,7 @@ { downloads_enabled: false, hide_spam: true, + guest_comments_off: true tag_wrangling_off: true }.each_pair do |field, value| it "prevents admins with support role from updating #{field}" do @@ -138,6 +140,7 @@ disable_support_form: true, downloads_enabled: false, hide_spam: true + guest_comments_off: true }.each_pair do |field, value| it "prevents admins with tag_wrangling role from updating #{field}" do expect do diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 24e6a2d3247..4fa5853849f 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -230,6 +230,30 @@ expect(LastWranglingActivity.all).to be_empty end end + + context "guest comments are turned on" do + before do + @admin_setting = AdminSetting.first || AdminSetting.create + create(:comment, :by_guest) + end + + it "allows guest comments" do + expect(comment.save).to be_truthy + expect(comment.errors.full_messages).to be_blank + end + end + + context "guest comments are turned off" do + before do + @admin_setting = AdminSetting.first || AdminSetting.create + @admin_setting.update_attribute(:guest_comments_off, true) + create(:comment, :by_guest) + end + + it "does not allow guest comments" do + expect(comment.errors.full_messages).to include('Sorry, this work doesn\'t allow non-Archive users to comment. You can however still leave Kudos!') + end + end end end diff --git a/test/fixtures/admin_settings.yml b/test/fixtures/admin_settings.yml index 1da015a83c6..5379d6346d2 100644 --- a/test/fixtures/admin_settings.yml +++ b/test/fixtures/admin_settings.yml @@ -19,3 +19,4 @@ admin_setting_3: creation_requires_invite: false downloads_enabled: true hide_spam: false + guest_comments_off: false From ecd495e3dcaac285177333571dce413f7ecaa126 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 20:51:34 +0100 Subject: [PATCH 02/17] AO3-6503 Fix tests --- features/admins/admin_settings.feature | 3 +-- spec/controllers/comments_controller_spec.rb | 26 ++++++++++++++++++++ spec/models/comment_spec.rb | 24 ------------------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 9cdbfe8fcb0..1f1990f34d3 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -43,8 +43,7 @@ Feature: Admin Settings Page And the work "Generic Work" And I view the work "Generic Work" When I fill in "Comment" with "Guest comment" - And I fill in "Email" with "guest@example.com" - And I press "Comment" + And I post a guest comment Then I should see "Comment created!" Scenario: Turn off guest comments diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 411c5e730cc..3ea1a77db0d 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -446,6 +446,32 @@ end end end + + context "guest comments are turned on in admin settings" do + let(:work) { create(:work) } + + it "allows guest comments" do + post :create, params: { work_id: work.id, comment: anon_comment_attributes } + + expect(flash[:error]).to be_nil + end + end + + context "guest comments are turned off in admin settings" do + before do + @admin_setting = AdminSetting.first || AdminSetting.create + @admin_setting.update_attribute(:guest_comments_off, true) + end + + let(:work) { create(:work) } + + it "does not allow guest comments" do + post :create, params: { work_id: work.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + end end describe "PUT #review_all" do diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 4fa5853849f..24e6a2d3247 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -230,30 +230,6 @@ expect(LastWranglingActivity.all).to be_empty end end - - context "guest comments are turned on" do - before do - @admin_setting = AdminSetting.first || AdminSetting.create - create(:comment, :by_guest) - end - - it "allows guest comments" do - expect(comment.save).to be_truthy - expect(comment.errors.full_messages).to be_blank - end - end - - context "guest comments are turned off" do - before do - @admin_setting = AdminSetting.first || AdminSetting.create - @admin_setting.update_attribute(:guest_comments_off, true) - create(:comment, :by_guest) - end - - it "does not allow guest comments" do - expect(comment.errors.full_messages).to include('Sorry, this work doesn\'t allow non-Archive users to comment. You can however still leave Kudos!') - end - end end end From 455965b9a3897d2fe4ce70358e3336bd8934bb07 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 20:59:40 +0100 Subject: [PATCH 03/17] AO3-6503 Pleasing the hound --- app/controllers/comments_controller.rb | 9 +++++---- spec/controllers/admin/settings_controller_spec.rb | 2 +- spec/controllers/comments_controller_spec.rb | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 65a03712842..7cbd479a4ea 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -133,10 +133,11 @@ def check_parent_comment_permissions def check_guest_comment_permissions admin_settings = AdminSetting.current - if admin_settings.guest_comments_off? && !logged_in? - flash[:error] = t("comments.commentable.guest_comments_disabled") - redirect_back(fallback_location: root_path) - end + + return unless admin_settings.guest_comments_off? && !logged_in? + + flash[:error] = t("comments.commentable.guest_comments_disabled") + redirect_back(fallback_location: root_path) end def check_unreviewed diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index 148b9e13dba..aba8358af85 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -139,7 +139,7 @@ { disable_support_form: true, downloads_enabled: false, - hide_spam: true + hide_spam: true, guest_comments_off: true }.each_pair do |field, value| it "prevents admins with tag_wrangling role from updating #{field}" do diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 3ea1a77db0d..8dd6088f193 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -458,18 +458,18 @@ end context "guest comments are turned off in admin settings" do + let(:work) { create(:work) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + before do - @admin_setting = AdminSetting.first || AdminSetting.create - @admin_setting.update_attribute(:guest_comments_off, true) + admin_setting.update_attribute(:guest_comments_off, true) end - let(:work) { create(:work) } - it "does not allow guest comments" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") end end end From f18706b0c0244e639da7c2c2692a4679abee67bb Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 21:01:55 +0100 Subject: [PATCH 04/17] AO3-6503 Fix tests --- db/schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index e43cd7a4764..569c4a93761 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -99,7 +99,6 @@ t.boolean "request_invite_enabled", default: false, null: false t.boolean "creation_requires_invite", default: false, null: false t.boolean "downloads_enabled", default: true - t.boolean "hide_spam", default: false, null: false t.boolean "guest_comments_off", default: false, null: false t.boolean "disable_support_form", default: false, null: false t.text "disabled_support_form_text" From 9b825429f88e369f099131fcc732f7901d5e19b8 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 21:04:42 +0100 Subject: [PATCH 05/17] AO3-6503 Fix tests 2 --- db/structure.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/structure.sql b/db/structure.sql index 1a96f25fffa..715b2f19f84 100755 --- a/db/structure.sql +++ b/db/structure.sql @@ -146,7 +146,6 @@ CREATE TABLE `admin_settings` ( `request_invite_enabled` tinyint(1) NOT NULL DEFAULT '0', `creation_requires_invite` tinyint(1) NOT NULL DEFAULT '0', `downloads_enabled` tinyint(1) DEFAULT '1', - `hide_spam` tinyint(1) NOT NULL DEFAULT '0', `guest_comments_off` tinyint(1) NOT NULL DEFAULT '0', `disable_support_form` tinyint(1) NOT NULL DEFAULT '0', `disabled_support_form_text` text COLLATE utf8mb4_unicode_ci, From ebfb1d00f6bc3e86a294e45dedfac41e1e1b647e Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 21:08:47 +0100 Subject: [PATCH 06/17] AO3-6503 Fix tests 3 --- db/schema.rb | 2 +- db/structure.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 569c4a93761..93293954335 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -99,7 +99,7 @@ t.boolean "request_invite_enabled", default: false, null: false t.boolean "creation_requires_invite", default: false, null: false t.boolean "downloads_enabled", default: true - t.boolean "guest_comments_off", default: false, null: false + t.boolean "hide_spam", default: false, null: false t.boolean "disable_support_form", default: false, null: false t.text "disabled_support_form_text" t.integer "disabled_support_form_text_sanitizer_version", limit: 2, default: 0, null: false diff --git a/db/structure.sql b/db/structure.sql index 715b2f19f84..c5f17edadb7 100755 --- a/db/structure.sql +++ b/db/structure.sql @@ -146,7 +146,7 @@ CREATE TABLE `admin_settings` ( `request_invite_enabled` tinyint(1) NOT NULL DEFAULT '0', `creation_requires_invite` tinyint(1) NOT NULL DEFAULT '0', `downloads_enabled` tinyint(1) DEFAULT '1', - `guest_comments_off` tinyint(1) NOT NULL DEFAULT '0', + `hide_spam` tinyint(1) NOT NULL DEFAULT '0', `disable_support_form` tinyint(1) NOT NULL DEFAULT '0', `disabled_support_form_text` text COLLATE utf8mb4_unicode_ci, `disabled_support_form_text_sanitizer_version` smallint(6) NOT NULL DEFAULT '0', From 59c13acac76dc9df567ed6e81cdf946d0ac3e00d Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 21:29:38 +0100 Subject: [PATCH 07/17] AO3-6503 Fix typo --- features/admins/admin_settings.feature | 3 ++- spec/controllers/admin/settings_controller_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 1f1990f34d3..ce520fb2c0a 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -51,4 +51,5 @@ Feature: Admin Settings Page And I am logged out And the work "Generic Work" When I view the work "Generic Work" - Then I should see "Sorry, the Archive doesn't allow guests to comment right now." \ No newline at end of file + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + \ No newline at end of file diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index aba8358af85..79e64cbf289 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -108,7 +108,7 @@ { downloads_enabled: false, hide_spam: true, - guest_comments_off: true + guest_comments_off: true, tag_wrangling_off: true }.each_pair do |field, value| it "prevents admins with support role from updating #{field}" do From 5dfb1e0c61c8281872325dff3cc13077a72b9012 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 23:15:20 +0100 Subject: [PATCH 08/17] AO3-6503 Hide reply button --- app/helpers/comments_helper.rb | 3 ++- features/admins/admin_settings.feature | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index e51e7462b52..6a94e7958f3 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -105,7 +105,8 @@ def can_reply_to_comment?(comment) parent_disallows_comments?(comment) || comment_parent_hidden?(comment) || blocked_by_comment?(comment) || - blocked_by?(comment.ultimate_parent)) + blocked_by?(comment.ultimate_parent) || + !logged_in? && @admin_settings.guest_comments_off?) end def can_edit_comment?(comment) diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index ce520fb2c0a..29cc949ed6b 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -41,15 +41,19 @@ Feature: Admin Settings Page Given guest comments are on And I am logged out And the work "Generic Work" - And I view the work "Generic Work" + And a guest comment on the work "Generic Work" + And I view the work "Generic Work" with comments When I fill in "Comment" with "Guest comment" And I post a guest comment Then I should see "Comment created!" + And I should see "Reply" Scenario: Turn off guest comments Given guest comments are off And I am logged out And the work "Generic Work" - When I view the work "Generic Work" + And a guest comment on the work "Generic Work" + When I view the work "Generic Work" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" \ No newline at end of file From 1b62328ada6b2f64cdc22f24df90213055911a41 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 8 Apr 2023 23:18:33 +0100 Subject: [PATCH 09/17] AO3-6503 Pleasing the hound --- app/helpers/comments_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 6a94e7958f3..67a9f75c40b 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -99,6 +99,8 @@ def show_hide_comments_link(commentable, options={}) #### HELPERS FOR CHECKING WHICH BUTTONS/FORMS TO DISPLAY ##### def can_reply_to_comment?(comment) + admin_settings = AdminSetting.current + !(comment.unreviewed? || comment.iced? || comment.hidden_by_admin? || @@ -106,7 +108,7 @@ def can_reply_to_comment?(comment) comment_parent_hidden?(comment) || blocked_by_comment?(comment) || blocked_by?(comment.ultimate_parent) || - !logged_in? && @admin_settings.guest_comments_off?) + !logged_in? && admin_settings.guest_comments_off?) end def can_edit_comment?(comment) From e8715fabe3feb8836e77e0149013df07cd321b84 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Wed, 17 May 2023 11:51:53 +0100 Subject: [PATCH 10/17] AO3-6503 Expand tests --- app/controllers/comments_controller.rb | 7 +- app/helpers/comments_helper.rb | 2 +- app/views/comments/_commentable.html.erb | 2 +- features/admins/admin_settings.feature | 99 +++++++++++++++++++- features/step_definitions/comment_steps.rb | 5 + spec/controllers/comments_controller_spec.rb | 56 +++++++++++ 6 files changed, 163 insertions(+), 8 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 8d5c26fa669..dd8c7c6bae3 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -18,8 +18,8 @@ class CommentsController < ApplicationController before_action :check_ownership, only: [:edit, :update, :cancel_comment_edit] before_action :check_permission_to_edit, only: [:edit, :update ] before_action :check_permission_to_delete, only: [:delete_comment, :destroy] + before_action :check_guest_comment_admin_setting, only: [:new, :create, :add_comment_reply] before_action :check_parent_comment_permissions, only: [:new, :create, :add_comment_reply] - before_action :check_guest_comment_permissions, only: [:new, :create, :add_comment_reply] before_action :check_unreviewed, only: [:add_comment_reply] before_action :check_frozen, only: [:new, :create, :add_comment_reply] before_action :check_hidden_by_admin, only: [:new, :create, :add_comment_reply] @@ -131,10 +131,11 @@ def check_parent_comment_permissions end end - def check_guest_comment_permissions + def check_guest_comment_admin_setting admin_settings = AdminSetting.current + parent = find_parent - return unless admin_settings.guest_comments_off? && !logged_in? + return unless admin_settings.guest_comments_off? && !logged_in? && !logged_in_as_admin? flash[:error] = t("comments.commentable.guest_comments_disabled") redirect_back(fallback_location: root_path) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 67a9f75c40b..25ce36f2051 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -108,7 +108,7 @@ def can_reply_to_comment?(comment) comment_parent_hidden?(comment) || blocked_by_comment?(comment) || blocked_by?(comment.ultimate_parent) || - !logged_in? && admin_settings.guest_comments_off?) + !logged_in? && !logged_in_as_admin? && admin_settings.guest_comments_off?) end def can_edit_comment?(comment) diff --git a/app/views/comments/_commentable.html.erb b/app/views/comments/_commentable.html.erb index 48e2a093455..99af259d7fb 100644 --- a/app/views/comments/_commentable.html.erb +++ b/app/views/comments/_commentable.html.erb @@ -75,7 +75,7 @@ <%= flash_div :comment_error, :comment_notice %> <% commentable_parent = find_parent(commentable) %> - <% if @admin_settings.guest_comments_off? && !logged_in? %> + <% if @admin_settings.guest_comments_off? && !logged_in? && !logged_in_as_admin? %>

<%= t(".guest_comments_disabled") %>

diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 29cc949ed6b..f2afdb1053c 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -37,7 +37,7 @@ Feature: Admin Settings Page And I go to the support page Then I should see "We can answer Support inquiries in" - Scenario: Turn on guest comments + Scenario: Turn on guest comments (on works) Given guest comments are on And I am logged out And the work "Generic Work" @@ -48,7 +48,18 @@ Feature: Admin Settings Page Then I should see "Comment created!" And I should see "Reply" - Scenario: Turn off guest comments + Scenario: Turn on guest comments (on admin posts) + Given guest comments are on + And I am logged out + And the admin post "Generic Post" + And a guest comment on the admin post "Generic Post" + And I view the admin post "Generic Post" with comments + When I fill in "Comment" with "Guest comment" + And I post a guest comment + Then I should see "Comment created!" + And I should see "Reply" + + Scenario: Turn off guest comments (when the work itself allows guest comments) Given guest comments are off And I am logged out And the work "Generic Work" @@ -56,4 +67,86 @@ Feature: Admin Settings Page When I view the work "Generic Work" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." And I should not see "Reply" - \ No newline at end of file + + Scenario: Turn off guest comments (when the admin post itself allows guest comments) + Given guest comments are off + And I am logged out + And the admin post "Generic Post" + And a guest comment on the admin post "Generic Post" + When I view the admin post "Generic Post" with comments + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" + + Scenario: Turn off guest comments (when the work itself does not allow guest comments) + Given guest comments are off + And I am logged in as "author" + And I post the work "Generic Work" + And a guest comment on the work "Generic Work" + And I edit the work "Generic Work" + And I choose "Only registered users can comment" + And I press "Post" + When I am logged out + And I view the work "Generic Work" with comments + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" + + Scenario: Turn off guest comments (when the admin post itself does not allow guest comments) + Given guest comments are off + And I have posted an admin post + And a guest comment on the admin post "Default Admin Post" + And I am logged in as a super admin + And I go to the admin-posts page + And I follow "Default Admin Post" + And I follow "Edit Post" + And I choose "Only registered users can comment" + And I press "Post" + When I am logged out + And I view the admin post "Default Admin Post" with comments + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" + + Scenario: Turn off guest comments (when work itself does not allow any comments) + Given guest comments are off + And I am logged in as "author" + And I post the work "Generic Work" + And a guest comment on the work "Generic Work" + And I edit the work "Generic Work" + And I choose "No one can comment" + And I press "Post" + When I am logged out + And I view the work "Generic Work" with comments + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" + + Scenario: Turn off guest comments (when the admin post itself does not allow any comments) + Given guest comments are off + And I have posted an admin post + And a guest comment on the admin post "Default Admin Post" + And I am logged in as a super admin + And I go to the admin-posts page + And I follow "Default Admin Post" + And I follow "Edit Post" + And I choose "No one can comment" + And I press "Post" + When I am logged out + And I view the admin post "Default Admin Post" with comments + Then I should see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see "Reply" + + Scenario: Logged in users should not be affected when guest comments are turned off + Given guest comments are off + And I am logged out + And the work "Generic Work" + And I am logged in + And a guest comment on the work "Generic Work" + When I view the work "Generic Work" with comments + Then I should see "Reply" + And I should not see "Sorry, the Archive doesn't allow guests to comment right now." + + Scenario: Admins should not be affected when guest comments are turned off + Given guest comments are off + And I am logged in as a super admin + And a fandom exists with name: "Stargate SG-1", canonical: true + When I post the comment "Important policy decision" on the tag "Stargate SG-1" via web + And I view the tag "Stargate SG-1" + Then I should see "1 comment" diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index ff9cc6558fb..5c83c32e91a 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -19,6 +19,11 @@ FactoryBot.create(:comment, :by_guest, commentable: work.first_chapter) end +Given "a guest comment on the admin post {string}" do |title| + admin_post = AdminPost.find_by(title: title) + FactoryBot.create(:comment, :by_guest, commentable: admin_post) +end + ParameterType( name: "commentable", regexp: /the (work|admin post|tag) "([^"]*)"/, diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 8dd6088f193..b45eb7a913d 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -449,28 +449,84 @@ context "guest comments are turned on in admin settings" do let(:work) { create(:work) } + let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } + let(:comment) { create(:comment) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + + before do + admin_setting.update_attribute(:guest_comments_off, false) + end + + it "allows guest comments" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + + expect(flash[:error]).to be_nil + end it "allows guest comments" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } expect(flash[:error]).to be_nil end + + it "allows guests to reply to comments" do + post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + + expect(flash[:error]).to be_nil + end + + it "does not allow guest comments when work has guest comments disabled" do + post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + + it_redirects_to_with_error(work_path(work_with_guest_comment_off), + "Sorry, this work doesn't allow non-Archive users to comment.") + end end context "guest comments are turned off in admin settings" do let(:work) { create(:work) } + let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } + let(:comment) { create(:comment) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } before do admin_setting.update_attribute(:guest_comments_off, true) end + it "does not allow guest comments" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + it "does not allow guest comments" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") end + + it "does not allow guests to reply to comments" do + post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "does not allow guest comments when work has guest comments disabled" do + post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "allows logged in users to comment" do + fake_login + post :new, params: { work_id: work.id } + + expect(flash[:error]).to be_nil + end end end From 161e2bd45fa3c16f1a4740048331cfe5d469b3f6 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Wed, 17 May 2023 11:54:12 +0100 Subject: [PATCH 11/17] AO3-6503 Pleasing the hound --- app/controllers/comments_controller.rb | 1 - spec/controllers/comments_controller_spec.rb | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index dd8c7c6bae3..84653ae842d 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -133,7 +133,6 @@ def check_parent_comment_permissions def check_guest_comment_admin_setting admin_settings = AdminSetting.current - parent = find_parent return unless admin_settings.guest_comments_off? && !logged_in? && !logged_in_as_admin? diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index b45eb7a913d..bd6b58b818b 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -457,13 +457,13 @@ admin_setting.update_attribute(:guest_comments_off, false) end - it "allows guest comments" do + it "allows guest comments for new" do post :new, params: { work_id: work.id, comment: anon_comment_attributes } expect(flash[:error]).to be_nil end - it "allows guest comments" do + it "allows guest comments for create" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } expect(flash[:error]).to be_nil @@ -493,14 +493,14 @@ admin_setting.update_attribute(:guest_comments_off, true) end - it "does not allow guest comments" do + it "does not allow guest comments for new" do post :new, params: { work_id: work.id, comment: anon_comment_attributes } it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") end - it "does not allow guest comments" do + it "does not allow guest comments for create" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } it_redirects_to_with_error("/where_i_came_from", From 24ae4c889272524bd18021f36550e75716cf7581 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Wed, 17 May 2023 16:05:47 +0100 Subject: [PATCH 12/17] AO3-6503 Change cache key & refactor tests --- app/models/admin_setting.rb | 4 ++-- features/step_definitions/admin_steps.rb | 4 ++-- features/step_definitions/comment_steps.rb | 15 +++++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/models/admin_setting.rb b/app/models/admin_setting.rb index 9385a8bfedc..755c6767e33 100644 --- a/app/models/admin_setting.rb +++ b/app/models/admin_setting.rb @@ -45,7 +45,7 @@ def self.default end def self.current - Rails.cache.fetch("admin_settings", race_condition_ttl: 10.seconds) { AdminSetting.first } || OpenStruct.new(DEFAULT_SETTINGS) + Rails.cache.fetch("admin_settings_1", race_condition_ttl: 10.seconds) { AdminSetting.first } || OpenStruct.new(DEFAULT_SETTINGS) end class << self @@ -79,7 +79,7 @@ def recache_settings self.reload # However, we only cache it if the transaction is successful. - after_commit { Rails.cache.write("admin_settings", self) } + after_commit { Rails.cache.write("admin_settings_1", self) } end private diff --git a/features/step_definitions/admin_steps.rb b/features/step_definitions/admin_steps.rb index 57a325009f4..ef4c0e412c3 100644 --- a/features/step_definitions/admin_steps.rb +++ b/features/step_definitions/admin_steps.rb @@ -88,14 +88,14 @@ click_button("Update") end -Given /^guest comments are on$/ do +Given "guest comments are on" do step("I am logged in as a super admin") visit(admin_settings_path) uncheck("Turn off guest comments across the site") click_button("Update") end -Given /^guest comments are off$/ do +Given "guest comments are off" do step("I am logged in as a super admin") visit(admin_settings_path) check("Turn off guest comments across the site") diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index 5c83c32e91a..c434b7ea7c3 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -14,16 +14,6 @@ user.preference.save end -Given "a guest comment on the work {string}" do |title| - work = Work.find_by(title: title) - FactoryBot.create(:comment, :by_guest, commentable: work.first_chapter) -end - -Given "a guest comment on the admin post {string}" do |title| - admin_post = AdminPost.find_by(title: title) - FactoryBot.create(:comment, :by_guest, commentable: admin_post) -end - ParameterType( name: "commentable", regexp: /the (work|admin post|tag) "([^"]*)"/, @@ -40,6 +30,11 @@ } ) +Given "a guest comment on {commentable}" do |commentable| + commentable = Comment.commentable_object(commentable) + FactoryBot.create(:comment, :by_guest, commentable: commentable) +end + Given "a comment {string} by {string} on {commentable}" do |text, user, commentable| user = ensure_user(user) commentable = Comment.commentable_object(commentable) From a55b32d3807cdff921470d7fecfad93d2edfb292 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Fri, 26 May 2023 09:39:20 +0100 Subject: [PATCH 13/17] AO3-6503 Refactor tests --- app/controllers/application_controller.rb | 1 + app/helpers/comments_helper.rb | 2 +- app/models/admin_setting.rb | 4 +- features/admins/admin_settings.feature | 144 +++++++++--------- features/step_definitions/admin_steps.rb | 8 + spec/controllers/comments_controller_spec.rb | 146 ++++++++++++------- 6 files changed, 178 insertions(+), 127 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 06079c806ad..27148b57516 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -74,6 +74,7 @@ def transform_sanitized_hash_to_ac_params(key, value) helper_method :current_admin helper_method :logged_in? helper_method :logged_in_as_admin? + helper_method :guest? # Title helpers helper_method :process_title diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 25ce36f2051..377e50c6e3d 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -108,7 +108,7 @@ def can_reply_to_comment?(comment) comment_parent_hidden?(comment) || blocked_by_comment?(comment) || blocked_by?(comment.ultimate_parent) || - !logged_in? && !logged_in_as_admin? && admin_settings.guest_comments_off?) + guest? && admin_settings.guest_comments_off?) end def can_edit_comment?(comment) diff --git a/app/models/admin_setting.rb b/app/models/admin_setting.rb index 755c6767e33..54297f04aa6 100644 --- a/app/models/admin_setting.rb +++ b/app/models/admin_setting.rb @@ -45,7 +45,7 @@ def self.default end def self.current - Rails.cache.fetch("admin_settings_1", race_condition_ttl: 10.seconds) { AdminSetting.first } || OpenStruct.new(DEFAULT_SETTINGS) + Rails.cache.fetch("admin_settings-v1", race_condition_ttl: 10.seconds) { AdminSetting.first } || OpenStruct.new(DEFAULT_SETTINGS) end class << self @@ -79,7 +79,7 @@ def recache_settings self.reload # However, we only cache it if the transaction is successful. - after_commit { Rails.cache.write("admin_settings_1", self) } + after_commit { Rails.cache.write("admin_settings-v1", self) } end private diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index f2afdb1053c..4fd724534b1 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -37,73 +37,72 @@ Feature: Admin Settings Page And I go to the support page Then I should see "We can answer Support inquiries in" - Scenario: Turn on guest comments (on works) + Scenario Outline: Guests can comment when guest coments are enabled Given guest comments are on And I am logged out - And the work "Generic Work" - And a guest comment on the work "Generic Work" - And I view the work "Generic Work" with comments - When I fill in "Comment" with "Guest comment" - And I post a guest comment - Then I should see "Comment created!" - And I should see "Reply" + And + And a guest comment on + And I view with comments + When I post a guest comment + Then I should see a link "Reply" - Scenario: Turn on guest comments (on admin posts) - Given guest comments are on - And I am logged out - And the admin post "Generic Post" - And a guest comment on the admin post "Generic Post" - And I view the admin post "Generic Post" with comments - When I fill in "Comment" with "Guest comment" - And I post a guest comment - Then I should see "Comment created!" - And I should see "Reply" + Examples: + | commentable | + | the work "Generic Work" | + | the admin post "Generic Post" | - Scenario: Turn off guest comments (when the work itself allows guest comments) + Scenario Outline: Guests cannot comment when guest comments are disabled, even if works or admin posts allow commets Given guest comments are off And I am logged out - And the work "Generic Work" - And a guest comment on the work "Generic Work" - When I view the work "Generic Work" with comments + And + And a guest comment on + When I view with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" + And I should not see a link "Reply" - Scenario: Turn off guest comments (when the admin post itself allows guest comments) - Given guest comments are off - And I am logged out - And the admin post "Generic Post" - And a guest comment on the admin post "Generic Post" - When I view the admin post "Generic Post" with comments - Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" + When I am logged in + And I view with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I am logged in as a super admin + And I view with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + + Examples: + | commentable | + | the work "Generic Work" | + | the admin post "Generic Post" | Scenario: Turn off guest comments (when the work itself does not allow guest comments) Given guest comments are off And I am logged in as "author" - And I post the work "Generic Work" - And a guest comment on the work "Generic Work" - And I edit the work "Generic Work" + And I set up the draft "Generic Work" And I choose "Only registered users can comment" - And I press "Post" + And I post the work without preview + And a comment "Nice job" by "user" on the work "Generic Work" When I am logged out And I view the work "Generic Work" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" + And I should not see a link "Reply" + When I am logged in + And I view the work "Generic Work" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I am logged in as a super admin + And I view the work "Generic Work" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." Scenario: Turn off guest comments (when the admin post itself does not allow guest comments) Given guest comments are off - And I have posted an admin post - And a guest comment on the admin post "Default Admin Post" - And I am logged in as a super admin - And I go to the admin-posts page - And I follow "Default Admin Post" - And I follow "Edit Post" - And I choose "Only registered users can comment" - And I press "Post" - When I am logged out + And I have posted an admin post with guest comments disabled + And a comment "Nice job" by "user" on the admin post "Default Admin Post" And I view the admin post "Default Admin Post" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" + And I should not see a link "Reply" + When I am logged in + And I view the admin post "Default Admin Post" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I am logged in as a super admin + And I view the admin post "Default Admin Post" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." Scenario: Turn off guest comments (when work itself does not allow any comments) Given guest comments are off @@ -116,37 +115,38 @@ Feature: Admin Settings Page When I am logged out And I view the work "Generic Work" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" + And I should not see a link "Reply" + When I am logged in + And I view the work "Generic Work" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I am logged in as a super admin + And I view the work "Generic Work" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." Scenario: Turn off guest comments (when the admin post itself does not allow any comments) Given guest comments are off - And I have posted an admin post - And a guest comment on the admin post "Default Admin Post" - And I am logged in as a super admin - And I go to the admin-posts page - And I follow "Default Admin Post" - And I follow "Edit Post" - And I choose "No one can comment" - And I press "Post" - When I am logged out + And I have posted an admin post with comments disabled + And a comment "Nice job" by "user" on the admin post "Default Admin Post" And I view the admin post "Default Admin Post" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." - And I should not see "Reply" - - Scenario: Logged in users should not be affected when guest comments are turned off - Given guest comments are off - And I am logged out - And the work "Generic Work" - And I am logged in - And a guest comment on the work "Generic Work" - When I view the work "Generic Work" with comments - Then I should see "Reply" - And I should not see "Sorry, the Archive doesn't allow guests to comment right now." + And I should not see a link "Reply" + When I am logged in + And I view the admin post "Default Admin Post" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I am logged in as a super admin + And I view the admin post "Default Admin Post" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." - Scenario: Admins should not be affected when guest comments are turned off + Scenario: Tag comments are not affected when guest comments are turned off Given guest comments are off - And I am logged in as a super admin And a fandom exists with name: "Stargate SG-1", canonical: true - When I post the comment "Important policy decision" on the tag "Stargate SG-1" via web - And I view the tag "Stargate SG-1" - Then I should see "1 comment" + When I am logged in as a super admin + And I view the tag "Stargate SG-1" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I post the comment "Important policy decision" on the tag "Stargate SG-1" + Then I should see "Comment created!" + When I am logged in as a tag wrangler + And I view the tag "Stargate SG-1" with comments + Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." + When I post the comment "Sent you a syn" on the tag "Stargate SG-1" + Then I should see "Comment created!" \ No newline at end of file diff --git a/features/step_definitions/admin_steps.rb b/features/step_definitions/admin_steps.rb index ef4c0e412c3..79f9c6f2811 100644 --- a/features/step_definitions/admin_steps.rb +++ b/features/step_definitions/admin_steps.rb @@ -173,6 +173,14 @@ end end +Given /^I have posted an admin post with guest comments disabled$/ do + step %{I am logged in as a "communications" admin} + step %{I start to make an admin post} + choose("Only registered users can comment") + click_button("Post") + step %{I log out} +end + Given /^I have posted an admin post with comments disabled$/ do step %{I am logged in as a "communications" admin} step %{I start to make an admin post} diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index bd6b58b818b..d17cfa8ce08 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -12,6 +12,10 @@ end describe "GET #add_comment_reply" do + let(:anon_comment_attributes) do + attributes_for(:comment, :by_guest).slice(:name, :email, :comment_content) + end + context "when comment is unreviewed" do it "redirects logged out user to login path with an error" do get :add_comment_reply, params: { comment_id: unreviewed_comment.id } @@ -104,6 +108,37 @@ it_behaves_like "no one can add comment reply on a hidden comment" end end + + context "guest comments are turned on in admin settings" do + let(:comment) { create(:comment) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + + before do + admin_setting.update_attribute(:guest_comments_off, false) + end + + it "allows guests to reply to comments" do + post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + + expect(flash[:error]).to be_nil + end + end + + context "guest comments are turned off in admin settings" do + let(:comment) { create(:comment) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + + before do + admin_setting.update_attribute(:guest_comments_off, true) + end + + it "does not allow guests to reply to comments" do + post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + end end describe "GET #unreviewed" do @@ -136,6 +171,10 @@ end describe "POST #new" do + let(:anon_comment_attributes) do + attributes_for(:comment, :by_guest).slice(:name, :email, :comment_content) + end + it "errors if the commentable is not a valid tag" do post :new, params: { tag_id: "Non existent tag" } expect(flash[:error]).to eq "What did you want to comment on?" @@ -196,6 +235,60 @@ end end + context "guest comments are turned on in admin settings" do + let(:work) { create(:work) } + let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + + before do + admin_setting.update_attribute(:guest_comments_off, false) + end + + it "allows guest comments" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + + expect(flash[:error]).to be_nil + end + + it "does not allow guest comments when work has guest comments disabled" do + post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + + it_redirects_to_with_error(work_path(work_with_guest_comment_off), + "Sorry, this work doesn't allow non-Archive users to comment.") + end + end + + context "guest comments are turned off in admin settings" do + let(:work) { create(:work) } + let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } + let(:admin_setting) { AdminSetting.first || AdminSetting.create } + + before do + admin_setting.update_attribute(:guest_comments_off, true) + end + + it "does not allow guest comments for new" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "does not allow guest comments when work has guest comments disabled" do + post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + + it_redirects_to_with_error("/where_i_came_from", + "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "allows logged in users to comment" do + fake_login + post :new, params: { work_id: work.id } + + expect(flash[:error]).to be_nil + end + end + it "renders the :new template if commentable is a valid comment" do comment = create(:comment) post :new, params: { comment_id: comment.id } @@ -449,84 +542,33 @@ context "guest comments are turned on in admin settings" do let(:work) { create(:work) } - let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } - let(:comment) { create(:comment) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } before do admin_setting.update_attribute(:guest_comments_off, false) end - it "allows guest comments for new" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } - - expect(flash[:error]).to be_nil - end - - it "allows guest comments for create" do + it "allows guest comments" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } expect(flash[:error]).to be_nil end - - it "allows guests to reply to comments" do - post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } - - expect(flash[:error]).to be_nil - end - - it "does not allow guest comments when work has guest comments disabled" do - post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } - - it_redirects_to_with_error(work_path(work_with_guest_comment_off), - "Sorry, this work doesn't allow non-Archive users to comment.") - end end context "guest comments are turned off in admin settings" do let(:work) { create(:work) } - let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } - let(:comment) { create(:comment) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } before do admin_setting.update_attribute(:guest_comments_off, true) end - it "does not allow guest comments for new" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } - - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") - end - it "does not allow guest comments for create" do post :create, params: { work_id: work.id, comment: anon_comment_attributes } it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") end - - it "does not allow guests to reply to comments" do - post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } - - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") - end - - it "does not allow guest comments when work has guest comments disabled" do - post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } - - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") - end - - it "allows logged in users to comment" do - fake_login - post :new, params: { work_id: work.id } - - expect(flash[:error]).to be_nil - end end end From 4e0935c3f885a6c27f2bef74731348efb0b8d450 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Mon, 29 May 2023 10:22:43 +0100 Subject: [PATCH 14/17] AO3-6503 Expand tests --- app/controllers/comments_controller.rb | 2 +- app/views/comments/_commentable.html.erb | 2 +- features/admins/admin_settings.feature | 4 +- spec/controllers/comments_controller_spec.rb | 136 +++++++++++++++---- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 84653ae842d..507c99114c4 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -134,7 +134,7 @@ def check_parent_comment_permissions def check_guest_comment_admin_setting admin_settings = AdminSetting.current - return unless admin_settings.guest_comments_off? && !logged_in? && !logged_in_as_admin? + return unless admin_settings.guest_comments_off? && guest? flash[:error] = t("comments.commentable.guest_comments_disabled") redirect_back(fallback_location: root_path) diff --git a/app/views/comments/_commentable.html.erb b/app/views/comments/_commentable.html.erb index 99af259d7fb..fb7261aa1af 100644 --- a/app/views/comments/_commentable.html.erb +++ b/app/views/comments/_commentable.html.erb @@ -75,7 +75,7 @@ <%= flash_div :comment_error, :comment_notice %> <% commentable_parent = find_parent(commentable) %> - <% if @admin_settings.guest_comments_off? && !logged_in? && !logged_in_as_admin? %> + <% if @admin_settings.guest_comments_off? && guest? %>

<%= t(".guest_comments_disabled") %>

diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 4fd724534b1..667b36ea468 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -41,10 +41,9 @@ Feature: Admin Settings Page Given guest comments are on And I am logged out And - And a guest comment on And I view with comments When I post a guest comment - Then I should see a link "Reply" + Then I should see a link "Reply" Examples: | commentable | @@ -59,7 +58,6 @@ Feature: Admin Settings Page When I view with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." And I should not see a link "Reply" - When I am logged in And I view with comments Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index d17cfa8ce08..3e0b694a432 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -12,10 +12,6 @@ end describe "GET #add_comment_reply" do - let(:anon_comment_attributes) do - attributes_for(:comment, :by_guest).slice(:name, :email, :comment_content) - end - context "when comment is unreviewed" do it "redirects logged out user to login path with an error" do get :add_comment_reply, params: { comment_id: unreviewed_comment.id } @@ -117,26 +113,58 @@ admin_setting.update_attribute(:guest_comments_off, false) end - it "allows guests to reply to comments" do - post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + it "redirects logged out user to the comment on the commentable without an error" do + get :add_comment_reply, params: { comment_id: comment.id } expect(flash[:error]).to be_nil + it_redirects_to(chapter_path(comment.commentable, show_comments: true, anchor: "comment_#{comment.id}")) end end context "guest comments are turned off in admin settings" do let(:comment) { create(:comment) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } + let(:work) { comment.ultimate_parent } before do admin_setting.update_attribute(:guest_comments_off, true) end - it "does not allow guests to reply to comments" do - post :add_comment_reply, params: { comment_id: comment.id, comment: anon_comment_attributes } + [:enable_all, :disable_anon].each do |permissions| + context "when work comment permissions are #{permissions}" do + before do + work.update_attribute(:comment_permissions, permissions) + end + + it "redirects logged out user with an error" do + get :add_comment_reply, params: { comment_id: comment.id } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") + it "redirects logged in user to the comment on the commentable without an error" do + fake_login + get :add_comment_reply, params: { comment_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 + + context "when work comment permissions are disable_all" do + before do + work.update_attribute(:comment_permissions, :disable_all) + end + + it "redirects logged out user with an error" do + get :add_comment_reply, params: { comment_id: comment.id } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "redirects logged in user with an error" do + fake_login + get :add_comment_reply, params: { comment_id: comment.id } + it_redirects_to_with_error(work_path(work), "Sorry, this work doesn't allow comments.") + end end end end @@ -260,32 +288,47 @@ context "guest comments are turned off in admin settings" do let(:work) { create(:work) } - let(:work_with_guest_comment_off) { create(:work, comment_permissions: :disable_anon) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } before do admin_setting.update_attribute(:guest_comments_off, true) end - it "does not allow guest comments for new" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } - - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") - end + [:enable_all, :disable_anon].each do |permissions| + context "when work comment permissions are #{permissions}" do + before do + work.update_attribute(:comment_permissions, permissions) + end - it "does not allow guest comments when work has guest comments disabled" do - post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + it "redirects logged out user with an error" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") + it "redirects logged in user to the comment on the commentable without an error" do + fake_login + post :new, params: { work_id: work.id } + expect(flash[:error]).to be_nil + expect(response).to render_template("new") + end + end end - it "allows logged in users to comment" do - fake_login - post :new, params: { work_id: work.id } + context "when work comment permissions are disable_all" do + before do + work.update_attribute(:comment_permissions, :disable_all) + end - expect(flash[:error]).to be_nil + it "redirects logged out user with an error" do + post :new, params: { work_id: work.id, comment: anon_comment_attributes } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "redirects logged in user with an error" do + fake_login + post :new, params: { work_id: work.id } + it_redirects_to_with_error(work_path(work), "Sorry, this work doesn't allow comments.") + end end end @@ -557,17 +600,52 @@ context "guest comments are turned off in admin settings" do let(:work) { create(:work) } + let(:user) { create(:user) } let(:admin_setting) { AdminSetting.first || AdminSetting.create } before do admin_setting.update_attribute(:guest_comments_off, true) end - it "does not allow guest comments for create" do - post :create, params: { work_id: work.id, comment: anon_comment_attributes } + [:enable_all, :disable_anon].each do |permissions| + context "when work comment permissions are #{permissions}" do + before do + work.update_attribute(:comment_permissions, permissions) + end - it_redirects_to_with_error("/where_i_came_from", - "Sorry, the Archive doesn't allow guests to comment right now.") + it "redirects logged out user with an error" do + post :create, params: { work_id: work.id, comment: anon_comment_attributes } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "redirects logged in user to the comment on the commentable without an error" do + fake_login + post :create, params: { work_id: work.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 + + context "when work comment permissions are disable_all" do + before do + work.update_attribute(:comment_permissions, :disable_all) + end + + it "redirects logged out user with an error" do + post :create, params: { work_id: work.id, comment: anon_comment_attributes } + it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") + end + + it "redirects logged in user with an error" do + comment_attributes = { + pseud_id: user.default_pseud_id, + comment_content: "Hello fellow human!" + } + fake_login_known_user(user) + post :create, params: { work_id: work.id, comment: comment_attributes } + it_redirects_to_with_error(work_path(work), "Sorry, this work doesn't allow comments.") + end end end end From cf1d9a2f31ab5c56129b3f43c30ce9741102307f Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Mon, 29 May 2023 11:16:13 +0100 Subject: [PATCH 15/17] AO3-6503 Fix test --- spec/controllers/comments_controller_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 3e0b694a432..c1aa65010d6 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -619,10 +619,15 @@ end it "redirects logged in user to the comment on the commentable without an error" do - fake_login - post :create, params: { work_id: work.id } + comment_attributes = { + pseud_id: user.default_pseud_id, + comment_content: "Hello fellow human!" + } + fake_login_known_user(user) + 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, anchor: "comment_#{comment.id}")) + expect(response).to redirect_to(work_chapter_path(work, comment.commentable, show_comments: true, view_full_work: false, anchor: "comment_#{comment.id}")) end end end From 4d105c104828485b460dae7c285ff6837c96e797 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Mon, 29 May 2023 11:36:37 +0100 Subject: [PATCH 16/17] AO3-6503 Normalise en.yml --- config/locales/models/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/models/en.yml b/config/locales/models/en.yml index 868b66256d4..23f9256ee02 100644 --- a/config/locales/models/en.yml +++ b/config/locales/models/en.yml @@ -74,7 +74,7 @@ en: abuse_report: attributes: url: - not_on_archive: "does not appear to be on this site." + not_on_archive: does not appear to be on this site. block: attributes: blocked: From d83b238ed9d99a0eed8b1300eded296ed2b81e11 Mon Sep 17 00:00:00 2001 From: EchoEkhi Date: Sat, 10 Jun 2023 10:32:59 +0100 Subject: [PATCH 17/17] AO3-6503 Fix tests --- features/admins/admin_settings.feature | 6 +-- spec/controllers/comments_controller_spec.rb | 40 +++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/features/admins/admin_settings.feature b/features/admins/admin_settings.feature index 667b36ea468..320f003be3a 100644 --- a/features/admins/admin_settings.feature +++ b/features/admins/admin_settings.feature @@ -92,7 +92,7 @@ Feature: Admin Settings Page Given guest comments are off And I have posted an admin post with guest comments disabled And a comment "Nice job" by "user" on the admin post "Default Admin Post" - And I view the admin post "Default Admin Post" with comments + When I view the admin post "Default Admin Post" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." And I should not see a link "Reply" When I am logged in @@ -125,7 +125,7 @@ Feature: Admin Settings Page Given guest comments are off And I have posted an admin post with comments disabled And a comment "Nice job" by "user" on the admin post "Default Admin Post" - And I view the admin post "Default Admin Post" with comments + When I view the admin post "Default Admin Post" with comments Then I should see "Sorry, the Archive doesn't allow guests to comment right now." And I should not see a link "Reply" When I am logged in @@ -147,4 +147,4 @@ Feature: Admin Settings Page And I view the tag "Stargate SG-1" with comments Then I should not see "Sorry, the Archive doesn't allow guests to comment right now." When I post the comment "Sent you a syn" on the tag "Stargate SG-1" - Then I should see "Comment created!" \ No newline at end of file + Then I should see "Comment created!" diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index c1aa65010d6..410dab6a512 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -198,19 +198,15 @@ end end - describe "POST #new" do - let(:anon_comment_attributes) do - attributes_for(:comment, :by_guest).slice(:name, :email, :comment_content) - end - + describe "GET #new" do it "errors if the commentable is not a valid tag" do - post :new, params: { tag_id: "Non existent tag" } + get :new, params: { tag_id: "Non existent tag" } expect(flash[:error]).to eq "What did you want to comment on?" end it "renders the :new template if commentable is a valid admin post" do admin_post = create(:admin_post) - post :new, params: { admin_post_id: admin_post.id } + get :new, params: { admin_post_id: admin_post.id } expect(response).to render_template("new") expect(assigns(:name)).to eq(admin_post.title) end @@ -222,7 +218,7 @@ before { fake_login_admin(create(:admin)) } it "renders the :new template" do - post :new, params: { tag_id: fandom.name } + get :new, params: { tag_id: fandom.name } expect(response).to render_template("new") expect(assigns(:name)).to eq("Fandom") end @@ -232,7 +228,7 @@ before { fake_login_known_user(create(:tag_wrangler)) } it "renders the :new template" do - post :new, params: { tag_id: fandom.name } + get :new, params: { tag_id: fandom.name } expect(response).to render_template("new") expect(assigns(:name)).to eq("Fandom") end @@ -242,7 +238,7 @@ before { fake_login } it "shows an error and redirects" do - post :new, params: { tag_id: fandom.name } + get :new, params: { tag_id: fandom.name } it_redirects_to_with_error(user_path(controller.current_user), "Sorry, you don't have permission to " \ "access the page you were trying to " \ @@ -254,7 +250,7 @@ before { fake_logout } it "shows an error and redirects" do - post :new, params: { tag_id: fandom.name } + get :new, params: { tag_id: fandom.name } it_redirects_to_with_error(new_user_session_path, "Sorry, you don't have permission to " \ "access the page you were trying to " \ @@ -273,13 +269,13 @@ end it "allows guest comments" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } + get :new, params: { work_id: work.id } - expect(flash[:error]).to be_nil + expect(response).to render_template(:new) end it "does not allow guest comments when work has guest comments disabled" do - post :new, params: { work_id: work_with_guest_comment_off.id, comment: anon_comment_attributes } + get :new, params: { work_id: work_with_guest_comment_off.id } it_redirects_to_with_error(work_path(work_with_guest_comment_off), "Sorry, this work doesn't allow non-Archive users to comment.") @@ -301,13 +297,13 @@ end it "redirects logged out user with an error" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } + get :new, params: { work_id: work.id } it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") end - it "redirects logged in user to the comment on the commentable without an error" do + it "renders the :new template for logged in user" do fake_login - post :new, params: { work_id: work.id } + get :new, params: { work_id: work.id } expect(flash[:error]).to be_nil expect(response).to render_template("new") end @@ -320,13 +316,13 @@ end it "redirects logged out user with an error" do - post :new, params: { work_id: work.id, comment: anon_comment_attributes } + get :new, params: { work_id: work.id } it_redirects_to_with_error("/where_i_came_from", "Sorry, the Archive doesn't allow guests to comment right now.") end it "redirects logged in user with an error" do fake_login - post :new, params: { work_id: work.id } + get :new, params: { work_id: work.id } it_redirects_to_with_error(work_path(work), "Sorry, this work doesn't allow comments.") end end @@ -334,20 +330,20 @@ it "renders the :new template if commentable is a valid comment" do comment = create(:comment) - post :new, params: { comment_id: comment.id } + get :new, params: { comment_id: comment.id } expect(response).to render_template("new") expect(assigns(:name)).to eq("Previous Comment") end it "shows an error and redirects if commentable is a frozen comment" do comment = create(:comment, iced: true) - post :new, params: { comment_id: comment.id } + get :new, params: { comment_id: comment.id } it_redirects_to_with_error("/where_i_came_from", "Sorry, you cannot reply to a frozen comment.") end it "shows an error and redirects if commentable is a hidden comment" do comment = create(:comment, hidden_by_admin: true) - post :new, params: { comment_id: comment.id } + get :new, params: { comment_id: comment.id } it_redirects_to_with_error("/where_i_came_from", "Sorry, you cannot reply to a hidden comment.") end end