From 6a2769a5cf6e2f3bf75138cfc29d0bbdab36aaf5 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 7 Dec 2015 15:12:24 -0300 Subject: [PATCH] assert_equivalent must have the same number of elements --- test/test_helper.rb | 2 +- test/unit/product_category_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index fe59a58..59b0b35 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -87,7 +87,7 @@ class ActiveSupport::TestCase alias :ok :assert_block def assert_equivalent(enum1, enum2) - assert( ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>") + assert( (enum1.length == enum2.length) && ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>") end def assert_mandatory(object, attribute, test_value = 'some random string') diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb index 406b9c6..6973558 100644 --- a/test/unit/product_category_test.rb +++ b/test/unit/product_category_test.rb @@ -44,6 +44,23 @@ class ProductCategoryTest < ActiveSupport::TestCase p1 = Product.new(:name => 'product1', :product_category => c1) p1.profile = enterprise p1.save! + p3 = Product.new(:name => 'product3', :product_category => c2) + p3.profile = enterprise + p3.save! + + scope = ProductCategory.by_enterprise(enterprise) + + assert_equivalent [c1,c2], scope + end + + should 'provide a scope based on the enterprise returning distinct elements' do + enterprise = fast_create(Enterprise) + c1 = ProductCategory.create!(:name => 'test cat 1', :environment => Environment.default) + c2 = ProductCategory.create!(:name => 'test cat 2', :environment => Environment.default) + c3 = ProductCategory.create!(:name => 'test cat 3', :environment => Environment.default) + p1 = Product.new(:name => 'product1', :product_category => c1) + p1.profile = enterprise + p1.save! p2 = Product.new(:name => 'product2', :product_category => c1) p2.profile = enterprise p2.save! -- libgit2 0.21.2