2017-05-26 21:13:26 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe Admin::BaseController do
|
2025-02-11 01:49:51 -05:00
|
|
|
render_views
|
|
|
|
|
2017-05-26 21:13:26 +09:00
|
|
|
controller do
|
|
|
|
def success
|
2022-07-05 02:41:40 +02:00
|
|
|
authorize :dashboard, :index?
|
2025-02-11 01:49:51 -05:00
|
|
|
render html: '<p>success</p>', layout: true
|
2017-05-26 21:13:26 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
before { routes.draw { get 'success' => 'admin/base#success' } }
|
2018-04-03 13:07:32 +02:00
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
context 'when signed in as regular user' do
|
|
|
|
before { sign_in Fabricate(:user) }
|
2017-05-26 21:13:26 +09:00
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
it 'responds with unauthorized' do
|
|
|
|
get :success
|
2023-04-19 16:07:29 +02:00
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
2023-04-19 16:07:29 +02:00
|
|
|
end
|
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
context 'when signed in as moderator' do
|
|
|
|
before { sign_in Fabricate(:moderator_user) }
|
|
|
|
|
|
|
|
it 'returns success with private headers and admin layout' do
|
|
|
|
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
|
2018-04-03 13:07:32 +02:00
|
|
|
end
|
2017-05-26 21:13:26 +09:00
|
|
|
|
2025-02-11 01:49:51 -05:00
|
|
|
context 'when signed in as admin' do
|
|
|
|
before { sign_in Fabricate(:admin_user) }
|
|
|
|
|
|
|
|
it 'returns success with private headers and admin layout' do
|
|
|
|
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
|
2017-05-26 21:13:26 +09:00
|
|
|
end
|
|
|
|
end
|