Created
October 16, 2013 14:28
-
-
Save Electron-libre/7008616 to your computer and use it in GitHub Desktop.
Test Policies with pundit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe PersonPolicy do | |
subject { PersonPolicy } | |
let(:person) { create(:person) } | |
let(:user) { create(:valid_user) } | |
context 'given user\'s role activities' do | |
permissions :create? do | |
context 'without person:create' do | |
before(:each) { user.roles << create(:role, activities: %w(person:show)) } | |
it 'denies' do | |
should_not permit(user, person) | |
end | |
end | |
context 'with person:create' do | |
before(:each) { user.roles << create(:role, activities: %w(person:create person:show)) } | |
it 'allow' do | |
should permit(user, person) | |
end | |
end | |
end | |
permissions :update? do | |
context 'without person:update role activity' do | |
before(:each) { user.roles << create(:role, activities: %w(person:show)) } | |
it 'denies' do | |
should_not permit(user, person) | |
end | |
end | |
context 'with person:update' do | |
before(:each) { user.roles << create(:role, activities: %w(person:update)) } | |
it 'allow' do | |
should permit(user, person) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment