Commit 2a2df48c2e39124e43e823636c01714ff0a2741e

Authored by Victor Costa
1 parent 7532ff75

api: hit specific article child

lib/noosfero/api/v1/articles.rb
@@ -110,7 +110,9 @@ module Noosfero @@ -110,7 +110,9 @@ module Noosfero
110 110
111 get ':id/children/:child_id' do 111 get ':id/children/:child_id' do
112 article = find_article(environment.articles, params[:id]) 112 article = find_article(environment.articles, params[:id])
113 - present find_article(article.children, params[:child_id]), :with => Entities::Article, :fields => params[:fields] 113 + child = find_article(article.children, params[:child_id])
  114 + child.hit
  115 + present child, :with => Entities::Article, :fields => params[:fields]
114 end 116 end
115 117
116 post ':id/children/suggest' do 118 post ':id/children/suggest' do
test/unit/api/articles_test.rb
@@ -348,6 +348,13 @@ class ArticlesTest < ActiveSupport::TestCase @@ -348,6 +348,13 @@ class ArticlesTest < ActiveSupport::TestCase
348 assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits] 348 assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits]
349 end 349 end
350 350
  351 + should 'update hit attribute of article specific children' do
  352 + a1 = fast_create(Article, :profile_id => user.person.id)
  353 + a2 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)
  354 + get "/api/v1/articles/#{a1.id}/children/#{a2.id}?#{params.to_query}"
  355 + json = JSON.parse(last_response.body)
  356 + assert_equal 1, json['article']['hits']
  357 + end
351 358
352 should 'list all events of a community in a given category' do 359 should 'list all events of a community in a given category' do
353 co = Community.create(identifier: 'my-community', name: 'name-my-community') 360 co = Community.create(identifier: 'my-community', name: 'name-my-community')