Skip to content

Commit

Permalink
Merge pull request #14657 from jntullo/bz/providers_href
Browse files Browse the repository at this point in the history
Return provider_class on provider requests
(cherry picked from commit 58efc71)
  • Loading branch information
abellotti authored and simaishi committed Apr 7, 2017
1 parent d7826fb commit f787f5f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/api/base_controller/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def normalize_time(value)
def normalize_url(value)
svalue = value.to_s
pref = @req.api_prefix
svalue.match(pref) ? svalue : "#{pref}/#{svalue}"
suffix = @req.api_suffix
svalue.match(pref) ? svalue : "#{pref}/#{svalue}#{suffix}"
end

#
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/base_controller/parser/request_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def api_prefix
@api_prefix ||= "#{base}#{prefix}"
end

def api_suffix
@api_suffix ||= "?provider_class=#{@params['provider_class']}" if @params['provider_class']
end

def attributes
@attributes ||= @params['attributes'].to_s.split(',')
end
Expand Down
31 changes: 31 additions & 0 deletions spec/requests/api/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,37 @@ def have_endpoint_attributes(expected_hash)
expect(provider.send(item)).to eq(sample_foreman[item])
end
end

it 'returns the correct href reference on the collection' do
provider = FactoryGirl.create(:provider_foreman)
api_basic_authorize collection_action_identifier(:providers, :read, :get)

run_get providers_url, :provider_class => 'provider'

expected = {
'resources' => [{'href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider")}],
'actions' => [a_hash_including('href' => a_string_including('?provider_class=provider'))]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'returns the correct href reference on a resource' do
provider = FactoryGirl.create(:provider_foreman)
api_basic_authorize action_identifier(:providers, :read, :resource_actions, :get),
action_identifier(:providers, :edit)

run_get providers_url(provider.id), :provider_class => :provider

expected = {
'href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider"),
'actions' => [
a_hash_including('href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider"))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe "Providers create" do
Expand Down

0 comments on commit f787f5f

Please sign in to comment.