diff --git a/lib/noosfero/api/v1/search.rb b/lib/noosfero/api/v1/search.rb index 1b0005c..6bfbb6c 100644 --- a/lib/noosfero/api/v1/search.rb +++ b/lib/noosfero/api/v1/search.rb @@ -1,14 +1,14 @@ module Noosfero module API module V1 - class Search < Grape::API + class Search < Grape::API resource :search do resource :article do paginate per_page: 20, max_per_page: 200 get do # Security checks - sanitize_params_hash(params) + sanitize_params_hash(params) # APIHelpers asset = :articles context = environment @@ -22,8 +22,8 @@ module Noosfero scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? - - query = params[:query] || "" + + query = params[:query] || "" order = "more_recent" options = {:filter => order, :template_id => params[:template_id]} @@ -33,9 +33,9 @@ module Noosfero articles = search_result[:results] result = present_articles_paginated(articles) - + result - end + end end end diff --git a/test/unit/api/search_test.rb b/test/unit/api/search_test.rb index cb080e5..a3c341d 100644 --- a/test/unit/api/search_test.rb +++ b/test/unit/api/search_test.rb @@ -10,9 +10,9 @@ class SearchTest < ActiveSupport::TestCase should 'not list unpublished articles' do Article.delete_all article = fast_create(Article, :profile_id => person.id, :published => false) - assert !article.published? + assert !article.published? get "/api/v1/search/article" - json = JSON.parse(last_response.body) + json = JSON.parse(last_response.body) assert_empty json['articles'] end @@ -26,7 +26,7 @@ class SearchTest < ActiveSupport::TestCase should 'invalid search string articles' do fast_create(Article, :profile_id => person.id, :name => 'some article') get "/api/v1/search/article?query=test" - json = JSON.parse(last_response.body) + json = JSON.parse(last_response.body) assert_empty json['articles'] end @@ -40,7 +40,7 @@ class SearchTest < ActiveSupport::TestCase should 'list articles of one type' do fast_create(Article, :profile_id => person.id) article = fast_create(TinyMceArticle, :profile_id => person.id) - + get "/api/v1/search/article?type=TinyMceArticle" json = JSON.parse(last_response.body) assert_equal article.id, json['articles'].first['id'] @@ -105,7 +105,7 @@ class SearchTest < ActiveSupport::TestCase json = JSON.parse(last_response.body) assert_equal 1, json['articles'].count assert_equal article.id, json['articles'].first["id"] - end + end should 'search filter by category' do Article.delete_all @@ -117,7 +117,7 @@ class SearchTest < ActiveSupport::TestCase json = JSON.parse(last_response.body) assert_equal 1, json['articles'].count assert_equal article.id, json['articles'].first["id"] - end + end should 'search filter by more than one category' do Article.delete_all @@ -133,6 +133,6 @@ class SearchTest < ActiveSupport::TestCase assert_equal 2, json['articles'].count assert_equal article1.id, json['articles'].first["id"] assert_equal article2.id, json['articles'].last["id"] - end + end end -- libgit2 0.21.2