1
0

base_controller_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::BaseController do
  4. controller do
  5. def success
  6. authorize :dashboard, :index?
  7. render 'admin/reports/show'
  8. end
  9. end
  10. it 'requires administrator or moderator' do
  11. routes.draw { get 'success' => 'admin/base#success' }
  12. sign_in(Fabricate(:user))
  13. get :success
  14. expect(response).to have_http_status(403)
  15. end
  16. it 'returns private cache control headers' do
  17. routes.draw { get 'success' => 'admin/base#success' }
  18. sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator')))
  19. get :success
  20. expect(response.headers['Cache-Control']).to include('private, no-store')
  21. end
  22. it 'renders admin layout as a moderator' do
  23. routes.draw { get 'success' => 'admin/base#success' }
  24. sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator')))
  25. get :success
  26. expect(response).to render_template layout: 'admin'
  27. end
  28. it 'renders admin layout as an admin' do
  29. routes.draw { get 'success' => 'admin/base#success' }
  30. sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Admin')))
  31. get :success
  32. expect(response).to render_template layout: 'admin'
  33. end
  34. end