Commit 6a2769a5cf6e2f3bf75138cfc29d0bbdab36aaf5
1 parent
d378acea
Exists in
staging
and in
39 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 | 87 | alias :ok :assert_block |
| 88 | 88 | |
| 89 | 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 | 91 | end |
| 92 | 92 | |
| 93 | 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 | 44 | p1 = Product.new(:name => 'product1', :product_category => c1) |
| 45 | 45 | p1.profile = enterprise |
| 46 | 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 | 64 | p2 = Product.new(:name => 'product2', :product_category => c1) |
| 48 | 65 | p2.profile = enterprise |
| 49 | 66 | p2.save! | ... | ... |