Skip to content

Commit

Permalink
Allows old orders to get promo adjustments
Browse files Browse the repository at this point in the history
UNACTIVATABLE_ORDER_STATES already covers scenarios where a promo should
not be applied to an order

Fixes spree#2388

Fixes spree#2395
  • Loading branch information
huoxito authored and radar committed Jan 8, 2013
1 parent b39aab8 commit a912c3f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
4 changes: 1 addition & 3 deletions promo/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def rules_are_eligible?(order, options = {})
end

def order_activatable?(order)
order &&
created_at.to_i < order.created_at.to_i &&
!UNACTIVATABLE_ORDER_STATES.include?(order.state)
order && !UNACTIVATABLE_ORDER_STATES.include?(order.state)
end

# Products assigned to all product rules
Expand Down
6 changes: 2 additions & 4 deletions promo/spec/models/promotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
promotion.activate(@payload)
end

it "does not activate if newer then order" do
@action1.should_not_receive(:perform).with(@payload)
it "does activate if newer then order" do
@action1.should_receive(:perform).with(@payload)
promotion.created_at = DateTime.now + 2
promotion.activate(@payload)
end
Expand Down Expand Up @@ -211,13 +211,11 @@

context "when it is expired" do
before { promotion.stub(:expired? => true) }

specify { promotion.should_not be_eligible(@order) }
end

context "when it is not expired" do
before { promotion.expires_at = Time.now + 1.day }

specify { promotion.should be_eligible(@order) }
end

Expand Down
7 changes: 0 additions & 7 deletions promo/spec/requests/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@
page.should have_content(I18n.t(:coupon_code_applied))
end

it "cannot enter a promotion code that was created after the order" do
promotion.update_column(:created_at, 1.day.from_now)
fill_in "Coupon code", :with => "onetwo"
click_button "Apply"
page.should have_content(I18n.t(:coupon_code_not_found))
end

it "informs the user about a coupon code which has exceeded its usage" do
promotion.update_column(:usage_limit, 5)
promotion.class.any_instance.stub(:credits_count => 10)
Expand Down

0 comments on commit a912c3f

Please sign in to comment.