Isolate each role section in a context

Matt Jankowski 2024-11-14 11:49:22 -05:00
parent 7508fc1c92
commit 2d52303cdf
1 changed files with 30 additions and 17 deletions

View File

@ -12,29 +12,42 @@ RSpec.describe Admin::BaseController do
before { routes.draw { get 'success' => 'admin/base#success' } } before { routes.draw { get 'success' => 'admin/base#success' } }
it 'requires administrator or moderator' do context 'when accessed by regular user' do
sign_in(Fabricate(:user)) before { sign_in(Fabricate(:user)) }
get :success
expect(response).to have_http_status(403) it 'returns forbidden' do
get :success
expect(response)
.to have_http_status(403)
end
end end
it 'returns private cache control headers' do context 'when accessed by moderator' do
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator'))) before { sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator'))) }
get :success
expect(response.headers['Cache-Control']).to include('private, no-store') it 'returns http success, private cache control, and uses admin layout' do
get :success
expect(response)
.to have_http_status(200)
expect(response.headers['Cache-Control'])
.to include('private, no-store')
expect(response)
.to render_template layout: 'admin'
end
end end
it 'renders admin layout as a moderator' do context 'when accessed by admin' do
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator'))) before { sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Admin'))) }
get :success
expect(response).to render_template layout: 'admin'
end
it 'renders admin layout as an admin' do it 'returns http success and uses admin layout' do
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Admin'))) get :success
get :success
expect(response).to render_template layout: 'admin' expect(response)
.to have_http_status(200)
expect(response)
.to render_template layout: 'admin'
end
end end
end end