diff options
author | John Hawthorn <john@stembolt.com> | 2017-04-18 14:08:32 -0700 |
---|---|---|
committer | Brendan Deere <brendan.g.deere@gmail.com> | 2017-05-23 03:43:05 -0700 |
commit | 47735dc25a80b2b95432814341c32c31205a0852 (patch) | |
tree | f2c26646e45bd060b0448e3ae056d32b6dfb40af | |
parent | 2deac6d200887f8e3e83bf492110d79879793c32 (diff) |
Ensure user exists when setting CC#default=true
This is necessary to support the new wallet schema in Solidus 2.2
3 files changed, 11 insertions, 12 deletions
diff --git a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb index 222f9ef..036b4c2 100644 --- a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb @@ -5,8 +5,9 @@ FactoryGirl.define do interval_units :month user do - ccs = build_list(:credit_card, 1, gateway_customer_profile_id: 'BGS-123', default: true) - build :user, :subscription_user, credit_cards: ccs + create(:user, :subscription_user).tap do |user| + create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user, default: true) + end end trait :with_line_item do diff --git a/spec/lib/solidus_subscriptions/processor_spec.rb b/spec/lib/solidus_subscriptions/processor_spec.rb index a21d22f..bccff78 100644 --- a/spec/lib/solidus_subscriptions/processor_spec.rb +++ b/spec/lib/solidus_subscriptions/processor_spec.rb @@ -4,9 +4,10 @@ RSpec.describe SolidusSubscriptions::Processor, :checkout do include ActiveJob::TestHelper around { |e| perform_enqueued_jobs { e.run } } - let(:user) do - ccs = build_list(:credit_card, 1, gateway_customer_profile_id: 'BGS-123', default: true) - build :user, :subscription_user, credit_cards: ccs + let!(:user) do + create(:user, :subscription_user).tap do |user| + create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user, default: true) + end end let!(:actionable_subscriptions) { create_list(:subscription, 2, :actionable, user: user) } diff --git a/spec/models/solidus_subscriptions/checkout_spec.rb b/spec/models/solidus_subscriptions/checkout_spec.rb index 30d6e40..5e8cc0b 100644 --- a/spec/models/solidus_subscriptions/checkout_spec.rb +++ b/spec/models/solidus_subscriptions/checkout_spec.rb @@ -4,8 +4,9 @@ RSpec.describe SolidusSubscriptions::Checkout do let(:checkout) { described_class.new(installments) } let(:root_order) { create :completed_order_with_pending_payment } let(:subscription_user) do - ccs = build_list(:credit_card, 1, gateway_customer_profile_id: 'BGS-123', default: true) - create :user, :subscription_user, credit_cards: ccs + create(:user, :subscription_user).tap do |user| + create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user, default: true) + end end let(:installments) { create_list(:installment, 2, installment_traits) } @@ -138,13 +139,9 @@ RSpec.describe SolidusSubscriptions::Checkout do end context 'the payment fails' do - let(:credit_card) { create(:credit_card, default: true) } + let!(:credit_card) { create(:credit_card, user: checkout.user, default: true) } let(:expected_date) { (DateTime.current + SolidusSubscriptions::Config.reprocessing_interval).beginning_of_minute } - before do - checkout.user.credit_cards << credit_card - end - it { is_expected.to be_nil } it 'marks all of the installments as failed' do |