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
factory :campaign do
profile
association :nonprofit, factory: :nm_justice
nonprofit_id { 55352 }
sequence(:name) { |i| "name #{i}" }
sequence(:slug) { |i| "slug_#{i}" }
end

View file

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

View file

@ -3,6 +3,7 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
FactoryBot.define do
factory :nm_justice, class: Nonprofit do
id { 55352 }
name { 'New Mexico Justice' }
city { 'Albuquerque' }
state_code { 'NM' }
@ -11,21 +12,10 @@ FactoryBot.define do
slug { 'new_mexican_equality' }
state_code_slug { 'nm'}
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
factory :fv_poverty, class: Nonprofit do
id { 22352 }
name { 'Ending Poverty in the Fox Valley Inc.' }
city { 'Appleton' }
state_code { 'WI' }
@ -36,5 +26,4 @@ FactoryBot.define do
state_code_slug { 'wi'}
city_slug { 'appleton'}
end
end

View file

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

View file

@ -6,7 +6,7 @@ require 'rails_helper'
describe CreatePeerToPeerCampaign do
describe '.create' do
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
it 'returns a hash' do

View file

@ -396,7 +396,7 @@ describe InsertCard do
end
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)
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

View file

@ -6,7 +6,7 @@ require 'support/payments_for_a_payout'
describe QueryPayments 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),
force_create(:supporter, name: 'supporter-1', nonprofit: @nonprofit)]

View file

@ -29,8 +29,8 @@ describe SlugNonprofitNamingAlgorithm do
describe 'nonprofits' do
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(: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_state) { force_create(:fv_poverty, slug: @name, state_code_slug: not_our_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, id: 523950250) }
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
(0..99).collect do |i|
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
end
let(:np) { force_create(:nm_justice) }
let(:supporter) { force_create(:supporter, nonprofit: np) }
let(:supporter) { force_create(:supporter) }
let(:donation) do
force_create(:donation, nonprofit: np,
dedication: initial_dedication,
@ -48,10 +48,10 @@ describe UpdateDonation do
fee_total: initial_fee,
net_amount: initial_amount - initial_fee)
end
let(:campaign) { force_create(:campaign, nonprofit: np) }
let(:event) { force_create(:event, nonprofit: np) }
let(:other_campaign) { force_create(:campaign) }
let(:other_event) { force_create(:event) }
let(:campaign) { force_create(:campaign) }
let(:event) { force_create(:event) }
let(:other_campaign) { force_create(:campaign, nonprofit: force_create(:fv_poverty)) }
let(:other_event) { force_create(:event, nonprofit: force_create(:fv_poverty)) }
let(:initial_date) { Date.new(2020, 4, 5).to_time }
let(:initial_dedication) { 'initial dedication' }

View file

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

View file

@ -86,7 +86,7 @@ shared_context 'payments for a payout' do
end
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')
return p
end