From c08905138092c091edcd95e956180263b08dcc20 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Fri, 19 Mar 2021 17:05:09 +0100 Subject: Improve subscription creation order promotion rule name --- .../subscription_creation_order_promotion_rule.rb | 40 ++++++++++++++++ .../subscription_promotion_rule.rb | 40 ---------------- ...cription_creation_order_promotion_rule.html.erb | 0 .../rules/_subscription_promotion_rule.html.erb | 0 lib/solidus_subscriptions/engine.rb | 2 +- ...scription_creation_order_promotion_rule_spec.rb | 55 ++++++++++++++++++++++ .../subscription_promotion_rule_spec.rb | 55 ---------------------- 7 files changed, 96 insertions(+), 96 deletions(-) create mode 100644 app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb delete mode 100644 app/models/solidus_subscriptions/subscription_promotion_rule.rb create mode 100644 app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb delete mode 100644 app/views/spree/admin/promotions/rules/_subscription_promotion_rule.html.erb create mode 100644 spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb delete mode 100644 spec/lib/solidus_subscriptions/subscription_promotion_rule_spec.rb diff --git a/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb new file mode 100644 index 0000000..9b5d465 --- /dev/null +++ b/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + class SubscriptionCreationOrderPromotionRule < ::Spree::PromotionRule + # Promotion can be applied to an entire order. Will only be true + # for Spree::Order + # + # @param promotable [Object] Any object which could have this + # promotion rule applied to it. + # + # @return [Boolean] + def applicable?(promotable) + promotable.is_a? ::Spree::Order + end + + # An order is eligible if it contains a line item with an associates + # subscription_line_item. This rule applies to order and so its eligibility + # will always be considered against an order. Will only return true for + # orders containing Spree::Line item with associated subscription_line_items + # + # @param order [Spree::Order] The order which could have this rule applied + # to it. + # + # @return [Boolean] + def eligible?(order, **_options) + order.subscription_line_items.any? + end + + # Certain actions create adjustments on line items. In this case, only + # line items with associated subscription_line_items are eligible to be + # adjusted. Will only return true # if :line_item has an associated + # subscription. + # + # @param line_item [Spree::LineItem] The line item which could be adjusted + # by the promotion. + def actionable?(line_item) + line_item.subscription_line_items.present? + end + end +end diff --git a/app/models/solidus_subscriptions/subscription_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_promotion_rule.rb deleted file mode 100644 index fd99979..0000000 --- a/app/models/solidus_subscriptions/subscription_promotion_rule.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - class SubscriptionPromotionRule < ::Spree::PromotionRule - # Promotion can be applied to an entire order. Will only be true - # for Spree::Order - # - # @param promotable [Object] Any object which could have this - # promotion rule applied to it. - # - # @return [Boolean] - def applicable?(promotable) - promotable.is_a? ::Spree::Order - end - - # An order is eligible if it contains a line item with an associates - # subscription_line_item. This rule applies to order and so its eligibility - # will always be considered against an order. Will only return true for - # orders containing Spree::Line item with associated subscription_line_items - # - # @param order [Spree::Order] The order which could have this rule applied - # to it. - # - # @return [Boolean] - def eligible?(order, **_options) - order.subscription_line_items.any? - end - - # Certain actions create adjustments on line items. In this case, only - # line items with associated subscription_line_items are eligible to be - # adjusted. Will only return true # if :line_item has an associated - # subscription. - # - # @param line_item [Spree::LineItem] The line item which could be adjusted - # by the promotion. - def actionable?(line_item) - line_item.subscription_line_items.present? - end - end -end diff --git a/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/spree/admin/promotions/rules/_subscription_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_promotion_rule.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index 2f3067e..01d7b0d 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -31,7 +31,7 @@ module SolidusSubscriptions end initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app| - app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionPromotionRule' + app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionCreationOrderPromotionRule' app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionOrderPromotionRule' end diff --git a/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb new file mode 100644 index 0000000..651c678 --- /dev/null +++ b/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +RSpec.describe SolidusSubscriptions::SubscriptionCreationOrderPromotionRule do + let(:rule) { described_class.new } + + describe '#applicable' do + subject { rule.applicable? promotable } + + context 'when the promotable is a Spree::Order' do + let(:promotable) { build_stubbed :order } + + it { is_expected.to be_truthy } + end + + context 'when the promotable is not a Spree::Order' do + let(:promotable) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end + + describe '#eligible?' do + subject { rule.eligible? order } + + let(:order) { create(:order, line_items: line_items) } + + context 'when the order contains a line item with a subscription' do + let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) } + + it { is_expected.to be_truthy } + end + + context 'when the order does not contain a line item with a subscription' do + let(:line_items) { build_list(:line_item, 1) } + + it { is_expected.to be_falsy } + end + end + + describe '#actionable?' do + subject { rule.actionable? line_item } + + context 'when the line item has a subscription' do + let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) } + + it { is_expected.to be_truthy } + end + + context 'when the line item has no subscription' do + let(:line_item) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end +end diff --git a/spec/lib/solidus_subscriptions/subscription_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_promotion_rule_spec.rb deleted file mode 100644 index f4c65cc..0000000 --- a/spec/lib/solidus_subscriptions/subscription_promotion_rule_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::SubscriptionPromotionRule do - let(:rule) { described_class.new } - - describe '#applicable' do - subject { rule.applicable? promotable } - - context 'when the promotable is a Spree::Order' do - let(:promotable) { build_stubbed :order } - - it { is_expected.to be_truthy } - end - - context 'when the promotable is not a Spree::Order' do - let(:promotable) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end - - describe '#eligible?' do - subject { rule.eligible? order } - - let(:order) { create(:order, line_items: line_items) } - - context 'when the order contains a line item with a subscription' do - let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) } - - it { is_expected.to be_truthy } - end - - context 'when the order does not contain a line item with a subscription' do - let(:line_items) { build_list(:line_item, 1) } - - it { is_expected.to be_falsy } - end - end - - describe '#actionable?' do - subject { rule.actionable? line_item } - - context 'when the line item has a subscription' do - let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) } - - it { is_expected.to be_truthy } - end - - context 'when the line item has no subscription' do - let(:line_item) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end -end -- cgit v1.2.3 From 19fcbb18387dd6a2d28d386fd5510203d6f18a77 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Fri, 19 Mar 2021 17:13:39 +0100 Subject: Improve installment order promotion rule name --- ...ubscription_installment_order_promotion_rule.rb | 27 ++++++++++++++++ .../subscription_order_promotion_rule.rb | 27 ---------------- ...ption_installment_order_promotion_rule.html.erb | 0 .../_subscription_order_promotion_rule.html.erb | 0 lib/solidus_subscriptions/engine.rb | 2 +- ...iption_installment_order_promotion_rule_spec.rb | 37 ++++++++++++++++++++++ .../subscription_order_promotion_rule_spec.rb | 37 ---------------------- 7 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb delete mode 100644 app/models/solidus_subscriptions/subscription_order_promotion_rule.rb create mode 100644 app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb delete mode 100644 app/views/spree/admin/promotions/rules/_subscription_order_promotion_rule.html.erb create mode 100644 spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb delete mode 100644 spec/lib/solidus_subscriptions/subscription_order_promotion_rule_spec.rb diff --git a/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb new file mode 100644 index 0000000..5714bb8 --- /dev/null +++ b/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + class SubscriptionInstallmentOrderPromotionRule < ::Spree::PromotionRule + # Promotion can be applied to an entire order. Will only be true + # for Spree::Order + # + # @param promotable [Object] Any object which could have this + # promotion rule applied to it. + # + # @return [Boolean] + def applicable?(promotable) + promotable.is_a? ::Spree::Order + end + + # An order is eligible if it fulfills a subscription Installment. Will only + # return true if the order fulfills one or more Installments + # + # @param order [Spree::Order] The order which could have this rule applied + # to it. + # + # @return [Boolean] + def eligible?(order, **_options) + order.subscription_order? + end + end +end diff --git a/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb deleted file mode 100644 index 17d280e..0000000 --- a/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - class SubscriptionOrderPromotionRule < ::Spree::PromotionRule - # Promotion can be applied to an entire order. Will only be true - # for Spree::Order - # - # @param promotable [Object] Any object which could have this - # promotion rule applied to it. - # - # @return [Boolean] - def applicable?(promotable) - promotable.is_a? ::Spree::Order - end - - # An order is eligible if it fulfills a subscription Installment. Will only - # return true if the order fulfills one or more Installments - # - # @param order [Spree::Order] The order which could have this rule applied - # to it. - # - # @return [Boolean] - def eligible?(order, **_options) - order.subscription_order? - end - end -end diff --git a/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/spree/admin/promotions/rules/_subscription_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_order_promotion_rule.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index 01d7b0d..4c3661a 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -32,7 +32,7 @@ module SolidusSubscriptions initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app| app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionCreationOrderPromotionRule' - app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionOrderPromotionRule' + app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule' end initializer 'solidus_subscriptions.configure_backend' do diff --git a/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb new file mode 100644 index 0000000..2e0019c --- /dev/null +++ b/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +RSpec.describe SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule do + let(:rule) { described_class.new } + + describe '#applicable' do + subject { rule.applicable? promotable } + + context 'when the promotable is a Spree::Order' do + let(:promotable) { build_stubbed :order } + + it { is_expected.to be_truthy } + end + + context 'when the promotable is not a Spree::Order' do + let(:promotable) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end + + describe '#eligible?' do + subject { rule.eligible? order } + + context 'when the order fulfills a subscription installment' do + let(:order) { create(:order, subscription_order: true) } + + it { is_expected.to be_truthy } + end + + context 'when the order contains does not fulfill a subscription installment' do + let(:order) { create(:order) } + + it { is_expected.to be_falsy } + end + end +end diff --git a/spec/lib/solidus_subscriptions/subscription_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_order_promotion_rule_spec.rb deleted file mode 100644 index bacbef2..0000000 --- a/spec/lib/solidus_subscriptions/subscription_order_promotion_rule_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::SubscriptionOrderPromotionRule do - let(:rule) { described_class.new } - - describe '#applicable' do - subject { rule.applicable? promotable } - - context 'when the promotable is a Spree::Order' do - let(:promotable) { build_stubbed :order } - - it { is_expected.to be_truthy } - end - - context 'when the promotable is not a Spree::Order' do - let(:promotable) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end - - describe '#eligible?' do - subject { rule.eligible? order } - - context 'when the order fulfills a subscription installment' do - let(:order) { create(:order, subscription_order: true) } - - it { is_expected.to be_truthy } - end - - context 'when the order contains does not fulfill a subscription installment' do - let(:order) { create(:order) } - - it { is_expected.to be_falsy } - end - end -end -- cgit v1.2.3 From 57a0e3d10363323269700d58c18359939f745759 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Fri, 19 Mar 2021 18:31:51 +0100 Subject: Set promotion rules model paths similar to Solidus This allows for naming the models in a way more consistent to Solidus (which doesn't include "PromotionRule" in the name of the class). Also, it easily allows for the promotion rules to be displayed with a better name in the admin panel (which just uses the promotions model name humanized). --- .../promotion/rules/subscription_creation_order.rb | 44 +++++++++++++++++ .../rules/subscription_installment_order.rb | 31 ++++++++++++ .../subscription_creation_order_promotion_rule.rb | 40 ---------------- ...ubscription_installment_order_promotion_rule.rb | 27 ----------- .../rules/_subscription_creation_order.html.erb | 0 ...cription_creation_order_promotion_rule.html.erb | 0 .../rules/_subscription_installment_order.html.erb | 0 ...ption_installment_order_promotion_rule.html.erb | 0 lib/solidus_subscriptions/engine.rb | 4 +- .../rules/subscription_creation_order_spec.rb | 55 ++++++++++++++++++++++ .../rules/subscription_installment_order_spec.rb | 37 +++++++++++++++ ...scription_creation_order_promotion_rule_spec.rb | 55 ---------------------- ...iption_installment_order_promotion_rule_spec.rb | 37 --------------- 13 files changed, 169 insertions(+), 161 deletions(-) create mode 100644 app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb create mode 100644 app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb delete mode 100644 app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb delete mode 100644 app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb create mode 100644 app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb delete mode 100644 app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb create mode 100644 app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb delete mode 100644 app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb create mode 100644 spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb create mode 100644 spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb delete mode 100644 spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb delete mode 100644 spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb new file mode 100644 index 0000000..1b44125 --- /dev/null +++ b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module Promotion + module Rules + class SubscriptionCreationOrder < ::Spree::PromotionRule + # Promotion can be applied to an entire order. Will only be true + # for Spree::Order + # + # @param promotable [Object] Any object which could have this + # promotion rule applied to it. + # + # @return [Boolean] + def applicable?(promotable) + promotable.is_a? ::Spree::Order + end + + # An order is eligible if it contains a line item with an associates + # subscription_line_item. This rule applies to order and so its eligibility + # will always be considered against an order. Will only return true for + # orders containing Spree::Line item with associated subscription_line_items + # + # @param order [Spree::Order] The order which could have this rule applied + # to it. + # + # @return [Boolean] + def eligible?(order, **_options) + order.subscription_line_items.any? + end + + # Certain actions create adjustments on line items. In this case, only + # line items with associated subscription_line_items are eligible to be + # adjusted. Will only return true # if :line_item has an associated + # subscription. + # + # @param line_item [Spree::LineItem] The line item which could be adjusted + # by the promotion. + def actionable?(line_item) + line_item.subscription_line_items.present? + end + end + end + end +end diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb new file mode 100644 index 0000000..455825d --- /dev/null +++ b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module Promotion + module Rules + class SubscriptionInstallmentOrder < ::Spree::PromotionRule + # Promotion can be applied to an entire order. Will only be true + # for Spree::Order + # + # @param promotable [Object] Any object which could have this + # promotion rule applied to it. + # + # @return [Boolean] + def applicable?(promotable) + promotable.is_a? ::Spree::Order + end + + # An order is eligible if it fulfills a subscription Installment. Will only + # return true if the order fulfills one or more Installments + # + # @param order [Spree::Order] The order which could have this rule applied + # to it. + # + # @return [Boolean] + def eligible?(order, **_options) + order.subscription_order? + end + end + end + end +end diff --git a/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb deleted file mode 100644 index 9b5d465..0000000 --- a/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - class SubscriptionCreationOrderPromotionRule < ::Spree::PromotionRule - # Promotion can be applied to an entire order. Will only be true - # for Spree::Order - # - # @param promotable [Object] Any object which could have this - # promotion rule applied to it. - # - # @return [Boolean] - def applicable?(promotable) - promotable.is_a? ::Spree::Order - end - - # An order is eligible if it contains a line item with an associates - # subscription_line_item. This rule applies to order and so its eligibility - # will always be considered against an order. Will only return true for - # orders containing Spree::Line item with associated subscription_line_items - # - # @param order [Spree::Order] The order which could have this rule applied - # to it. - # - # @return [Boolean] - def eligible?(order, **_options) - order.subscription_line_items.any? - end - - # Certain actions create adjustments on line items. In this case, only - # line items with associated subscription_line_items are eligible to be - # adjusted. Will only return true # if :line_item has an associated - # subscription. - # - # @param line_item [Spree::LineItem] The line item which could be adjusted - # by the promotion. - def actionable?(line_item) - line_item.subscription_line_items.present? - end - end -end diff --git a/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb deleted file mode 100644 index 5714bb8..0000000 --- a/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - class SubscriptionInstallmentOrderPromotionRule < ::Spree::PromotionRule - # Promotion can be applied to an entire order. Will only be true - # for Spree::Order - # - # @param promotable [Object] Any object which could have this - # promotion rule applied to it. - # - # @return [Boolean] - def applicable?(promotable) - promotable.is_a? ::Spree::Order - end - - # An order is eligible if it fulfills a subscription Installment. Will only - # return true if the order fulfills one or more Installments - # - # @param order [Spree::Order] The order which could have this rule applied - # to it. - # - # @return [Boolean] - def eligible?(order, **_options) - order.subscription_order? - end - end -end diff --git a/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb b/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb b/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index 4c3661a..0f274d8 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -31,8 +31,8 @@ module SolidusSubscriptions end initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app| - app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionCreationOrderPromotionRule' - app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule' + app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder' + app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder' end initializer 'solidus_subscriptions.configure_backend' do diff --git a/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb new file mode 100644 index 0000000..f7975f1 --- /dev/null +++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder do + let(:rule) { described_class.new } + + describe '#applicable' do + subject { rule.applicable? promotable } + + context 'when the promotable is a Spree::Order' do + let(:promotable) { build_stubbed :order } + + it { is_expected.to be_truthy } + end + + context 'when the promotable is not a Spree::Order' do + let(:promotable) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end + + describe '#eligible?' do + subject { rule.eligible? order } + + let(:order) { create(:order, line_items: line_items) } + + context 'when the order contains a line item with a subscription' do + let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) } + + it { is_expected.to be_truthy } + end + + context 'when the order does not contain a line item with a subscription' do + let(:line_items) { build_list(:line_item, 1) } + + it { is_expected.to be_falsy } + end + end + + describe '#actionable?' do + subject { rule.actionable? line_item } + + context 'when the line item has a subscription' do + let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) } + + it { is_expected.to be_truthy } + end + + context 'when the line item has no subscription' do + let(:line_item) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end +end diff --git a/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb new file mode 100644 index 0000000..d17fa61 --- /dev/null +++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder do + let(:rule) { described_class.new } + + describe '#applicable' do + subject { rule.applicable? promotable } + + context 'when the promotable is a Spree::Order' do + let(:promotable) { build_stubbed :order } + + it { is_expected.to be_truthy } + end + + context 'when the promotable is not a Spree::Order' do + let(:promotable) { build_stubbed :line_item } + + it { is_expected.to be_falsy } + end + end + + describe '#eligible?' do + subject { rule.eligible? order } + + context 'when the order fulfills a subscription installment' do + let(:order) { create(:order, subscription_order: true) } + + it { is_expected.to be_truthy } + end + + context 'when the order contains does not fulfill a subscription installment' do + let(:order) { create(:order) } + + it { is_expected.to be_falsy } + end + end +end diff --git a/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb deleted file mode 100644 index 651c678..0000000 --- a/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::SubscriptionCreationOrderPromotionRule do - let(:rule) { described_class.new } - - describe '#applicable' do - subject { rule.applicable? promotable } - - context 'when the promotable is a Spree::Order' do - let(:promotable) { build_stubbed :order } - - it { is_expected.to be_truthy } - end - - context 'when the promotable is not a Spree::Order' do - let(:promotable) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end - - describe '#eligible?' do - subject { rule.eligible? order } - - let(:order) { create(:order, line_items: line_items) } - - context 'when the order contains a line item with a subscription' do - let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) } - - it { is_expected.to be_truthy } - end - - context 'when the order does not contain a line item with a subscription' do - let(:line_items) { build_list(:line_item, 1) } - - it { is_expected.to be_falsy } - end - end - - describe '#actionable?' do - subject { rule.actionable? line_item } - - context 'when the line item has a subscription' do - let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) } - - it { is_expected.to be_truthy } - end - - context 'when the line item has no subscription' do - let(:line_item) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end -end diff --git a/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb deleted file mode 100644 index 2e0019c..0000000 --- a/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule do - let(:rule) { described_class.new } - - describe '#applicable' do - subject { rule.applicable? promotable } - - context 'when the promotable is a Spree::Order' do - let(:promotable) { build_stubbed :order } - - it { is_expected.to be_truthy } - end - - context 'when the promotable is not a Spree::Order' do - let(:promotable) { build_stubbed :line_item } - - it { is_expected.to be_falsy } - end - end - - describe '#eligible?' do - subject { rule.eligible? order } - - context 'when the order fulfills a subscription installment' do - let(:order) { create(:order, subscription_order: true) } - - it { is_expected.to be_truthy } - end - - context 'when the order contains does not fulfill a subscription installment' do - let(:order) { create(:order) } - - it { is_expected.to be_falsy } - end - end -end -- cgit v1.2.3 From 41ecbb5e79081373592374b8ec376b8fe7447f73 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Fri, 19 Mar 2021 18:33:50 +0100 Subject: Update promotion rules descriptions This displays a correct description in the admin panel --- config/locales/en.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index b921a2c..7055aad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -97,6 +97,10 @@ en: solidus_subscriptions/installment/state: fulfilled: Fulfilled unfulfilled: Unfulfilled + solidus_subscriptions/promotion/rules/subscription_creation_order: + description: Creates a subscription + solidus_subscriptions/promotion/rules/subscription_installment_order: + description: Is a subscription installment models: solidus_subscriptions/subscription: one: Subscription -- cgit v1.2.3 From 4c2fecd938c826e5119d50aef5eb8702fadb1161 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Fri, 19 Mar 2021 18:39:13 +0100 Subject: Update README with promotion rules --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bc7c8bf..0f196bf 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,11 @@ The task creates ActiveJob jobs which can be fulfilled by your queue library of We suggest using the [Whenever](https://github.com/javan/whenever) gem to schedule the task. +### Promotion rules +This extensions adds the following [Promotion rules](https://guides.solidus.io/developers/promotions/promotion-rules.html): +* `SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder` which applies if the order is creating a subscription; +* `SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder` which applies if the order is an installment of a subscription. + ### API documentation You can find the API documentation [here](https://stoplight.io/p/docs/gh/solidusio-contrib/solidus_subscriptions?group=master). -- cgit v1.2.3