rework roles with rolify
This commit is contained in:
parent
f9f840c811
commit
4af0e59ca6
40 changed files with 167 additions and 228 deletions
|
|
@ -3,27 +3,25 @@ require 'spec_helper'
|
|||
describe User do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:admin) { create(:user) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:organizer) { create(:user) }
|
||||
|
||||
it 'returns the correct role' do
|
||||
participant = create(:user, email: 'participant@example.de')
|
||||
expect(admin.roles.first).to eq(admin_role)
|
||||
expect(organizer.roles.first).to eq(organizer_role)
|
||||
expect(participant.roles.first).to eq(participant_role)
|
||||
end
|
||||
|
||||
it 'returns the correct roles' do
|
||||
roles = [organizer_role.id, participant_role.id, admin_role.id]
|
||||
roles = [participant_role.id, organizer_role.id]
|
||||
user_with_all_roles = create(:user, email: 'participant@example.de')
|
||||
user_with_all_roles.role_ids = roles
|
||||
user_with_all_roles.save
|
||||
|
||||
expect(user_with_all_roles.roles.length).to eq(3)
|
||||
expect(user_with_all_roles.roles.length).to eq(2)
|
||||
expect(user_with_all_roles.roles[0]).to eq(participant_role)
|
||||
expect(user_with_all_roles.roles[1]).to eq(organizer_role)
|
||||
expect(user_with_all_roles.roles[2]).to eq(admin_role)
|
||||
end
|
||||
|
||||
describe '#role?' do
|
||||
|
|
@ -37,19 +35,17 @@ describe User do
|
|||
end
|
||||
end
|
||||
|
||||
context 'admin' do
|
||||
it_behaves_like '#role?', :admin, 'orgAnizer', false
|
||||
it_behaves_like '#role?', :admin, 'adMin', true
|
||||
it_behaves_like '#role?', :admin, 'partiCipant', false
|
||||
context 'organizer' do
|
||||
it_behaves_like '#role?', :organizer, 'oRganIzeR', true
|
||||
it_behaves_like '#role?', :organizer, 'partiCipant', false
|
||||
|
||||
it 'assigns first user admin role' do
|
||||
expect(admin.role?('Admin')).to be true
|
||||
expect(admin.role_ids).to match_array([admin_role.id])
|
||||
it 'assigns first user organizer role' do
|
||||
expect(organizer.role?('Organizer')).to be true
|
||||
expect(organizer.role_ids).to match_array([organizer_role.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'participant' do
|
||||
it_behaves_like '#role?', :participant, 'orgAnizer', false
|
||||
it_behaves_like '#role?', :participant, 'adMin', false
|
||||
it_behaves_like '#role?', :participant, 'partiCipant', true
|
||||
|
||||
|
|
@ -58,11 +54,5 @@ describe User do
|
|||
expect(participant.role_ids).to match_array([participant_role.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'organizer' do
|
||||
it_behaves_like '#role?', :organizer, 'orgAnizer', true
|
||||
it_behaves_like '#role?', :organizer, 'adMin', false
|
||||
it_behaves_like '#role?', :organizer, 'partiCipant', false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue