Commit 6a2769a5cf6e2f3bf75138cfc29d0bbdab36aaf5
1 parent
d378acea
Exists in
master
and in
18 other branches
assert_equivalent must have the same number of elements
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
test/test_helper.rb
@@ -87,7 +87,7 @@ class ActiveSupport::TestCase | @@ -87,7 +87,7 @@ class ActiveSupport::TestCase | ||
87 | alias :ok :assert_block | 87 | alias :ok :assert_block |
88 | 88 | ||
89 | def assert_equivalent(enum1, enum2) | 89 | def assert_equivalent(enum1, enum2) |
90 | - assert( ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>") | 90 | + assert( (enum1.length == enum2.length) && ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>") |
91 | end | 91 | end |
92 | 92 | ||
93 | def assert_mandatory(object, attribute, test_value = 'some random string') | 93 | def assert_mandatory(object, attribute, test_value = 'some random string') |
test/unit/product_category_test.rb
@@ -44,6 +44,23 @@ class ProductCategoryTest < ActiveSupport::TestCase | @@ -44,6 +44,23 @@ class ProductCategoryTest < ActiveSupport::TestCase | ||
44 | p1 = Product.new(:name => 'product1', :product_category => c1) | 44 | p1 = Product.new(:name => 'product1', :product_category => c1) |
45 | p1.profile = enterprise | 45 | p1.profile = enterprise |
46 | p1.save! | 46 | p1.save! |
47 | + p3 = Product.new(:name => 'product3', :product_category => c2) | ||
48 | + p3.profile = enterprise | ||
49 | + p3.save! | ||
50 | + | ||
51 | + scope = ProductCategory.by_enterprise(enterprise) | ||
52 | + | ||
53 | + assert_equivalent [c1,c2], scope | ||
54 | + end | ||
55 | + | ||
56 | + should 'provide a scope based on the enterprise returning distinct elements' do | ||
57 | + enterprise = fast_create(Enterprise) | ||
58 | + c1 = ProductCategory.create!(:name => 'test cat 1', :environment => Environment.default) | ||
59 | + c2 = ProductCategory.create!(:name => 'test cat 2', :environment => Environment.default) | ||
60 | + c3 = ProductCategory.create!(:name => 'test cat 3', :environment => Environment.default) | ||
61 | + p1 = Product.new(:name => 'product1', :product_category => c1) | ||
62 | + p1.profile = enterprise | ||
63 | + p1.save! | ||
47 | p2 = Product.new(:name => 'product2', :product_category => c1) | 64 | p2 = Product.new(:name => 'product2', :product_category => c1) |
48 | p2.profile = enterprise | 65 | p2.profile = enterprise |
49 | p2.save! | 66 | p2.save! |