2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-21 20:03:46 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SlugNonprofitNamingAlgorithm 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-05-21 20:03:46 +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-00' }
|
|
|
|
let(:short_slug_copy_today_plus_1) { 'slug_name-01' }
|
|
|
|
let(:copy_base) { 'slug_name' }
|
2018-05-21 20:03:46 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:state_slug) { 'state_slug' }
|
|
|
|
let(:city_slug) { 'city_slug' }
|
|
|
|
let(:not_our_state_slug) { 'not_our_state_slug' }
|
|
|
|
let(:not_our_city_slug) { 'not_our_city_slug' }
|
2018-05-21 20:03:46 +00:00
|
|
|
|
|
|
|
describe 'nonprofits' do
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:nonprofit) { force_create(:nonprofit, slug: @name, state_code_slug: state_slug, city_slug: city_slug) }
|
|
|
|
let(:nonprofit2) { force_create(:nonprofit, slug: @name2, state_code_slug: state_slug, city_slug: city_slug) }
|
|
|
|
let(:nonprofit_in_other_city) { force_create(:nonprofit, slug: @name, state_code_slug: state_slug, city_slug: not_our_city_slug) }
|
|
|
|
let(:nonprofit_in_other_state) { force_create(:nonprofit, slug: @name, state_code_slug: not_our_state_slug, city_slug: city_slug) }
|
|
|
|
let(:nonprofit_at_max_copies) do
|
|
|
|
(0..99).collect do |i|
|
|
|
|
force_create(:nonprofit, slug: "#{@copy_base}-#{format('%02d', i)}", state_code_slug: state_slug, city_slug: city_slug)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let(:algo) { SlugNonprofitNamingAlgorithm.new(state_slug, city_slug) }
|
2018-05-21 20:03:46 +00:00
|
|
|
|
|
|
|
describe 'nonprofit slugs' do
|
|
|
|
it 'not a copy' do
|
|
|
|
@name = short_slug
|
|
|
|
nonprofit
|
|
|
|
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
|
|
|
|
nonprofit
|
|
|
|
nonprofit2
|
|
|
|
nonprofit_in_other_city
|
|
|
|
nonprofit_in_other_state
|
|
|
|
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 'it has 99 as max copies' do
|
|
|
|
expect(algo.max_copies).to eq 99
|
2018-05-21 20:03:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|