Commit 8a3ed72f1c0e5b273a2f4a67bdd3f87daf7f196d
1 parent
e168cf92
Exists in
staging
and in
42 other branches
Change track list block to handle categories selection
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
plugins/community_track/lib/community_track_plugin/track_list_block.rb
@@ -34,6 +34,10 @@ class CommunityTrackPlugin::TrackListBlock < Block | @@ -34,6 +34,10 @@ class CommunityTrackPlugin::TrackListBlock < Block | ||
34 | settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact | 34 | settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact |
35 | end | 35 | end |
36 | 36 | ||
37 | + def categories | ||
38 | + Category.find(category_ids) | ||
39 | + end | ||
40 | + | ||
37 | def all_tracks | 41 | def all_tracks |
38 | tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') | 42 | tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') |
39 | if !category_ids.empty? | 43 | if !category_ids.empty? |
plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb
@@ -99,4 +99,16 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -99,4 +99,16 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
99 | assert !condition[:environment].empty? | 99 | assert !condition[:environment].empty? |
100 | end | 100 | end |
101 | 101 | ||
102 | + should 'return track list block categories' do | ||
103 | + category1 = fast_create(Category) | ||
104 | + category2 = fast_create(Category) | ||
105 | + @block.category_ids = [category1.id, category2.id] | ||
106 | + assert_equivalent [category1, category2], @block.categories | ||
107 | + end | ||
108 | + | ||
109 | + should 'return nothing if track list block has no categories' do | ||
110 | + @block.category_ids = [] | ||
111 | + assert_equivalent [], @block.categories | ||
112 | + end | ||
113 | + | ||
102 | end | 114 | end |