Commit 5fc67fe4de1d2f03797176707b750595632de7f9
1 parent
1ad1af3d
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
should set the source in comment creation
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
lib/noosfero/api/v1/comments.rb
@@ -30,8 +30,8 @@ module Noosfero | @@ -30,8 +30,8 @@ module Noosfero | ||
30 | # POST api/v1/articles/12/comments?private_token=2298743290432&body=new comment&title=New | 30 | # POST api/v1/articles/12/comments?private_token=2298743290432&body=new comment&title=New |
31 | post ":id/comments" do | 31 | post ":id/comments" do |
32 | article = find_article(environment.articles, params[:id]) | 32 | article = find_article(environment.articles, params[:id]) |
33 | - options = params.select { |key,v| !['id','private_token'].include?(key) }.merge(:author => current_person) | ||
34 | - present article.comments.create(options), :with => Entities::Comment | 33 | + options = params.select { |key,v| !['id','private_token'].include?(key) }.merge(:author => current_person, :source => article) |
34 | + present Comment.create(options), :with => Entities::Comment | ||
35 | end | 35 | end |
36 | end | 36 | end |
37 | 37 |
test/unit/api/comments_test.rb
@@ -65,4 +65,17 @@ class CommentsTest < ActiveSupport::TestCase | @@ -65,4 +65,17 @@ class CommentsTest < ActiveSupport::TestCase | ||
65 | assert_equal 201, last_response.status | 65 | assert_equal 201, last_response.status |
66 | assert_equal body, json['comment']['body'] | 66 | assert_equal body, json['comment']['body'] |
67 | end | 67 | end |
68 | + | ||
69 | + should 'comment creation define the source' do | ||
70 | + amount = Comment.count | ||
71 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | ||
72 | + body = 'My comment' | ||
73 | + params.merge!({:body => body}) | ||
74 | + | ||
75 | + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | ||
76 | + assert_equal amount + 1, Comment.count | ||
77 | + comment = Comment.last | ||
78 | + assert_not_nil comment.source | ||
79 | + end | ||
80 | + | ||
68 | end | 81 | end |