diff --git a/app/controllers/api/base_controller/normalizer.rb b/app/controllers/api/base_controller/normalizer.rb index bf127d9ff8c..188be4513c5 100644 --- a/app/controllers/api/base_controller/normalizer.rb +++ b/app/controllers/api/base_controller/normalizer.rb @@ -91,6 +91,14 @@ def normalize_url(value) # Let's normalize an href based on type and id value # def normalize_href(type, value) + type.to_s == @req.subcollection ? subcollection_href(type, value) : collection_href(type, value) + end + + def subcollection_href(type, value) + normalize_url("#{@req.collection}/#{@req.c_id}/#{type}/#{value}") + end + + def collection_href(type, value) normalize_url("#{type}/#{value}") end diff --git a/spec/requests/api/custom_attributes_spec.rb b/spec/requests/api/custom_attributes_spec.rb index 64ce3d79c1d..e45beff1d5f 100644 --- a/spec/requests/api/custom_attributes_spec.rb +++ b/spec/requests/api/custom_attributes_spec.rb @@ -10,4 +10,16 @@ expect(response).to have_http_status(:no_content) end + + it 'returns the correct href' do + provider = FactoryGirl.create(:ext_management_system) + custom_attribute = FactoryGirl.create(:custom_attribute, :resource => provider, :name => 'foo', :value => 'bar') + url = "#{providers_url(provider.id)}/custom_attributes/#{custom_attribute.id}" + api_basic_authorize subcollection_action_identifier(:providers, :custom_attributes, :edit, :post) + + run_post(url, :action => :edit, :name => 'name1') + + expect(response).to have_http_status(:ok) + expect(response.parsed_body['href']).to include(url) + end end diff --git a/spec/requests/api/tenant_quotas_spec.rb b/spec/requests/api/tenant_quotas_spec.rb index b2634972da1..83b8b9cf7be 100644 --- a/spec/requests/api/tenant_quotas_spec.rb +++ b/spec/requests/api/tenant_quotas_spec.rb @@ -76,7 +76,7 @@ expect(response).to have_http_status(:ok) quota.reload expect(quota.value).to eq(5) - expect(response.parsed_body).to include('href' => /quotas/) + expect(response.parsed_body).to include('href' => a_string_including("tenants/#{tenant.id}/quotas/#{quota.id}")) end it "can update multiple quotas from a tenant with POST" do