mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 01:23:43 +08:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
83 lines
2.3 KiB
Ruby
83 lines
2.3 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'discourse_version_check'
|
|
|
|
describe Admin::DashboardController do
|
|
before do
|
|
AdminDashboardData.stubs(:fetch_cached_stats).returns({reports:[]})
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
|
end
|
|
|
|
it "is a subclass of AdminController" do
|
|
expect(Admin::DashboardController < Admin::AdminController).to eq(true)
|
|
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
|
|
expect(response).to 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)
|
|
expect(json['version_check']).to 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)
|
|
expect(json['version_check']).not_to be_present
|
|
end
|
|
end
|
|
end
|
|
|
|
context '.problems' do
|
|
it 'should be successful' do
|
|
AdminDashboardData.stubs(:fetch_problems).returns([])
|
|
xhr :get, :problems
|
|
expect(response).to 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)
|
|
expect(json['problems'].size).to eq(0)
|
|
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)
|
|
expect(json['problems'].size).to eq(2)
|
|
expect(json['problems'][0]).to be_a(String)
|
|
expect(json['problems'][1]).to be_a(String)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|