Commit 6ea506857da5935e59f884e65ad4447a88e20635
Exists in
master
and in
18 other branches
Merge branch 'fix_equivalent' into 'master'
Refactoring assert_equivalent Refactoring assert_equivalent to take in consideration the length of arrays on equivalency analisys See merge request !743
Showing
3 changed files
with
19 additions
and
2 deletions
Show diff stats
app/controllers/themes_controller.rb
@@ -13,7 +13,7 @@ class ThemesController < ApplicationController | @@ -13,7 +13,7 @@ class ThemesController < ApplicationController | ||
13 | 13 | ||
14 | def index | 14 | def index |
15 | @environment = environment | 15 | @environment = environment |
16 | - @themes = (environment.themes + Theme.approved_themes(target)).sort_by { |t| t.name } | 16 | + @themes = (environment.themes + Theme.approved_themes(target)).uniq.sort_by { |t| t.name } |
17 | 17 | ||
18 | @current_theme = target.theme | 18 | @current_theme = target.theme |
19 | 19 |
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! |