Commit 37dd81ce488e67c418a6f988a347dac6a07fda15
1 parent
d2159684
Exists in
send_email_to_admins
and in
5 other branches
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".
Showing
3 changed files
with
11 additions
and
4 deletions
Show diff stats
lib/acts_as_filesystem.rb
@@ -119,7 +119,7 @@ module ActsAsFileSystem | @@ -119,7 +119,7 @@ module ActsAsFileSystem | ||
119 | end | 119 | end |
120 | 120 | ||
121 | def top_ancestor | 121 | def top_ancestor |
122 | - if has_ancestry? and !ancestry.nil? | 122 | + if has_ancestry? and !ancestry.blank? |
123 | self.class.base_class.find_by id: self.top_ancestor_id | 123 | self.class.base_class.find_by id: self.top_ancestor_id |
124 | else | 124 | else |
125 | self.hierarchy.first | 125 | self.hierarchy.first |
plugins/community_track/test/unit/community_track_plugin/track_test.rb
@@ -61,6 +61,13 @@ class TrackTest < ActiveSupport::TestCase | @@ -61,6 +61,13 @@ class TrackTest < ActiveSupport::TestCase | ||
61 | assert_equal 'top category', @track.category_name | 61 | assert_equal 'top category', @track.category_name |
62 | end | 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 | should 'return empty for category name if it has no category' do | 71 | should 'return empty for category name if it has no category' do |
65 | @track.categories.delete_all | 72 | @track.categories.delete_all |
66 | assert_equal '', @track.category_name | 73 | assert_equal '', @track.category_name |
test/unit/category_test.rb
@@ -160,9 +160,9 @@ class CategoryTest < ActiveSupport::TestCase | @@ -160,9 +160,9 @@ class CategoryTest < ActiveSupport::TestCase | ||
160 | end | 160 | end |
161 | 161 | ||
162 | should 'be able to get top ancestor' do | 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 | assert_equal c1, c1.top_ancestor | 167 | assert_equal c1, c1.top_ancestor |
168 | assert_equal c1, c2.top_ancestor | 168 | assert_equal c1, c2.top_ancestor |