Use common `before` and contexts in admin/base controller spec (#33879)

pull/33889/head
Matt Jankowski 3 weeks ago committed by GitHub
parent 7d20c12913
commit 4e58570f73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,40 +3,54 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Admin::BaseController do RSpec.describe Admin::BaseController do
render_views
controller do controller do
def success def success
authorize :dashboard, :index? authorize :dashboard, :index?
render 'admin/reports/show' render html: '<p>success</p>', layout: true
end end
end end
it 'requires administrator or moderator' do before { routes.draw { get 'success' => 'admin/base#success' } }
routes.draw { get 'success' => 'admin/base#success' }
sign_in(Fabricate(:user))
get :success
expect(response).to have_http_status(403) context 'when signed in as regular user' do
end before { sign_in Fabricate(:user) }
it 'returns private cache control headers' do it 'responds with unauthorized' do
routes.draw { get 'success' => 'admin/base#success' } get :success
sign_in(Fabricate(:moderator_user))
get :success
expect(response.headers['Cache-Control']).to include('private, no-store') expect(response).to have_http_status(403)
end
end end
it 'renders admin layout as a moderator' do context 'when signed in as moderator' do
routes.draw { get 'success' => 'admin/base#success' } before { sign_in Fabricate(:moderator_user) }
sign_in(Fabricate(:moderator_user))
get :success it 'returns success with private headers and admin layout' do
expect(response).to render_template layout: 'admin' get :success
expect(response)
.to have_http_status(200)
expect(response.headers['Cache-Control'])
.to include('private, no-store')
expect(response.parsed_body)
.to have_css('body.admin')
end
end end
it 'renders admin layout as an admin' do context 'when signed in as admin' do
routes.draw { get 'success' => 'admin/base#success' } before { sign_in Fabricate(:admin_user) }
sign_in(Fabricate(:admin_user))
get :success it 'returns success with private headers and admin layout' do
expect(response).to render_template layout: 'admin' get :success
expect(response)
.to have_http_status(200)
expect(response.headers['Cache-Control'])
.to include('private, no-store')
expect(response.parsed_body)
.to have_css('body.admin')
end
end end
end end

Loading…
Cancel
Save