Commit 57e3afc186238eca67223797c0fc2a84adda5567
1 parent
ea5cb22f
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Added parent to search
Showing
2 changed files
with
18 additions
and
3 deletions
Show diff stats
lib/noosfero/api/v1/search.rb
... | ... | @@ -18,6 +18,8 @@ module Noosfero |
18 | 18 | scope = profile.nil? ? environment.articles.public : profile.articles.public |
19 | 19 | |
20 | 20 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') |
21 | + | |
22 | + scope = scope.where(:parent_id => params[:parent]) if params[:parent].present? | |
21 | 23 | |
22 | 24 | category = params[:category] || "" |
23 | 25 | ... | ... |
test/unit/api/search_test.rb
... | ... | @@ -2,8 +2,8 @@ require File.dirname(__FILE__) + '/test_helper' |
2 | 2 | |
3 | 3 | class SearchTest < ActiveSupport::TestCase |
4 | 4 | |
5 | - def create_article_with_optional_category(name, profile, category = nil) | |
6 | - fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category, :title => name) | |
5 | + def create_article_with_optional_category(name, profile, category = nil, parent = nil) | |
6 | + fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category, :title => name, :parent => parent) | |
7 | 7 | end |
8 | 8 | |
9 | 9 | should 'not list unpublished articles' do |
... | ... | @@ -97,11 +97,24 @@ class SearchTest < ActiveSupport::TestCase |
97 | 97 | end |
98 | 98 | |
99 | 99 | should 'search with fields' do |
100 | - person = fast_create(Person) | |
100 | + person = fast_create(Person) | |
101 | 101 | art = create_article_with_optional_category('an article to be found', person) |
102 | 102 | get "/api/v1/search/article?fields=title" |
103 | 103 | json = JSON.parse(last_response.body) |
104 | 104 | assert_not_empty json['articles'] |
105 | 105 | assert_equal ['title'], json['articles'].first.keys |
106 | 106 | end |
107 | + | |
108 | + should 'search with parent' do | |
109 | + person = fast_create(Person) | |
110 | + parent = fast_create(Folder, :profile_id => person.id, :name => "parent", :published => true) | |
111 | + art = fast_create(Article, :profile_id => person.id, :name => "child", :parent_id => parent.id) | |
112 | + art2 = fast_create(Article, :profile_id => person.id, :name => "child2") | |
113 | + get "/api/v1/search/article?parent=#{parent.id}" | |
114 | + json = JSON.parse(last_response.body) | |
115 | + assert_not_empty json['articles'] | |
116 | + assert_equal art.id, json['articles'].first["id"] | |
117 | + assert_equal 1, json['articles'].count | |
118 | + end | |
119 | + | |
107 | 120 | end |
108 | 121 | \ No newline at end of file | ... | ... |