1
0

base_controller_spec.rb 947 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::BaseController, type: :controller 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(:forbidden)
  15. end
  16. it 'renders admin layout as a moderator' 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).to render_template layout: 'admin'
  21. end
  22. it 'renders admin layout as an admin' do
  23. routes.draw { get 'success' => 'admin/base#success' }
  24. sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Admin')))
  25. get :success
  26. expect(response).to render_template layout: 'admin'
  27. end
  28. end