Add tests for orders and products
This commit is contained in:
parent
d79474b18c
commit
95987e48fe
3 changed files with 22 additions and 24 deletions
|
@ -1,17 +0,0 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: order_products
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# order_id :integer
|
||||
# product_id :integer
|
||||
# count :integer default(1)
|
||||
#
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class OrderProductTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -12,10 +12,17 @@
|
|||
require 'test_helper'
|
||||
|
||||
class OrderTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@order = Order.new
|
||||
@order.order_items.build(product: products(:fanta), count: 1)
|
||||
@order.order_items.build(product: products(:bueno), count: 2)
|
||||
end
|
||||
|
||||
test "order total price is correct" do
|
||||
o = Order.new
|
||||
o.order_items.build(product: products(:fanta), count: 1)
|
||||
o.order_items.build(product: products(:bueno), count: 2)
|
||||
assert_equal o.price, 300
|
||||
assert_equal @order.price, 300
|
||||
end
|
||||
|
||||
test "to_sentence is correct" do
|
||||
assert_equal @order.to_sentence, "1 Fanta and 2 Kinder Buenos"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,15 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ProductTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test "price behaves correctly" do
|
||||
p = products(:fanta)
|
||||
|
||||
assert_equal p.price_cents, 60
|
||||
assert_equal p.price, 0.6
|
||||
|
||||
p.price = 1.3
|
||||
|
||||
assert_equal p.price, 1.3
|
||||
assert_equal p.price_cents, 130
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue