Skip to content

Commit

Permalink
Fixes issue that causes order totals to be stale after calling Order#…
Browse files Browse the repository at this point in the history
…add_variant.

Merges #1595
  • Loading branch information
mscottford authored and radar committed May 24, 2012
1 parent 4101f1f commit 7868902
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/app/models/spree/order.rb
Expand Up @@ -282,6 +282,8 @@ def add_variant(variant, quantity = 1)
current_item.price = variant.price
self.line_items << current_item
end

self.reload
current_item
end

Expand Down
14 changes: 14 additions & 0 deletions core/spec/models/order_spec.rb
Expand Up @@ -982,4 +982,18 @@ def compute(computable)
end
end

context "#add_variant" do
it "should update order totals" do
order = Spree::Order.create!

order.item_total.to_f.should == 0.00
order.total.to_f.should == 0.00

product = Spree::Product.create!(:name => 'Test', :sku => 'TEST-1', :price => 22.25)
order.add_variant(product.master)

order.item_total.to_f.should == 22.25
order.total.to_f.should == 22.25
end
end
end
4 changes: 2 additions & 2 deletions core/spec/requests/admin/orders/payments_spec.rb
Expand Up @@ -36,14 +36,14 @@

click_link "Payments"
within('#payment_status') { page.should have_content("Payment: balance due") }
find('table.index tbody tr:nth-child(2) td:nth-child(2)').text.should == "$39.98"
find('table.index tbody tr:nth-child(2) td:nth-child(2)').text.should == "$49.98"
find('table.index tbody tr:nth-child(2) td:nth-child(3)').text.should == "Credit Card"
find('table.index tbody tr:nth-child(2) td:nth-child(4)').text.should == "pending"

click_button "Void"
within('#payment_status') { page.should have_content("Payment: balance due") }
page.should have_content("Payment Updated")
find('table.index tbody tr:nth-child(2) td:nth-child(2)').text.should == "$39.98"
find('table.index tbody tr:nth-child(2) td:nth-child(2)').text.should == "$49.98"
find('table.index tbody tr:nth-child(2) td:nth-child(3)').text.should == "Credit Card"
find('table.index tbody tr:nth-child(2) td:nth-child(4)').text.should == "void"

Expand Down

0 comments on commit 7868902

Please sign in to comment.