diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-06-17 17:10:38 +0200 |
---|---|---|
committer | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-06-17 17:26:49 +0200 |
commit | 7068b2226bc009b425fb6c6a98a350ea17323b87 (patch) | |
tree | e1e651ad25d794dde685561fac5ad594da607c6f /spec | |
parent | 5437d0d72d6d6fc6d7baaa80020d60819f6640af (diff) |
Move actionable_date update logic from LineItem to Subscription
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/solidus_subscriptions/line_item_spec.rb | 54 | ||||
-rw-r--r-- | spec/models/solidus_subscriptions/subscription_spec.rb | 48 |
2 files changed, 48 insertions, 54 deletions
diff --git a/spec/models/solidus_subscriptions/line_item_spec.rb b/spec/models/solidus_subscriptions/line_item_spec.rb index 52ef2df..42349fc 100644 --- a/spec/models/solidus_subscriptions/line_item_spec.rb +++ b/spec/models/solidus_subscriptions/line_item_spec.rb @@ -110,58 +110,4 @@ RSpec.describe SolidusSubscriptions::LineItem, type: :model do end end end - - describe "#update_actionable_date_if_interval_changed" do - let(:subscription) { create :subscription } - let(:line_item) { create :subscription_line_item, subscription: subscription, interval_length: 3, interval_units: "month" } - - before do - Timecop.freeze(Date.parse("2016-09-22")) - line_item.subscription.update!(actionable_date: 1.month.ago) - end - after { Timecop.return } - - subject { line_item.update!(interval_length: 1, interval_units: "month") } - - context "with installments" do - before do - create(:installment, subscription: subscription, created_at: last_installment_date) - end - - context "when the last installment date would cause the interval to be in the past" do - let(:last_installment_date) { 2.months.ago } - it "sets the actionable_date to the current day" do - subject - expect(subscription.actionable_date).to eq Time.zone.now - end - end - - context "when the last installment date would cause the interval to be in the future" do - let(:last_installment_date) { 4.days.ago } - it "sets the actionable_date to an interval from the last installment" do - subject - expect(subscription.actionable_date).to eq 1.month.from_now(last_installment_date) - end - end - end - - context "when there are no installments" do - context "when the subscription creation date would cause the interval to be in the past" do - before do - subscription.update(created_at: 4.months.ago) - end - it "sets the actionable_date to one interval past the subscription creation date" do - subject - expect(subscription.actionable_date).to eq Time.zone.now - end - end - - context "when the subscription creation date would cause the interval to be in the future" do - it "sets the actionable_date to one interval past the subscription creation date" do - subject - expect(subscription.actionable_date).to eq Date.parse("2016-10-22") - end - end - end - end end diff --git a/spec/models/solidus_subscriptions/subscription_spec.rb b/spec/models/solidus_subscriptions/subscription_spec.rb index c54eca2..3e5ee9f 100644 --- a/spec/models/solidus_subscriptions/subscription_spec.rb +++ b/spec/models/solidus_subscriptions/subscription_spec.rb @@ -280,4 +280,52 @@ RSpec.describe SolidusSubscriptions::Subscription, type: :model do subject { described_class.processing_states } it { is_expected.to match_array [:pending, :success, :failed] } end + + describe "#update_actionable_date_if_interval_changed" do + context "with installments" do + context "when the last installment date would cause the interval to be in the past" do + it "sets the actionable_date to the current day" do + subscription = create(:subscription, actionable_date: Time.zone.parse('2016-08-22')) + create(:installment, subscription: subscription, created_at: Time.zone.parse('2016-07-22')) + + subscription.update!(interval_length: 1, interval_units: 'month') + + expect(subscription.actionable_date.to_date).to eq(Time.zone.today) + end + end + + context "when the last installment date would cause the interval to be in the future" do + it "sets the actionable_date to an interval from the last installment" do + subscription = create(:subscription, actionable_date: Time.zone.parse('2016-08-22')) + create(:installment, subscription: subscription, created_at: 4.days.ago) + + subscription.update!(interval_length: 1, interval_units: 'month') + + expect(subscription.actionable_date.to_date).to eq((4.days.ago + 1.month).to_date) + end + end + end + + context "when there are no installments" do + context "when the subscription creation date would cause the interval to be in the past" do + it "sets the actionable_date to the current day" do + subscription = create(:subscription, created_at: Time.zone.parse('2016-08-22')) + + subscription.update!(interval_length: 1, interval_units: 'month') + + expect(subscription.actionable_date.to_date).to eq(Time.zone.today) + end + end + + context "when the subscription creation date would cause the interval to be in the future" do + it "sets the actionable_date to one interval past the subscription creation date" do + subscription = create(:subscription, created_at: 4.days.ago) + + subscription.update!(interval_length: 1, interval_units: 'month') + + expect(subscription.actionable_date.to_date).to eq((4.days.ago + 1.month).to_date) + end + end + end + end end |