2013-03-19 23:18:00 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AdminDashboardData do
|
|
|
|
|
|
|
|
describe "rails_env_check" do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.rails_env_check }
|
2013-03-19 23:18:00 -04:00
|
|
|
|
|
|
|
it 'returns nil when running in production mode' do
|
|
|
|
Rails.stubs(:env).returns('production')
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when running in development mode' do
|
|
|
|
Rails.stubs(:env).returns('development')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when running in test mode' do
|
|
|
|
Rails.stubs(:env).returns('test')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-20 15:38:28 -04:00
|
|
|
describe 'host_names_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.host_names_check }
|
2013-03-20 15:38:28 -04:00
|
|
|
|
|
|
|
it 'returns nil when host_names is set' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('something.com')
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when host_name is localhost' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('localhost')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when host_name is production.localhost' do
|
|
|
|
Discourse.stubs(:current_hostname).returns('production.localhost')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-20 16:16:23 -04:00
|
|
|
describe 'gc_checks' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.gc_checks }
|
2013-03-20 16:16:23 -04:00
|
|
|
|
|
|
|
it 'returns nil when gc params are set' do
|
|
|
|
ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when gc params are not set' do
|
|
|
|
ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(nil)
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 11:35:32 -04:00
|
|
|
describe 'sidekiq_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.sidekiq_check }
|
2013-03-22 11:35:32 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
subject.should 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)
|
|
|
|
subject.should 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)
|
|
|
|
subject.should 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)
|
|
|
|
subject.should_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)
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 15:47:25 -04:00
|
|
|
describe 'ram_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.ram_check }
|
2013-03-22 15:47:25 -04:00
|
|
|
|
|
|
|
it 'returns nil when total ram is 1 GB' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(1025272)
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when total ram cannot be determined' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(nil)
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when total ram is less than 1 GB' do
|
|
|
|
MemInfo.any_instance.stubs(:mem_total).returns(512636)
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-10 03:08:06 -04:00
|
|
|
describe 'send_consumer_email_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.send_consumer_email_check }
|
2013-05-29 13:54:49 -04:00
|
|
|
|
|
|
|
it 'returns nil if gmail.com is not in the smtp_settings address' do
|
|
|
|
ActionMailer::Base.stubs(:smtp_settings).returns({address: 'mandrillapp.com'})
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'gmail.com is in the smtp_settings address' do
|
|
|
|
before { ActionMailer::Base.stubs(:smtp_settings).returns({address: 'smtp.gmail.com'}) }
|
|
|
|
|
|
|
|
it 'returns nil in development env' do
|
|
|
|
Rails.stubs(:env).returns('development')
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when in production env' do
|
|
|
|
Rails.stubs(:env).returns('production')
|
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-05 16:43:39 -04:00
|
|
|
describe 'default_logo_check' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.default_logo_check }
|
2013-06-05 16:43:39 -04:00
|
|
|
|
|
|
|
describe 'favicon_url check' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:logo_url).returns('/assets/my-logo.jpg')
|
|
|
|
SiteSetting.stubs(:logo_small_url).returns('/assets/my-small-logo.jpg')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when favicon_url is default' do
|
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
|
2013-06-05 16:59:19 -04:00
|
|
|
it 'returns a string when favicon_url contains default filename' do
|
|
|
|
SiteSetting.stubs(:favicon_url).returns("/prefix#{SiteSetting.defaults[:favicon_url]}")
|
2013-06-05 16:43:39 -04:00
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when favicon_url does not match default-favicon.png' do
|
|
|
|
SiteSetting.stubs(:favicon_url).returns('/assets/my-favicon.png')
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'logo_url check' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:favicon_url).returns('/assets/my-favicon.png')
|
|
|
|
SiteSetting.stubs(:logo_small_url).returns('/assets/my-small-logo.jpg')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when logo_url is default' do
|
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
|
2013-06-05 16:59:19 -04:00
|
|
|
it 'returns a string when logo_url contains default filename' do
|
|
|
|
SiteSetting.stubs(:logo_url).returns("/prefix#{SiteSetting.defaults[:logo_url]}")
|
2013-06-05 16:43:39 -04:00
|
|
|
expect(subject).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when logo_url does not match d-logo-sketch.png' do
|
|
|
|
SiteSetting.stubs(:logo_url).returns('/assets/my-logo.png')
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# etc.
|
|
|
|
end
|
|
|
|
|
2013-03-29 13:31:00 -04:00
|
|
|
describe 'auth_config_checks' do
|
|
|
|
|
2013-05-29 13:54:49 -04:00
|
|
|
shared_examples 'problem detection for login providers' do
|
2013-03-29 13:31:00 -04:00
|
|
|
context 'when disabled' do
|
|
|
|
it 'returns nil' do
|
|
|
|
SiteSetting.stubs(enable_setting).returns(false)
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when enabled' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(enable_setting).returns(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil key and secret are set' do
|
|
|
|
SiteSetting.stubs(key).returns('12313213')
|
|
|
|
SiteSetting.stubs(secret).returns('12312313123')
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when key is not set' do
|
|
|
|
SiteSetting.stubs(key).returns('')
|
|
|
|
SiteSetting.stubs(secret).returns('12312313123')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when secret is not set' do
|
|
|
|
SiteSetting.stubs(key).returns('123123')
|
|
|
|
SiteSetting.stubs(secret).returns('')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when key and secret are not set' do
|
|
|
|
SiteSetting.stubs(key).returns('')
|
|
|
|
SiteSetting.stubs(secret).returns('')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'facebook' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.facebook_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_facebook_logins }
|
|
|
|
let(:key) { :facebook_app_id }
|
|
|
|
let(:secret) { :facebook_app_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'twitter' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.twitter_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_twitter_logins }
|
|
|
|
let(:key) { :twitter_consumer_key }
|
|
|
|
let(:secret) { :twitter_consumer_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'github' do
|
2013-11-18 13:44:55 -05:00
|
|
|
subject { described_class.new.github_config_check }
|
2013-03-29 13:31:00 -04:00
|
|
|
let(:enable_setting) { :enable_github_logins }
|
|
|
|
let(:key) { :github_client_id }
|
|
|
|
let(:secret) { :github_client_secret }
|
2013-05-29 13:54:49 -04:00
|
|
|
include_examples 'problem detection for login providers'
|
2013-03-29 13:31:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-18 13:44:55 -05:00
|
|
|
describe "enforce_global_nicknames_check" do
|
|
|
|
subject { described_class.new.enforce_global_nicknames_check }
|
|
|
|
|
|
|
|
it 'returns nil when enforce_global_nicknames and discourse_org_access_key are set' do
|
|
|
|
SiteSetting.stubs(:enforce_global_nicknames).returns(true)
|
|
|
|
SiteSetting.stubs(:discourse_org_access_key).returns('123')
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string when enforce_global_nicknames is true but discourse_org_access_key is not' do
|
|
|
|
SiteSetting.stubs(:enforce_global_nicknames).returns(true)
|
|
|
|
SiteSetting.stubs(:discourse_org_access_key).returns('')
|
|
|
|
subject.should_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when enforce_global_nicknames is false and discourse_org_access_key is set' do
|
|
|
|
SiteSetting.stubs(:enforce_global_nicknames).returns(false)
|
|
|
|
SiteSetting.stubs(:discourse_org_access_key).returns('123')
|
|
|
|
subject.should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-29 22:43:21 -04:00
|
|
|
end
|