From 70ba11a8a4378bc75bc99ae77ec27d4b6a9be952 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Sat, 3 Aug 2013 12:49:50 -0300 Subject: [PATCH] rails3: fix PriceDetail unit tests --- app/models/price_detail.rb | 2 ++ test/unit/price_detail_test.rb | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/price_detail.rb b/app/models/price_detail.rb index d6a7038..d2718e3 100644 --- a/app/models/price_detail.rb +++ b/app/models/price_detail.rb @@ -1,5 +1,7 @@ class PriceDetail < ActiveRecord::Base + attr_accessible :price, :production_cost_id + belongs_to :product validates_presence_of :product_id diff --git a/test/unit/price_detail_test.rb b/test/unit/price_detail_test.rb index 81ee5d8..75d50eb 100644 --- a/test/unit/price_detail_test.rb +++ b/test/unit/price_detail_test.rb @@ -39,7 +39,7 @@ class PriceDetailTest < ActiveSupport::TestCase p = PriceDetail.new p.valid? - assert p.errors.invalid?(:product_id) + assert p.errors[:product_id].any? end should 'have production cost' do @@ -54,7 +54,7 @@ class PriceDetailTest < ActiveSupport::TestCase p = PriceDetail.new p.valid? - assert p.errors.invalid?(:production_cost) + assert p.errors[:production_cost].any? end should 'th production cost be unique on scope of product' do @@ -65,7 +65,7 @@ class PriceDetailTest < ActiveSupport::TestCase detail2 = product.price_details.build(:production_cost_id => cost.id, :price => 10) detail2.valid? - assert detail2.errors.invalid?(:production_cost_id) + assert detail2.errors[:production_cost_id].any? end should 'format values to float with 2 decimals' do @@ -82,7 +82,7 @@ class PriceDetailTest < ActiveSupport::TestCase product = fast_create(Product) cost = fast_create(ProductionCost, :name => 'Energy',:owner_id => Environment.default.id, :owner_type => 'environment') - detail = product.price_details.create(:production_cost => cost, :price => 10) + detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) assert_equal 'Energy', detail.name end -- libgit2 0.21.2