diff --git a/core/spec/models/spree/promotion_spec.rb b/core/spec/models/spree/promotion_spec.rb index 24d4660cd83..aaec7f7475d 100644 --- a/core/spec/models/spree/promotion_spec.rb +++ b/core/spec/models/spree/promotion_spec.rb @@ -525,6 +525,58 @@ promotion.expires_at = nil expect(promotion.active?).to eq(true) end + + context 'with actionless_promotion_inactive true' do + before { stub_spree_preferences(actionless_promotion_inactive: true) } + + it "shouldn't be active if it has started already" do + promotion.starts_at = Time.current - 1.day + expect(promotion.active?).to eq(false) + end + + it "shouldn't be active if it has not ended yet" do + promotion.expires_at = Time.current + 1.day + expect(promotion.active?).to eq(false) + end + + it "shouldn't be active if current time is within starts_at and expires_at range" do + promotion.starts_at = Time.current - 1.day + promotion.expires_at = Time.current + 1.day + expect(promotion.active?).to eq(false) + end + + it "shouldn't be active if there are no start and end times set" do + promotion.starts_at = nil + promotion.expires_at = nil + expect(promotion.active?).to eq(false) + end + + context 'when promotion has an action' do + let(:promotion) { create(:promotion, :with_action, name: "name1") } + + it "should be active if it has started already" do + promotion.starts_at = Time.current - 1.day + expect(promotion.active?).to eq(true) + end + + it "should be active if it has not ended yet" do + promotion.expires_at = Time.current + 1.day + expect(promotion.active?).to eq(true) + end + + it "should be active if current time is within starts_at and expires_at range" do + promotion.starts_at = Time.current - 1.day + promotion.expires_at = Time.current + 1.day + expect(promotion.active?).to eq(true) + end + + it "should be active if there are no start and end times set" do + promotion.starts_at = nil + promotion.expires_at = nil + expect(promotion.active?).to eq(true) + end + end + end end context "#usage_count" do