From 73a5446e4b7bd9de266618cf8e4515fe62168e81 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Wed, 27 Nov 2013 11:01:54 -0300 Subject: [PATCH] Display top ancestor category at track card title --- plugins/community_track/lib/community_track_plugin/track.rb | 2 +- plugins/community_track/test/unit/community_track_plugin/track_test.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/community_track/lib/community_track_plugin/track.rb b/plugins/community_track/lib/community_track_plugin/track.rb index 221b6ad..c267bdf 100644 --- a/plugins/community_track/lib/community_track_plugin/track.rb +++ b/plugins/community_track/lib/community_track_plugin/track.rb @@ -57,7 +57,7 @@ class CommunityTrackPlugin::Track < Folder def category_name category = categories.first - category ? category.name : '' + category ? category.top_ancestor.name : '' end def to_html(options = {}) 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 5ca89c8..c323e8c 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 @@ -39,10 +39,12 @@ class TrackTest < ActiveSupport::TestCase assert_equal [@step], @track.steps_unsorted end - should 'return category name' do - category = fast_create(Category, :name => 'category') - @track.add_category(category, true) - assert_equal 'category', @track.category_name + should 'return name of the top category' do + top = fast_create(Category, :name => 'top category') + category1 = fast_create(Category, :name => 'category1', :parent_id => top.id ) + category2 = fast_create(Category, :name => 'category2', :parent_id => category1.id ) + @track.add_category(category2, true) + assert_equal 'top category', @track.category_name end should 'return empty for category name if it has no category' do -- libgit2 0.21.2