Commit aed0150e4e6a096b7f238f948411322a1bcea9c1
1 parent
ccdb0565
Exists in
staging
and in
42 other branches
Fix ProductCategory unit tests
Showing
3 changed files
with
13 additions
and
9 deletions
Show diff stats
app/models/product.rb
app/models/product_category.rb
test/unit/product_category_test.rb
| ... | ... | @@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 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 < 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 | ... | ... |