2013-03-15 06:26:12 +08:00
|
|
|
require 'spec_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
|
2013-08-03 06:31:25 +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
|
2014-09-25 23:44:48 +08:00
|
|
|
(Admin::DashboardController < Admin::AdminController).should == 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
|
|
|
|
it 'should be successful' do
|
|
|
|
xhr :get, :index
|
|
|
|
response.should be_successful
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'version checking is enabled' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:version_checks).returns(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns discourse version info' do
|
|
|
|
xhr :get, :index
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
json['version_check'].should be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'version checking is disabled' do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:version_checks).returns(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return discourse version info' do
|
|
|
|
xhr :get, :index
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
json['version_check'].should_not be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-30 03:48:26 +08:00
|
|
|
|
|
|
|
context '.problems' do
|
|
|
|
it 'should be successful' do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns([])
|
|
|
|
xhr :get, :problems
|
|
|
|
response.should be_successful
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no problems' do
|
|
|
|
before do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array' do
|
|
|
|
xhr :get, :problems
|
|
|
|
json = JSON.parse(response.body)
|
2014-11-07 22:05:44 +08:00
|
|
|
json['problems'].size.should == 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
|
|
|
|
xhr :get, :problems
|
|
|
|
json = JSON.parse(response.body)
|
2014-11-07 22:05:44 +08:00
|
|
|
json['problems'].size.should == 2
|
2013-03-30 03:48:26 +08:00
|
|
|
json['problems'][0].should be_a(String)
|
|
|
|
json['problems'][1].should be_a(String)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
2013-07-08 10:25:38 +08:00
|
|
|
end
|