From c716972740dba2f5882b658008c27a1807e1d585 Mon Sep 17 00:00:00 2001 From: Moshi <54333972+MoshiKoi@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:31:54 -0700 Subject: [PATCH 01/30] Remove special case notifying author of threads Instead of special casing creating a notification, we just have them follow normally automatically. --- app/controllers/comments_controller.rb | 5 +---- app/controllers/posts_controller.rb | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 57894f297..0a2b3751f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -41,12 +41,9 @@ def create_thread if success notification = "New comment thread on #{@comment.root.title}: #{@comment_thread.title}" - unless @comment.post.user == current_user - @comment.post.user.create_notification(notification, helpers.comment_link(@comment)) - end ThreadFollower.where(post: @post).each do |tf| - unless tf.user == current_user || tf.user == @comment.post.user + unless tf.user == current_user tf.user.create_notification(notification, helpers.comment_link(@comment)) end ThreadFollower.create(user: tf.user, comment_thread: @comment_thread) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d3295ea77..3b95348f6 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -100,6 +100,7 @@ def create if @post.save @post.update(last_activity: @post.created_at, last_activity_by: current_user) + ThreadFollower.create user: @post.user, post: @post if @post_type.has_parent? unless @post.user_id == @post.parent.user_id @post.parent.user.create_notification("New response to your post #{@post.parent.title}", From f0f5555f5c9851eda6c14e5cb40817551375468e Mon Sep 17 00:00:00 2001 From: Moshi <54333972+MoshiKoi@users.noreply.github.com> Date: Tue, 16 May 2023 17:00:36 -0700 Subject: [PATCH 02/30] Fix duplicate ThreadFollowers --- app/controllers/comments_controller.rb | 3 +-- app/models/comment_thread.rb | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0a2b3751f..a3eb1f311 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -227,8 +227,7 @@ def thread_unrestrict end @comment_thread.update(deleted: false, deleted_by: nil) when 'follow' - tf = ThreadFollower.find_by(comment_thread: @comment_thread, user: current_user) - tf&.destroy + ThreadFollower.where(comment_thread: @comment_thread, user: current_user).destroy_all else return not_found end diff --git a/app/models/comment_thread.rb b/app/models/comment_thread.rb index 39f5dcf5c..4858a4d16 100644 --- a/app/models/comment_thread.rb +++ b/app/models/comment_thread.rb @@ -13,8 +13,6 @@ class CommentThread < ApplicationRecord scope :publicly_available, -> { where(deleted: false).where('reply_count > 0') } scope :archived, -> { where(archived: true) } - after_create :create_follower - def read_only? locked? || archived? || deleted? end @@ -38,12 +36,4 @@ def self.post_followed?(post, user) private - # Comment author and post author are automatically followed to the thread. Question author is NOT - # automatically followed on new answer comment threads. Comment author follower creation is done - # on the Comment model. - def create_follower - if post.user.preference('auto_follow_comment_threads') == 'true' - ThreadFollower.create comment_thread: self, user: post.user - end - end end From 21e5500ffc45c7bf9bdf14e60df244f7bc995d0f Mon Sep 17 00:00:00 2001 From: trichoplax Date: Mon, 3 Mar 2025 23:17:55 +0000 Subject: [PATCH 03/30] Remove now redundant private label --- app/models/comment_thread.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/comment_thread.rb b/app/models/comment_thread.rb index 4858a4d16..b8335ed00 100644 --- a/app/models/comment_thread.rb +++ b/app/models/comment_thread.rb @@ -33,7 +33,4 @@ def can_access?(user) def self.post_followed?(post, user) ThreadFollower.where(post: post, user: user).any? end - - private - end From 2dc903527c30253addc2d5b0e312936081b79d75 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Wed, 5 Mar 2025 16:49:09 +0000 Subject: [PATCH 04/30] Move followed_by? method to post model to simplify calling --- app/controllers/comments_controller.rb | 2 +- app/models/comment_thread.rb | 4 ---- app/models/post.rb | 4 ++++ app/views/posts/_expanded.html.erb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1e435ba4f..74aae5215 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -257,7 +257,7 @@ def post def post_follow @post = Post.find(params[:post_id]) - if CommentThread.post_followed?(@post, current_user) + if @post.followed_by?(current_user) ThreadFollower.where(post: @post, user: current_user).destroy_all else ThreadFollower.create(post: @post, user: current_user) diff --git a/app/models/comment_thread.rb b/app/models/comment_thread.rb index b8335ed00..f2b75f561 100644 --- a/app/models/comment_thread.rb +++ b/app/models/comment_thread.rb @@ -29,8 +29,4 @@ def can_access?(user) (!deleted? || user&.privilege?('flag_curate') || user&.has_post_privilege?('flag_curate', post)) && post.can_access?(user) end - - def self.post_followed?(post, user) - ThreadFollower.where(post: post, user: user).any? - end end diff --git a/app/models/post.rb b/app/models/post.rb index 4a1d1ba99..3616e5946 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -224,6 +224,10 @@ def reaction_list .to_h { |_k, v| [v.first.reaction_type, v] } end + def followed_by?(user) + ThreadFollower.where(post: self, user: user).any? + end + private ## diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 5f28e9d23..a2fefb165 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -529,7 +529,7 @@ <%= pluralize(public_count, 'comment thread') %> <% if user_signed_in? %> - <% if CommentThread.post_followed?(post, current_user) %> + <% if post.followed_by?(current_user) %> <%= link_to follow_post_comments_path(post_id: post.id), method: :post, class: "button is-muted is-outlined is-small", title: 'Don\'t follow new comment threads on this post', From 11f7e25094cefe021cfa68e8dc4a8ef17f832224 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 13:29:27 +0000 Subject: [PATCH 05/30] Split post_follow method to avoid toggling if called twice --- app/controllers/comments_controller.rb | 12 +++++++----- app/views/posts/_expanded.html.erb | 2 +- config/routes.rb | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 74aae5215..c7989f02a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -257,11 +257,13 @@ def post def post_follow @post = Post.find(params[:post_id]) - if @post.followed_by?(current_user) - ThreadFollower.where(post: @post, user: current_user).destroy_all - else - ThreadFollower.create(post: @post, user: current_user) - end + ThreadFollower.create(post: @post, user: current_user) + redirect_to post_path(@post) + end + + def post_unfollow + @post = Post.find(params[:post_id]) + ThreadFollower.where(post: @post, user: current_user).destroy_all redirect_to post_path(@post) end diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index a2fefb165..a626118b6 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -530,7 +530,7 @@ <% if user_signed_in? %> <% if post.followed_by?(current_user) %> - <%= link_to follow_post_comments_path(post_id: post.id), method: :post, + <%= link_to unfollow_post_comments_path(post_id: post.id), method: :post, class: "button is-muted is-outlined is-small", title: 'Don\'t follow new comment threads on this post', role: 'button', diff --git a/config/routes.rb b/config/routes.rb index 5a9c2f225..b8ee1ebac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -237,6 +237,7 @@ get 'thread/:id/followers', to: 'comments#thread_followers', as: :comment_thread_followers get 'post/:post_id', to: 'comments#post', as: :post_comments post 'post/:post_id/follow', to: 'comments#post_follow', as: :follow_post_comments + post 'post/:post_id/unfollow', to: 'comments#post_unfollow', as: :unfollow_post_comments get ':id', to: 'comments#show', as: :comment get 'thread/:id', to: 'comments#thread', as: :comment_thread post ':id/edit', to: 'comments#update', as: :update_comment From 7b4f1addd5d2bc703aeb66e1d426d516ff2438b8 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 13:52:48 +0000 Subject: [PATCH 06/30] Allow follow/unfollow new threads on a locked post --- 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 c7989f02a..714ba0b8b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -4,7 +4,7 @@ class CommentsController < ApplicationController before_action :set_comment, only: [:update, :destroy, :undelete, :show] before_action :set_thread, only: [:thread, :thread_rename, :thread_restrict, :thread_unrestrict, :thread_followers] before_action :check_privilege, only: [:update, :destroy, :undelete] - before_action :check_if_target_post_locked, only: [:create, :post_follow] + before_action :check_if_target_post_locked, only: [:create] before_action :check_if_parent_post_locked, only: [:update, :destroy] def create_thread From acbb32567db826417a4f51d217f2021f68d3c311 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 14:32:55 +0000 Subject: [PATCH 07/30] Prevent adding a new comment thread to a locked post --- 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 714ba0b8b..665b3c405 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -4,7 +4,7 @@ class CommentsController < ApplicationController before_action :set_comment, only: [:update, :destroy, :undelete, :show] before_action :set_thread, only: [:thread, :thread_rename, :thread_restrict, :thread_unrestrict, :thread_followers] before_action :check_privilege, only: [:update, :destroy, :undelete] - before_action :check_if_target_post_locked, only: [:create] + before_action :check_if_target_post_locked, only: [:create, :create_thread] before_action :check_if_parent_post_locked, only: [:update, :destroy] def create_thread From 0696dff062edbe9864c7e650080d81f52a78109d Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 14:34:00 +0000 Subject: [PATCH 08/30] Remove redundant check for admin (covered by moderator) --- app/views/posts/_expanded.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index a626118b6..3293f5759 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -558,11 +558,11 @@ <% end %> <% if user_signed_in? %> - <% if post.locked? && !moderator? && !admin? %> + <% if post.locked? && !moderator? %>

Comments are disabled on locked posts.

<% elsif post.deleted %>

Comments are disabled on deleted posts.

- <% elsif post.comments_disabled && !moderator? && !admin? %> + <% elsif post.comments_disabled && !moderator? %>

Comments have been disabled on this post.

<% else %> <% if post.locked? %> From a6fe076f91debfec920b67ac6f56066936802242 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 14:43:29 +0000 Subject: [PATCH 09/30] Hide 'Start new comment thread' button when not permitted --- app/views/posts/_expanded.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 3293f5759..10fb7c2b6 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -571,10 +571,12 @@

Comments have been disabled on this post, but as a moderator you are exempt from that block.

<% end %> <% end %> + <% if moderator? || !(post.locked? || post.deleted || post.comments_disabled) %> Start new comment thread <%= render 'comments/new_thread_modal', post: post %> + <% end %> <% end %> From 4ce10027d1ee157469fd58def46bdec876b5ef51 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 15:05:23 +0000 Subject: [PATCH 10/30] Tidy up tangled if blocks to keep like with like --- app/views/posts/_expanded.html.erb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 10fb7c2b6..378ef13a8 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -558,17 +558,23 @@ <% end %> <% if user_signed_in? %> - <% if post.locked? && !moderator? %> -

Comments are disabled on locked posts.

- <% elsif post.deleted %> -

Comments are disabled on deleted posts.

- <% elsif post.comments_disabled && !moderator? %> -

Comments have been disabled on this post.

- <% else %> - <% if post.locked? %> + <% if post.locked? %> + <% if moderator? %>

Comments are disabled on locked posts, but as a moderator you are exempt from that block.

- <% elsif post.comments_disabled %> + <% else %> +

Comments are disabled on locked posts.

+ <% end %> + <% elsif post.deleted %> + <% if moderator? %> +

Comments are disabled on deleted posts, but as a moderator you are exempt from that block.

+ <% else %> +

Comments are disabled on deleted posts.

+ <% end %> + <% elsif post.comments_disabled %> + <% if moderator? %>

Comments have been disabled on this post, but as a moderator you are exempt from that block.

+ <% else %> +

Comments have been disabled on this post.

<% end %> <% end %> <% if moderator? || !(post.locked? || post.deleted || post.comments_disabled) %> From b0bc5bcc84937eea1f5a0a48b98effedd3c8529b Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 6 Mar 2025 16:51:33 +0000 Subject: [PATCH 11/30] Allow moderators to reply to a restricted comment thread --- app/views/comments/thread.html.erb | 75 +++++++++++++++++++----------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/app/views/comments/thread.html.erb b/app/views/comments/thread.html.erb index 98aa32ebd..b66e335b9 100644 --- a/app/views/comments/thread.html.erb +++ b/app/views/comments/thread.html.erb @@ -100,38 +100,57 @@ <% unless current_user.nil? || params[:inline] == 'true' %> <% end %> From 39c31dec09ba1fe590dcad85f7b00e7ee2f584dd Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 20:57:45 +0000 Subject: [PATCH 12/30] Add href to make anchor usable with system tests --- app/views/posts/_expanded.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 378ef13a8..8049fd1b6 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -578,8 +578,8 @@ <% end %> <% end %> <% if moderator? || !(post.locked? || post.deleted || post.comments_disabled) %> - - Start new comment thread + + Start new comment thread <%= render 'comments/new_thread_modal', post: post %> <% end %> From 9a702364eed2f920031dcd0f017fe7a5cd7e7851 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 21:00:28 +0000 Subject: [PATCH 13/30] Add labels to preferences for accessibility and to allow system tests --- app/views/users/_prefs.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/_prefs.html.erb b/app/views/users/_prefs.html.erb index e8a8f7687..170abc5eb 100644 --- a/app/views/users/_prefs.html.erb +++ b/app/views/users/_prefs.html.erb @@ -1,6 +1,6 @@ <% prefs.each do |name, value| %> <% pref_config = AppConfig.preferences[name] %> -
+
+ <% end %> \ No newline at end of file From 0c399280cb5d40f738d5d996a274fb47c47389e6 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 21:07:00 +0000 Subject: [PATCH 14/30] Add system tests for thread following --- test/application_system_test_case.rb | 42 +++++++++++ test/system/thread_test.rb | 102 +++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 test/system/thread_test.rb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index da6f04b00..2d5a177d2 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -100,4 +100,46 @@ def post_form_select_tag(tag_name, create_new = false) 'but could not select it from options without creating a new tag.' end end + + def create_post(body_text, title_text) + click_on 'Create Post' + fill_in 'Body', with: body_text + fill_in 'Summarize your post with a title:', with: title_text + post_form_select_tag tags(:faq).name + + assert_difference 'Post.count' do + click_on 'Save Post in ' + end + end + + def create_thread(comment_body_text, thread_title) + click_on 'Start new comment thread' + fill_in 'Your comment', with: comment_body_text + fill_in 'Comment thread title', with: thread_title + + assert_difference 'Comment.count' do + click_on 'Create thread' + end + end + + def create_comment(comment_body_text) + click_on 'See the whole thread' + fill_in 'Your message', with: comment_body_text + + assert_difference 'Comment.count' do + click_on 'Add reply' + end + end + + def assert_notification(notification_title) + click_on 'Open notifications' + assert_text(notification_title) + click_on 'Open notifications' + end + + def assert_no_notification(notification_title) + click_on 'Open notifications' + assert_no_text(notification_title) + click_on 'Open notifications' + end end diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb new file mode 100644 index 000000000..71d59ed39 --- /dev/null +++ b/test/system/thread_test.rb @@ -0,0 +1,102 @@ +require 'application_system_test_case' + +class ThreadTest < ApplicationSystemTestCase + test 'post author can unfollow and follow new comment threads' do + category = categories(:meta) + log_in :standard_user + visit category_path(category) + create_post('Test body text for testing threads.', 'Test title text for testing threads') + + assert_text 'Unfollow new' + click_on 'Unfollow new' + assert_text 'Follow new' + click_on 'Follow new' + assert_text 'Unfollow new' + end + + test 'other can follow and unfollow new comment threads' do + category = categories(:meta) + log_in :standard_user + visit category_path(category) + post_title_text = 'Test title text for testing threads' + create_post('Test body text for testing threads.', post_title_text) + + log_out + log_in :basic_user + visit category_path(category) + click_on post_title_text + + assert_text 'Follow new' + click_on 'Follow new' + assert_text 'Unfollow new' + click_on 'Unfollow new' + assert_text 'Follow new' + end + + test 'auto follow comment threads tick causes following threads commented in' do + category = categories(:meta) + log_in :basic_user + visit category_path(category) + post_body = 'Test body text for testing threads.' + post_title = 'Test title text for testing threads' + create_post post_body, post_title + thread_body = 'Test comment text for testing adding to a comment thread.' + thread_title = 'Auto followed comment thread' + create_thread thread_body, thread_title + + log_out + log_in :editor + visit category_path(category) + click_on post_title + click_on thread_title + create_comment 'Test comment text for testing adding to a comment thread.' + assert_text 'unfollow' + + log_out + log_in :basic_user + visit category_path(category) + click_on post_title + click_on thread_title + create_comment('Test comment text for testing adding to a comment thread.') + + log_out + log_in :editor + assert_notification "There are new comments in a followed thread '#{thread_title}'" + end + + test 'no auto follow comment threads tick causes not following threads commented in' do + category = categories(:meta) + log_in :basic_user + visit category_path(category) + post_body = 'Test body text for testing threads.' + post_title = 'Test title text for testing threads' + create_post post_body, post_title + thread_body = 'Test comment body text for testing adding to a comment thread.' + thread_title = 'Not auto followed comment thread' + create_thread thread_body, thread_title + + log_out + log_in :editor + click_on 'Manage profile' + click_on 'Preferences' + uncheck 'Auto follow comment threads' + visit category_path(category) + click_on post_title + click_on thread_title + create_comment 'Test comment text for testing adding to a comment thread.' + assert_text 'follow' + + log_out + log_in :basic_user + visit category_path(category) + click_on post_title + click_on thread_title + create_comment 'Test comment text for testing adding to a comment thread.' + + log_out + log_in :editor + assert_no_notification "There are new comments in a followed thread '#{thread_title}'" + end + + +end From df9a153ad3ed2eff0c9e57fcae74eb72f4f92410 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 21:40:51 +0000 Subject: [PATCH 15/30] Remove blank lines for rubocop --- test/system/thread_test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb index 71d59ed39..85a33a97c 100644 --- a/test/system/thread_test.rb +++ b/test/system/thread_test.rb @@ -97,6 +97,4 @@ class ThreadTest < ApplicationSystemTestCase log_in :editor assert_no_notification "There are new comments in a followed thread '#{thread_title}'" end - - end From 9036febfca9d1f8d75218bbd2429e185f16cfd34 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 22:21:38 +0000 Subject: [PATCH 16/30] Make user a follower of their own post to fix test Now that pull request 1548 makes post author notification of new threads part of the standard post following rather than an author-specific special case, the author needs to be a follower of the post in the test fixtures to prevent a test failing. The test is: test/controllers/comments_controller_test.rb 'Should create new thread' Line 18 --- test/fixtures/thread_followers.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/fixtures/thread_followers.yml b/test/fixtures/thread_followers.yml index 893c177d7..9ccb0f991 100644 --- a/test/fixtures/thread_followers.yml +++ b/test/fixtures/thread_followers.yml @@ -5,3 +5,7 @@ deleter_normal: standard_author_normal: user: standard_user comment_thread: normal + +standard_author_question_one: + user: standard_user + post: question_one \ No newline at end of file From 587644ffdaba85f88799e2bfd18e7bea7f465ab5 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 22:52:20 +0000 Subject: [PATCH 17/30] Add user to avoid confusing filter behaviour in tests --- test/fixtures/community_users.yml | 7 +++++++ test/fixtures/filters.yml | 4 ++-- test/fixtures/users.yml | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/fixtures/community_users.yml b/test/fixtures/community_users.yml index 4d7ac6963..3731b7561 100644 --- a/test/fixtures/community_users.yml +++ b/test/fixtures/community_users.yml @@ -77,3 +77,10 @@ sample_deleted_profile: deleted: true deleted_at: 2020-01-02T00:00:00.000000Z deleted_by: global_admin + +sample_filters_user: + user: filters_user + community: sample + is_admin: false + is_moderator: false + reputation: 50 diff --git a/test/fixtures/filters.yml b/test/fixtures/filters.yml index f47aa1e31..2dbf4b71d 100644 --- a/test/fixtures/filters.yml +++ b/test/fixtures/filters.yml @@ -2,7 +2,7 @@ one: name: MyFilterOne - user: standard_user + user: filters_user min_score: 1.5 max_score: 1.5 min_answers: 1 @@ -11,7 +11,7 @@ one: two: name: MyFilterTwo - user: standard_user + user: filters_user min_score: 1.5 max_score: 1.5 min_answers: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 82cd00ba7..a9203475c 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -138,3 +138,12 @@ enabled_2fa: enabled_2fa: true two_factor_token: WT65ANYXBB2SBR7III7IVWNJDS4PQF2T backup_2fa_code: M8lENyehyCvo9F9MbyTl1aOL + +filters_user: + email: filters@qpixel-test.net + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' + sign_in_count: 1337 + username: filters_user + is_global_admin: false + is_global_moderator: false + confirmed_at: 2020-01-01T00:00:00.000000Z From 2809664cd6c2634832524aada999ecbb0aca33cb Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 22:57:40 +0000 Subject: [PATCH 18/30] Use standard user for tests now that filters are removed --- test/system/thread_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb index 85a33a97c..e320fdf29 100644 --- a/test/system/thread_test.rb +++ b/test/system/thread_test.rb @@ -35,7 +35,7 @@ class ThreadTest < ApplicationSystemTestCase test 'auto follow comment threads tick causes following threads commented in' do category = categories(:meta) - log_in :basic_user + log_in :standard_user visit category_path(category) post_body = 'Test body text for testing threads.' post_title = 'Test title text for testing threads' @@ -45,7 +45,7 @@ class ThreadTest < ApplicationSystemTestCase create_thread thread_body, thread_title log_out - log_in :editor + log_in :basic_user visit category_path(category) click_on post_title click_on thread_title @@ -53,20 +53,20 @@ class ThreadTest < ApplicationSystemTestCase assert_text 'unfollow' log_out - log_in :basic_user + log_in :standard_user visit category_path(category) click_on post_title click_on thread_title create_comment('Test comment text for testing adding to a comment thread.') log_out - log_in :editor + log_in :basic_user assert_notification "There are new comments in a followed thread '#{thread_title}'" end test 'no auto follow comment threads tick causes not following threads commented in' do category = categories(:meta) - log_in :basic_user + log_in :standard_user visit category_path(category) post_body = 'Test body text for testing threads.' post_title = 'Test title text for testing threads' @@ -76,7 +76,7 @@ class ThreadTest < ApplicationSystemTestCase create_thread thread_body, thread_title log_out - log_in :editor + log_in :basic_user click_on 'Manage profile' click_on 'Preferences' uncheck 'Auto follow comment threads' @@ -87,14 +87,14 @@ class ThreadTest < ApplicationSystemTestCase assert_text 'follow' log_out - log_in :basic_user + log_in :standard_user visit category_path(category) click_on post_title click_on thread_title create_comment 'Test comment text for testing adding to a comment thread.' log_out - log_in :editor + log_in :basic_user assert_no_notification "There are new comments in a followed thread '#{thread_title}'" end end From 920deaa08a72a135219d7e946357d843170bc8ca Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 22 Mar 2025 23:15:56 +0000 Subject: [PATCH 19/30] Reassign overlooked filter defaults to filters_user for tests --- test/fixtures/category_filter_defaults.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/category_filter_defaults.yml b/test/fixtures/category_filter_defaults.yml index 697b14ee7..a9e59518d 100644 --- a/test/fixtures/category_filter_defaults.yml +++ b/test/fixtures/category_filter_defaults.yml @@ -1,11 +1,11 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html main_default_filter: - user: standard_user + user: filters_user filter: one category: main meta_default_filter: - user: standard_user + user: filters_user filter: one category: meta From a907b16927e3050da09cc932e76c751c1f7218f4 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sun, 23 Mar 2025 14:24:56 +0000 Subject: [PATCH 20/30] Add asserts to see if it lets CI system tests pass --- test/system/thread_test.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb index e320fdf29..ee76d7deb 100644 --- a/test/system/thread_test.rb +++ b/test/system/thread_test.rb @@ -18,13 +18,14 @@ class ThreadTest < ApplicationSystemTestCase category = categories(:meta) log_in :standard_user visit category_path(category) - post_title_text = 'Test title text for testing threads' - create_post('Test body text for testing threads.', post_title_text) + post_title = 'Test title text for testing threads' + create_post('Test body text for testing threads.', post_title) log_out log_in :basic_user visit category_path(category) - click_on post_title_text + assert_text post_title + click_on post_title assert_text 'Follow new' click_on 'Follow new' @@ -47,6 +48,7 @@ class ThreadTest < ApplicationSystemTestCase log_out log_in :basic_user visit category_path(category) + assert_text post_title click_on post_title click_on thread_title create_comment 'Test comment text for testing adding to a comment thread.' @@ -81,6 +83,7 @@ class ThreadTest < ApplicationSystemTestCase click_on 'Preferences' uncheck 'Auto follow comment threads' visit category_path(category) + assert_text post_title click_on post_title click_on thread_title create_comment 'Test comment text for testing adding to a comment thread.' From 9d418a851f806e4c4e1cb895690b15e914543588 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sun, 23 Mar 2025 16:04:47 +0000 Subject: [PATCH 21/30] Attempt to fix system test timing problem --- test/system/thread_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb index ee76d7deb..6e1507e56 100644 --- a/test/system/thread_test.rb +++ b/test/system/thread_test.rb @@ -20,11 +20,11 @@ class ThreadTest < ApplicationSystemTestCase visit category_path(category) post_title = 'Test title text for testing threads' create_post('Test body text for testing threads.', post_title) + assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems log_out log_in :basic_user visit category_path(category) - assert_text post_title click_on post_title assert_text 'Follow new' @@ -41,6 +41,7 @@ class ThreadTest < ApplicationSystemTestCase post_body = 'Test body text for testing threads.' post_title = 'Test title text for testing threads' create_post post_body, post_title + assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems thread_body = 'Test comment text for testing adding to a comment thread.' thread_title = 'Auto followed comment thread' create_thread thread_body, thread_title @@ -48,7 +49,6 @@ class ThreadTest < ApplicationSystemTestCase log_out log_in :basic_user visit category_path(category) - assert_text post_title click_on post_title click_on thread_title create_comment 'Test comment text for testing adding to a comment thread.' @@ -73,6 +73,7 @@ class ThreadTest < ApplicationSystemTestCase post_body = 'Test body text for testing threads.' post_title = 'Test title text for testing threads' create_post post_body, post_title + assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems thread_body = 'Test comment body text for testing adding to a comment thread.' thread_title = 'Not auto followed comment thread' create_thread thread_body, thread_title @@ -83,7 +84,6 @@ class ThreadTest < ApplicationSystemTestCase click_on 'Preferences' uncheck 'Auto follow comment threads' visit category_path(category) - assert_text post_title click_on post_title click_on thread_title create_comment 'Test comment text for testing adding to a comment thread.' From 3c15525398f1f84d4f9e830693df3c62803afbce Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sun, 23 Mar 2025 21:57:56 +0000 Subject: [PATCH 22/30] Add temporary system tests to analyse CI failures --- test/system/thread_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb index 6e1507e56..c23e716d7 100644 --- a/test/system/thread_test.rb +++ b/test/system/thread_test.rb @@ -100,4 +100,32 @@ class ThreadTest < ApplicationSystemTestCase log_in :basic_user assert_no_notification "There are new comments in a followed thread '#{thread_title}'" end + + test 'temporary test to analyse CI failures what does basic user see in main' do + category = categories(:main) + log_in :basic_user + visit category_path(category) + assert_text 'Nonexistent to force screenshot' + end + + test 'temporary test to analyse CI failures what does standard user see in main' do + category = categories(:main) + log_in :standard_user + visit category_path(category) + assert_text 'Nonexistent to force screenshot' + end + + test 'temporary test to analyse CI failures what does standard user see after adding post to meta' do + category = categories(:meta) + log_in :standard_user + visit category_path(category) + post_title = 'Test title text for testing threads' + create_post('Test body text for testing threads.', post_title) + assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems + + log_out + log_in :standard_user + visit category_path(category) + assert_text 'Nonexistent to force screenshot' + end end From 56e042a36a84e7c826de29732eea95e546fd2406 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 13 Jun 2025 20:46:14 +0100 Subject: [PATCH 23/30] Add missing parentheses for Rubocop --- test/application_system_test_case.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 484438784..49efdac4f 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -105,9 +105,9 @@ def create_post(body_text, title_text) click_on 'Create Post' fill_in 'Body', with: body_text fill_in 'Summarize your post with a title:', with: title_text - post_form_select_tag tags(:faq).name + post_form_select_tag(tags(:faq).name) - assert_difference 'Post.count' do + assert_difference('Post.count') do click_on 'Save Post in ' end end @@ -117,7 +117,7 @@ def create_thread(comment_body_text, thread_title) fill_in 'Your comment', with: comment_body_text fill_in 'Comment thread title', with: thread_title - assert_difference 'Comment.count' do + assert_difference('Comment.count') do click_on 'Create thread' end end @@ -126,7 +126,7 @@ def create_comment(comment_body_text) click_on 'See the whole thread' fill_in 'Your message', with: comment_body_text - assert_difference 'Comment.count' do + assert_difference('Comment.count') do click_on 'Add reply' end end From 812260fc8eca5404fa0b67ababe3e164f83bbaa1 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 13 Jun 2025 20:55:37 +0100 Subject: [PATCH 24/30] Improve notes to moderators on read only threads --- app/views/comments/thread.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/comments/thread.html.erb b/app/views/comments/thread.html.erb index 595f6e436..b1329bf50 100644 --- a/app/views/comments/thread.html.erb +++ b/app/views/comments/thread.html.erb @@ -104,19 +104,19 @@ <% if standard? %> <%= render 'shared/lock_notice', level: 'info', text: 'You cannot reply to this thread because it has been deleted.' %> <% else %> - <%= render 'shared/lock_notice', text: 'You cannot reply to this thread because it has been deleted, but as a moderator you are exempt from that block.' %> + <%= render 'shared/lock_notice', text: 'Replies are disabled on deleted threads, but as a moderator you are exempt from that block.' %> <% end %> <% elsif @comment_thread.locked? %> <% if standard? %> <%= render 'shared/lock_notice', level: 'info', text: 'You cannot reply to this thread because it has been locked.' %> <% else %> - <%= render 'shared/lock_notice', text: 'You cannot reply to this thread because it has been locked, but as a moderator you are exempt from that block.' %> + <%= render 'shared/lock_notice', text: 'Replies are disabled on locked threads, but as a moderator you are exempt from that block.' %> <% end %> <% elsif @comment_thread.archived %> <% if standard? %> <%= render 'shared/lock_notice', level: 'info', text: 'This thread has been archived and cannot be replied to.' %> <% else %> - <%= render 'shared/lock_notice', text: 'This thread has been archived and cannot be replied to, but as a moderator you are exempt from that block.' %> + <%= render 'shared/lock_notice', text: 'Replies are disabled on archived threads, but as a moderator you are exempt from that block.' %> <% end %> <% elsif @post.locked? %> <% if standard? %> From e098fafaded16acff8d57da54f3cf94c7e8b43e2 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Sat, 19 Jul 2025 01:51:34 +0100 Subject: [PATCH 25/30] Add Participate ability for newly added fixture user --- test/fixtures/user_abilities.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/fixtures/user_abilities.yml b/test/fixtures/user_abilities.yml index efbaaf83e..11e10c443 100644 --- a/test/fixtures/user_abilities.yml +++ b/test/fixtures/user_abilities.yml @@ -57,3 +57,7 @@ d_et: b_eo: community_user: sample_basic_user ability: everyone + +f_eo: + community_user: sample_filters_user + ability: everyone From 36b7eec2eaa34c4e5c2d965ce2a5ca690d8d9f22 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Thu, 24 Jul 2025 13:45:26 +0100 Subject: [PATCH 26/30] Add Participate Everywhere ability for new filters user to fix test --- test/fixtures/user_abilities.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/fixtures/user_abilities.yml b/test/fixtures/user_abilities.yml index 11e10c443..147009854 100644 --- a/test/fixtures/user_abilities.yml +++ b/test/fixtures/user_abilities.yml @@ -61,3 +61,7 @@ b_eo: f_eo: community_user: sample_filters_user ability: everyone + +f_ur: + community_user: sample_filters_user + ability: unrestricted From abc5505182d9c45d2b6d01009f8a67ddc3535c62 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 15 Aug 2025 11:56:33 +0100 Subject: [PATCH 27/30] Remove attempts at system tests until underlying problems are fixed --- test/application_system_test_case.rb | 43 ------- test/fixtures/category_filter_defaults.yml | 4 +- test/fixtures/community_users.yml | 7 -- test/fixtures/filters.yml | 4 +- test/fixtures/thread_followers.yml | 2 +- test/fixtures/user_abilities.yml | 8 -- test/fixtures/users.yml | 9 -- test/system/thread_test.rb | 131 --------------------- 8 files changed, 5 insertions(+), 203 deletions(-) delete mode 100644 test/system/thread_test.rb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 2ba92991e..d9ab729b4 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -97,46 +97,3 @@ def post_form_select_tag(tag_name, create_new = false) 'but could not select it from options without creating a new tag.' end end - - def create_post(body_text, title_text) - click_on 'Create Post' - fill_in 'Body', with: body_text - fill_in 'Summarize your post with a title:', with: title_text - post_form_select_tag(tags(:faq).name) - - assert_difference('Post.count') do - click_on 'Save Post in ' - end - end - - def create_thread(comment_body_text, thread_title) - click_on 'Start new comment thread' - fill_in 'Your comment', with: comment_body_text - fill_in 'Comment thread title', with: thread_title - - assert_difference('Comment.count') do - click_on 'Create thread' - end - end - - def create_comment(comment_body_text) - click_on 'See the whole thread' - fill_in 'Your message', with: comment_body_text - - assert_difference('Comment.count') do - click_on 'Add reply' - end - end - - def assert_notification(notification_title) - click_on 'Open notifications' - assert_text(notification_title) - click_on 'Open notifications' - end - - def assert_no_notification(notification_title) - click_on 'Open notifications' - assert_no_text(notification_title) - click_on 'Open notifications' - end -end diff --git a/test/fixtures/category_filter_defaults.yml b/test/fixtures/category_filter_defaults.yml index a9e59518d..697b14ee7 100644 --- a/test/fixtures/category_filter_defaults.yml +++ b/test/fixtures/category_filter_defaults.yml @@ -1,11 +1,11 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html main_default_filter: - user: filters_user + user: standard_user filter: one category: main meta_default_filter: - user: filters_user + user: standard_user filter: one category: meta diff --git a/test/fixtures/community_users.yml b/test/fixtures/community_users.yml index e484e3037..727e850f4 100644 --- a/test/fixtures/community_users.yml +++ b/test/fixtures/community_users.yml @@ -105,10 +105,3 @@ sample_spammer: is_admin: false is_moderator: false reputation: 1 - -sample_filters_user: - user: filters_user - community: sample - is_admin: false - is_moderator: false - reputation: 50 diff --git a/test/fixtures/filters.yml b/test/fixtures/filters.yml index 2dbf4b71d..f47aa1e31 100644 --- a/test/fixtures/filters.yml +++ b/test/fixtures/filters.yml @@ -2,7 +2,7 @@ one: name: MyFilterOne - user: filters_user + user: standard_user min_score: 1.5 max_score: 1.5 min_answers: 1 @@ -11,7 +11,7 @@ one: two: name: MyFilterTwo - user: filters_user + user: standard_user min_score: 1.5 max_score: 1.5 min_answers: 1 diff --git a/test/fixtures/thread_followers.yml b/test/fixtures/thread_followers.yml index 9ccb0f991..b51e03b64 100644 --- a/test/fixtures/thread_followers.yml +++ b/test/fixtures/thread_followers.yml @@ -8,4 +8,4 @@ standard_author_normal: standard_author_question_one: user: standard_user - post: question_one \ No newline at end of file + post: question_one diff --git a/test/fixtures/user_abilities.yml b/test/fixtures/user_abilities.yml index 6b9737d59..0b6c586d4 100644 --- a/test/fixtures/user_abilities.yml +++ b/test/fixtures/user_abilities.yml @@ -80,11 +80,3 @@ sp_eo: sp_ur: community_user: sample_spammer ability: unrestricted - -f_eo: - community_user: sample_filters_user - ability: everyone - -f_ur: - community_user: sample_filters_user - ability: unrestricted diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 81ddbd9cc..4f20ce3dc 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -163,12 +163,3 @@ spammer: is_global_admin: false is_global_moderator: false confirmed_at: 2020-01-01T00:00:00.000000Z - -filters_user: - email: filters@qpixel-test.net - encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' - sign_in_count: 1337 - username: filters_user - is_global_admin: false - is_global_moderator: false - confirmed_at: 2020-01-01T00:00:00.000000Z diff --git a/test/system/thread_test.rb b/test/system/thread_test.rb deleted file mode 100644 index c23e716d7..000000000 --- a/test/system/thread_test.rb +++ /dev/null @@ -1,131 +0,0 @@ -require 'application_system_test_case' - -class ThreadTest < ApplicationSystemTestCase - test 'post author can unfollow and follow new comment threads' do - category = categories(:meta) - log_in :standard_user - visit category_path(category) - create_post('Test body text for testing threads.', 'Test title text for testing threads') - - assert_text 'Unfollow new' - click_on 'Unfollow new' - assert_text 'Follow new' - click_on 'Follow new' - assert_text 'Unfollow new' - end - - test 'other can follow and unfollow new comment threads' do - category = categories(:meta) - log_in :standard_user - visit category_path(category) - post_title = 'Test title text for testing threads' - create_post('Test body text for testing threads.', post_title) - assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems - - log_out - log_in :basic_user - visit category_path(category) - click_on post_title - - assert_text 'Follow new' - click_on 'Follow new' - assert_text 'Unfollow new' - click_on 'Unfollow new' - assert_text 'Follow new' - end - - test 'auto follow comment threads tick causes following threads commented in' do - category = categories(:meta) - log_in :standard_user - visit category_path(category) - post_body = 'Test body text for testing threads.' - post_title = 'Test title text for testing threads' - create_post post_body, post_title - assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems - thread_body = 'Test comment text for testing adding to a comment thread.' - thread_title = 'Auto followed comment thread' - create_thread thread_body, thread_title - - log_out - log_in :basic_user - visit category_path(category) - click_on post_title - click_on thread_title - create_comment 'Test comment text for testing adding to a comment thread.' - assert_text 'unfollow' - - log_out - log_in :standard_user - visit category_path(category) - click_on post_title - click_on thread_title - create_comment('Test comment text for testing adding to a comment thread.') - - log_out - log_in :basic_user - assert_notification "There are new comments in a followed thread '#{thread_title}'" - end - - test 'no auto follow comment threads tick causes not following threads commented in' do - category = categories(:meta) - log_in :standard_user - visit category_path(category) - post_body = 'Test body text for testing threads.' - post_title = 'Test title text for testing threads' - create_post post_body, post_title - assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems - thread_body = 'Test comment body text for testing adding to a comment thread.' - thread_title = 'Not auto followed comment thread' - create_thread thread_body, thread_title - - log_out - log_in :basic_user - click_on 'Manage profile' - click_on 'Preferences' - uncheck 'Auto follow comment threads' - visit category_path(category) - click_on post_title - click_on thread_title - create_comment 'Test comment text for testing adding to a comment thread.' - assert_text 'follow' - - log_out - log_in :standard_user - visit category_path(category) - click_on post_title - click_on thread_title - create_comment 'Test comment text for testing adding to a comment thread.' - - log_out - log_in :basic_user - assert_no_notification "There are new comments in a followed thread '#{thread_title}'" - end - - test 'temporary test to analyse CI failures what does basic user see in main' do - category = categories(:main) - log_in :basic_user - visit category_path(category) - assert_text 'Nonexistent to force screenshot' - end - - test 'temporary test to analyse CI failures what does standard user see in main' do - category = categories(:main) - log_in :standard_user - visit category_path(category) - assert_text 'Nonexistent to force screenshot' - end - - test 'temporary test to analyse CI failures what does standard user see after adding post to meta' do - category = categories(:meta) - log_in :standard_user - visit category_path(category) - post_title = 'Test title text for testing threads' - create_post('Test body text for testing threads.', post_title) - assert_text 'Unfollow new' # Ensure post has finished saving to avoid timing problems - - log_out - log_in :standard_user - visit category_path(category) - assert_text 'Nonexistent to force screenshot' - end -end From 229efcb6bacfe0a67e878e810a190d3e7fc65718 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 15 Aug 2025 12:02:00 +0100 Subject: [PATCH 28/30] Replace accidentally removed end from test class --- test/application_system_test_case.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d9ab729b4..73a444150 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -97,3 +97,4 @@ def post_form_select_tag(tag_name, create_new = false) 'but could not select it from options without creating a new tag.' end end +end From 506e82b436bf782a0070662d5f152d8038584ac3 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 15 Aug 2025 13:59:40 +0100 Subject: [PATCH 29/30] Remove unnecessary change in otherwise untouched file --- app/views/comments/thread.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/comments/thread.html.erb b/app/views/comments/thread.html.erb index ffeddcf7b..2c5ea8406 100644 --- a/app/views/comments/thread.html.erb +++ b/app/views/comments/thread.html.erb @@ -31,3 +31,4 @@ show_deleted: params[:show_deleted_comments] == '1', thread: @comment_thread %> + From 7846110840e71b2cbf38791a0f3e329e8ca20181 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Mon, 18 Aug 2025 21:40:43 +0100 Subject: [PATCH 30/30] Add tests after removing thread following special case for post author --- test/controllers/comments/post_follow_test.rb | 21 +++++++++++++++++++ test/controllers/posts/create_test.rb | 10 +++++++++ 2 files changed, 31 insertions(+) diff --git a/test/controllers/comments/post_follow_test.rb b/test/controllers/comments/post_follow_test.rb index 2547d6114..48f07791a 100644 --- a/test/controllers/comments/post_follow_test.rb +++ b/test/controllers/comments/post_follow_test.rb @@ -49,4 +49,25 @@ class CommentsControllerTest < ActionController::TestCase # Assert user still only follows post once assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count end + + test 'post author can unfollow post then follow' do + user = users(:standard_user) + sign_in user + question = posts(:question_one) + + # Assert user follows post + assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count + + try_post_unfollow(question) + assert_response(:found) + + # Assert user does not follow post + assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count + + try_post_follow(question) + assert_response(:found) + + # Assert user follows post + assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count + end end diff --git a/test/controllers/posts/create_test.rb b/test/controllers/posts/create_test.rb index 255f50742..0cb3cb4d7 100644 --- a/test/controllers/posts/create_test.rb +++ b/test/controllers/posts/create_test.rb @@ -118,6 +118,16 @@ class PostsControllerTest < ActionController::TestCase assert_redirected_to_sign_in end + test 'should make post author a thread follower of the post' do + user = users(:standard_user) + sign_in user + try_create_post + assert_response(:found) + + # Assert user follows post + assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', assigns(:post), user]).count + end + private # Attempts to create a post