Sha256: 67647bce039a539eae1bfe74f43dec5ff44999ace909eee5b694707bd6beb4ca

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

require 'rails_helper'

RSpec.describe Admin::ApplicationController, :type => :controller do
  
  before :each do
    activate_authlogic
    @user = FactoryGirl.create(:spud_user)
    @role = FactoryGirl.create(:spud_role)
    @session = SpudUserSession.create(@user)
  end
  
  describe 'require_user' do
    controller(Admin::ApplicationController) do
      def index
        render :nothing => true
      end
    end
    it "should respond successfully if the current user is a super admin" do
      @user.update_attribute(:super_admin, true)
      get :index
      expect(response).to be_success
    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_success
    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

10 entries across 10 versions & 1 rubygems

Version Path
tb_core-1.3.10 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.9 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.7 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.6 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.5 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.4 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.3 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.2 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.1 spec/controllers/admin/application_controller_spec.rb
tb_core-1.3.0 spec/controllers/admin/application_controller_spec.rb