2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SlugCopyNamingAlgorithm do
|
|
|
|
describe '.create_copy_name' do
|
2019-07-30 21:29:24 +00:00
|
|
|
before(:all) do
|
|
|
|
Timecop.freeze(2020, 5, 4)
|
|
|
|
end
|
|
|
|
after(:all) do
|
|
|
|
Timecop.return
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def set_name(name)
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:short_slug) { 'slug_name' }
|
|
|
|
let(:short_slug_copy_today) { 'slug_name_copy_00' }
|
|
|
|
let(:short_slug_copy_today_plus_1) { 'slug_name_copy_01' }
|
|
|
|
let(:copy_base) { 'slug_name_copy' }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2020-04-16 20:50:03 +00:00
|
|
|
let(:nonprofit) { force_create(:nm_justice) }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
describe 'events' do
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:event) { force_create(:event, slug: @name, nonprofit: nonprofit) }
|
|
|
|
let(:event2) { force_create(:event, slug: @name2, nonprofit: nonprofit) }
|
|
|
|
let(:events_at_max_copies) do
|
|
|
|
(0..30).collect do |i|
|
|
|
|
force_create(:event, slug: "#{@copy_base}_#{format('%02d', i)}", nonprofit: nonprofit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let(:algo) { SlugCopyNamingAlgorithm.new(Event, nonprofit.id) }
|
2018-03-25 17:30:42 +00:00
|
|
|
describe 'event slugs' do
|
|
|
|
it 'not a copy' do
|
|
|
|
@name = short_slug
|
|
|
|
event
|
|
|
|
expect(algo.create_copy_name(@name)).to eq short_slug_copy_today
|
|
|
|
end
|
|
|
|
it 'one copy exists' do
|
|
|
|
@name = short_slug
|
|
|
|
@name2 = short_slug_copy_today
|
|
|
|
event
|
|
|
|
event2
|
|
|
|
expect(algo.create_copy_name(@name)).to eq short_slug_copy_today_plus_1
|
|
|
|
expect(algo.create_copy_name(@name2)).to eq short_slug_copy_today_plus_1
|
|
|
|
end
|
|
|
|
|
2018-12-10 19:24:35 +00:00
|
|
|
it 'has 30 as max copies' do
|
|
|
|
expect(algo.max_copies).to eq 30
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'campaigns' do
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:campaign) { force_create(:campaign, slug: @name, nonprofit: nonprofit) }
|
|
|
|
let(:campaign2) { force_create(:campaign, slug: @name2, nonprofit: nonprofit) }
|
|
|
|
let(:campaigns_at_max_copies) do
|
|
|
|
(0..30).collect do |i|
|
|
|
|
force_create(:campaign, slug: "#{@copy_base}_#{format('%02d', i)}", nonprofit: nonprofit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let(:algo) { SlugCopyNamingAlgorithm.new(Campaign, nonprofit.id) }
|
2018-03-25 17:30:42 +00:00
|
|
|
describe 'campaign slugs' do
|
|
|
|
it 'not a copy' do
|
|
|
|
@name = short_slug
|
|
|
|
campaign
|
|
|
|
expect(algo.create_copy_name(@name)).to eq short_slug_copy_today
|
|
|
|
end
|
|
|
|
it 'one copy exists' do
|
|
|
|
@name = short_slug
|
|
|
|
@name2 = short_slug_copy_today
|
|
|
|
campaign
|
|
|
|
campaign2
|
|
|
|
expect(algo.create_copy_name(@name)).to eq short_slug_copy_today_plus_1
|
|
|
|
expect(algo.create_copy_name(@name2)).to eq short_slug_copy_today_plus_1
|
|
|
|
end
|
|
|
|
|
2018-12-10 19:24:35 +00:00
|
|
|
it 'has 30 as max copies' do
|
|
|
|
expect(algo.max_copies).to eq 30
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|