Commit 5f40b80d8223ff086a55b2ee7285782ece09adfd

Authored by Victor Costa
2 parents 8ccaa1b3 2027742c
Exists in staging and in 1 other branch production

Merge branch 'api-search-order' into staging

lib/noosfero/api/v1/search.rb
... ... @@ -19,10 +19,14 @@ module Noosfero
19 19 scope = scope.where(make_conditions_with_parameter(params))
20 20 scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present?
21 21 scope = scope.where('articles.children_count > 0') if params[:has_children].present?
  22 +
  23 + order = make_order_with_parameters(profile || environment, :articles, params)
  24 + scope = scope.reorder(order)
  25 +
22 26 query = params[:query] || ""
23   - order = "more_recent"
  27 + search_order = "more_recent"
24 28  
25   - options = {:filter => order, :template_id => params[:template_id]}
  29 + options = {:filter => search_order, :template_id => params[:template_id]}
26 30  
27 31 search_result = find_by_contents(asset, context, scope, query, {:page => 1}, options)
28 32  
... ...
test/api/search_test.rb
... ... @@ -155,4 +155,12 @@ class SearchTest < ActiveSupport::TestCase
155 155 assert_equal [article2.id], json['articles'].map {|a| a['id']}
156 156 end
157 157  
  158 + should 'list articles with order' do
  159 + article1 = fast_create(Article, :profile_id => person.id, created_at: Time.now - 1.day)
  160 + article2 = fast_create(Article, :profile_id => person.id, created_at: Time.now)
  161 + params = {order: 'created_at DESC'}
  162 + get "/api/v1/search/article?#{params.to_query}"
  163 + json = JSON.parse(last_response.body)
  164 + assert_equal [article2.id, article1.id], json['articles'].map {|a| a['id']}
  165 + end
158 166 end
... ...