diff options
author | Brendan Deere <brendan@stembolt.com> | 2016-09-28 13:54:52 -0700 |
---|---|---|
committer | Brendan Deere <brendan@stembolt.com> | 2016-09-28 13:54:52 -0700 |
commit | 7414d6856d4f746ca7000985860e415385edef31 (patch) | |
tree | bea694423c05384b8f89180284ab480ab1c92718 /spec | |
parent | a0150954d6c00e625e4f0ca934e8965ebb1899ec (diff) |
Add SubscriptionPromotionRule
This is a promotion for targeting orders and line items which have
associated subscription line items
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/solidus_subscriptions/subscription_promotion_rule_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/models/solidus_subscriptions/subscription_promotion_rule_spec.rb b/spec/models/solidus_subscriptions/subscription_promotion_rule_spec.rb new file mode 100644 index 0000000..a2ce07e --- /dev/null +++ b/spec/models/solidus_subscriptions/subscription_promotion_rule_spec.rb @@ -0,0 +1,48 @@ +require 'rails_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 contains 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 |