base_controller_spec.rb 891 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::BaseController, type: :controller do
  4. controller do
  5. def success
  6. render 'admin/reports/show'
  7. end
  8. end
  9. it 'requires administrator or moderator' do
  10. routes.draw { get 'success' => 'admin/base#success' }
  11. sign_in(Fabricate(:user, admin: false, moderator: false))
  12. get :success
  13. expect(response).to have_http_status(:forbidden)
  14. end
  15. it 'renders admin layout as a moderator' do
  16. routes.draw { get 'success' => 'admin/base#success' }
  17. sign_in(Fabricate(:user, moderator: true))
  18. get :success
  19. expect(response).to render_template layout: 'admin'
  20. end
  21. it 'renders admin layout as an admin' do
  22. routes.draw { get 'success' => 'admin/base#success' }
  23. sign_in(Fabricate(:user, admin: true))
  24. get :success
  25. expect(response).to render_template layout: 'admin'
  26. end
  27. end