Commit 6d5f6b634a4a492bc5c40cf69372d63f41969c75
1 parent
f9404f28
Exists in
master
and in
9 other branches
Add api method to create proposal task
Showing
2 changed files
with
27 additions
and
0 deletions
Show diff stats
lib/proposals_discussion_plugin/api.rb
... | ... | @@ -22,6 +22,22 @@ class ProposalsDiscussionPlugin::API < Grape::API |
22 | 22 | ranking |
23 | 23 | end |
24 | 24 | |
25 | + post ':id/propose' do | |
26 | + parent_article = environment.articles.find(params[:id]) | |
27 | + | |
28 | + proposal_task = ProposalsDiscussionPlugin::ProposalTask.new | |
29 | + proposal_task.article = params[:article] | |
30 | + proposal_task.article[:parent_id] = parent_article.id | |
31 | + proposal_task.target = parent_article.profile | |
32 | + proposal_task.requestor = current_person | |
33 | + | |
34 | + unless proposal_task.save | |
35 | + render_api_errors!(proposal_task.article_object.errors.full_messages) | |
36 | + end | |
37 | + {:success => true} | |
38 | + #present proposal_task, :with => Entities::Task, :fields => params[:fields] | |
39 | + end | |
40 | + | |
25 | 41 | end |
26 | 42 | |
27 | 43 | end | ... | ... |
test/unit/api_test.rb
... | ... | @@ -34,4 +34,15 @@ class APITest < ActiveSupport::TestCase |
34 | 34 | assert_equal [proposal2.id, proposal3.id, proposal1.id], json['proposals'].map {|p| p['id']} |
35 | 35 | end |
36 | 36 | |
37 | + should 'suggest article children' do | |
38 | + discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id) | |
39 | + topic = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => user.person.id, :parent_id => discussion.id) | |
40 | + params[:article] = {:name => "Proposal name", :body => "Proposal body"} | |
41 | + assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do | |
42 | + post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}" | |
43 | + end | |
44 | + json = JSON.parse(last_response.body) | |
45 | + assert json['success'] | |
46 | + end | |
47 | + | |
37 | 48 | end | ... | ... |