Add test for g_order_items in order
This commit is contained in:
parent
51ba90d70a
commit
41140e0784
1 changed files with 19 additions and 0 deletions
19
test/integration/generate_order_items_test.rb
Normal file
19
test/integration/generate_order_items_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'test_helper'
|
||||
|
||||
class GenerateOrderItemsTest < ActiveSupport::TestCase
|
||||
test "g_order_items works" do
|
||||
order = Order.new
|
||||
products = Product.all.where("stock > 0")
|
||||
size = products.size
|
||||
|
||||
order.order_items.build(product: products(:fanta), count: 150)
|
||||
order.order_items.build(product: products(:mate), count: 50)
|
||||
order.g_order_items(products)
|
||||
|
||||
assert_equal order.order_items.size, size
|
||||
assert_equal order.order_items.select { |oi| oi.product == products(:fanta) }.first.count, products(:fanta).stock
|
||||
assert_equal order.order_items.select { |oi| oi.product == products(:cola) }.size, 0
|
||||
assert_equal order.order_items.select { |oi| oi.product == products(:mate) }.first.count, 50
|
||||
assert_equal order.order_items.select { |oi| oi.product == products(:bueno) }.first.count, 0
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue