Commit ce1aa8ec authored by Etienne Baqué's avatar Etienne Baqué

Added evidence json to release controller

Added evidence method to Projects::ReleaseController.
Added test accordingly.
Added new route.
parent a7b5d2aa
......@@ -20,6 +20,15 @@ class Projects::ReleasesController < Projects::ApplicationController
end
end
def evidence
summary = release.evidence_summary || {}
respond_to do |format|
format.json do
render json: summary
end
end
end
protected
def releases
......
......@@ -77,6 +77,10 @@ class Release < ApplicationRecord
evidence&.summary_sha
end
def evidence_summary
evidence&.summary
end
private
def actual_sha
......
......@@ -179,7 +179,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
end
resources :releases, only: [:index, :edit], param: :tag, constraints: { tag: %r{[^/]+} }
resources :releases, only: [:index, :edit], param: :tag, constraints: { tag: %r{[^/]+} } do
member do
get :evidence
end
end
resources :starrers, only: [:index]
resources :forks, only: [:index, :new, :create]
resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ }
......
......@@ -166,6 +166,40 @@ describe Projects::ReleasesController do
end
end
describe 'GET #evidence' do
let!(:release) { create(:release, project: project) }
let(:tag) { CGI.escape(release.tag) }
let(:format) { :json }
subject do
get :evidence, params: {
namespace_id: project.namespace,
project_id: project,
tag: tag,
format: format
}
end
before do
sign_in(user)
CreateEvidenceWorker.new.perform(release.id)
end
it 'returns the correct evidence summary as a json' do
subject
expect(response.body).to eq(release.evidence.summary.to_json)
end
context 'when the release was created before evidence existed' do
it 'returns an empty json' do
release.evidence.destroy
subject
expect(response.body).to eq('{}')
end
end
end
private
def get_index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment