Commit 8b3a53b888d8e3761b9ac9c1744f9195470b6362

Authored by Victor Costa
1 parent 6d54bf95

comment_paragraph: return discussions in api content

plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
... ... @@ -49,4 +49,11 @@ class CommentParagraphPlugin::DiscussionBlock < Block
49 49 attr == self.presentation_mode
50 50 end
51 51  
  52 + def api_content
  53 + Api::Entities::ArticleBase.represent(self.discussions).as_json
  54 + end
  55 +
  56 + def display_api_content_by_default?
  57 + false
  58 + end
52 59 end
... ...
plugins/comment_paragraph/test/unit/discussion_block_test.rb
... ... @@ -174,4 +174,18 @@ class DiscussionBlockViewTest < ActionView::TestCase
174 174  
175 175 assert_match /discussion-full/, content
176 176 end
  177 +
  178 + should 'return discussions in api_content' do
  179 + community = fast_create(Community)
  180 + community.boxes << Box.new
  181 + b = CommentParagraphPlugin::DiscussionBlock.new
  182 + b.box = community.boxes.last
  183 + b.save
  184 + a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
  185 + fast_create(Event, :profile_id => community.id)
  186 + fast_create(TinyMceArticle, :profile_id => community.id)
  187 + a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
  188 + assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]}
  189 + end
  190 +
177 191 end
... ...