diff --git a/app/controllers/api/v2/planning_elements_controller.rb b/app/controllers/api/v2/planning_elements_controller.rb index 8715608f7c..9b242e662f 100644 --- a/app/controllers/api/v2/planning_elements_controller.rb +++ b/app/controllers/api/v2/planning_elements_controller.rb @@ -92,7 +92,9 @@ module Api def update @planning_element = WorkPackage.find(params[:id]) - @planning_element.attributes = permitted_params.planning_element + @planning_element.attributes = permitted_params.planning_element.except :note + + @planning_element.add_journal(User.current, permitted_params.planning_element[:note]) successfully_updated = @planning_element.save diff --git a/spec/controllers/api/v2/planning_elements_controller_spec.rb b/spec/controllers/api/v2/planning_elements_controller_spec.rb index 870dbedc64..8d7af609ec 100644 --- a/spec/controllers/api/v2/planning_elements_controller_spec.rb +++ b/spec/controllers/api/v2/planning_elements_controller_spec.rb @@ -601,6 +601,7 @@ describe Api::V2::PlanningElementsController do describe 'update.xml' do let(:project) { FactoryGirl.create(:project, :is_public => false) } + let(:work_package) { FactoryGirl.create(:work_package) } become_admin @@ -621,6 +622,41 @@ describe Api::V2::PlanningElementsController do it_should_behave_like "a controller action which needs project permissions" end + describe 'empty' do + before do + put :update, + project_id: work_package.project_id, + id: work_package.id, + format: :xml + end + + it { expect(response.status).to eq(400) } + end + + describe 'notes' do + let(:note) { "A note set by API" } + + before do + put :update, + project_id: work_package.project_id, + id: work_package.id, + planning_element: { note: note }, + format: :xml + end + + it { expect(response.status).to eq(204) } + + describe 'journals' do + subject { work_package.reload.journals } + + it { expect(subject.count).to eq(2) } + + it { expect(subject.last.notes).to eq(note) } + + it { expect(subject.last.user).to eq(User.current) } + end + end + describe 'with custom fields' do let(:type) { Type.find_by_name("None") || FactoryGirl.create(:type_standard) }