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 | 5 | |
| 6 | 6 | resource :search do |
| 7 | 7 | resource :article do |
| 8 | - paginate per_page: 20, max_per_page: 200 | |
| 9 | 8 | get do |
| 10 | 9 | # Security checks |
| 11 | 10 | sanitize_params_hash(params) |
| ... | ... | @@ -14,25 +13,24 @@ module Noosfero |
| 14 | 13 | context = environment |
| 15 | 14 | |
| 16 | 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 | 17 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') |
| 21 | - | |
| 22 | 18 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? |
| 23 | - | |
| 24 | 19 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? |
| 25 | - | |
| 26 | 20 | query = params[:query] || "" |
| 27 | 21 | order = "more_recent" |
| 28 | 22 | |
| 29 | 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 | 29 | search_result = find_by_contents(asset, context, scope, query, paginate_options, options) |
| 32 | 30 | |
| 33 | 31 | articles = search_result[:results] |
| 34 | 32 | |
| 35 | - result = present_articles_paginated(articles) | |
| 33 | + result = present_articles(articles) | |
| 36 | 34 | |
| 37 | 35 | result |
| 38 | 36 | end | ... | ... |
test/unit/api/search_test.rb
| ... | ... | @@ -131,8 +131,10 @@ class SearchTest < ActiveSupport::TestCase |
| 131 | 131 | article2.categories<< category2 |
| 132 | 132 | get "/api/v1/search/article?category_ids[]=#{category1.id}&category_ids[]=#{category2.id}" |
| 133 | 133 | json = JSON.parse(last_response.body) |
| 134 | + ids = [article1.id, article2.id] | |
| 134 | 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 | 138 | end |
| 137 | 139 | |
| 138 | 140 | end | ... | ... |