From 37dd81ce488e67c418a6f988a347dac6a07fda15 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 27 Apr 2016 13:23:15 +0000 Subject: [PATCH] Fix top_ancestor of root categories --- lib/acts_as_filesystem.rb | 2 +- plugins/community_track/test/unit/community_track_plugin/track_test.rb | 7 +++++++ test/unit/category_test.rb | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb index 11163a7..36406c6 100644 --- 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 diff --git a/plugins/community_track/test/unit/community_track_plugin/track_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_test.rb index fd86499..e5b2ab5 100644 --- 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 diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index e43f81c..302f0f8 100644 --- 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 -- libgit2 0.21.2