Commit 37dd81ce488e67c418a6f988a347dac6a07fda15
1 parent
d2159684
Exists in
staging
and in
31 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
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 | ... | ... |