From f265ef22366c224c307fa2d4743ce0aa3e823375 Mon Sep 17 00:00:00 2001 From: Rafael Martins Date: Fri, 24 Feb 2012 17:12:21 -0200 Subject: [PATCH] Product validates the presence of Enterprise --- app/models/product.rb | 1 + test/unit/product_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index e8affa7..aca6251 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,7 @@ class Product < ActiveRecord::Base belongs_to :enterprise has_one :region, :through => :enterprise + validates_presence_of :enterprise belongs_to :product_category diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index 5bd67a8..7ce4821 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -200,7 +200,7 @@ class ProductTest < ActiveSupport::TestCase end should 'use name of category when has no name yet' do - product = Product.new(:product_category => @product_category) + product = Product.new(:product_category => @product_category, :enterprise_id => @profile.id) assert product.valid? assert_equal product.name, @product_category.name end @@ -331,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) assert_equal Product.find_by_contents('thing')[:results], [p1] uses_postgresql 'schema_two' - p2 = Product.create!(:name => 'another thing', :product_category => @product_category) + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) assert_not_includes Product.find_by_contents('thing')[:results], p1 assert_includes Product.find_by_contents('thing')[:results], p2 uses_postgresql 'schema_one' -- libgit2 0.21.2