mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 10:41:25 +08:00
DEV: Update the rubocop-discourse gem
This enables cops related to RSpec `subject`. See https://github.com/discourse/rubocop-discourse/pull/32
This commit is contained in:

committed by
Loïc Guitaut

parent
8e1d049e6b
commit
0f4beab0fb
@ -126,93 +126,93 @@ RSpec.describe AdminDashboardData do
|
||||
end
|
||||
|
||||
describe "rails_env_check" do
|
||||
subject { described_class.new.rails_env_check }
|
||||
subject(:check) { described_class.new.rails_env_check }
|
||||
|
||||
it "returns nil when running in production mode" do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new("production"))
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns a string when running in development mode" do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new("development"))
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
|
||||
it "returns a string when running in test mode" do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new("test"))
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "host_names_check" do
|
||||
subject { described_class.new.host_names_check }
|
||||
subject(:check) { described_class.new.host_names_check }
|
||||
|
||||
it "returns nil when host_names is set" do
|
||||
Discourse.stubs(:current_hostname).returns("something.com")
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns a string when host_name is localhost" do
|
||||
Discourse.stubs(:current_hostname).returns("localhost")
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
|
||||
it "returns a string when host_name is production.localhost" do
|
||||
Discourse.stubs(:current_hostname).returns("production.localhost")
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "sidekiq_check" do
|
||||
subject { described_class.new.sidekiq_check }
|
||||
subject(:check) { described_class.new.sidekiq_check }
|
||||
|
||||
it "returns nil when sidekiq processed a job recently" do
|
||||
Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns nil when last job processed was a long time ago, but no jobs are queued" do
|
||||
Jobs.stubs(:last_job_performed_at).returns(7.days.ago)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns nil when no jobs have ever been processed, but no jobs are queued" do
|
||||
Jobs.stubs(:last_job_performed_at).returns(nil)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns a string when no jobs were processed recently and some jobs are queued" do
|
||||
Jobs.stubs(:last_job_performed_at).returns(20.minutes.ago)
|
||||
Jobs.stubs(:queued).returns(1)
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
|
||||
it "returns a string when no jobs have ever been processed, and some jobs are queued" do
|
||||
Jobs.stubs(:last_job_performed_at).returns(nil)
|
||||
Jobs.stubs(:queued).returns(1)
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "ram_check" do
|
||||
subject { described_class.new.ram_check }
|
||||
subject(:check) { described_class.new.ram_check }
|
||||
|
||||
it "returns nil when total ram is 1 GB" do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(1_025_272)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns nil when total ram cannot be determined" do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(nil)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns a string when total ram is less than 1 GB" do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(512_636)
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -221,7 +221,7 @@ RSpec.describe AdminDashboardData do
|
||||
context "when disabled" do
|
||||
it "returns nil" do
|
||||
SiteSetting.set(enable_setting, false)
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -231,31 +231,32 @@ RSpec.describe AdminDashboardData do
|
||||
it "returns nil when key and secret are set" do
|
||||
SiteSetting.set(key, "12313213")
|
||||
SiteSetting.set(secret, "12312313123")
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns a string when key is not set" do
|
||||
SiteSetting.set(key, "")
|
||||
SiteSetting.set(secret, "12312313123")
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
|
||||
it "returns a string when secret is not set" do
|
||||
SiteSetting.set(key, "123123")
|
||||
SiteSetting.set(secret, "")
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
|
||||
it "returns a string when key and secret are not set" do
|
||||
SiteSetting.set(key, "")
|
||||
SiteSetting.set(secret, "")
|
||||
expect(subject).to_not be_nil
|
||||
expect(check).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "facebook" do
|
||||
subject { described_class.new.facebook_config_check }
|
||||
subject(:check) { described_class.new.facebook_config_check }
|
||||
|
||||
let(:enable_setting) { :enable_facebook_logins }
|
||||
let(:key) { :facebook_app_id }
|
||||
let(:secret) { :facebook_app_secret }
|
||||
@ -263,7 +264,8 @@ RSpec.describe AdminDashboardData do
|
||||
end
|
||||
|
||||
describe "twitter" do
|
||||
subject { described_class.new.twitter_config_check }
|
||||
subject(:check) { described_class.new.twitter_config_check }
|
||||
|
||||
let(:enable_setting) { :enable_twitter_logins }
|
||||
let(:key) { :twitter_consumer_key }
|
||||
let(:secret) { :twitter_consumer_secret }
|
||||
@ -271,7 +273,8 @@ RSpec.describe AdminDashboardData do
|
||||
end
|
||||
|
||||
describe "github" do
|
||||
subject { described_class.new.github_config_check }
|
||||
subject(:check) { described_class.new.github_config_check }
|
||||
|
||||
let(:enable_setting) { :enable_github_logins }
|
||||
let(:key) { :github_client_id }
|
||||
let(:secret) { :github_client_secret }
|
||||
@ -280,28 +283,28 @@ RSpec.describe AdminDashboardData do
|
||||
end
|
||||
|
||||
describe "force_https_check" do
|
||||
subject { described_class.new(check_force_https: true).force_https_check }
|
||||
subject(:check) { described_class.new(check_force_https: true).force_https_check }
|
||||
|
||||
it "returns nil if force_https site setting enabled" do
|
||||
SiteSetting.force_https = true
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
|
||||
it "returns nil if force_https site setting not enabled" do
|
||||
SiteSetting.force_https = false
|
||||
expect(subject).to eq(I18n.t("dashboard.force_https_warning", base_path: Discourse.base_path))
|
||||
expect(check).to eq(I18n.t("dashboard.force_https_warning", base_path: Discourse.base_path))
|
||||
end
|
||||
end
|
||||
|
||||
describe "ignore force_https_check" do
|
||||
subject { described_class.new(check_force_https: false).force_https_check }
|
||||
subject(:check) { described_class.new(check_force_https: false).force_https_check }
|
||||
|
||||
it "returns nil" do
|
||||
SiteSetting.force_https = true
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
|
||||
SiteSetting.force_https = false
|
||||
expect(subject).to be_nil
|
||||
expect(check).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user