Skip to content

Commit

Permalink
Add Spree::Promotion#active? specs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielePalombo committed Aug 31, 2020
1 parent 0afe10d commit 96bd049
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions core/spec/models/spree/promotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96bd049

Please sign in to comment.