Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return correct custom_attributes href #14752

Merged
merged 2 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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