Skip to content

Commit

Permalink
Merge pull request #1855 from 3scale/THREESCALE-4938-api-metric-paren…
Browse files Browse the repository at this point in the history
…t_id-json

[API] Return parent_id for JSON in Metric endpoints
  • Loading branch information
Martouta committed May 4, 2020
2 parents 70cd396 + d288a4a commit bf0b1a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/representers/method_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module MethodRepresenter
property :system_name
property :friendly_name
property :description
property :parent_id

property :created_at
property :updated_at
Expand Down
1 change: 1 addition & 0 deletions app/representers/metric_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module MetricRepresenter
property :description

property :unit
property :parent_id, if: ->(*) { method_metric? }

property :created_at
property :updated_at
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/api/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

json(:resource) do
let(:root) { 'method' }
it { should have_properties('id', 'name', 'system_name', 'friendly_name', 'description') }
it { should have_properties('id', 'name', 'system_name', 'friendly_name', 'description', 'parent_id').from(resource) }
it { should_not include('unit')}
it { should have_links('self', 'parent') }
end
Expand Down
15 changes: 14 additions & 1 deletion spec/acceptance/api/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@
delete '/admin/api/services/:service_id/metrics/:id', action: :destroy
end

api 'method_metric' do
let(:resource) { FactoryBot.build(:metric, parent: service.metrics.hits) }

get '/admin/api/services/:service_id/metrics/:id.:format', action: :show

json(:resource) do
let(:root) { 'metric' }

it { should have_properties('id', 'name', 'system_name', 'friendly_name', 'parent_id').from(resource) }
end
end

json(:resource) do
let(:root) { 'metric' }

it { should have_properties('id', 'name', 'system_name', 'friendly_name', 'unit') }
it { should have_properties('id', 'name', 'system_name', 'friendly_name', 'unit').from(resource) }
it { should_not have_properties('parent_id') }
it { should have_links('service', 'self') }
it { should_not have_links('parent') }
end
Expand Down

0 comments on commit bf0b1a7

Please sign in to comment.