Commit 3ca7d77baabe39919c0d2d58b621a8168dc32bbf
1 parent
37ffee3b
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fixed search result type
Showing
2 changed files
with
13 additions
and
11 deletions
Show diff stats
lib/noosfero/api/v1/search.rb
| ... | ... | @@ -11,9 +11,10 @@ module Noosfero |
| 11 | 11 | # APIHelpers |
| 12 | 12 | asset = :articles |
| 13 | 13 | context = environment |
| 14 | + | |
| 14 | 15 | profile = environment.profiles.find(params[:profile_id]) if params[:profile_id] |
| 15 | 16 | |
| 16 | - scope = profile.articles.public || scope = environment.articles.public | |
| 17 | + scope = profile.nil? ? environment.articles.public : profile.articles.public | |
| 17 | 18 | |
| 18 | 19 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') |
| 19 | 20 | |
| ... | ... | @@ -25,7 +26,8 @@ module Noosfero |
| 25 | 26 | options = {:filter => order, :template_id => params[:template_id], :category => category} |
| 26 | 27 | |
| 27 | 28 | articles = find_by_contents(asset, context, scope, query, paginate_options, options) |
| 28 | - present articles | |
| 29 | + | |
| 30 | + present articles[:results], :with => Entities::Article | |
| 29 | 31 | end |
| 30 | 32 | end |
| 31 | 33 | end | ... | ... |
test/unit/api/search_test.rb
| ... | ... | @@ -12,7 +12,7 @@ class SearchTest < ActiveSupport::TestCase |
| 12 | 12 | assert !article.published? |
| 13 | 13 | get "/api/v1/search/article" |
| 14 | 14 | json = JSON.parse(last_response.body) |
| 15 | - assert_empty json['results'] | |
| 15 | + assert_empty json['articles'] | |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | should 'list articles' do |
| ... | ... | @@ -20,7 +20,7 @@ class SearchTest < ActiveSupport::TestCase |
| 20 | 20 | art = create_article_with_optional_category('an article to be found', person) |
| 21 | 21 | get "/api/v1/search/article" |
| 22 | 22 | json = JSON.parse(last_response.body) |
| 23 | - assert_not_empty json['results'] | |
| 23 | + assert_not_empty json['articles'] | |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 26 | should 'invalid search string articles' do |
| ... | ... | @@ -28,7 +28,7 @@ class SearchTest < ActiveSupport::TestCase |
| 28 | 28 | art = create_article_with_optional_category('an article to be found', person) |
| 29 | 29 | get "/api/v1/search/article?query=test" |
| 30 | 30 | json = JSON.parse(last_response.body) |
| 31 | - assert_empty json['results'] | |
| 31 | + assert_empty json['articles'] | |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | should 'do not list articles of wrong type' do |
| ... | ... | @@ -36,7 +36,7 @@ class SearchTest < ActiveSupport::TestCase |
| 36 | 36 | art = create_article_with_optional_category('an article to be found', person) |
| 37 | 37 | get "/api/v1/search/article?type=TinyMceArticle" |
| 38 | 38 | json = JSON.parse(last_response.body) |
| 39 | - assert_empty json['results'] | |
| 39 | + assert_empty json['articles'] | |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | should 'list articles of one type' do |
| ... | ... | @@ -45,7 +45,7 @@ class SearchTest < ActiveSupport::TestCase |
| 45 | 45 | article = fast_create(TinyMceArticle, :profile_id => person.id, :name => "Some thing", :published => true) |
| 46 | 46 | get "/api/v1/search/article?type=TinyMceArticle" |
| 47 | 47 | json = JSON.parse(last_response.body) |
| 48 | - assert_equal 1, json['results'].size | |
| 48 | + assert_equal 1, json['articles'].count | |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | 51 | should 'list articles of one type and query string' do |
| ... | ... | @@ -55,7 +55,7 @@ class SearchTest < ActiveSupport::TestCase |
| 55 | 55 | article = fast_create(TinyMceArticle, :profile_id => person.id, :name => "Some thing", :published => true) |
| 56 | 56 | get "/api/v1/search/article?type=TinyMceArticle&query=thing" |
| 57 | 57 | json = JSON.parse(last_response.body) |
| 58 | - assert_equal 1, json['results'].size | |
| 58 | + assert_equal 1, json['articles'].count | |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 61 | should 'not return more entries than page limit' do |
| ... | ... | @@ -67,7 +67,7 @@ class SearchTest < ActiveSupport::TestCase |
| 67 | 67 | get "/api/v1/search/article?query=Article&limit=3" |
| 68 | 68 | json = JSON.parse(last_response.body) |
| 69 | 69 | |
| 70 | - assert_equal 3, json['results'].size | |
| 70 | + assert_equal 3, json['articles'].count | |
| 71 | 71 | end |
| 72 | 72 | |
| 73 | 73 | should 'return entries second page' do |
| ... | ... | @@ -79,7 +79,7 @@ class SearchTest < ActiveSupport::TestCase |
| 79 | 79 | get "/api/v1/search/article?query=Article&limit=3&page=2" |
| 80 | 80 | json = JSON.parse(last_response.body) |
| 81 | 81 | |
| 82 | - assert_equal 2, json['results'].size | |
| 82 | + assert_equal 2, json['articles'].count | |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | should 'search articles in profile' do |
| ... | ... | @@ -93,6 +93,6 @@ class SearchTest < ActiveSupport::TestCase |
| 93 | 93 | get "/api/v1/search/article?query=Article&profile_id=#{person1.id}" |
| 94 | 94 | json = JSON.parse(last_response.body) |
| 95 | 95 | # Only for person1 |
| 96 | - assert_equal 2, json['results'].size | |
| 96 | + assert_equal 2, json['articles'].count | |
| 97 | 97 | end |
| 98 | 98 | end |
| 99 | 99 | \ No newline at end of file | ... | ... |