diff --git a/.rubocop.yml b/.rubocop.yml index 1e682c1045f..f9dafa672c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,14 @@ AllCops: - "public/**/*" - "plugins/**/gems/**/*" +Discourse: + Enabled: true + +Discourse/NoChdir: + Exclude: + - 'spec/**/*' # Specs are run sequentially, so chdir can be used + - 'plugins/*/spec/**/*' + # Prefer &&/|| over and/or. Style/AndOr: Enabled: true @@ -127,15 +135,6 @@ Style/Semicolon: Style/RedundantReturn: Enabled: true -DiscourseCops/NoChdir: - Enabled: true - Exclude: - - 'spec/**/*' # Specs are run sequentially, so chdir can be used - - 'plugins/*/spec/**/*' - -DiscourseCops/NoURIEscapeEncode: - Enabled: true - Style/GlobalVars: Enabled: true Severity: warning diff --git a/Gemfile.lock b/Gemfile.lock index 08056d633de..cc1ebd682f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -253,7 +253,7 @@ GEM parallel (1.19.1) parallel_tests (2.32.0) parallel - parser (2.7.0.4) + parser (2.7.0.5) ast (~> 2.4.0) pg (1.2.3) progress (3.5.2) @@ -348,7 +348,7 @@ GEM rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-discourse (1.0.2) + rubocop-discourse (2.0.1) rubocop (>= 0.69.0) ruby-prof (1.3.1) ruby-progressbar (1.10.1) diff --git a/lib/autospec/simple_runner.rb b/lib/autospec/simple_runner.rb index 1f944d906fa..a5c295d9298 100644 --- a/lib/autospec/simple_runner.rb +++ b/lib/autospec/simple_runner.rb @@ -32,7 +32,7 @@ module Autospec end # launch rspec - Dir.chdir(Rails.root) do # rubocop:disable DiscourseCops/NoChdir because this is not part of the app + Dir.chdir(Rails.root) do # rubocop:disable Discourse/NoChdir because this is not part of the app env = { "RAILS_ENV" => "test" } if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ } env["LOAD_PLUGINS"] = "1" diff --git a/script/plugin-translations.rb b/script/plugin-translations.rb index 78535b4a546..87bf4e8db8e 100644 --- a/script/plugin-translations.rb +++ b/script/plugin-translations.rb @@ -42,7 +42,7 @@ class PluginTxUpdater PLUGINS.each do |plugin_name| plugin_dir = File.join(@base_dir, plugin_name) Bundler.with_clean_env do - Dir.chdir(plugin_dir) do # rubocop:disable DiscourseCops/NoChdir because this is not part of the app + Dir.chdir(plugin_dir) do # rubocop:disable Discourse/NoChdir because this is not part of the app puts '', plugin_dir, '-' * 80, '' begin diff --git a/spec/lib/bookmark_manager_spec.rb b/spec/lib/bookmark_manager_spec.rb index 11a0b7d8599..a19380bb831 100644 --- a/spec/lib/bookmark_manager_spec.rb +++ b/spec/lib/bookmark_manager_spec.rb @@ -6,7 +6,7 @@ RSpec.describe BookmarkManager do let(:user) { Fabricate(:user) } let(:reminder_type) { 'tomorrow' } - let(:reminder_at) { (Time.zone.now + 1.day).iso8601 } + let(:reminder_at) { 1.day.from_now } fab!(:post) { Fabricate(:post) } let(:name) { 'Check this out!' } @@ -26,7 +26,7 @@ RSpec.describe BookmarkManager do subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at) bookmark = Bookmark.find_by(user: user) - expect(bookmark.reminder_at).to eq(reminder_at) + expect(bookmark.reminder_at).to eq_time(reminder_at) expect(bookmark.reminder_set_at).not_to eq(nil) expect(bookmark.reminder_type).to eq(Bookmark.reminder_types[:tomorrow]) end @@ -76,7 +76,8 @@ RSpec.describe BookmarkManager do end context "when the reminder time is in the past" do - let(:reminder_at) { (Time.zone.now - 10.days).iso8601 } + let(:reminder_at) { 10.days.ago } + it "adds an error to the manager" do subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at) expect(subject.errors.full_messages).to include(I18n.t("bookmarks.errors.cannot_set_past_reminder")) @@ -84,7 +85,8 @@ RSpec.describe BookmarkManager do end context "when the reminder time is far-flung (> 10 years from now)" do - let(:reminder_at) { (Time.zone.now + 11.years).iso8601 } + let(:reminder_at) { 11.years.from_now } + it "adds an error to the manager" do subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at) expect(subject.errors.full_messages).to include(I18n.t("bookmarks.errors.cannot_set_reminder_in_distant_future")) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 66ba358ad57..4cc716d6916 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1172,7 +1172,7 @@ describe Post do result = post.rebake! - expect(post.baked_at).not_to eq(first_baked) + expect(post.baked_at).not_to eq_time(first_baked) expect(post.cooked).to eq(first_cooked) expect(result).to eq(true) end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4bc237ab276..dc649a9b91d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -240,7 +240,7 @@ RSpec.configure do |config| config.before :each, &TestSetup.method(:test_setup) config.before(:each, type: :multisite) do - Rails.configuration.multisite = true + Rails.configuration.multisite = true # rubocop:disable Discourse/NoDirectMultisiteManipulation RailsMultisite::ConnectionManagement.config_filename = "spec/fixtures/multisite/two_dbs.yml" @@ -248,7 +248,7 @@ RSpec.configure do |config| config.after(:each, type: :multisite) do ActiveRecord::Base.clear_all_connections! - Rails.configuration.multisite = false + Rails.configuration.multisite = false # rubocop:disable Discourse/NoDirectMultisiteManipulation RailsMultisite::ConnectionManagement.clear_settings! ActiveRecord::Base.establish_connection end diff --git a/spec/serializers/user_bookmark_serializer_spec.rb b/spec/serializers/user_bookmark_serializer_spec.rb index 36b05abf7ba..e97ebfe4674 100644 --- a/spec/serializers/user_bookmark_serializer_spec.rb +++ b/spec/serializers/user_bookmark_serializer_spec.rb @@ -12,12 +12,12 @@ RSpec.describe UserBookmarkSerializer do s = UserBookmarkSerializer.new(bookmark_list.last) expect(s.id).to eq(bookmark.id) - expect(s.created_at).to eq(bookmark.created_at) + expect(s.created_at).to eq_time(bookmark.created_at) expect(s.topic_id).to eq(bookmark.topic_id) expect(s.linked_post_number).to eq(bookmark.post.post_number) expect(s.post_id).to eq(bookmark.post_id) expect(s.name).to eq(bookmark.name) - expect(s.reminder_at).to eq(bookmark.reminder_at) + expect(s.reminder_at).to eq_time(bookmark.reminder_at) expect(s.title).to eq(bookmark.topic.title) expect(s.deleted).to eq(false) expect(s.hidden).to eq(false) @@ -26,7 +26,7 @@ RSpec.describe UserBookmarkSerializer do expect(s.category_id).to eq(bookmark.topic.category_id) expect(s.archetype).to eq(bookmark.topic.archetype) expect(s.highest_post_number).to eq(1) - expect(s.bumped_at.to_s).to eq(bookmark.topic.bumped_at.to_s) + expect(s.bumped_at).to eq_time(bookmark.topic.bumped_at) expect(s.slug).to eq(bookmark.topic.slug) expect(s.username).to eq(bookmark.post.user.username) end diff --git a/spec/services/anonymous_shadow_creator_spec.rb b/spec/services/anonymous_shadow_creator_spec.rb index c47635f9552..cb5fcb4abd7 100644 --- a/spec/services/anonymous_shadow_creator_spec.rb +++ b/spec/services/anonymous_shadow_creator_spec.rb @@ -56,7 +56,7 @@ describe AnonymousShadowCreator do expect(shadow.trust_level).to eq(1) expect(shadow.username).to eq("anonymous") - expect(shadow.created_at).not_to eq(user.created_at) + expect(shadow.created_at).not_to eq_time(user.created_at) p = create_post