2017-05-26 14:13:26 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
describe Admin::BaseController do
|
2017-05-26 14:13:26 +02:00
|
|
|
controller do
|
|
|
|
def success
|
2022-07-05 02:41:40 +02:00
|
|
|
authorize :dashboard, :index?
|
2017-05-26 14:13:26 +02:00
|
|
|
render 'admin/reports/show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-03 13:07:32 +02:00
|
|
|
it 'requires administrator or moderator' do
|
2017-05-26 14:13:26 +02:00
|
|
|
routes.draw { get 'success' => 'admin/base#success' }
|
2022-07-05 02:41:40 +02:00
|
|
|
sign_in(Fabricate(:user))
|
2017-05-26 14:13:26 +02:00
|
|
|
get :success
|
2018-04-03 13:07:32 +02:00
|
|
|
|
2023-02-20 03:16:40 +01:00
|
|
|
expect(response).to have_http_status(403)
|
2017-05-26 14:13:26 +02:00
|
|
|
end
|
|
|
|
|
2023-04-19 16:07:29 +02:00
|
|
|
it 'returns private cache control headers' do
|
|
|
|
routes.draw { get 'success' => 'admin/base#success' }
|
|
|
|
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator')))
|
|
|
|
get :success
|
|
|
|
|
|
|
|
expect(response.headers['Cache-Control']).to include('private, no-store')
|
|
|
|
end
|
|
|
|
|
2018-04-03 13:07:32 +02:00
|
|
|
it 'renders admin layout as a moderator' do
|
2017-05-26 14:13:26 +02:00
|
|
|
routes.draw { get 'success' => 'admin/base#success' }
|
2022-07-05 02:41:40 +02:00
|
|
|
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator')))
|
2017-05-26 14:13:26 +02:00
|
|
|
get :success
|
2018-04-03 13:07:32 +02:00
|
|
|
expect(response).to render_template layout: 'admin'
|
|
|
|
end
|
2017-05-26 14:13:26 +02:00
|
|
|
|
2018-04-03 13:07:32 +02:00
|
|
|
it 'renders admin layout as an admin' do
|
|
|
|
routes.draw { get 'success' => 'admin/base#success' }
|
2022-07-05 02:41:40 +02:00
|
|
|
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Admin')))
|
2018-04-03 13:07:32 +02:00
|
|
|
get :success
|
|
|
|
expect(response).to render_template layout: 'admin'
|
2017-05-26 14:13:26 +02:00
|
|
|
end
|
|
|
|
end
|