2015-03-04 10:25:03 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class StockTest < ActiveSupport::TestCase
|
|
|
|
test "creating and deleting orders updates stock of products" do
|
|
|
|
order = users(:benji).orders.build
|
|
|
|
order.order_items.build(product: products(:fanta), count: 2)
|
|
|
|
|
|
|
|
assert_difference "products(:fanta).stock", -2 do
|
|
|
|
order.save(validate: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_difference "products(:fanta).stock", +2 do
|
2015-03-19 16:22:55 +01:00
|
|
|
order.cancel
|
2015-03-04 10:25:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|