verify user if accessing admin area. Testing: setup organizer_conference_1_role

This commit is contained in:
Stella Rouzi 2014-07-18 20:49:50 +03:00
parent ab17e6db11
commit 940f76bf13
22 changed files with 91 additions and 62 deletions

View file

@ -4,44 +4,44 @@ describe User do
# It is necessary to use bang version of let to build roles before user
let!(:participant_role) { create(:participant_role) }
let!(:organizer_role) { create(:organizer_role) }
let!(:organizer) { create(:user) }
let!(:organizer_conference_1_role ) { create(:organizer_conference_1_role ) }
let!(:organizer) { create(:organizer_conference_1 ) }
it 'returns the correct role' do
participant = create(:user, email: 'participant@example.de')
expect(organizer.roles.first).to eq(organizer_role)
expect(participant.roles.first).to eq(participant_role)
expect(organizer.roles.first).to eq(organizer_conference_1_role)
expect(participant.roles.first).to eq(organizer_conference_1_role)
end
it 'returns the correct roles' do
roles = [participant_role.id, organizer_role.id]
roles = [participant_role.id, organizer_conference_1_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(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[1]).to eq(organizer_conference_1_role )
end
describe '#role?' do
shared_examples '#role?' do |user, role, expected|
it "returns #{expected} for #{role}" do
user_obj = create(user, email: 'e@example.com')
expect(user_obj.role?(role)).to be expected
expect(user_obj.role?(role.downcase)).to be expected
expect(user_obj.role?(role.upcase)).to be expected
expect(user_obj.role?(role.downcase.capitalize)).to be expected
expect(user_obj.has_role?(role)).to be expected
expect(user_obj.has_role?(role.downcase)).to be expected
expect(user_obj.has_role?(role.upcase)).to be expected
expect(user_obj.has_role?(role.downcase.capitalize)).to be expected
end
end
context 'organizer' do
it_behaves_like '#role?', :organizer, 'oRganIzeR', true
it_behaves_like '#role?', :organizer, 'partiCipant', false
it_behaves_like '#role?', :organizer_conference_1_role, 'oRganIzeR', true
it_behaves_like '#role?', :organizer_conference_1_role, 'partiCipant', false
it 'assigns first user organizer role' do
expect(organizer.role?('Organizer')).to be true
expect(organizer.role_ids).to match_array([organizer_role.id])
expect(organizer.has_role?('organizer', Conference.first)).to be true
expect(organizer.role_ids).to match_array([organizer_conference_1_role.id])
end
end