Commit b65da5afe7aa265c1b22c0654ac85a7454d641aa
Committed by
Rodrigo Souto
1 parent
91951aa4
Exists in
api_tasks
and in
4 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,6 +40,7 @@ module Noosfero | ||
40 | articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC') | 40 | articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC') |
41 | end | 41 | end |
42 | 42 | ||
43 | + Article.hit(articles) | ||
43 | present articles, :with => Entities::Article, :fields => params[:fields] | 44 | present articles, :with => Entities::Article, :fields => params[:fields] |
44 | end | 45 | end |
45 | 46 |
test/unit/api/articles_test.rb
@@ -473,4 +473,14 @@ class ArticlesTest < ActiveSupport::TestCase | @@ -473,4 +473,14 @@ class ArticlesTest < ActiveSupport::TestCase | ||
473 | assert_equal 'SuggestArticle', json['type'] | 473 | assert_equal 'SuggestArticle', json['type'] |
474 | end | 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 | end | 486 | end |