2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-07-08 10:25:38 +08:00
|
|
|
require_dependency 'discourse_version_check'
|
2013-03-15 06:26:12 +08:00
|
|
|
|
|
|
|
describe Admin::DashboardController do
|
2013-07-08 10:25:38 +08:00
|
|
|
before do
|
2017-07-28 09:20:09 +08:00
|
|
|
AdminDashboardData.stubs(:fetch_cached_stats).returns(reports: [])
|
2013-07-03 23:06:07 +08:00
|
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
2013-07-08 10:25:38 +08:00
|
|
|
end
|
2013-03-15 06:26:12 +08:00
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(Admin::DashboardController < Admin::AdminController).to eq(true)
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'while logged in as an admin' do
|
|
|
|
let!(:admin) { log_in(:admin) }
|
|
|
|
|
|
|
|
context '.index' do
|
|
|
|
context 'version checking is enabled' do
|
|
|
|
before do
|
2017-07-07 14:09:14 +08:00
|
|
|
SiteSetting.version_checks = true
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns discourse version info' do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2017-08-31 12:06:56 +08:00
|
|
|
expect(JSON.parse(response.body)['version_check']).to be_present
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'version checking is disabled' do
|
|
|
|
before do
|
2017-07-07 14:09:14 +08:00
|
|
|
SiteSetting.version_checks = false
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return discourse version info' do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, format: :json
|
2013-03-15 06:26:12 +08:00
|
|
|
json = JSON.parse(response.body)
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['version_check']).not_to be_present
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-30 03:48:26 +08:00
|
|
|
|
|
|
|
context '.problems' do
|
|
|
|
context 'when there are no problems' do
|
|
|
|
before do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array' do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :problems, format: :json
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).to be_successful
|
2013-03-30 03:48:26 +08:00
|
|
|
json = JSON.parse(response.body)
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['problems'].size).to eq(0)
|
2013-03-30 03:48:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are problems' do
|
|
|
|
before do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns(['Not enough awesome', 'Too much sass'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of strings' do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :problems, format: :json
|
2013-03-30 03:48:26 +08:00
|
|
|
json = JSON.parse(response.body)
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['problems'].size).to eq(2)
|
|
|
|
expect(json['problems'][0]).to be_a(String)
|
|
|
|
expect(json['problems'][1]).to be_a(String)
|
2013-03-30 03:48:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
2013-07-08 10:25:38 +08:00
|
|
|
end
|