From 74e15cb8459033713e0d985ecc3b192cf8067bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Thu, 22 Feb 2024 16:51:15 +0100 Subject: [PATCH] DEV: Fix new Rubocop offenses --- Gemfile.lock | 40 ++++++++++++++++--- .../list_controller_extension.rb | 6 +-- lib/discourse_assign/post_extension.rb | 6 +-- lib/discourse_assign/topic_extension.rb | 6 +-- lib/discourse_assign/web_hook_extension.rb | 11 ++--- spec/components/topic_query_spec.rb | 2 +- spec/components/topics_bulk_action_spec.rb | 2 +- spec/integration/assign_spec.rb | 6 +-- .../regular/unassign_notification_spec.rb | 4 +- spec/lib/topic_query_spec.rb | 6 +-- spec/models/reviewable_spec.rb | 4 +- spec/requests/assign_controller_spec.rb | 6 +-- spec/requests/search_controller_spec.rb | 2 +- .../flagged_topic_serializer_spec.rb | 2 +- .../serializers/group_show_serializer_spec.rb | 4 +- spec/serializers/post_serializer_spec.rb | 4 +- .../suggested_topic_serializer_spec.rb | 4 +- .../serializers/topic_list_serializer_spec.rb | 2 +- .../serializers/topic_view_serializer_spec.rb | 4 +- .../user_bookmark_base_serializer_spec.rb | 4 +- spec/system/assign_topic_spec.rb | 4 +- spec/system/user_menu_spec.rb | 2 +- 22 files changed, 80 insertions(+), 51 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 23ad67df..1e1370c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,60 @@ GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.6) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + drb (2.2.0) + ruby2_keywords + i18n (1.14.1) + concurrent-ruby (~> 1.0) json (2.7.1) language_server-protocol (3.17.0.3) + minitest (5.22.2) + mutex_m (0.2.0) parallel (1.24.0) - parser (3.3.0.3) + parser (3.3.0.5) ast (~> 2.4.1) racc prettier_print (1.2.1) + prism (0.24.0) racc (1.7.3) rainbow (3.1.1) regexp_parser (2.9.0) rexml (3.2.6) - rubocop (1.59.0) + rubocop (1.61.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.0) + parser (>= 3.3.0.4) + prism (>= 0.24.0) rubocop-capybara (2.20.0) rubocop (~> 1.41) - rubocop-discourse (3.6.0) + rubocop-discourse (3.7.1) + activesupport (>= 6.1) rubocop (>= 1.59.0) + rubocop-capybara (>= 2.0.0) + rubocop-factory_bot (>= 2.0.0) rubocop-rspec (>= 2.25.0) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) @@ -38,8 +63,11 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) syntax_tree (6.2.0) prettier_print (>= 1.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) PLATFORMS diff --git a/lib/discourse_assign/list_controller_extension.rb b/lib/discourse_assign/list_controller_extension.rb index 34b9c04e..88908aa8 100644 --- a/lib/discourse_assign/list_controller_extension.rb +++ b/lib/discourse_assign/list_controller_extension.rb @@ -2,8 +2,8 @@ module DiscourseAssign module ListControllerExtension - def self.prepended(base) - base.class_eval { ListController.generate_message_route(:private_messages_assigned) } - end + extend ActiveSupport::Concern + + prepended { generate_message_route(:private_messages_assigned) } end end diff --git a/lib/discourse_assign/post_extension.rb b/lib/discourse_assign/post_extension.rb index c6c8ab60..014b1a86 100644 --- a/lib/discourse_assign/post_extension.rb +++ b/lib/discourse_assign/post_extension.rb @@ -2,8 +2,8 @@ module DiscourseAssign module PostExtension - def self.prepended(base) - base.class_eval { has_one :assignment, as: :target, dependent: :destroy } - end + extend ActiveSupport::Concern + + prepended { has_one :assignment, as: :target, dependent: :destroy } end end diff --git a/lib/discourse_assign/topic_extension.rb b/lib/discourse_assign/topic_extension.rb index 5c6c60be..6221eeac 100644 --- a/lib/discourse_assign/topic_extension.rb +++ b/lib/discourse_assign/topic_extension.rb @@ -2,8 +2,8 @@ module DiscourseAssign module TopicExtension - def self.prepended(base) - base.class_eval { has_one :assignment, as: :target, dependent: :destroy } - end + extend ActiveSupport::Concern + + prepended { has_one :assignment, as: :target, dependent: :destroy } end end diff --git a/lib/discourse_assign/web_hook_extension.rb b/lib/discourse_assign/web_hook_extension.rb index b80f4cf1..377c11a1 100644 --- a/lib/discourse_assign/web_hook_extension.rb +++ b/lib/discourse_assign/web_hook_extension.rb @@ -2,11 +2,12 @@ module DiscourseAssign module WebHookExtension - def self.prepended(base) - base.class_eval do - def self.enqueue_assign_hooks(event, payload) - WebHook.enqueue_hooks(:assign, event, payload: payload) if active_web_hooks(event).exists? - end + extend ActiveSupport::Concern + + class_methods do + def enqueue_assign_hooks(event, payload) + return unless active_web_hooks(event).exists? + enqueue_hooks(:assign, event, payload: payload) end end end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 264792b1..7ce0690c 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -6,7 +6,7 @@ describe TopicQuery do before { SiteSetting.assign_enabled = true } - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:user2) { Fabricate(:user) } fab!(:user3) { Fabricate(:user) } fab!(:user4) { Fabricate(:user) } diff --git a/spec/components/topics_bulk_action_spec.rb b/spec/components/topics_bulk_action_spec.rb index 84dd2995..2df3bcc6 100644 --- a/spec/components/topics_bulk_action_spec.rb +++ b/spec/components/topics_bulk_action_spec.rb @@ -4,7 +4,7 @@ require_relative "../support/assign_allowed_group" describe TopicsBulkAction do - fab!(:post) { Fabricate(:post) } + fab!(:post) fab!(:post1) { Fabricate(:post) } fab!(:post2) { Fabricate(:post) } diff --git a/spec/integration/assign_spec.rb b/spec/integration/assign_spec.rb index 6865d749..327d3e5b 100644 --- a/spec/integration/assign_spec.rb +++ b/spec/integration/assign_spec.rb @@ -142,10 +142,10 @@ def assert_publish_topic_state(topic, user: nil, group: nil) end context "when already assigned" do - fab!(:post) { Fabricate(:post) } + fab!(:post) fab!(:post_2) { Fabricate(:post, topic: post.topic) } let(:topic) { post.topic } - fab!(:user) { Fabricate(:user) } + fab!(:user) include_context "with group that is allowed to assign" @@ -170,7 +170,7 @@ def assert_publish_topic_state(topic, user: nil, group: nil) describe "move post" do fab!(:old_topic) { Fabricate(:topic) } fab!(:post) { Fabricate(:post, topic: old_topic) } - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:assignment) do Assignment.create!( target_id: post.id, diff --git a/spec/jobs/regular/unassign_notification_spec.rb b/spec/jobs/regular/unassign_notification_spec.rb index 352a1001..9d7f4ff8 100644 --- a/spec/jobs/regular/unassign_notification_spec.rb +++ b/spec/jobs/regular/unassign_notification_spec.rb @@ -6,7 +6,7 @@ describe "#execute" do fab!(:user1) { Fabricate(:user) } fab!(:user2) { Fabricate(:user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } fab!(:pm_post) { Fabricate(:private_message_post) } fab!(:pm) { pm_post.topic } @@ -61,7 +61,7 @@ def assert_publish_topic_state(topic, user) describe "Group" do fab!(:assign_allowed_group) { Group.find_by(name: "staff") } fab!(:user3) { Fabricate(:user) } - fab!(:group) { Fabricate(:group) } + fab!(:group) fab!(:assignment) do Fabricate(:topic_assignment, topic: topic, assigned_to: group, assigned_by_user: user1) end diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rb index 0ff0a42e..4c152285 100644 --- a/spec/lib/topic_query_spec.rb +++ b/spec/lib/topic_query_spec.rb @@ -3,15 +3,15 @@ require "topic_view" describe TopicQuery do - fab!(:user) { Fabricate(:user) } - fab!(:admin) { Fabricate(:admin) } + fab!(:user) + fab!(:admin) fab!(:other_admin) { Fabricate(:admin) } fab!(:user_pm) { Fabricate(:private_message_topic, user: user) } fab!(:admin_pm) { Fabricate(:private_message_topic, user: admin) } fab!(:other_admin_pm) { Fabricate(:private_message_topic, user: other_admin) } - fab!(:group) { Fabricate(:group) } + fab!(:group) describe "#list_group_topics_assigned" do before do diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb index 3c944a52..59eed8b4 100644 --- a/spec/models/reviewable_spec.rb +++ b/spec/models/reviewable_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true describe Reviewable do - fab!(:user) { Fabricate(:user) } - fab!(:admin) { Fabricate(:admin) } + fab!(:user) + fab!(:admin) fab!(:post1) { Fabricate(:post) } fab!(:post2) { Fabricate(:post) } fab!(:reviewable1) { Fabricate(:reviewable_flagged_post, target: post1) } diff --git a/spec/requests/assign_controller_spec.rb b/spec/requests/assign_controller_spec.rb index 5b938b2c..d7704414 100644 --- a/spec/requests/assign_controller_spec.rb +++ b/spec/requests/assign_controller_spec.rb @@ -13,12 +13,12 @@ fab!(:non_allowed_group) { Fabricate(:group) } fab!(:allowed_group) { Fabricate(:group) } - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) fab!(:allowed_user) { Fabricate(:user, username: "mads", name: "Mads", groups: [allowed_group]) } fab!(:non_admin_staff) { Fabricate(:user, groups: [staff_group]) } fab!(:user_in_non_allowed_group) { Fabricate(:user, groups: [non_allowed_group]) } - fab!(:post) { Fabricate(:post) } + fab!(:post) describe "only allow users from allowed groups to assign" do it "filters requests where current_user is not member of an allowed group" do @@ -339,7 +339,7 @@ def assign_user_to_post describe "#group_members" do fab!(:other_allowed_user) { Fabricate(:user, groups: [allowed_group]) } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post_in_same_topic) { Fabricate(:post, topic: topic) } fab!(:assignments) do diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rb index 4e4e3b61..af81de65 100644 --- a/spec/requests/search_controller_spec.rb +++ b/spec/requests/search_controller_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe SearchController do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) fab!(:group) do Fabricate( :group, diff --git a/spec/serializers/flagged_topic_serializer_spec.rb b/spec/serializers/flagged_topic_serializer_spec.rb index 1611f637..d598f274 100644 --- a/spec/serializers/flagged_topic_serializer_spec.rb +++ b/spec/serializers/flagged_topic_serializer_spec.rb @@ -4,7 +4,7 @@ require_relative "../support/assign_allowed_group" describe FlaggedTopicSerializer do - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:guardian) { Guardian.new(user) } include_context "with group that is allowed to assign" diff --git a/spec/serializers/group_show_serializer_spec.rb b/spec/serializers/group_show_serializer_spec.rb index f8153232..68793e1b 100644 --- a/spec/serializers/group_show_serializer_spec.rb +++ b/spec/serializers/group_show_serializer_spec.rb @@ -3,10 +3,10 @@ require "rails_helper" RSpec.describe GroupShowSerializer do - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:group) { Fabricate(:group, assignable_level: Group::ALIAS_LEVELS[:everyone]) } fab!(:group_user) { Fabricate(:group_user, group: group, user: user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } fab!(:topic2) { Fabricate(:topic) } fab!(:post2) { Fabricate(:post, topic: topic2) } diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index d5b63843..4aef4140 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -4,8 +4,8 @@ require_relative "../support/assign_allowed_group" describe PostSerializer do - fab!(:user) { Fabricate(:user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:user) + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } let(:guardian) { Guardian.new(user) } diff --git a/spec/serializers/suggested_topic_serializer_spec.rb b/spec/serializers/suggested_topic_serializer_spec.rb index e43d2983..c185b567 100644 --- a/spec/serializers/suggested_topic_serializer_spec.rb +++ b/spec/serializers/suggested_topic_serializer_spec.rb @@ -3,10 +3,10 @@ require "rails_helper" RSpec.describe SuggestedTopicSerializer do - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:group) { Fabricate(:group, assignable_level: Group::ALIAS_LEVELS[:everyone]) } fab!(:group_user) { Fabricate(:group_user, group: group, user: user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } fab!(:topic2) { Fabricate(:topic) } fab!(:post2) { Fabricate(:post, topic: topic2) } diff --git a/spec/serializers/topic_list_serializer_spec.rb b/spec/serializers/topic_list_serializer_spec.rb index b3e34cdc..25373277 100644 --- a/spec/serializers/topic_list_serializer_spec.rb +++ b/spec/serializers/topic_list_serializer_spec.rb @@ -4,7 +4,7 @@ require_relative "../support/assign_allowed_group" RSpec.describe TopicListSerializer do - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:private_message_topic) do topic = diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb index c9e050b1..6669e121 100644 --- a/spec/serializers/topic_view_serializer_spec.rb +++ b/spec/serializers/topic_view_serializer_spec.rb @@ -4,8 +4,8 @@ require_relative "../support/assign_allowed_group" RSpec.describe TopicViewSerializer do - fab!(:user) { Fabricate(:user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:user) + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } let(:guardian) { Guardian.new(user) } diff --git a/spec/serializers/user_bookmark_base_serializer_spec.rb b/spec/serializers/user_bookmark_base_serializer_spec.rb index c502a575..56e09e33 100644 --- a/spec/serializers/user_bookmark_base_serializer_spec.rb +++ b/spec/serializers/user_bookmark_base_serializer_spec.rb @@ -11,8 +11,8 @@ add_to_assign_allowed_group(user) end - fab!(:user) { Fabricate(:user) } - fab!(:topic) { Fabricate(:topic) } + fab!(:user) + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } let(:guardian) { Guardian.new(user) } diff --git a/spec/system/assign_topic_spec.rb b/spec/system/assign_topic_spec.rb index fd4a822a..1eb9ab88 100644 --- a/spec/system/assign_topic_spec.rb +++ b/spec/system/assign_topic_spec.rb @@ -4,8 +4,8 @@ let(:topic_page) { PageObjects::Pages::Topic.new } let(:assign_modal) { PageObjects::Modals::Assign.new } fab!(:staff_user) { Fabricate(:user, groups: [Group[:staff]]) } - fab!(:admin) { Fabricate(:admin) } - fab!(:topic) { Fabricate(:topic) } + fab!(:admin) + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } before do diff --git a/spec/system/user_menu_spec.rb b/spec/system/user_menu_spec.rb index 73f22b35..ef0ab80b 100644 --- a/spec/system/user_menu_spec.rb +++ b/spec/system/user_menu_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe "Assign | User Menu", type: :system, js: true do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) let(:user_menu) { PageObjects::Components::UserMenu.new }