Permalink
Browse files

Fixes issue that causes order totals to be stale after calling Order#…

…add_variant.

Also, Changes order api test to use actual Spree::Variant objects instead of stubs, because of the interactions between Spree::LineItem and Spree::Order.

Merges #1595
  • Loading branch information...
1 parent fd6e97a commit a864a6ab651d69c9614b284dcc963a4af5bcde7b @mscottford mscottford committed with radar May 24, 2012
@@ -5,14 +5,14 @@ module Spree
let(:user) { stub_model(User) }
it 'can build an order from API parameters' do
-
- Spree::Variant.should_receive(:find).and_return(stub_model(Variant, :id => 1))
- order = Order.build_from_api(user, { :line_items_attributes => [{ :variant_id => 1, :quantity => 5 }]})
+ product = Spree::Product.create!(:name => 'Test', :sku => 'TEST-1', :price => 33.22)
+ variant_id = product.master.id
+ order = Order.build_from_api(user, { :line_items_attributes => [{ :variant_id => variant_id, :quantity => 5 }]})
order.user.should == user
line_item = order.line_items.first
line_item.quantity.should == 5
- line_item.variant_id.should == 1
+ line_item.variant_id.should == variant_id
end
end
end
@@ -287,6 +287,8 @@ def add_variant(variant, quantity = 1)
current_item.price = variant.price
self.line_items << current_item
end
+
+ self.reload
current_item
end
@@ -992,4 +992,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
@@ -38,14 +38,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"

0 comments on commit a864a6a

Please sign in to comment.