Commit e7aecdac406b942733780faff9cc681d450837c4
1 parent
bac4c761
Exists in
web_steps_improvements
and in
6 other branches
api: add filter option to return only root comments
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
lib/noosfero/api/v1/comments.rb
... | ... | @@ -20,7 +20,7 @@ module Noosfero |
20 | 20 | get ":id/comments" do |
21 | 21 | article = find_article(environment.articles, params[:id]) |
22 | 22 | comments = select_filtered_collection_of(article, :comments, params) |
23 | - | |
23 | + comments = comments.without_reply if(params[:without_reply].present?) | |
24 | 24 | present comments, :with => Entities::Comment, :current_person => current_person |
25 | 25 | end |
26 | 26 | ... | ... |
test/api/comments_test.rb
... | ... | @@ -88,4 +88,16 @@ class CommentsTest < ActiveSupport::TestCase |
88 | 88 | assert_equal 200, last_response.status |
89 | 89 | assert_equal 3, json["comments"].length |
90 | 90 | end |
91 | + | |
92 | + should 'return only root comments' do | |
93 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
94 | + comment1 = article.comments.create!(:body => "some comment", :author => user.person) | |
95 | + comment2 = article.comments.create!(:body => "another comment", :author => user.person, :reply_of_id => comment1.id) | |
96 | + params[:without_reply] = true | |
97 | + | |
98 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
99 | + json = JSON.parse(last_response.body) | |
100 | + assert_equal 200, last_response.status | |
101 | + assert_equal [comment1.id], json["comments"].map { |c| c['id'] } | |
102 | + end | |
91 | 103 | end | ... | ... |