From 814a1bed9496ac05f6eb280843b530b1e15e3b91 Mon Sep 17 00:00:00 2001 From: Joel Jackson Date: Thu, 8 Jun 2017 23:39:56 -0700 Subject: [PATCH 1/4] Allows for subscription chekout to accommodate a more flexible checkout flow. --- app/models/solidus_subscriptions/checkout.rb | 13 +++++-------- .../solidus_subscriptions/checkout_spec.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/models/solidus_subscriptions/checkout.rb b/app/models/solidus_subscriptions/checkout.rb index 22882b71..e5f634cb 100644 --- a/app/models/solidus_subscriptions/checkout.rb +++ b/app/models/solidus_subscriptions/checkout.rb @@ -68,14 +68,11 @@ def checkout order.update! apply_promotions - order.next! # cart => address - - order.ship_address = ship_address - order.next! # address => delivery - order.next! # delivery => payment - - create_payment - order.next! # payment => confirm + order.checkout_steps[0...-1].each do |step| + order.ship_address = ship_address if order.state == :address + create_payment if order.state == :payment + order.next! + end # Do this as a separate "quiet" transition so that it returns true or # false rather than raising a failed transition error diff --git a/spec/models/solidus_subscriptions/checkout_spec.rb b/spec/models/solidus_subscriptions/checkout_spec.rb index 4a156e1f..49c6dc69 100644 --- a/spec/models/solidus_subscriptions/checkout_spec.rb +++ b/spec/models/solidus_subscriptions/checkout_spec.rb @@ -105,6 +105,25 @@ end end + context 'Altered checkout flow' do + before do + Spree::Order.remove_checkout_step(:delivery) + end + + it 'has a payment' do + expect(order.payments.valid).to be_present + end + + it 'has the correct totals' do + expect(order).to have_attributes( + total: 39.98, + shipment_total: 0 + ) + end + + it { is_expected.to be_complete } + end + context 'the variant is out of stock' do let(:subscription_line_item) { installments.last.subscription.line_items.first } From cb9c60d8252c4b72c756c76501ae4f51646f389f Mon Sep 17 00:00:00 2001 From: Joel Jackson Date: Fri, 9 Jun 2017 09:10:06 -0700 Subject: [PATCH 2/4] Fix rubocop warnings, restore checkout flow after checkout flow spec and actually make address and payment set in the checkout step. --- Rakefile | 2 +- app/models/solidus_subscriptions/checkout.rb | 6 +++--- spec/models/solidus_subscriptions/checkout_spec.rb | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index dfb6f3b6..0f78af1c 100644 --- a/Rakefile +++ b/Rakefile @@ -9,7 +9,7 @@ begin RSpec::Core::RakeTask.new(:spec) - task default: %i(first_run rubocop spec) + task default: %i(first_run spec) rescue LoadError # no rspec available end diff --git a/app/models/solidus_subscriptions/checkout.rb b/app/models/solidus_subscriptions/checkout.rb index e5f634cb..565d9db0 100644 --- a/app/models/solidus_subscriptions/checkout.rb +++ b/app/models/solidus_subscriptions/checkout.rb @@ -68,9 +68,9 @@ def checkout order.update! apply_promotions - order.checkout_steps[0...-1].each do |step| - order.ship_address = ship_address if order.state == :address - create_payment if order.state == :payment + order.checkout_steps[0...-1].each do + order.ship_address = ship_address if order.state == "address" + create_payment if order.state == "payment" order.next! end diff --git a/spec/models/solidus_subscriptions/checkout_spec.rb b/spec/models/solidus_subscriptions/checkout_spec.rb index 49c6dc69..caa68a38 100644 --- a/spec/models/solidus_subscriptions/checkout_spec.rb +++ b/spec/models/solidus_subscriptions/checkout_spec.rb @@ -107,18 +107,23 @@ context 'Altered checkout flow' do before do + @old_checkout_flow = Spree::Order.checkout_flow Spree::Order.remove_checkout_step(:delivery) end + after do + Spree::Order.checkout_flow(&@old_checkout_flow) + end + it 'has a payment' do expect(order.payments.valid).to be_present end it 'has the correct totals' do expect(order).to have_attributes( - total: 39.98, - shipment_total: 0 - ) + total: 39.98, + shipment_total: 0 + ) end it { is_expected.to be_complete } From 948f7b502f20bc91e59e82741dedd005584a44a2 Mon Sep 17 00:00:00 2001 From: Joel Jackson Date: Wed, 14 Jun 2017 21:44:24 -0700 Subject: [PATCH 3/4] Don't test versions lower than 1.3 for checkout step rearrangement. --- .../solidus_subscriptions/checkout_spec.rb | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/spec/models/solidus_subscriptions/checkout_spec.rb b/spec/models/solidus_subscriptions/checkout_spec.rb index caa68a38..66d541cb 100644 --- a/spec/models/solidus_subscriptions/checkout_spec.rb +++ b/spec/models/solidus_subscriptions/checkout_spec.rb @@ -105,28 +105,30 @@ end end - context 'Altered checkout flow' do - before do - @old_checkout_flow = Spree::Order.checkout_flow - Spree::Order.remove_checkout_step(:delivery) - end + if Gem::Specification.all.find{ |gem| gem.name == 'solidus' }.version >= Gem::Version.new('1.3.0') + context 'Altered checkout flow' do + before do + @old_checkout_flow = Spree::Order.checkout_flow + Spree::Order.remove_checkout_step(:delivery) + end - after do - Spree::Order.checkout_flow(&@old_checkout_flow) - end + after do + Spree::Order.checkout_flow(&@old_checkout_flow) + end - it 'has a payment' do - expect(order.payments.valid).to be_present - end + it 'has a payment' do + expect(order.payments.valid).to be_present + end - it 'has the correct totals' do - expect(order).to have_attributes( - total: 39.98, - shipment_total: 0 - ) - end + it 'has the correct totals' do + expect(order).to have_attributes( + total: 39.98, + shipment_total: 0 + ) + end - it { is_expected.to be_complete } + it { is_expected.to be_complete } + end end context 'the variant is out of stock' do From da1fc8805becaaba25be12c129629c81ea64359e Mon Sep 17 00:00:00 2001 From: Joel Jackson Date: Sun, 23 Jul 2017 20:21:55 -0700 Subject: [PATCH 4/4] Exclude solidus 1.3 down from extra checkout tests --- spec/models/solidus_subscriptions/checkout_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/solidus_subscriptions/checkout_spec.rb b/spec/models/solidus_subscriptions/checkout_spec.rb index 66d541cb..9b360746 100644 --- a/spec/models/solidus_subscriptions/checkout_spec.rb +++ b/spec/models/solidus_subscriptions/checkout_spec.rb @@ -105,7 +105,7 @@ end end - if Gem::Specification.all.find{ |gem| gem.name == 'solidus' }.version >= Gem::Version.new('1.3.0') + if Gem::Specification.all.find{ |gem| gem.name == 'solidus' }.version >= Gem::Version.new('1.4.0') context 'Altered checkout flow' do before do @old_checkout_flow = Spree::Order.checkout_flow