diff --git a/app/controllers/api/services_controller.rb b/app/controllers/api/services_controller.rb index 1ae29c0dcf1..5609e30556a 100644 --- a/app/controllers/api/services_controller.rb +++ b/app/controllers/api/services_controller.rb @@ -12,6 +12,11 @@ def create_resource(_type, _id, data) service end + def edit_resource(type, id, data) + attributes = build_service_attributes(data) + super(type, id, attributes) + end + def reconfigure_resource(type, id = nil, data = nil) raise BadRequestError, "Must specify an id for Reconfiguring a #{type} resource" unless id diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 1606faa3ae0..4a61745d9cf 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -26,6 +26,7 @@ let(:svc) { FactoryGirl.create(:service, :name => "svc", :description => "svc description") } let(:svc1) { FactoryGirl.create(:service, :name => "svc1", :description => "svc1 description") } let(:svc2) { FactoryGirl.create(:service, :name => "svc2", :description => "svc2 description") } + let(:svc_orchestration) { FactoryGirl.create(:service_orchestration) } let(:orchestration_template) { FactoryGirl.create(:orchestration_template) } let(:ems) { FactoryGirl.create(:ext_management_system) } @@ -123,6 +124,54 @@ expect(svc.reload.name).to eq("updated svc1") end + it 'accepts reference signature hrefs' do + api_basic_authorize collection_action_identifier(:services, :edit) + + resource = { + 'action' => 'edit', + 'resource' => { + 'parent_service' => { 'href' => services_url(svc1.id) }, + 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.id) }, + 'orchestration_manager' => { 'href' => providers_url(ems.id) } + } + } + run_post(services_url(svc_orchestration.id), resource) + + expected = { + 'id' => svc_orchestration.id, + 'ancestry' => svc1.id.to_s + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + expect(svc_orchestration.reload.parent).to eq(svc1) + expect(svc_orchestration.orchestration_template).to eq(orchestration_template) + expect(svc_orchestration.orchestration_manager).to eq(ems) + end + + it 'accepts reference signature ids' do + api_basic_authorize collection_action_identifier(:services, :edit) + + resource = { + 'action' => 'edit', + 'resource' => { + 'parent_service' => { 'id' => svc1.id }, + 'orchestration_template' => { 'id' => orchestration_template.id }, + 'orchestration_manager' => { 'id' => ems.id } + } + } + run_post(services_url(svc_orchestration.id), resource) + + expected = { + 'id' => svc_orchestration.id, + 'ancestry' => svc1.id.to_s + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + expect(svc_orchestration.reload.parent).to eq(svc1) + expect(svc_orchestration.orchestration_template).to eq(orchestration_template) + expect(svc_orchestration.orchestration_manager).to eq(ems) + end + it "supports edits of single resource via PUT" do api_basic_authorize collection_action_identifier(:services, :edit)