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 provider_class on provider requests #14657

Merged
merged 1 commit into from
Apr 7, 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
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
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