diff --git a/lib/noosfero/api/v1/comments.rb b/lib/noosfero/api/v1/comments.rb index d38ac81..edbcba8 100644 --- a/lib/noosfero/api/v1/comments.rb +++ b/lib/noosfero/api/v1/comments.rb @@ -30,8 +30,8 @@ module Noosfero # POST api/v1/articles/12/comments?private_token=2298743290432&body=new comment&title=New post ":id/comments" do article = find_article(environment.articles, params[:id]) - options = params.select { |key,v| !['id','private_token'].include?(key) }.merge(:author => current_person) - present article.comments.create(options), :with => Entities::Comment + options = params.select { |key,v| !['id','private_token'].include?(key) }.merge(:author => current_person, :source => article) + present Comment.create(options), :with => Entities::Comment end end diff --git a/test/unit/api/comments_test.rb b/test/unit/api/comments_test.rb index 0a718ea..3f1bfbe 100644 --- a/test/unit/api/comments_test.rb +++ b/test/unit/api/comments_test.rb @@ -65,4 +65,17 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 201, last_response.status assert_equal body, json['comment']['body'] end + + should 'comment creation define the source' do + amount = Comment.count + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + body = 'My comment' + params.merge!({:body => body}) + + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + assert_equal amount + 1, Comment.count + comment = Comment.last + assert_not_nil comment.source + end + end -- libgit2 0.21.2