Commit 9c7cf5bca7fda31e206388a3cacfa88d798377df
1 parent
44c5519f
Exists in
theme-brasil-digital-from-staging
and in
4 other branches
Fix merge
Showing
2 changed files
with
9 additions
and
9 deletions
Show diff stats
lib/noosfero/api/v1/search.rb
@@ -5,7 +5,6 @@ module Noosfero | @@ -5,7 +5,6 @@ module Noosfero | ||
5 | 5 | ||
6 | resource :search do | 6 | resource :search do |
7 | resource :article do | 7 | resource :article do |
8 | - paginate per_page: 20, max_per_page: 200 | ||
9 | get do | 8 | get do |
10 | # Security checks | 9 | # Security checks |
11 | sanitize_params_hash(params) | 10 | sanitize_params_hash(params) |
@@ -14,25 +13,24 @@ module Noosfero | @@ -14,25 +13,24 @@ module Noosfero | ||
14 | context = environment | 13 | context = environment |
15 | 14 | ||
16 | profile = environment.profiles.find(params[:profile_id]) if params[:profile_id] | 15 | profile = environment.profiles.find(params[:profile_id]) if params[:profile_id] |
17 | - | ||
18 | - scope = profile.nil? ? environment.articles.public : profile.articles.public | ||
19 | - | 16 | + scope = profile.nil? ? environment.articles.is_public : profile.articles.is_public |
20 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') | 17 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') |
21 | - | ||
22 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? | 18 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? |
23 | - | ||
24 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? | 19 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? |
25 | - | ||
26 | query = params[:query] || "" | 20 | query = params[:query] || "" |
27 | order = "more_recent" | 21 | order = "more_recent" |
28 | 22 | ||
29 | options = {:filter => order, :template_id => params[:template_id]} | 23 | options = {:filter => order, :template_id => params[:template_id]} |
30 | 24 | ||
25 | + paginate_options = params.select{|k,v| [:page, :per_page].include?(k.to_sym)}.symbolize_keys | ||
26 | + paginate_options.each_pair{|k,v| v=v.to_i} | ||
27 | + paginate_options[:page]=1 if !paginate_options.keys.include?(:page) | ||
28 | + | ||
31 | search_result = find_by_contents(asset, context, scope, query, paginate_options, options) | 29 | search_result = find_by_contents(asset, context, scope, query, paginate_options, options) |
32 | 30 | ||
33 | articles = search_result[:results] | 31 | articles = search_result[:results] |
34 | 32 | ||
35 | - result = present_articles_paginated(articles) | 33 | + result = present_articles(articles) |
36 | 34 | ||
37 | result | 35 | result |
38 | end | 36 | end |
test/unit/api/search_test.rb
@@ -131,8 +131,10 @@ class SearchTest < ActiveSupport::TestCase | @@ -131,8 +131,10 @@ class SearchTest < ActiveSupport::TestCase | ||
131 | article2.categories<< category2 | 131 | article2.categories<< category2 |
132 | get "/api/v1/search/article?category_ids[]=#{category1.id}&category_ids[]=#{category2.id}" | 132 | get "/api/v1/search/article?category_ids[]=#{category1.id}&category_ids[]=#{category2.id}" |
133 | json = JSON.parse(last_response.body) | 133 | json = JSON.parse(last_response.body) |
134 | + ids = [article1.id, article2.id] | ||
134 | assert_equal 2, json['articles'].count | 135 | assert_equal 2, json['articles'].count |
135 | - assert_equivalent [article1.id, article2.id], json['articles'].map{|a| a['id']} | 136 | + assert_includes ids, json['articles'].first["id"] |
137 | + assert_includes ids, json['articles'].last["id"] | ||
136 | end | 138 | end |
137 | 139 | ||
138 | end | 140 | end |