respond with new custom fields after PATCH-ing WP

pull/2673/head
Jan Sandbrink 10 years ago
parent 467fc9dba6
commit 22180a5d88
  1. 7
      lib/api/v3/work_packages/work_packages_api.rb
  2. 66
      spec/requests/api/v3/work_package_resource_spec.rb

@ -108,8 +108,11 @@ module API
send_notifications) send_notifications)
if write_request_valid? && update_service.save if write_request_valid? && update_service.save
@representer.represented.reload work_package = @representer.represented
@representer work_package.reload
@representer = WorkPackages::WorkPackageRepresenter.create(
work_package,
current_user: current_user)
else else
fail ::API::Errors::ErrorBase.create(@representer.represented.errors.dup) fail ::API::Errors::ErrorBase.create(@representer.represented.errors.dup)
end end

@ -198,7 +198,6 @@ h4. things we like
end end
end end
# disabled the its below because the implementation was temporarily disabled
describe '#patch' do describe '#patch' do
let(:patch_path) { "/api/v3/work_packages/#{work_package.id}" } let(:patch_path) { "/api/v3/work_packages/#{work_package.id}" }
let(:valid_params) do let(:valid_params) do
@ -472,6 +471,71 @@ h4. things we like
end end
end end
context 'type' do
let(:target_type) { FactoryGirl.create(:type) }
let(:type_link) { "/api/v3/types/#{target_type.id}" }
let(:type_parameter) { { _links: { type: { href: type_link } } } }
let(:params) { valid_params.merge(type_parameter) }
before { allow(User).to receive(:current).and_return current_user }
context 'valid type' do
before do
project.types << target_type
end
include_context 'patch request'
it { expect(response.status).to eq(200) }
it 'should respond with updated work package type' do
expect(subject.body).to be_json_eql(target_type.name.to_json)
.at_path('_embedded/type/name')
end
it_behaves_like 'lock version updated'
end
context 'valid type changing custom fields' do
let(:custom_field) { FactoryGirl.create(:work_package_custom_field) }
before do
project.types << target_type
project.work_package_custom_fields << custom_field
target_type.custom_fields << custom_field
end
include_context 'patch request'
it 'responds with the new custom field added' do
expect(subject.body).to have_json_path("customField#{custom_field.id}")
end
end
context 'invalid type' do
include_context 'patch request'
it_behaves_like 'constraint violation' do
let(:message) { "Type #{I18n.t('activerecord.errors.messages.inclusion')}" }
end
end
context 'wrong resource' do
let(:type_link) { "/api/v3/users/#{current_user.id}" }
include_context 'patch request'
it_behaves_like 'constraint violation' do
let(:message) {
I18n.t('api_v3.errors.invalid_resource',
property: 'type',
expected: '/api/v3/types/:id',
actual: type_link)
}
end
end
end
context 'assignee and responsible' do context 'assignee and responsible' do
let(:user) { FactoryGirl.create(:user, member_in_project: project) } let(:user) { FactoryGirl.create(:user, member_in_project: project) }
let(:params) { valid_params.merge(user_parameter) } let(:params) { valid_params.merge(user_parameter) }

Loading…
Cancel
Save