From 37ffee3bd22abe0d4ccffa1562103ed2b36aefd2 Mon Sep 17 00:00:00 2001 From: Carlos Purificacao Date: Thu, 3 Sep 2015 11:20:51 -0300 Subject: [PATCH] Added search by profile --- lib/noosfero/api/v1/search.rb | 5 ++++- test/unit/api/search_test.rb | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/noosfero/api/v1/search.rb b/lib/noosfero/api/v1/search.rb index 0f80863..84429fe 100644 --- a/lib/noosfero/api/v1/search.rb +++ b/lib/noosfero/api/v1/search.rb @@ -11,11 +11,14 @@ module Noosfero # APIHelpers asset = :articles context = environment - scope = environment.articles.public + profile = environment.profiles.find(params[:profile_id]) if params[:profile_id] + + scope = profile.articles.public || scope = environment.articles.public scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') category = params[:category] || "" + query = params[:query] || "" order = "more_recent" diff --git a/test/unit/api/search_test.rb b/test/unit/api/search_test.rb index 4ecbf41..f965f12 100644 --- a/test/unit/api/search_test.rb +++ b/test/unit/api/search_test.rb @@ -67,7 +67,6 @@ class SearchTest < ActiveSupport::TestCase get "/api/v1/search/article?query=Article&limit=3" json = JSON.parse(last_response.body) - assert_equal 3, json['results'].size end @@ -80,8 +79,20 @@ class SearchTest < ActiveSupport::TestCase get "/api/v1/search/article?query=Article&limit=3&page=2" json = JSON.parse(last_response.body) - assert_equal 2, json['results'].size end + should 'search articles in profile' do + person1 = fast_create(Person) + person2 = fast_create(Person) + + art1 = create_article_with_optional_category("Article 1 for profile #{person1.id}", person1) + art2 = create_article_with_optional_category("Article for profile #{person2.id}", person2) + art3 = create_article_with_optional_category("Article 2 for profile #{person1.id}", person1) + + get "/api/v1/search/article?query=Article&profile_id=#{person1.id}" + json = JSON.parse(last_response.body) + # Only for person1 + assert_equal 2, json['results'].size + end end \ No newline at end of file -- libgit2 0.21.2