Commit 0c420f13bdd79dbbdc23305505ede4c33aefba23

Authored by Leandro Santos
2 parents ef2dd356 81c8608d

Merge branch 'master' of gitlab.com:noosfero-plugins/proposals_discussion

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", :abstract => "Proposal abstract", :type => 'ProposalsDiscussionPlugin::Proposal'}
  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
... ...
views/tasks/proposals_discussion_plugin/_proposal_task_accept_details.html.erb
1   -<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %>
  1 +<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target, task.article_parent_id) %>
2 2  
3 3 <%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width: 488px; height: 30px') %>
4 4  
... ...