Add tests for orders and products

This commit is contained in:
benji 2015-03-03 17:41:53 +01:00
parent d79474b18c
commit 95987e48fe
3 changed files with 22 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -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