From abe51c2aba772918c6c04b16d86e6a766e00125b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Thu, 29 Feb 2024 18:15:57 +0100 Subject: [PATCH] DEV: Fix new Rubocop offenses (#282) --- Gemfile.lock | 40 ++++++++++++++++--- plugin.rb | 6 +-- .../recurring_data_explorer_result_pm_spec.rb | 12 ++---- spec/data_explorer_spec.rb | 2 +- spec/guardian_spec.rb | 2 +- .../integration/custom_api_key_scopes_spec.rb | 2 +- .../query_group_bookmarkable_spec.rb | 2 +- spec/report_generator_spec.rb | 2 +- spec/requests/group_spec.rb | 2 +- spec/requests/query_controller_spec.rb | 4 +- spec/result_to_markdown_spec.rb | 4 +- 11 files changed, 49 insertions(+), 29 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 23ad67d..1e1370c 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/plugin.rb b/plugin.rb index 1852de4..d63fec4 100644 --- a/plugin.rb +++ b/plugin.rb @@ -81,11 +81,7 @@ after_initialize do require_relative "lib/result_to_markdown" reloadable_patch do if defined?(DiscourseAutomation) - DiscourseAutomation::Scriptable::RECURRING_DATA_EXPLORER_RESULT_PM = - "recurring_data_explorer_result_pm" - add_automation_scriptable( - DiscourseAutomation::Scriptable::RECURRING_DATA_EXPLORER_RESULT_PM, - ) do + add_automation_scriptable("recurring_data_explorer_result_pm") do queries = DiscourseDataExplorer::Query .where(hidden: false) diff --git a/spec/automation/recurring_data_explorer_result_pm_spec.rb b/spec/automation/recurring_data_explorer_result_pm_spec.rb index efaf7c4..59528d5 100644 --- a/spec/automation/recurring_data_explorer_result_pm_spec.rb +++ b/spec/automation/recurring_data_explorer_result_pm_spec.rb @@ -3,9 +3,9 @@ require "rails_helper" describe "RecurringDataExplorerResultPm" do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:another_user) { Fabricate(:user) } fab!(:group_user) { Fabricate(:user) } fab!(:not_allowed_user) { Fabricate(:user) } @@ -14,13 +14,9 @@ describe "RecurringDataExplorerResultPm" do fab!(:another_group) { Fabricate(:group, users: [group_user]) } fab!(:automation) do - Fabricate( - :automation, - script: DiscourseAutomation::Scriptable::RECURRING_DATA_EXPLORER_RESULT_PM, - trigger: "recurring", - ) + Fabricate(:automation, script: "recurring_data_explorer_result_pm", trigger: "recurring") end - fab!(:query) { Fabricate(:query) } + fab!(:query) fab!(:query_group) { Fabricate(:query_group, query: query, group: group) } fab!(:query_group) { Fabricate(:query_group, query: query, group: another_group) } diff --git a/spec/data_explorer_spec.rb b/spec/data_explorer_spec.rb index 8cb7a6a..2c0a664 100644 --- a/spec/data_explorer_spec.rb +++ b/spec/data_explorer_spec.rb @@ -2,7 +2,7 @@ describe DiscourseDataExplorer::DataExplorer do describe ".run_query" do - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) it "should run a query that includes PG template patterns" do sql = <<~SQL diff --git a/spec/guardian_spec.rb b/spec/guardian_spec.rb index 39bfd9a..be1c470 100644 --- a/spec/guardian_spec.rb +++ b/spec/guardian_spec.rb @@ -19,7 +19,7 @@ describe Guardian do let(:user) { build(:user) } let(:admin) { build(:admin) } - fab!(:group) { Fabricate(:group) } + fab!(:group) describe "#user_is_a_member_of_group?" do it "is true when the user is an admin" do diff --git a/spec/integration/custom_api_key_scopes_spec.rb b/spec/integration/custom_api_key_scopes_spec.rb index 03dcdaa..d072320 100644 --- a/spec/integration/custom_api_key_scopes_spec.rb +++ b/spec/integration/custom_api_key_scopes_spec.rb @@ -11,7 +11,7 @@ describe "API keys scoped to query#run" do fab!(:query2) do DiscourseDataExplorer::Query.create!(name: "Query 2", sql: "SELECT 1 AS query2_res") end - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) let(:all_queries_api_key) do key = ApiKey.create! diff --git a/spec/lib/data_explorer/query_group_bookmarkable_spec.rb b/spec/lib/data_explorer/query_group_bookmarkable_spec.rb index 12ff78e..c688c17 100644 --- a/spec/lib/data_explorer/query_group_bookmarkable_spec.rb +++ b/spec/lib/data_explorer/query_group_bookmarkable_spec.rb @@ -8,7 +8,7 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do end fab!(:admin_user) { Fabricate(:admin) } - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:guardian) { Guardian.new(user) } fab!(:group0) { Fabricate(:group) } fab!(:group1) { Fabricate(:group) } diff --git a/spec/report_generator_spec.rb b/spec/report_generator_spec.rb index 35a40fa..fa5d304 100644 --- a/spec/report_generator_spec.rb +++ b/spec/report_generator_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe DiscourseDataExplorer::ReportGenerator do - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:unauthorised_user) { Fabricate(:user) } fab!(:unauthorised_group) { Fabricate(:group) } fab!(:group) { Fabricate(:group, users: [user]) } diff --git a/spec/requests/group_spec.rb b/spec/requests/group_spec.rb index 7aeaec6..96fa860 100644 --- a/spec/requests/group_spec.rb +++ b/spec/requests/group_spec.rb @@ -5,7 +5,7 @@ require "rails_helper" describe "Data explorer group serializer additions" do fab!(:group_user) { Fabricate(:user) } fab!(:other_user) { Fabricate(:user) } - fab!(:group) { Fabricate(:group) } + fab!(:group) let!(:query) { DiscourseDataExplorer::Query.create!(name: "My query", sql: "") } before do diff --git a/spec/requests/query_controller_spec.rb b/spec/requests/query_controller_spec.rb index d589818..1d9761d 100644 --- a/spec/requests/query_controller_spec.rb +++ b/spec/requests/query_controller_spec.rb @@ -22,7 +22,7 @@ describe DiscourseDataExplorer::QueryController do end describe "Admin" do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) before { sign_in(admin) } @@ -437,7 +437,7 @@ describe DiscourseDataExplorer::QueryController do end describe "Non-Admin" do - fab!(:user) { Fabricate(:user) } + fab!(:user) fab!(:group) { Fabricate(:group, users: [user]) } before { sign_in(user) } diff --git a/spec/result_to_markdown_spec.rb b/spec/result_to_markdown_spec.rb index ab10142..3e58140 100644 --- a/spec/result_to_markdown_spec.rb +++ b/spec/result_to_markdown_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true describe DiscourseDataExplorer::ResultToMarkdown do - fab!(:user) { Fabricate(:user) } - fab!(:post) { Fabricate(:post) } + fab!(:user) + fab!(:post) fab!(:query) { DiscourseDataExplorer::Query.find(-1) } let(:query_params) { [{ from_days_ago: 0 }, { duration_days: 15 }] }