summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2021-02-26 18:20:52 +0100
committerGitHub <noreply@github.com>2021-02-26 18:20:52 +0100
commit5d965b6ac0b2b9fcb69d3b40cd274c3c9eef6355 (patch)
tree7594315c808384003a39e644da247bbdfbb10188 /spec
parentf39f79dc97577016c0229598a3ef3d1d7d224553 (diff)
parent4bbe6a7b5660f05b8feb0ba7ce17f145872e1a64 (diff)
Merge pull request #195 from igorbp/fix-duplicated-line-items
Fix duplicated line items creation
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/spree/admin/subscriptions_controller_spec.rb68
1 files changed, 59 insertions, 9 deletions
diff --git a/spec/controllers/spree/admin/subscriptions_controller_spec.rb b/spec/controllers/spree/admin/subscriptions_controller_spec.rb
index 7626efd..b2a5ec5 100644
--- a/spec/controllers/spree/admin/subscriptions_controller_spec.rb
+++ b/spec/controllers/spree/admin/subscriptions_controller_spec.rb
@@ -42,20 +42,70 @@ RSpec.describe Spree::Admin::SubscriptionsController, type: :request do
end
describe 'PUT :update' do
- subject { put spree.admin_subscription_path(subscription), params: subscription_params }
+ it 'redirects to edit subscription page' do
+ subscription = create :subscription
+ subscription_params = { subscription: { interval_length: 1 } }
- let(:expected_date) { DateTime.parse('2001/11/12') }
- let(:subscription) { create :subscription, :actionable }
- let(:subscription_params) do
- {
- subscription: { actionable_date: expected_date }
+ expect(put(spree.admin_subscription_path(subscription), params: subscription_params)).
+ to redirect_to spree.edit_admin_subscription_path(subscription)
+ end
+
+ it 'updates the subscription attributes', :aggregate_failures do
+ expected_date = DateTime.parse('2001/11/12')
+ subscription = create :subscription, :actionable
+ subscription_params = { subscription: { actionable_date: expected_date } }
+
+ expect { put spree.admin_subscription_path(subscription), params: subscription_params }.
+ to change { subscription.reload.actionable_date }.
+ to expected_date
+ end
+
+ it 'does not duplicate line items' do
+ variant = create :variant, subscribable: true
+ subscription = create :subscription
+ subscription_params = {
+ subscription: {
+ line_items_attributes: [
+ { subscribable_id: variant.id, quantity: 1 }
+ ]
+ }
}
+
+ expect { put spree.admin_subscription_path(subscription), params: subscription_params }.
+ to change { subscription.reload.line_items.count }.
+ by 1
end
- it { is_expected.to redirect_to spree.edit_admin_subscription_path(subscription) }
+ context 'when updating the payment method' do
+ it 'updates the subscription payment method' do
+ check_payment_method = create :check_payment_method
+ subscription = create :subscription
+ subscription_params = { subscription: { payment_method_id: check_payment_method.id } }
- it 'updates the subscription attributes', :aggregate_failures do
- expect { subject }.to change { subscription.reload.actionable_date }.to expected_date
+ put spree.admin_subscription_path(subscription), params: subscription_params
+
+ expect(subscription.reload).to have_attributes(
+ payment_method: check_payment_method,
+ payment_source: nil,
+ )
+ end
+
+ it 'updates the subscription payment source if payment method requires source' do
+ subscription = create :subscription
+ payment = create :credit_card_payment
+ payment_source = payment.source
+ payment_method = payment.payment_method
+ subscription_params = {
+ subscription: {
+ payment_method_id: payment_method.id,
+ payment_source_id: payment_source.id,
+ }
+ }
+
+ put spree.admin_subscription_path(subscription), params: subscription_params
+
+ expect(subscription.reload.payment_source).to eq(payment_source)
+ end
end
end