Implements targets and campaigns for conference
This commit is contained in:
parent
678fe38a25
commit
857ac43e74
40 changed files with 1086 additions and 44 deletions
8
spec/factories/campaigns.rb
Normal file
8
spec/factories/campaigns.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :campaign do
|
||||
name 'Test Campaign'
|
||||
utm_campaign 'testcampaign'
|
||||
end
|
||||
end
|
||||
9
spec/factories/targets.rb
Normal file
9
spec/factories/targets.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :target do
|
||||
due_date Date.today + 14
|
||||
target_count 100
|
||||
unit Target.units[:submissions]
|
||||
end
|
||||
end
|
||||
6
spec/factories/visits.rb
Normal file
6
spec/factories/visits.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :visit do
|
||||
end
|
||||
end
|
||||
59
spec/features/campaign_spec.rb
Normal file
59
spec/features/campaign_spec.rb
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature Campaign 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) }
|
||||
|
||||
shared_examples 'add and update campaign' do |user|
|
||||
scenario 'adds and update a campaign', feature: true, js: true do
|
||||
expected_count = Campaign.count + 1
|
||||
conference = create(:conference, short_title: 'osc14')
|
||||
sign_in create(user)
|
||||
|
||||
visit admin_conference_campaigns_path(conference.short_title)
|
||||
|
||||
click_link 'New Campaign'
|
||||
|
||||
click_button 'Create Campaign'
|
||||
|
||||
expect(flash).
|
||||
to eq("Creating of Campaign for osc14 failed.Name can't be blank. Utm campaign can't be blank.")
|
||||
|
||||
fill_in 'campaign_name', with: 'Test Campaign'
|
||||
fill_in 'campaign_utm_campaign', with: 'campaign'
|
||||
fill_in 'campaign_utm_source', with: 'source'
|
||||
fill_in 'campaign_utm_medium', with: 'medium'
|
||||
fill_in 'campaign_utm_term', with: 'term'
|
||||
fill_in 'campaign_utm_content', with: 'content'
|
||||
|
||||
click_button 'Create Campaign'
|
||||
|
||||
# Validations
|
||||
expect(flash).
|
||||
to eq('Campaign successfully created.')
|
||||
|
||||
expect(find('#name_0').text).to eq('Test Campaign')
|
||||
expect(find('#visits_0').text).to eq('0')
|
||||
expect(find('#registrations_0').text).to eq('0')
|
||||
expect(find('#submissions_0').text).to eq('0')
|
||||
|
||||
expect(Campaign.count).to eq(expected_count)
|
||||
|
||||
campaign = Campaign.where('name'=> 'Test Campaign').first
|
||||
visit edit_admin_conference_campaign_path(conference.short_title, campaign.id)
|
||||
|
||||
fill_in 'campaign_name', with: 'Test Campaign 42'
|
||||
click_button 'Update Campaign'
|
||||
expect(flash).
|
||||
to eq("Campaign 'Test Campaign 42' successfully updated.")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'add and update campaign', :admin
|
||||
it_behaves_like 'add and update campaign', :organizer
|
||||
end
|
||||
end
|
||||
71
spec/models/campaign_spec.rb
Normal file
71
spec/models/campaign_spec.rb
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
require 'spec_helper'
|
||||
require 'ahoy'
|
||||
|
||||
describe Campaign do
|
||||
describe 'validations' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:campaign)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a name' do
|
||||
should validate_presence_of(:name)
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
result = '?utm_source=google+&utm_medium=advertisement&utm_term=opensource&utm_content=content&utm_campaign=20percent'
|
||||
expect(campaign.url_parameters).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns only utm_campaign parameter if there are no parameters' do
|
||||
campaign = create(:campaign)
|
||||
campaign.conference = create(:conference)
|
||||
expect(campaign.url_parameters).to eq('?utm_campaign=testcampaign')
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
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)
|
||||
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')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
expect(campaign.visits_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.registrations_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.submissions_count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,35 +6,98 @@ describe Conference do
|
|||
|
||||
let(:subject) { create(:conference) }
|
||||
|
||||
# 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) }
|
||||
#
|
||||
# it 'calculates correct hash with top submitters' do
|
||||
# event = create(:event, conference: subject)
|
||||
# result = {
|
||||
# event.submitter => 1
|
||||
# }
|
||||
# expect(subject.get_top_submitter).to eq(result)
|
||||
# end
|
||||
#
|
||||
# it 'returns the submitter ordered by submissions' do
|
||||
# e1 = create(:event, conference: subject)
|
||||
#
|
||||
# e2 = create(:event, conference: subject)
|
||||
# e3 = create(:event, conference: subject)
|
||||
# e4 = create(:event, conference: subject)
|
||||
#
|
||||
# e3.event_people = [create(:event_person, person: e2.submitter, event_role: 'submitter')]
|
||||
# e4.event_people = [create(:event_person, person: e2.submitter, event_role: 'submitter')]
|
||||
#
|
||||
# expect(subject.get_top_submitter.values).to eq([3, 1])
|
||||
# expect(subject.get_top_submitter.keys).to eq([e2.submitter, e1.submitter])
|
||||
# end
|
||||
#
|
||||
# end
|
||||
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) }
|
||||
|
||||
it 'calculates correct hash with top submitters' do
|
||||
event = create(:event, conference: subject)
|
||||
result = {
|
||||
event.submitter => 1
|
||||
}
|
||||
expect(subject.get_top_submitter).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns the submitter ordered by submissions' do
|
||||
e1 = create(:event, conference: subject)
|
||||
|
||||
e2 = create(:event, conference: subject)
|
||||
e3 = create(:event, conference: subject)
|
||||
e4 = create(:event, conference: subject)
|
||||
|
||||
e3.event_people = [create(:event_person, person: e2.submitter, event_role: 'submitter')]
|
||||
e4.event_people = [create(:event_person, person: e2.submitter, event_role: 'submitter')]
|
||||
|
||||
expect(subject.get_top_submitter.values).to eq([3, 1])
|
||||
expect(subject.get_top_submitter.keys).to eq([e2.submitter, e1.submitter])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#get_targets' do
|
||||
it 'returns 0 if there is no registration' do
|
||||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns 10 if there is 1 registration of 10' do
|
||||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
subject.targets = [target]
|
||||
subject.registrations = [create(:registration)]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns an empty hash if there is no target' do
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq({})
|
||||
end
|
||||
|
||||
it 'returns 0 if there is no submission' do
|
||||
target = build(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns 10 if there is 1 submissions of 10' do
|
||||
target = build(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns 0 if there is no program minute' do
|
||||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
|
||||
it 'returns 10 if there is 30 program minutes of 300' do
|
||||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
||||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'program hours' do
|
||||
before(:each) do
|
||||
|
|
|
|||
105
spec/models/target_spec.rb
Normal file
105
spec/models/target_spec.rb
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Target do
|
||||
|
||||
describe 'validations' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:target)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a due date' do
|
||||
should validate_presence_of(:due_date)
|
||||
end
|
||||
|
||||
it 'is not valid without a target_count' do
|
||||
should validate_presence_of(:target_count)
|
||||
end
|
||||
|
||||
it 'is not valid without a unit' do
|
||||
should validate_presence_of(:unit)
|
||||
end
|
||||
|
||||
it 'is valid with a target_count greater than zero' do
|
||||
should allow_value(10).for(:target_count)
|
||||
end
|
||||
|
||||
it 'is not valid with a target_count equals zero' do
|
||||
should_not allow_value(0).for(:target_count)
|
||||
end
|
||||
|
||||
it 'is not valid with a target_count smaller than zero' do
|
||||
should_not allow_value(-10).for(:target_count)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get_progress' do
|
||||
it 'returns zero if there are no registrations' do
|
||||
conference = build(:conference)
|
||||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
conference.targets = [target]
|
||||
|
||||
expect(target.get_progress).to eq('0')
|
||||
end
|
||||
|
||||
it 'returns 10 if there one registrations of 10' do
|
||||
conference = create(:conference)
|
||||
target = create(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
registration = create(:registration)
|
||||
|
||||
conference.targets = [target]
|
||||
conference.registrations = [registration]
|
||||
|
||||
expect(target.get_progress).to eq('10')
|
||||
end
|
||||
|
||||
it 'returns zero if there are no submissions' do
|
||||
conference = build(:conference)
|
||||
target = build(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
conference.targets = [target]
|
||||
|
||||
expect(target.get_progress).to eq('0')
|
||||
end
|
||||
|
||||
it 'returns 10 if there one submissions of 10' do
|
||||
conference = create(:conference)
|
||||
target = create(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
event = create(:event)
|
||||
|
||||
conference.targets = [target]
|
||||
conference.events = [event]
|
||||
|
||||
expect(target.get_progress).to eq('10')
|
||||
end
|
||||
|
||||
it 'returns zero if there are no program minutes' do
|
||||
conference = build(:conference)
|
||||
target = build(:target, target_count: 10, unit: Target.units[:program_minutes])
|
||||
conference.targets = [target]
|
||||
|
||||
expect(target.get_progress).to eq('0')
|
||||
end
|
||||
|
||||
it 'returns 10 if there are 30 program minutes of 300' do
|
||||
conference = create(:conference)
|
||||
target = create(:target, target_count: 300, unit: Target.units[:program_minutes])
|
||||
event = create(:event)
|
||||
|
||||
conference.targets = [target]
|
||||
conference.events = [event]
|
||||
|
||||
expect(target.get_progress).to eq('10')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it 'returns a string in the correct format' do
|
||||
conference = build(:conference)
|
||||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
conference.targets = [target]
|
||||
|
||||
result = "10 Registrations by #{Date.today + 14}"
|
||||
|
||||
expect(target.to_s).to eq(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue