Skip to content

Commit

Permalink
Merge pull request #14752 from jntullo/bz/custom_attributes_href
Browse files Browse the repository at this point in the history
return correct custom_attributes href
  • Loading branch information
abellotti authored Apr 19, 2017
2 parents 73e8741 + 6c2adb7 commit f6b90aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/controllers/api/base_controller/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions spec/requests/api/custom_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,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
2 changes: 1 addition & 1 deletion spec/requests/api/tenant_quotas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6b90aa

Please sign in to comment.