Skip to content

Commit

Permalink
CreateAdjustment promotion action now associates adjustments through …
Browse files Browse the repository at this point in the history
…both order_id and adjustable_id.

Fixes spree#3858
  • Loading branch information
heisenbugged authored and radar committed Oct 14, 2013
1 parent 7222a8f commit 831f874
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/app/models/spree/promotion/actions/create_adjustment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def perform(options = {})
return if promotion_credit_exists?(order)

amount = compute_amount(order)
order.adjustments.create!(
Spree::Adjustment.create!(
amount: amount,
order: order,
adjustable: order,
source: self,
label: "#{Spree.t(:promotion)} (#{promotion.name})",
label: "#{Spree.t(:promotion)} (#{promotion.name})"
)
true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
order.adjustments.first.amount.to_i.should == -10
end

it "should create a discount accessible through both order_id and adjustable_id" do
action.perform(:order => order)
order.adjustments.count.should == 1
order.all_adjustments.count.should == 1
end

it "should not create a discount when order already has one from this promotion" do
order.shipments.create!(:cost => 10)

Expand All @@ -47,7 +53,7 @@

context "when order is complete" do
let(:order) do
create(:order_with_line_items,
create(:order_with_line_items,
:state => "complete",
:completed_at => Time.now,
:line_items_count => 1)
Expand Down

0 comments on commit 831f874

Please sign in to comment.