From aed0150e4e6a096b7f238f948411322a1bcea9c1 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Fri, 26 Jul 2013 18:22:56 -0300 Subject: [PATCH] Fix ProductCategory unit tests --- app/models/product.rb | 2 ++ app/models/product_category.rb | 2 ++ test/unit/product_category_test.rb | 18 +++++++++--------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index a6fd4c8..e62a2be 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,6 +11,8 @@ class Product < ActiveRecord::Base SEARCH_DISPLAYS = %w[map full] + attr_accessible :name, :product_category + def self.default_search_display 'full' end diff --git a/app/models/product_category.rb b/app/models/product_category.rb index c3c1553..2118ce7 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -3,6 +3,8 @@ class ProductCategory < Category has_many :products has_many :inputs + attr_accessible :name, :parent + def all_products Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) end diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb index 7c99072..37452e1 100644 --- a/test/unit/product_category_test.rb +++ b/test/unit/product_category_test.rb @@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../test_helper' class ProductCategoryTest < ActiveSupport::TestCase def test_all_products - c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) + c0 = Environment.default.product_categories.create!(:name => 'base_cat') assert_equivalent [], c0.all_products profile = fast_create(Enterprise) - p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id) + p0 = profile.products.create(:name => 'product1', :product_category => c0) c0.reload assert_equivalent [p0], c0.all_products - c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) - p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id) + c1 = Environment.default.product_categories.create!(:name => 'cat_1', :parent => c0) + p1 = profile.products.create(:name => 'product2', :product_category => c1) c0.reload; c1.reload assert_equivalent [p0, p1], c0.all_products assert_equivalent [p1], c1.all_products @@ -22,16 +22,16 @@ class ProductCategoryTest < ActiveSupport::TestCase env1 = Environment.create!(:name => 'test env 1') env2 = Environment.create!(:name => 'test env 2') - c1 = ProductCategory.create!(:name => 'test cat 1', :environment => env1) - c2 = ProductCategory.create!(:name => 'test cat 2', :environment => env2) + c1 = env1.product_categories.create!(:name => 'test cat 1') + c2 = env2.product_categories.create!(:name => 'test cat 2') assert_equal [c1], ProductCategory.menu_categories(nil, env1) end should 'return children of parent category' do - c1 = ProductCategory.create!(:name => 'test cat 1', :environment => Environment.default) - c11 = ProductCategory.create!(:name => 'test cat 11', :environment => Environment.default, :parent => c1) - c2 = ProductCategory.create!(:name => 'test cat 2', :environment => Environment.default) + c1 = Environment.default.product_categories.create!(:name => 'test cat 1') + c11 = Environment.default.product_categories.create!(:name => 'test cat 11', :parent => c1) + c2 = Environment.default.product_categories.create!(:name => 'test cat 2') assert_equal [c11], ProductCategory.menu_categories(c1, nil) end -- libgit2 0.21.2