Commit 38212a9ce6c4aaaddfa075b9cfceda0d0f1c2e36
Committed by
Rodrigo Souto
1 parent
2e32b7c4
Exists in
master
and in
29 other branches
api: update hits for article children
Showing
3 changed files
with
12 additions
and
0 deletions
Show diff stats
lib/noosfero/api/entities.rb
lib/noosfero/api/v1/articles.rb
| ... | ... | @@ -40,6 +40,7 @@ module Noosfero |
| 40 | 40 | articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC') |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | + Article.hit(articles) | |
| 43 | 44 | present articles, :with => Entities::Article, :fields => params[:fields] |
| 44 | 45 | end |
| 45 | 46 | ... | ... |
test/unit/api/articles_test.rb
| ... | ... | @@ -473,4 +473,14 @@ class ArticlesTest < ActiveSupport::TestCase |
| 473 | 473 | assert_equal 'SuggestArticle', json['type'] |
| 474 | 474 | end |
| 475 | 475 | |
| 476 | + should 'update hit attribute of article children' do | |
| 477 | + a1 = fast_create(Article, :profile_id => user.person.id) | |
| 478 | + a2 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id) | |
| 479 | + a3 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id) | |
| 480 | + get "/api/v1/articles/#{a1.id}/children?#{params.to_query}" | |
| 481 | + json = JSON.parse(last_response.body) | |
| 482 | + assert_equal [1, 1], json['articles'].map { |a| a['hits']} | |
| 483 | + assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits] | |
| 484 | + end | |
| 485 | + | |
| 476 | 486 | end | ... | ... |