diff --git a/src/supermarket/app/controllers/api/v1/cookbook_versions_controller.rb b/src/supermarket/app/controllers/api/v1/cookbook_versions_controller.rb index 179209462..be466cfda 100644 --- a/src/supermarket/app/controllers/api/v1/cookbook_versions_controller.rb +++ b/src/supermarket/app/controllers/api/v1/cookbook_versions_controller.rb @@ -11,7 +11,7 @@ class Api::V1::CookbookVersionsController < Api::V1Controller def show @cookbook = Cookbook.with_name(params[:cookbook]).first! @cookbook_version = @cookbook.get_version!(params[:version]) - @cookbook_version_metrics = @cookbook_version.metric_results + @cookbook_version_metrics = @cookbook_version.metric_results.includes(:quality_metric) end # diff --git a/src/supermarket/app/views/api/v1/cookbook_versions/_cookbook_version.json.jbuilder b/src/supermarket/app/views/api/v1/cookbook_versions/_cookbook_version.json.jbuilder index 5efd2eb12..55b99963c 100644 --- a/src/supermarket/app/views/api/v1/cookbook_versions/_cookbook_version.json.jbuilder +++ b/src/supermarket/app/views/api/v1/cookbook_versions/_cookbook_version.json.jbuilder @@ -4,17 +4,17 @@ json.version cookbook_version.version json.average_rating nil json.cookbook api_v1_cookbook_url(cookbook) json.file api_v1_cookbook_version_download_url(cookbook_version.cookbook, cookbook_version) + if !@cookbook_version_metrics.nil? && @cookbook_version_metrics.any? - json.quality do - @cookbook_version_metrics.each do |metric| - json.name metric.quality_metric.name - json.failed metric.failure - json.feedback metric.feedback - end - end + json.quality_metrics @cookbook_version_metrics do |metric| + json.name metric.quality_metric.name + json.failed metric.failure + json.feedback metric.feedback end - json.set! :dependencies do - cookbook_version.cookbook_dependencies.each do |dependency| +end + +json.set! :dependencies do + cookbook_version.cookbook_dependencies.each do |dependency| json.set! dependency.name, dependency.version_constraint end end diff --git a/src/supermarket/spec/api/cookbook_version_spec.rb b/src/supermarket/spec/api/cookbook_version_spec.rb index 783ec1b10..fc303fdbe 100644 --- a/src/supermarket/spec/api/cookbook_version_spec.rb +++ b/src/supermarket/spec/api/cookbook_version_spec.rb @@ -70,16 +70,18 @@ let(:quality_metrics) do { - 'quality' => { - 'foodcritic' => { + 'quality_metrics' => [ + { + 'name' => quality_metric_foodcritic.name, 'failed' => foodcritic_result.failure, 'feedback' => foodcritic_result.feedback }, - 'collaborator' => { + { + 'name' => quality_metric_collab_num.name, 'failed' => collab_result.failure, 'feedback' => collab_result.feedback } - } + ] } end @@ -101,7 +103,6 @@ it 'returns quality metrics for the cookbook version' do get json_body['versions'].find { |v| v =~ /0.1.0/ } - expect(signature(json_body)).to include(quality_metrics) end @@ -114,7 +115,6 @@ it 'returns a 200' do get "/api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook_version.version}" - puts response.body.inspect expect(response.status.to_i).to eql(200) end