Every campaign has an end.

Drop ahoy, because it's more trouble than it's worth. This means dropping
visits, campaigns, targets.

Campaigns are better run to analytics, such as:
* https://matomo.org/docs/tracking-campaigns/
* https://matomo.org/docs/tracking-goals-web-analytics/
* https://support.google.com/analytics/answer/1012040?hl=en
This commit is contained in:
James Mason 2018-10-08 17:58:41 -07:00 committed by Henne Vogelsang
parent 62056fc044
commit b11001cdba
47 changed files with 19 additions and 1420 deletions

View file

@ -1,73 +0,0 @@
# frozen_string_literal: true
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 + 1.hour)
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

View file

@ -302,69 +302,6 @@ describe Conference do
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.program.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.program.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 and minutes' do
before(:each) do
@long = create(:event_type, length: 120)

View file

@ -1,166 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe Target do
let(:registration_target) { create(:target, target_count: 10, unit: Target.units[:registrations]) }
let(:submission_target) { create(:target, target_count: 10, unit: Target.units[:submissions]) }
let(:program_minutes_target) { create(:target, target_count: 300, unit: Target.units[:program_minutes]) }
describe 'validation' 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 'default scope' do
before do
@first_target = create(:target, due_date: 2.days.from_now)
@second_target = create(:target, due_date: 3.days.from_now)
end
it 'orders by ascending due_date' do
expect(Target.all).to match_array [@first_target, @second_target]
end
end
describe 'association' do
it { should belong_to(:conference) }
it { should belong_to(:campaign) }
end
describe '#get_progress' do
it 'returns zero, when there are no registrations' do
expect(registration_target.get_progress).to eq('0')
end
it 'returns 10, when there is 1 registration and the target is 10' do
create(:registration, conference: registration_target.conference)
expect(registration_target.get_progress).to eq('10')
end
it 'returns zero, when there are no submissions' do
expect(submission_target.get_progress).to eq('0')
end
it 'returns 10, when there is 1 submission and the target is 10' do
create(:event, program: submission_target.conference.program)
expect(submission_target.get_progress).to eq('10')
end
it 'returns zero, when there are no program minutes' do
expect(program_minutes_target.get_progress).to eq('0')
end
it 'returns 10, when there are 30 program minutes and the target is 300' do
create(:event, program: program_minutes_target.conference.program)
expect(program_minutes_target.get_progress).to eq('10')
end
end
describe '#get_campaign' do
context 'submissions' do
before do
submission_target.campaign = create(:campaign, name: 'Submission Campaign', conference: submission_target.conference)
submission_target.created_at = Time.utc(2014, 5, 10)
submission_target.due_date = Date.today + 4.days
allow(submission_target.campaign).to receive(:submissions_count) { 20 }
end
it 'returns a hash with values of the corresponding campaign submissions' do
result = {
'target_name' => "10 Submissions by #{Date.today + 4.days}",
'campaign_name' => 'Submission Campaign',
'value' => 20,
'unit' => 'Submission',
'created_at' => Time.utc(2014, 5, 10).in_time_zone,
'progress' => '200',
'days_left' => 4
}
expect(submission_target.get_campaign).to eq result
end
end
context 'registrations' do
before do
registration_target.campaign = create(:campaign, name: 'Registration Campaign', conference: registration_target.conference)
registration_target.created_at = Time.utc(2014, 5, 10)
registration_target.due_date = Date.today + 4.days
allow(registration_target.campaign).to receive(:registrations_count) { 20 }
end
it 'returns a hash with values of the corresponding campaign registrations' do
result = {
'target_name' => "10 Registrations by #{Date.today + 4.days}",
'campaign_name' => 'Registration Campaign',
'value' => 20,
'unit' => 'Registration',
'created_at' => Time.utc(2014, 5, 10).in_time_zone,
'progress' => '200',
'days_left' => 4
}
expect(registration_target.get_campaign).to eq result
end
end
context 'program_minutes' do
before do
program_minutes_target.campaign = create(:campaign, name: 'Program Campaign', conference: program_minutes_target.conference)
program_minutes_target.created_at = Time.utc(2014, 5, 10)
program_minutes_target.due_date = Date.today + 4.days
allow(program_minutes_target.conference).to receive(:current_program_minutes) { 20 }
end
it 'returns a hash with values of the corresponding campaign program minutes' do
result = {
'target_name' => "300 Program minutes by #{Date.today + 4.days}",
'campaign_name' => 'Program Campaign',
'value' => 20,
'unit' => 'Program minute',
'created_at' => Time.utc(2014, 5, 10).in_time_zone,
'progress' => '7',
'days_left' => 4
}
expect(program_minutes_target.get_campaign).to eq result
end
end
end
describe '#to_s' do
it 'returns a string in the correct format' do
result = "10 Registrations by #{14.days.from_now.to_date}"
expect(registration_target.to_s).to eq(result)
end
end
end