Skip to content

Commit

Permalink
Merge pull request #14124 from jntullo/enhancement/api_parent_services
Browse files Browse the repository at this point in the history
Enhance service edit to accept attribute references
  • Loading branch information
abellotti authored Mar 1, 2017
2 parents 4e1ed16 + 48061fa commit c5de329
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/api/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 49 additions & 0 deletions spec/requests/api/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c5de329

Please sign in to comment.