Commit f265ef22366c224c307fa2d4743ce0aa3e823375
1 parent
ebc5cf24
Exists in
master
and in
29 other branches
Product validates the presence of Enterprise
Showing
2 changed files
with
3 additions
and
2 deletions
Show diff stats
app/models/product.rb
1 | class Product < ActiveRecord::Base | 1 | class Product < ActiveRecord::Base |
2 | belongs_to :enterprise | 2 | belongs_to :enterprise |
3 | has_one :region, :through => :enterprise | 3 | has_one :region, :through => :enterprise |
4 | + validates_presence_of :enterprise | ||
4 | 5 | ||
5 | belongs_to :product_category | 6 | belongs_to :product_category |
6 | 7 |
test/unit/product_test.rb
@@ -200,7 +200,7 @@ class ProductTest < ActiveSupport::TestCase | @@ -200,7 +200,7 @@ class ProductTest < ActiveSupport::TestCase | ||
200 | end | 200 | end |
201 | 201 | ||
202 | should 'use name of category when has no name yet' do | 202 | should 'use name of category when has no name yet' do |
203 | - product = Product.new(:product_category => @product_category) | 203 | + product = Product.new(:product_category => @product_category, :enterprise_id => @profile.id) |
204 | assert product.valid? | 204 | assert product.valid? |
205 | assert_equal product.name, @product_category.name | 205 | assert_equal product.name, @product_category.name |
206 | end | 206 | end |
@@ -331,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase | @@ -331,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase | ||
331 | p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) | 331 | p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) |
332 | assert_equal Product.find_by_contents('thing')[:results], [p1] | 332 | assert_equal Product.find_by_contents('thing')[:results], [p1] |
333 | uses_postgresql 'schema_two' | 333 | uses_postgresql 'schema_two' |
334 | - p2 = Product.create!(:name => 'another thing', :product_category => @product_category) | 334 | + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) |
335 | assert_not_includes Product.find_by_contents('thing')[:results], p1 | 335 | assert_not_includes Product.find_by_contents('thing')[:results], p1 |
336 | assert_includes Product.find_by_contents('thing')[:results], p2 | 336 | assert_includes Product.find_by_contents('thing')[:results], p2 |
337 | uses_postgresql 'schema_one' | 337 | uses_postgresql 'schema_one' |