Commit aed0150e4e6a096b7f238f948411322a1bcea9c1
1 parent
ccdb0565
Exists in
master
and in
29 other branches
Fix ProductCategory unit tests
Showing
3 changed files
with
13 additions
and
9 deletions
Show diff stats
app/models/product.rb
@@ -11,6 +11,8 @@ class Product < ActiveRecord::Base | @@ -11,6 +11,8 @@ class Product < ActiveRecord::Base | ||
11 | 11 | ||
12 | SEARCH_DISPLAYS = %w[map full] | 12 | SEARCH_DISPLAYS = %w[map full] |
13 | 13 | ||
14 | + attr_accessible :name, :product_category | ||
15 | + | ||
14 | def self.default_search_display | 16 | def self.default_search_display |
15 | 'full' | 17 | 'full' |
16 | end | 18 | end |
app/models/product_category.rb
@@ -3,6 +3,8 @@ class ProductCategory < Category | @@ -3,6 +3,8 @@ class ProductCategory < Category | ||
3 | has_many :products | 3 | has_many :products |
4 | has_many :inputs | 4 | has_many :inputs |
5 | 5 | ||
6 | + attr_accessible :name, :parent | ||
7 | + | ||
6 | def all_products | 8 | def all_products |
7 | Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) | 9 | Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) |
8 | end | 10 | end |
test/unit/product_category_test.rb
@@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
3 | class ProductCategoryTest < ActiveSupport::TestCase | 3 | class ProductCategoryTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def test_all_products | 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 | assert_equivalent [], c0.all_products | 7 | assert_equivalent [], c0.all_products |
8 | 8 | ||
9 | profile = fast_create(Enterprise) | 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 | c0.reload | 11 | c0.reload |
12 | assert_equivalent [p0], c0.all_products | 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 | c0.reload; c1.reload | 16 | c0.reload; c1.reload |
17 | assert_equivalent [p0, p1], c0.all_products | 17 | assert_equivalent [p0, p1], c0.all_products |
18 | assert_equivalent [p1], c1.all_products | 18 | assert_equivalent [p1], c1.all_products |
@@ -22,16 +22,16 @@ class ProductCategoryTest < ActiveSupport::TestCase | @@ -22,16 +22,16 @@ class ProductCategoryTest < ActiveSupport::TestCase | ||
22 | env1 = Environment.create!(:name => 'test env 1') | 22 | env1 = Environment.create!(:name => 'test env 1') |
23 | env2 = Environment.create!(:name => 'test env 2') | 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 | assert_equal [c1], ProductCategory.menu_categories(nil, env1) | 28 | assert_equal [c1], ProductCategory.menu_categories(nil, env1) |
29 | end | 29 | end |
30 | 30 | ||
31 | should 'return children of parent category' do | 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 | assert_equal [c11], ProductCategory.menu_categories(c1, nil) | 36 | assert_equal [c11], ProductCategory.menu_categories(c1, nil) |
37 | end | 37 | end |