Merge branch 'cleanup_factory_bot' into rails-v5

This commit is contained in:
Eric Schultz 2020-04-17 14:14:33 -05:00
commit 2df19e64a2
11 changed files with 16 additions and 29 deletions

View file

@ -4,7 +4,7 @@
FactoryBot.define do FactoryBot.define do
factory :campaign do factory :campaign do
profile profile
association :nonprofit, factory: :nm_justice nonprofit_id { 55352 }
sequence(:name) { |i| "name #{i}" } sequence(:name) { |i| "name #{i}" }
sequence(:slug) { |i| "slug_#{i}" } sequence(:slug) { |i| "slug_#{i}" }
end end

View file

@ -10,7 +10,7 @@ FactoryBot.define do
city { 'Appleton' } city { 'Appleton' }
state_code { 'WI' } state_code { 'WI' }
slug { 'event-of-wonders' } slug { 'event-of-wonders' }
association :nonprofit, factory: :nm_justice nonprofit_id { 55352 }
profile profile
end end
end end

View file

@ -3,6 +3,7 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
FactoryBot.define do FactoryBot.define do
factory :nm_justice, class: Nonprofit do factory :nm_justice, class: Nonprofit do
id { 55352 }
name { 'New Mexico Justice' } name { 'New Mexico Justice' }
city { 'Albuquerque' } city { 'Albuquerque' }
state_code { 'NM' } state_code { 'NM' }
@ -11,21 +12,10 @@ FactoryBot.define do
slug { 'new_mexican_equality' } slug { 'new_mexican_equality' }
state_code_slug { 'nm'} state_code_slug { 'nm'}
city_slug { 'albuquerque'} city_slug { 'albuquerque'}
# factory :nonprofit_with_cards do
# after(:create) do |nonprofit, _evaluator|
# create(:active_card_1, holder: nonprofit)
# create(:active_card_2, holder: nonprofit)
# create(:inactive_card, holder: nonprofit)
# end
# end
# after(:create) do |nonprofit, _evaluator|
# create(:supporter, nonprofit: nonprofit)
# end
end end
factory :fv_poverty, class: Nonprofit do factory :fv_poverty, class: Nonprofit do
id { 22352 }
name { 'Ending Poverty in the Fox Valley Inc.' } name { 'Ending Poverty in the Fox Valley Inc.' }
city { 'Appleton' } city { 'Appleton' }
state_code { 'WI' } state_code { 'WI' }
@ -36,5 +26,4 @@ FactoryBot.define do
state_code_slug { 'wi'} state_code_slug { 'wi'}
city_slug { 'appleton'} city_slug { 'appleton'}
end end
end end

View file

@ -4,7 +4,7 @@
FactoryBot.define do FactoryBot.define do
factory :supporter do factory :supporter do
name { 'Fake Supporter Name' } name { 'Fake Supporter Name' }
association :nonprofit, factory: :nm_justice nonprofit_id { 55352 }
trait :has_a_card do trait :has_a_card do
after(:create) do |supporter| after(:create) do |supporter|
create(:active_card_1, holder: supporter) create(:active_card_1, holder: supporter)

View file

@ -6,7 +6,7 @@ require 'rails_helper'
describe CreatePeerToPeerCampaign do describe CreatePeerToPeerCampaign do
describe '.create' do describe '.create' do
let!(:profile) { force_create(:profile, user: force_create(:user)) } let!(:profile) { force_create(:profile, user: force_create(:user)) }
let!(:parent_campaign) { force_create(:campaign, name: 'Parent campaign') } let!(:parent_campaign) { force_create(:campaign, name: 'Parent campaign', nonprofit: force_create(:nm_justice)) }
context 'on success' do context 'on success' do
it 'returns a hash' do it 'returns a hash' do

View file

@ -396,7 +396,7 @@ describe InsertCard do
end end
it 'should return proper error when event doesnt match the supporters nonprofit' do it 'should return proper error when event doesnt match the supporters nonprofit' do
supporter2 = force_create(:supporter) supporter2 = force_create(:supporter, nonprofit: force_create(:fv_poverty))
ret = InsertCard.with_stripe({ holder_id: supporter2.id, holder_type: 'Supporter', stripe_card_id: 'card_fafjeht', stripe_card_token: stripe_card_token, name: 'name' }, nil, event.id, user_not_from_nonprofit) ret = InsertCard.with_stripe({ holder_id: supporter2.id, holder_type: 'Supporter', stripe_card_id: 'card_fafjeht', stripe_card_token: stripe_card_token, name: 'name' }, nil, event.id, user_not_from_nonprofit)
expect(ret).to eq(status: :unprocessable_entity, json: { error: "Oops! There was an error: Event #{event.id} is not for the same nonprofit as supporter #{supporter2.id}" }) expect(ret).to eq(status: :unprocessable_entity, json: { error: "Oops! There was an error: Event #{event.id} is not for the same nonprofit as supporter #{supporter2.id}" })
end end

