rework roles with rolify
This commit is contained in:
parent
f9f840c811
commit
4af0e59ca6
40 changed files with 167 additions and 228 deletions
|
|
@ -15,7 +15,8 @@ describe Campaign do
|
|||
describe '#url_parameters' do
|
||||
it 'returns the parameters in the correct format' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
result = '?utm_source=google+&utm_medium=advertisement&utm_term=opensource&utm_content=content&utm_campaign=20percent'
|
||||
|
|
@ -32,17 +33,19 @@ describe Campaign do
|
|||
describe '#visits' do
|
||||
it 'returns one if there is one visit' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
create(:visit, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent', started_at: Time.now)
|
||||
create(:visit, utm_source: 'google+', utm_medium: 'advertisement', utm_term: 'opensource',
|
||||
utm_content: 'content', utm_campaign: '20percent', started_at: Time.now)
|
||||
expect(campaign.visits_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'returns zero if there are no visits' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
expect(campaign.visits_count).to eq(0)
|
||||
|
|
@ -52,7 +55,8 @@ describe Campaign do
|
|||
describe '#registrations' do
|
||||
it 'returns zero if there are no registration' do
|
||||
campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.registrations_count).to eq(0)
|
||||
|
|
@ -62,7 +66,8 @@ describe Campaign do
|
|||
describe '#submissions' do
|
||||
it 'returns zero if there are no submissions' do
|
||||
campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.submissions_count).to eq(0)
|
||||
|
|
|
|||
|
|
@ -274,9 +274,8 @@ describe Conference do
|
|||
|
||||
describe '#get_top_submitter' 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!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
it 'calculates correct hash with top submitters' do
|
||||
event = create(:event, conference: subject)
|
||||
|
|
@ -307,7 +306,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '0'
|
||||
"10 Registrations by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
|
@ -317,7 +316,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.registrations = [create(:registration)]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '10'
|
||||
"10 Registrations by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
|
@ -330,7 +329,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '0'
|
||||
"10 Submissions by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
|
@ -340,7 +339,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '10'
|
||||
"10 Submissions by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
|
@ -349,7 +348,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '0'
|
||||
"300 Program minutes by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
|
|
@ -359,7 +358,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '10'
|
||||
"300 Program minutes by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
|
|
@ -897,9 +896,8 @@ describe Conference do
|
|||
|
||||
describe 'self#event_distribution' 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!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
it 'self#event_distribution calculates correct values with user' do
|
||||
create(:user, last_sign_in_at: Date.today - 3.months) # active
|
||||
|
|
@ -1426,9 +1424,8 @@ describe Conference do
|
|||
describe '#user_registered?' 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!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
|
||||
|
|
|
|||
|
|
@ -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