Sha256: be5f436d1ac77d85705b0d35e0d756a7b9020cd088e8e1e8860702140e3ce1dd

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'rails_helper'

RSpec.describe Admin::ApplicationController, type: :controller do

  before :each do
    activate_authlogic
    @user = FactoryBot.create(:spud_user)
    @role = FactoryBot.create(:spud_role)
    @session = SpudUserSession.create(@user)
  end

  describe 'require_user' do
    controller(Admin::ApplicationController) do
      def index
        head :ok
      end
    end

    it 'should respond successfully if the current user is a super admin' do
      @user.update(super_admin: true)
      get :index
      expect(response).to be_successful
    end

    it 'should respond successfully if the current user has admin permissions' do
      @role.permission_tags = ['admin.users.full_access']
      @role.save
      @user.role = @role
      @user.save
      get :index
      expect(response).to be_successful
    end

    it 'should redirect to the login if the current user is not logged in' do
      @session.destroy
      get :index
      expect(response).to redirect_to(admin_login_path(return_to: '/admin/application'))
    end

    it 'should redirect to the root for a user without administrative priviledges' do
      @user.super_admin = false
      @user.role = nil
      @user.save
      get :index
      expect(response.code).to eq('403')
      expect(response).to render_template('layouts/admin/error_page')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tb_core-1.5.4 spec/controllers/admin/application_controller_spec.rb
tb_core-1.5.3 spec/controllers/admin/application_controller_spec.rb
tb_core-1.5.2 spec/controllers/admin/application_controller_spec.rb
tb_core-1.5.1 spec/controllers/admin/application_controller_spec.rb
tb_core-1.5.0 spec/controllers/admin/application_controller_spec.rb
tb_core-1.4.8 spec/controllers/admin/application_controller_spec.rb