From 325f975ed313c7e624af6d9e064ac6b7916f5cb7 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Mon, 11 Jun 2018 07:47:42 +0300 Subject: [PATCH] REFACTOR: admin dashboard controller specs to requests (#5967) --- .../admin/dashboard_controller_spec.rb | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) rename spec/{controllers => requests}/admin/dashboard_controller_spec.rb (82%) diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb similarity index 82% rename from spec/controllers/admin/dashboard_controller_spec.rb rename to spec/requests/admin/dashboard_controller_spec.rb index f10397a345d..5d269792676 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/requests/admin/dashboard_controller_spec.rb @@ -12,16 +12,20 @@ describe Admin::DashboardController do end context 'while logged in as an admin' do - let!(:admin) { log_in(:admin) } + let(:admin) { Fabricate(:admin) } - context '.index' do + before do + sign_in(admin) + end + + describe '#index' do context 'version checking is enabled' do before do SiteSetting.version_checks = true end it 'returns discourse version info' do - get :index, format: :json + get "/admin/dashboard.json" expect(response.status).to eq(200) expect(JSON.parse(response.body)['version_check']).to be_present @@ -34,21 +38,22 @@ describe Admin::DashboardController do end it 'does not return discourse version info' do - get :index, format: :json + get "/admin/dashboard.json" + expect(response.status).to eq(200) json = JSON.parse(response.body) expect(json['version_check']).not_to be_present end end end - context '.problems' do + describe '#problems' do context 'when there are no problems' do before do AdminDashboardData.stubs(:fetch_problems).returns([]) end it 'returns an empty array' do - get :problems, format: :json + get "/admin/dashboard/problems.json" expect(response.status).to eq(200) json = JSON.parse(response.body) @@ -62,7 +67,8 @@ describe Admin::DashboardController do end it 'returns an array of strings' do - get :problems, format: :json + get "/admin/dashboard/problems.json" + expect(response.status).to eq(200) json = JSON.parse(response.body) expect(json['problems'].size).to eq(2) expect(json['problems'][0]).to be_a(String)