Commit 6fe7f895205880391e17e9f54ac5f905a17b2f91
1 parent
01a9fb9f
Exists in
staging
and in
29 other branches
recent_content: return block content in api call
Showing
2 changed files
with
22 additions
and
0 deletions
Show diff stats
plugins/recent_content/lib/recent_content_block.rb
@@ -48,4 +48,12 @@ class RecentContentBlock < Block | @@ -48,4 +48,12 @@ class RecentContentBlock < Block | ||
48 | attr == self.presentation_mode | 48 | attr == self.presentation_mode |
49 | end | 49 | end |
50 | 50 | ||
51 | + def api_content | ||
52 | + children = self.articles_of_folder(self.root, self.total_items) | ||
53 | + Noosfero::API::Entities::ArticleBase.represent(children).as_json | ||
54 | + end | ||
55 | + | ||
56 | + def display_api_content_by_default? | ||
57 | + false | ||
58 | + end | ||
51 | end | 59 | end |
plugins/recent_content/test/unit/recent_content_block_test.rb
@@ -142,4 +142,18 @@ class RecentContentBlockViewTest < ActionView::TestCase | @@ -142,4 +142,18 @@ class RecentContentBlockViewTest < ActionView::TestCase | ||
142 | 142 | ||
143 | assert_match /Block Title/, content | 143 | assert_match /Block Title/, content |
144 | end | 144 | end |
145 | + | ||
146 | + should 'return articles in api_content' do | ||
147 | + profile = create_user('testuser').person | ||
148 | + | ||
149 | + root = fast_create(Blog, name: 'test-blog', profile_id: profile.id) | ||
150 | + article = fast_create(TextArticle, parent_id: root.id, profile_id: profile.id) | ||
151 | + | ||
152 | + block = RecentContentBlock.new | ||
153 | + block.stubs(:holder).returns(profile) | ||
154 | + block.selected_folder = root.id | ||
155 | + block.presentation_mode = '' | ||
156 | + assert_equal [article.id], block.api_content['articles'].map {|a| a[:id]} | ||
157 | + end | ||
158 | + | ||
145 | end | 159 | end |