permission_spec.rb revision 8e3f37bc508aba0ca3408003cc59c6bec0d5ffca
0N/Arequire 'spec_helper'
0N/A
0N/Adescribe Permission do
0N/A let(:owner) { create :user }
0N/A let(:permission) { create(:permission, subject: owner, role: 'owner') }
0N/A
0N/A context 'one owner' do
0N/A it 'should not be possible to remove him' do
0N/A expect{ permission.destroy }.to raise_error(Permission::PowerVaccuumError)
0N/A end
0N/A
0N/A it 'should not be possible to degrade his role' do
0N/A permission.role = 'editor'
0N/A expect(permission).not_to be_valid
0N/A end
0N/A
0N/A it 'should be possible to remove another permission' do
0N/A %w(editor reader).each do |role|
0N/A other_permission = create(:permission, subject: owner, role: role)
0N/A expect{ other_permission.destroy }.not_to raise_error
0N/A end
0N/A end
0N/A end
0N/A
0N/A context 'many owners' do
0N/A let(:other_owner) { create(:user) }
0N/A before do
0N/A create(:permission, subject: other_owner, role: 'owner', item: permission.item)
0N/A end
0N/A
0N/A it 'should be possible to remove one' do
0N/A expect{ permission.destroy }.not_to raise_error
0N/A end
0N/A
0N/A it 'should be possible to degrade his role' do
41N/A permission.role = 'editor'
0N/A expect(permission).to be_valid
0N/A end
0N/A end
88N/Aend
88N/A