[Git][noosfero/noosfero][master] 3 commits: assert_equivalent must have the same number of elements

Leandro Nunes gitlab at mg.gitlab.com
Mon Dec 7 16:40:08 BRST 2015


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
6a2769a5 by Leandro Nunes dos Santos at 2015-12-07T15:12:24Z
assert_equivalent must have the same number of elements

- - - - -
0e6a068c by Leandro Nunes dos Santos at 2015-12-07T15:20:58Z
should not return a theme twice

- - - - -
6ea50685 by Leandro Nunes at 2015-12-07T18:39:13Z
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
- - - - -


3 changed files:

- app/controllers/themes_controller.rb
- test/test_helper.rb
- test/unit/product_category_test.rb


Changes:

=====================================
app/controllers/themes_controller.rb
=====================================
--- a/app/controllers/themes_controller.rb
+++ b/app/controllers/themes_controller.rb
@@ -13,7 +13,7 @@ class ThemesController < ApplicationController
 
   def index
     @environment = environment
-    @themes = (environment.themes + Theme.approved_themes(target)).sort_by { |t| t.name }
+    @themes = (environment.themes + Theme.approved_themes(target)).uniq.sort_by { |t| t.name }
 
     @current_theme = target.theme
 


=====================================
test/test_helper.rb
=====================================
--- 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')


=====================================
test/unit/product_category_test.rb
=====================================
--- 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!



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/d378acea9ee176129de1bf94010df154bac7e720...6ea506857da5935e59f884e65ad4447a88e20635
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151207/aa24ee49/attachment.html>


More information about the Noosfero-dev mailing list