[Git][noosfero/noosfero][master] 2 commits: Fix top_ancestor of root categories

Leandro Nunes gitlab at mg.gitlab.com
Thu May 5 13:19:51 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
37dd81ce by Daniela Soares Feitosa at 2016-04-27T13:23:15+00:00
Fix top_ancestor of root categories

The root categories are created with "blank" as ancestry, not with nil.
And should return itself when calling "top_ancestor".

- - - - -
53dbec92 by Leandro Nunes at 2016-05-05T16:19:41+00:00
Merge branch 'category_ancestor' into 'master'

Fix top_ancestor of root categories

The root categories are created with "blank" as ancestry, not with nil.
And should return itself when calling "top_ancestor".

See merge request !880
- - - - -


3 changed files:

- lib/acts_as_filesystem.rb
- plugins/community_track/test/unit/community_track_plugin/track_test.rb
- test/unit/category_test.rb


Changes:

=====================================
lib/acts_as_filesystem.rb
=====================================
--- a/lib/acts_as_filesystem.rb
+++ b/lib/acts_as_filesystem.rb
@@ -119,7 +119,7 @@ module ActsAsFileSystem
     end
 
     def top_ancestor
-      if has_ancestry? and !ancestry.nil?
+      if has_ancestry? and !ancestry.blank?
         self.class.base_class.find_by id: self.top_ancestor_id
       else
         self.hierarchy.first


=====================================
plugins/community_track/test/unit/community_track_plugin/track_test.rb
=====================================
--- a/plugins/community_track/test/unit/community_track_plugin/track_test.rb
+++ b/plugins/community_track/test/unit/community_track_plugin/track_test.rb
@@ -61,6 +61,13 @@ class TrackTest < ActiveSupport::TestCase
     assert_equal 'top category', @track.category_name
   end
 
+  should 'return name of the top category when has no subcategory' do
+    top = create(Category, :name => 'top category', :environment => Environment.default)
+    @track.categories.delete_all
+    @track.add_category(top, true)
+    assert_equal 'top category', @track.category_name
+  end
+
   should 'return empty for category name if it has no category' do
     @track.categories.delete_all
     assert_equal '', @track.category_name


=====================================
test/unit/category_test.rb
=====================================
--- a/test/unit/category_test.rb
+++ b/test/unit/category_test.rb
@@ -160,9 +160,9 @@ class CategoryTest < ActiveSupport::TestCase
   end
 
   should 'be able to get top ancestor' do
-    c1 = fast_create(Category, :name => 'test category', :environment_id => @env.id)
-    c2 = fast_create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c1.id)
-    c3 = fast_create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c2.id)
+    c1 = create(Category, :name => 'test category', :environment_id => @env.id)
+    c2 = create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c1.id)
+    c3 = create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c2.id)
 
     assert_equal c1, c1.top_ancestor
     assert_equal c1, c2.top_ancestor



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/27b6a398fbe8d8a81a6ef9c68524f05455c02d55...53dbec924ee6317b809924ed6f2b5033d05fa561
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160505/517996ff/attachment-0001.html>


More information about the Noosfero-dev mailing list