Commit b69e4d6a20962f920c49b1e03ed9004842c80fa5
1 parent
30cd68bf
Exists in
theme-brasil-digital-from-staging
and in
8 other branches
Remove trailing spaces
Showing
2 changed files
with
13 additions
and
13 deletions
Show diff stats
lib/noosfero/api/v1/search.rb
1 | module Noosfero | 1 | module Noosfero |
2 | module API | 2 | module API |
3 | module V1 | 3 | module V1 |
4 | - class Search < Grape::API | 4 | + class Search < Grape::API |
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 | 8 | paginate per_page: 20, max_per_page: 200 |
9 | get do | 9 | get do |
10 | # Security checks | 10 | # Security checks |
11 | - sanitize_params_hash(params) | 11 | + sanitize_params_hash(params) |
12 | # APIHelpers | 12 | # APIHelpers |
13 | asset = :articles | 13 | asset = :articles |
14 | context = environment | 14 | context = environment |
@@ -22,8 +22,8 @@ module Noosfero | @@ -22,8 +22,8 @@ module Noosfero | ||
22 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? | 22 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? |
23 | 23 | ||
24 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? | 24 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? |
25 | - | ||
26 | - query = params[:query] || "" | 25 | + |
26 | + query = params[:query] || "" | ||
27 | order = "more_recent" | 27 | order = "more_recent" |
28 | 28 | ||
29 | options = {:filter => order, :template_id => params[:template_id]} | 29 | options = {:filter => order, :template_id => params[:template_id]} |
@@ -33,9 +33,9 @@ module Noosfero | @@ -33,9 +33,9 @@ module Noosfero | ||
33 | articles = search_result[:results] | 33 | articles = search_result[:results] |
34 | 34 | ||
35 | result = present_articles_paginated(articles) | 35 | result = present_articles_paginated(articles) |
36 | - | 36 | + |
37 | result | 37 | result |
38 | - end | 38 | + end |
39 | end | 39 | end |
40 | end | 40 | end |
41 | 41 |
test/unit/api/search_test.rb
@@ -10,9 +10,9 @@ class SearchTest < ActiveSupport::TestCase | @@ -10,9 +10,9 @@ class SearchTest < ActiveSupport::TestCase | ||
10 | should 'not list unpublished articles' do | 10 | should 'not list unpublished articles' do |
11 | Article.delete_all | 11 | Article.delete_all |
12 | article = fast_create(Article, :profile_id => person.id, :published => false) | 12 | article = fast_create(Article, :profile_id => person.id, :published => false) |
13 | - assert !article.published? | 13 | + assert !article.published? |
14 | get "/api/v1/search/article" | 14 | get "/api/v1/search/article" |
15 | - json = JSON.parse(last_response.body) | 15 | + json = JSON.parse(last_response.body) |
16 | assert_empty json['articles'] | 16 | assert_empty json['articles'] |
17 | end | 17 | end |
18 | 18 | ||
@@ -26,7 +26,7 @@ class SearchTest < ActiveSupport::TestCase | @@ -26,7 +26,7 @@ class SearchTest < ActiveSupport::TestCase | ||
26 | should 'invalid search string articles' do | 26 | should 'invalid search string articles' do |
27 | fast_create(Article, :profile_id => person.id, :name => 'some article') | 27 | fast_create(Article, :profile_id => person.id, :name => 'some article') |
28 | get "/api/v1/search/article?query=test" | 28 | get "/api/v1/search/article?query=test" |
29 | - json = JSON.parse(last_response.body) | 29 | + json = JSON.parse(last_response.body) |
30 | assert_empty json['articles'] | 30 | assert_empty json['articles'] |
31 | end | 31 | end |
32 | 32 | ||
@@ -40,7 +40,7 @@ class SearchTest < ActiveSupport::TestCase | @@ -40,7 +40,7 @@ class SearchTest < ActiveSupport::TestCase | ||
40 | should 'list articles of one type' do | 40 | should 'list articles of one type' do |
41 | fast_create(Article, :profile_id => person.id) | 41 | fast_create(Article, :profile_id => person.id) |
42 | article = fast_create(TinyMceArticle, :profile_id => person.id) | 42 | article = fast_create(TinyMceArticle, :profile_id => person.id) |
43 | - | 43 | + |
44 | get "/api/v1/search/article?type=TinyMceArticle" | 44 | get "/api/v1/search/article?type=TinyMceArticle" |
45 | json = JSON.parse(last_response.body) | 45 | json = JSON.parse(last_response.body) |
46 | assert_equal article.id, json['articles'].first['id'] | 46 | assert_equal article.id, json['articles'].first['id'] |
@@ -105,7 +105,7 @@ class SearchTest < ActiveSupport::TestCase | @@ -105,7 +105,7 @@ class SearchTest < ActiveSupport::TestCase | ||
105 | json = JSON.parse(last_response.body) | 105 | json = JSON.parse(last_response.body) |
106 | assert_equal 1, json['articles'].count | 106 | assert_equal 1, json['articles'].count |
107 | assert_equal article.id, json['articles'].first["id"] | 107 | assert_equal article.id, json['articles'].first["id"] |
108 | - end | 108 | + end |
109 | 109 | ||
110 | should 'search filter by category' do | 110 | should 'search filter by category' do |
111 | Article.delete_all | 111 | Article.delete_all |
@@ -117,7 +117,7 @@ class SearchTest < ActiveSupport::TestCase | @@ -117,7 +117,7 @@ class SearchTest < ActiveSupport::TestCase | ||
117 | json = JSON.parse(last_response.body) | 117 | json = JSON.parse(last_response.body) |
118 | assert_equal 1, json['articles'].count | 118 | assert_equal 1, json['articles'].count |
119 | assert_equal article.id, json['articles'].first["id"] | 119 | assert_equal article.id, json['articles'].first["id"] |
120 | - end | 120 | + end |
121 | 121 | ||
122 | should 'search filter by more than one category' do | 122 | should 'search filter by more than one category' do |
123 | Article.delete_all | 123 | Article.delete_all |
@@ -133,6 +133,6 @@ class SearchTest < ActiveSupport::TestCase | @@ -133,6 +133,6 @@ class SearchTest < ActiveSupport::TestCase | ||
133 | assert_equal 2, json['articles'].count | 133 | assert_equal 2, json['articles'].count |
134 | assert_equal article1.id, json['articles'].first["id"] | 134 | assert_equal article1.id, json['articles'].first["id"] |
135 | assert_equal article2.id, json['articles'].last["id"] | 135 | assert_equal article2.id, json['articles'].last["id"] |
136 | - end | 136 | + end |
137 | 137 | ||
138 | end | 138 | end |