Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Adds specs for controller access
Browse files Browse the repository at this point in the history
  • Loading branch information
alxberardi committed Sep 15, 2015
1 parent 84f4d9f commit 3dc18b5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/right_on_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,38 @@ class User < ActiveRecord::Base
expect(@r1.roles.size).to eq 1
end
end

describe 'when checking accessibility to a controller' do

let(:test_controller_right) { Right.new(name: 'test', controller: 'test') }
let(:user) { double(rights: [test_controller_right]) }
let(:controller) { 'test' }
let(:action) { 'index' }
let(:params) { {controller: 'test', action: 'index'} }

before do
stub_const 'TestController', double(current_user: user, params: params)
TestController.extend RightOn::ActionControllerExtensions
allow(TestController).to receive(:rights_from).and_return(nil)
end

specify { expect(TestController.access_allowed?(controller)).to be_truthy }
specify { expect(TestController.access_allowed?('other')).to be_falsey }
specify { expect(TestController.access_allowed_to_controller?(controller)).to be_truthy }
specify { expect(TestController.access_allowed_to_controller?('other')).to be_falsey }

describe 'when inheriting rights' do
let(:controller) { 'test_inherited' }

before do
stub_const 'TestInheritedController', double(current_user: user, params: params)
TestInheritedController.extend RightOn::ActionControllerExtensions
allow(TestInheritedController).to receive(:rights_from).and_return(:test)
end

specify { expect(TestInheritedController.access_allowed?(controller)).to be_falsey }
specify { expect(TestInheritedController.access_allowed?('other')).to be_falsey }
specify { expect(TestInheritedController.access_allowed_to_controller?(controller)).to be_truthy }
specify { expect(TestInheritedController.access_allowed_to_controller?('other')).to be_falsey }
end
end

0 comments on commit 3dc18b5

Please sign in to comment.