mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:57:29 +08:00
DEV: Update rubocop-discourse (#9270)
Includes: * DEV: Use `eq_time` matcher
This commit is contained in:
parent
ef3d6d6580
commit
d21d80198c
17
.rubocop.yml
17
.rubocop.yml
|
@ -12,6 +12,14 @@ AllCops:
|
||||||
- "public/**/*"
|
- "public/**/*"
|
||||||
- "plugins/**/gems/**/*"
|
- "plugins/**/gems/**/*"
|
||||||
|
|
||||||
|
Discourse:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Discourse/NoChdir:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/**/*' # Specs are run sequentially, so chdir can be used
|
||||||
|
- 'plugins/*/spec/**/*'
|
||||||
|
|
||||||
# Prefer &&/|| over and/or.
|
# Prefer &&/|| over and/or.
|
||||||
Style/AndOr:
|
Style/AndOr:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
@ -127,15 +135,6 @@ Style/Semicolon:
|
||||||
Style/RedundantReturn:
|
Style/RedundantReturn:
|
||||||
Enabled: true
|
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:
|
Style/GlobalVars:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Severity: warning
|
Severity: warning
|
||||||
|
|
|
@ -253,7 +253,7 @@ GEM
|
||||||
parallel (1.19.1)
|
parallel (1.19.1)
|
||||||
parallel_tests (2.32.0)
|
parallel_tests (2.32.0)
|
||||||
parallel
|
parallel
|
||||||
parser (2.7.0.4)
|
parser (2.7.0.5)
|
||||||
ast (~> 2.4.0)
|
ast (~> 2.4.0)
|
||||||
pg (1.2.3)
|
pg (1.2.3)
|
||||||
progress (3.5.2)
|
progress (3.5.2)
|
||||||
|
@ -348,7 +348,7 @@ GEM
|
||||||
rexml
|
rexml
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 1.4.0, < 1.7)
|
unicode-display_width (>= 1.4.0, < 1.7)
|
||||||
rubocop-discourse (1.0.2)
|
rubocop-discourse (2.0.1)
|
||||||
rubocop (>= 0.69.0)
|
rubocop (>= 0.69.0)
|
||||||
ruby-prof (1.3.1)
|
ruby-prof (1.3.1)
|
||||||
ruby-progressbar (1.10.1)
|
ruby-progressbar (1.10.1)
|
||||||
|
|
|
@ -32,7 +32,7 @@ module Autospec
|
||||||
end
|
end
|
||||||
|
|
||||||
# launch rspec
|
# 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" }
|
env = { "RAILS_ENV" => "test" }
|
||||||
if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ }
|
if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ }
|
||||||
env["LOAD_PLUGINS"] = "1"
|
env["LOAD_PLUGINS"] = "1"
|
||||||
|
|
|
@ -42,7 +42,7 @@ class PluginTxUpdater
|
||||||
PLUGINS.each do |plugin_name|
|
PLUGINS.each do |plugin_name|
|
||||||
plugin_dir = File.join(@base_dir, plugin_name)
|
plugin_dir = File.join(@base_dir, plugin_name)
|
||||||
Bundler.with_clean_env do
|
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, ''
|
puts '', plugin_dir, '-' * 80, ''
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe BookmarkManager do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
let(:reminder_type) { 'tomorrow' }
|
let(:reminder_type) { 'tomorrow' }
|
||||||
let(:reminder_at) { (Time.zone.now + 1.day).iso8601 }
|
let(:reminder_at) { 1.day.from_now }
|
||||||
fab!(:post) { Fabricate(:post) }
|
fab!(:post) { Fabricate(:post) }
|
||||||
let(:name) { 'Check this out!' }
|
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)
|
subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at)
|
||||||
bookmark = Bookmark.find_by(user: user)
|
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_set_at).not_to eq(nil)
|
||||||
expect(bookmark.reminder_type).to eq(Bookmark.reminder_types[:tomorrow])
|
expect(bookmark.reminder_type).to eq(Bookmark.reminder_types[:tomorrow])
|
||||||
end
|
end
|
||||||
|
@ -76,7 +76,8 @@ RSpec.describe BookmarkManager do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the reminder time is in the past" do
|
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
|
it "adds an error to the manager" do
|
||||||
subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at)
|
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"))
|
expect(subject.errors.full_messages).to include(I18n.t("bookmarks.errors.cannot_set_past_reminder"))
|
||||||
|
@ -84,7 +85,8 @@ RSpec.describe BookmarkManager do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the reminder time is far-flung (> 10 years from now)" do
|
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
|
it "adds an error to the manager" do
|
||||||
subject.create(post_id: post.id, name: name, reminder_type: reminder_type, reminder_at: reminder_at)
|
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"))
|
expect(subject.errors.full_messages).to include(I18n.t("bookmarks.errors.cannot_set_reminder_in_distant_future"))
|
||||||
|
|
|
@ -1172,7 +1172,7 @@ describe Post do
|
||||||
|
|
||||||
result = post.rebake!
|
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(post.cooked).to eq(first_cooked)
|
||||||
expect(result).to eq(true)
|
expect(result).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -240,7 +240,7 @@ RSpec.configure do |config|
|
||||||
config.before :each, &TestSetup.method(:test_setup)
|
config.before :each, &TestSetup.method(:test_setup)
|
||||||
|
|
||||||
config.before(:each, type: :multisite) do
|
config.before(:each, type: :multisite) do
|
||||||
Rails.configuration.multisite = true
|
Rails.configuration.multisite = true # rubocop:disable Discourse/NoDirectMultisiteManipulation
|
||||||
|
|
||||||
RailsMultisite::ConnectionManagement.config_filename =
|
RailsMultisite::ConnectionManagement.config_filename =
|
||||||
"spec/fixtures/multisite/two_dbs.yml"
|
"spec/fixtures/multisite/two_dbs.yml"
|
||||||
|
@ -248,7 +248,7 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
config.after(:each, type: :multisite) do
|
config.after(:each, type: :multisite) do
|
||||||
ActiveRecord::Base.clear_all_connections!
|
ActiveRecord::Base.clear_all_connections!
|
||||||
Rails.configuration.multisite = false
|
Rails.configuration.multisite = false # rubocop:disable Discourse/NoDirectMultisiteManipulation
|
||||||
RailsMultisite::ConnectionManagement.clear_settings!
|
RailsMultisite::ConnectionManagement.clear_settings!
|
||||||
ActiveRecord::Base.establish_connection
|
ActiveRecord::Base.establish_connection
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,12 +12,12 @@ RSpec.describe UserBookmarkSerializer do
|
||||||
s = UserBookmarkSerializer.new(bookmark_list.last)
|
s = UserBookmarkSerializer.new(bookmark_list.last)
|
||||||
|
|
||||||
expect(s.id).to eq(bookmark.id)
|
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.topic_id).to eq(bookmark.topic_id)
|
||||||
expect(s.linked_post_number).to eq(bookmark.post.post_number)
|
expect(s.linked_post_number).to eq(bookmark.post.post_number)
|
||||||
expect(s.post_id).to eq(bookmark.post_id)
|
expect(s.post_id).to eq(bookmark.post_id)
|
||||||
expect(s.name).to eq(bookmark.name)
|
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.title).to eq(bookmark.topic.title)
|
||||||
expect(s.deleted).to eq(false)
|
expect(s.deleted).to eq(false)
|
||||||
expect(s.hidden).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.category_id).to eq(bookmark.topic.category_id)
|
||||||
expect(s.archetype).to eq(bookmark.topic.archetype)
|
expect(s.archetype).to eq(bookmark.topic.archetype)
|
||||||
expect(s.highest_post_number).to eq(1)
|
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.slug).to eq(bookmark.topic.slug)
|
||||||
expect(s.username).to eq(bookmark.post.user.username)
|
expect(s.username).to eq(bookmark.post.user.username)
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,7 @@ describe AnonymousShadowCreator do
|
||||||
expect(shadow.trust_level).to eq(1)
|
expect(shadow.trust_level).to eq(1)
|
||||||
expect(shadow.username).to eq("anonymous")
|
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
|
p = create_post
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user