View file

@ -6,7 +6,7 @@ require 'support/payments_for_a_payout'
describe QueryPayments do describe QueryPayments do
before :each do before :each do
@nonprofit = force_create(:nm_justice, name: 'npo1') @nonprofit = force_create(:nm_justice, name: 'npo1', id: 515152)
@supporters = [force_create(:supporter, name: 'supporter-0', nonprofit: @nonprofit), @supporters = [force_create(:supporter, name: 'supporter-0', nonprofit: @nonprofit),
force_create(:supporter, name: 'supporter-1', nonprofit: @nonprofit)] force_create(:supporter, name: 'supporter-1', nonprofit: @nonprofit)]

View file

@ -29,8 +29,8 @@ describe SlugNonprofitNamingAlgorithm do
describe 'nonprofits' do describe 'nonprofits' do
let(:nonprofit) { force_create(:nm_justice, slug: @name, state_code_slug: state_slug, city_slug: city_slug) } let(:nonprofit) { force_create(:nm_justice, slug: @name, state_code_slug: state_slug, city_slug: city_slug) }
let(:nonprofit2) { force_create(:fv_poverty, slug: @name2, state_code_slug: state_slug, city_slug: city_slug) } let(:nonprofit2) { force_create(:fv_poverty, slug: @name2, state_code_slug: state_slug, city_slug: city_slug) }
let(:nonprofit_in_other_city) { force_create(:nm_justice, slug: @name, state_code_slug: state_slug, city_slug: not_our_city_slug) } let(:nonprofit_in_other_city) { force_create(:nm_justice, slug: @name, state_code_slug: state_slug, city_slug: not_our_city_slug, id: 523950250) }
let(:nonprofit_in_other_state) { force_create(:fv_poverty, slug: @name, state_code_slug: not_our_state_slug, city_slug: city_slug) } let(:nonprofit_in_other_state) { force_create(:fv_poverty, slug: @name, state_code_slug: not_our_state_slug, city_slug: city_slug, id: 5239502) }
let(:nonprofit_at_max_copies) do let(:nonprofit_at_max_copies) do
(0..99).collect do |i| (0..99).collect do |i|
force_create(:nonprofit, slug: "#{@copy_base}-#{format('%02d', i)}", state_code_slug: state_slug, city_slug: city_slug) force_create(:nonprofit, slug: "#{@copy_base}-#{format('%02d', i)}", state_code_slug: state_slug, city_slug: city_slug)

View file

@ -12,7 +12,7 @@ describe UpdateDonation do
Timecop.return Timecop.return
end end
let(:np) { force_create(:nm_justice) } let(:np) { force_create(:nm_justice) }
let(:supporter) { force_create(:supporter, nonprofit: np) } let(:supporter) { force_create(:supporter) }
let(:donation) do let(:donation) do
force_create(:donation, nonprofit: np, force_create(:donation, nonprofit: np,
dedication: initial_dedication, dedication: initial_dedication,
@ -48,10 +48,10 @@ describe UpdateDonation do
fee_total: initial_fee, fee_total: initial_fee,
net_amount: initial_amount - initial_fee) net_amount: initial_amount - initial_fee)
end end
let(:campaign) { force_create(:campaign, nonprofit: np) } let(:campaign) { force_create(:campaign) }
let(:event) { force_create(:event, nonprofit: np) } let(:event) { force_create(:event) }
let(:other_campaign) { force_create(:campaign) } let(:other_campaign) { force_create(:campaign, nonprofit: force_create(:fv_poverty)) }
let(:other_event) { force_create(:event) } let(:other_event) { force_create(:event, nonprofit: force_create(:fv_poverty)) }
let(:initial_date) { Date.new(2020, 4, 5).to_time } let(:initial_date) { Date.new(2020, 4, 5).to_time }
let(:initial_dedication) { 'initial dedication' } let(:initial_dedication) { 'initial dedication' }

View file

@ -6,8 +6,6 @@ require 'rails_helper'
describe UpdateRecurringDonations do describe UpdateRecurringDonations do
# deactivate a recurring donation # deactivate a recurring donation
describe '.cancel' do describe '.cancel' do
before(:each) do
end
let(:np) { force_create(:nm_justice) } let(:np) { force_create(:nm_justice) }
let(:s) { force_create(:supporter) } let(:s) { force_create(:supporter) }

View file

@ -86,7 +86,7 @@ shared_context 'payments for a payout' do
end end
let(:other_np_payment) do let(:other_np_payment) do
p = create_payment(nonprofit: force_create(:nm_justice)) p = create_payment(nonprofit: force_create(:fv_poverty))
create_charge(payment: p, amount: 2000, fee: -400, status: 'available') create_charge(payment: p, amount: 2000, fee: -400, status: 'available')
return p return p
end end