Commit aed0150e4e6a096b7f238f948411322a1bcea9c1

Authored by Leandro Santos
1 parent ccdb0565

Fix ProductCategory unit tests

app/models/product.rb
... ... @@ -11,6 +11,8 @@ class Product < ActiveRecord::Base
11 11  
12 12 SEARCH_DISPLAYS = %w[map full]
13 13  
  14 + attr_accessible :name, :product_category
  15 +
14 16 def self.default_search_display
15 17 'full'
16 18 end
... ...
app/models/product_category.rb
... ... @@ -3,6 +3,8 @@ class ProductCategory < Category
3 3 has_many :products
4 4 has_many :inputs
5 5  
  6 + attr_accessible :name, :parent
  7 +
6 8 def all_products
7 9 Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) })
8 10 end
... ...
test/unit/product_category_test.rb
... ... @@ -3,16 +3,16 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class ProductCategoryTest < ActiveSupport::TestCase
4 4  
5 5 def test_all_products
6   - c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default)
  6 + c0 = Environment.default.product_categories.create!(:name => 'base_cat')
7 7 assert_equivalent [], c0.all_products
8 8  
9 9 profile = fast_create(Enterprise)
10   - p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id)
  10 + p0 = profile.products.create(:name => 'product1', :product_category => c0)
11 11 c0.reload
12 12 assert_equivalent [p0], c0.all_products
13 13  
14   - c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default)
15   - p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id)
  14 + c1 = Environment.default.product_categories.create!(:name => 'cat_1', :parent => c0)
  15 + p1 = profile.products.create(:name => 'product2', :product_category => c1)
16 16 c0.reload; c1.reload
17 17 assert_equivalent [p0, p1], c0.all_products
18 18 assert_equivalent [p1], c1.all_products
... ... @@ -22,16 +22,16 @@ class ProductCategoryTest &lt; ActiveSupport::TestCase
22 22 env1 = Environment.create!(:name => 'test env 1')
23 23 env2 = Environment.create!(:name => 'test env 2')
24 24  
25   - c1 = ProductCategory.create!(:name => 'test cat 1', :environment => env1)
26   - c2 = ProductCategory.create!(:name => 'test cat 2', :environment => env2)
  25 + c1 = env1.product_categories.create!(:name => 'test cat 1')
  26 + c2 = env2.product_categories.create!(:name => 'test cat 2')
27 27  
28 28 assert_equal [c1], ProductCategory.menu_categories(nil, env1)
29 29 end
30 30  
31 31 should 'return children of parent category' do
32   - c1 = ProductCategory.create!(:name => 'test cat 1', :environment => Environment.default)
33   - c11 = ProductCategory.create!(:name => 'test cat 11', :environment => Environment.default, :parent => c1)
34   - c2 = ProductCategory.create!(:name => 'test cat 2', :environment => Environment.default)
  32 + c1 = Environment.default.product_categories.create!(:name => 'test cat 1')
  33 + c11 = Environment.default.product_categories.create!(:name => 'test cat 11', :parent => c1)
  34 + c2 = Environment.default.product_categories.create!(:name => 'test cat 2')
35 35  
36 36 assert_equal [c11], ProductCategory.menu_categories(c1, nil)
37 37 end
... ...