Commit 7a56a75ed67c4b1a9e63b6d15b9a3ab86852bab3
Committed by
Victor Costa
1 parent
4c7d2f35
Exists in
theme-brasil-digital-from-staging
and in
3 other branches
api: added param 'has_children' into search article endpoint
Showing
4 changed files
with
17 additions
and
4 deletions
Show diff stats
lib/noosfero/api/v1/articles.rb
| ... | ... | @@ -197,7 +197,7 @@ module Noosfero |
| 197 | 197 | child.hit |
| 198 | 198 | present child, :with => Entities::Article, :fields => params[:fields] |
| 199 | 199 | end |
| 200 | - | |
| 200 | + | |
| 201 | 201 | desc 'Suggest a article to another profile' do |
| 202 | 202 | detail 'Suggest a article to another profile (person, community...)' |
| 203 | 203 | params Noosfero::API::Entities::Article.documentation | ... | ... |
lib/noosfero/api/v1/search.rb
| ... | ... | @@ -23,6 +23,8 @@ module Noosfero |
| 23 | 23 | |
| 24 | 24 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? |
| 25 | 25 | |
| 26 | + scope = scope.where('children_count > 0') if params[:has_children].present? | |
| 27 | + | |
| 26 | 28 | query = params[:query] || "" |
| 27 | 29 | order = "more_recent" |
| 28 | 30 | ... | ... |
test/unit/api/articles_test.rb
| ... | ... | @@ -40,11 +40,12 @@ class ArticlesTest < ActiveSupport::TestCase |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | should 'list article children' do |
| 43 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
| 44 | - child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") | |
| 45 | - child2 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") | |
| 43 | + article = create(Article, :profile_id => user.person.id, :name => "Parent") | |
| 44 | + child1 = create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some Child") | |
| 45 | + child2 = create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some Child2") | |
| 46 | 46 | get "/api/v1/articles/#{article.id}/children?#{params.to_query}" |
| 47 | 47 | json = JSON.parse(last_response.body) |
| 48 | + | |
| 48 | 49 | assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] } |
| 49 | 50 | end |
| 50 | 51 | ... | ... |
test/unit/api/search_test.rb
| ... | ... | @@ -23,6 +23,16 @@ class SearchTest < ActiveSupport::TestCase |
| 23 | 23 | assert_not_empty json['articles'] |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | + should 'list only articles that has children' do | |
| 27 | + article = fast_create(Article, :profile_id => person.id) | |
| 28 | + parent = create(Article, :profile_id => person.id, :name => 'parent article') | |
| 29 | + child = create(Article, :profile_id => person.id, :parent_id => parent.id, :name => 'child article') | |
| 30 | + | |
| 31 | + get "/api/v1/search/article?has_children=true" | |
| 32 | + json = JSON.parse(last_response.body) | |
| 33 | + assert_equal parent.id, json['articles'].first['id'] | |
| 34 | + end | |
| 35 | + | |
| 26 | 36 | should 'invalid search string articles' do |
| 27 | 37 | fast_create(Article, :profile_id => person.id, :name => 'some article') |
| 28 | 38 | get "/api/v1/search/article?query=test" | ... | ... |