|
|
|
@ -87,8 +87,8 @@ describe 'API v3 Work package resource', type: :request, content_type: :json do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:dependent_error_result) do |
|
|
|
|
proc do |instance| |
|
|
|
|
result = ServiceResult.new(success: true, result: instance.work_package) |
|
|
|
|
proc do |instance, _attributes, work_package| |
|
|
|
|
result = ServiceResult.new(success: true, result: instance.work_package || work_package) |
|
|
|
|
dep = parent |
|
|
|
|
dep.errors.add :base, "invalid", message: "invalid" |
|
|
|
|
|
|
|
|
@ -146,4 +146,57 @@ describe 'API v3 Work package resource', type: :request, content_type: :json do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe '#post' do |
|
|
|
|
let(:current_user) { FactoryGirl.create :admin } |
|
|
|
|
|
|
|
|
|
let(:path) { api_v3_paths.work_packages } |
|
|
|
|
let(:valid_params) do |
|
|
|
|
{ |
|
|
|
|
_type: 'WorkPackage', |
|
|
|
|
lockVersion: 0, |
|
|
|
|
_links: { |
|
|
|
|
author: { href: "/api/v3/users/#{current_user.id}" }, |
|
|
|
|
project: { href: "/api/v3/projects/#{project.id}" }, |
|
|
|
|
status: { href: "/api/v3/statuses/#{status.id}" }, |
|
|
|
|
priority: { href: "/api/v3/priorities/#{work_package.priority.id}" } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
subject(:response) { last_response } |
|
|
|
|
|
|
|
|
|
shared_context 'post request' do |
|
|
|
|
before(:each) do |
|
|
|
|
post path, params.to_json, 'CONTENT_TYPE' => 'application/json' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
allow_any_instance_of(WorkPackages::CreateService).to receive(:create, &dependent_error_result) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'request' do |
|
|
|
|
let(:params) { valid_params.merge(subject: "Test Subject") } |
|
|
|
|
|
|
|
|
|
include_context 'post request' |
|
|
|
|
|
|
|
|
|
it { expect(response.status).to eq(422) } |
|
|
|
|
|
|
|
|
|
it 'should respond with an error' do |
|
|
|
|
expected_error = { |
|
|
|
|
"_type": "Error", |
|
|
|
|
"errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation", |
|
|
|
|
"message": "Error in dependent work package ##{parent.id} #{parent.subject}: invalid", |
|
|
|
|
"_embedded": { |
|
|
|
|
"details": { |
|
|
|
|
"attribute": "base" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
expect(subject.body).to be_json_eql(expected_error.to_json) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|