Commit 37dd81ce488e67c418a6f988a347dac6a07fda15

Authored by Daniela Feitosa
1 parent d2159684

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".
lib/acts_as_filesystem.rb
... ... @@ -119,7 +119,7 @@ module ActsAsFileSystem
119 119 end
120 120  
121 121 def top_ancestor
122   - if has_ancestry? and !ancestry.nil?
  122 + if has_ancestry? and !ancestry.blank?
123 123 self.class.base_class.find_by id: self.top_ancestor_id
124 124 else
125 125 self.hierarchy.first
... ...
plugins/community_track/test/unit/community_track_plugin/track_test.rb
... ... @@ -61,6 +61,13 @@ class TrackTest < ActiveSupport::TestCase
61 61 assert_equal 'top category', @track.category_name
62 62 end
63 63  
  64 + should 'return name of the top category when has no subcategory' do
  65 + top = create(Category, :name => 'top category', :environment => Environment.default)
  66 + @track.categories.delete_all
  67 + @track.add_category(top, true)
  68 + assert_equal 'top category', @track.category_name
  69 + end
  70 +
64 71 should 'return empty for category name if it has no category' do
65 72 @track.categories.delete_all
66 73 assert_equal '', @track.category_name
... ...
test/unit/category_test.rb
... ... @@ -160,9 +160,9 @@ class CategoryTest < ActiveSupport::TestCase
160 160 end
161 161  
162 162 should 'be able to get top ancestor' do
163   - c1 = fast_create(Category, :name => 'test category', :environment_id => @env.id)
164   - c2 = fast_create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c1.id)
165   - c3 = fast_create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c2.id)
  163 + c1 = create(Category, :name => 'test category', :environment_id => @env.id)
  164 + c2 = create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c1.id)
  165 + c3 = create(Category, :name => 'test category', :environment_id => @env.id, :parent_id => c2.id)
166 166  
167 167 assert_equal c1, c1.top_ancestor
168 168 assert_equal c1, c2.top_ancestor
... ...