Skip to content

Commit

Permalink
Do not serialize a deployment commit showing a job
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek authored and Filipa Lacerda committed May 24, 2019
1 parent 1052f64 commit 412a385
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/serializers/build_details_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class BuildDetailsEntity < JobEntity

expose :deployment_status, if: -> (*) { build.starts_environment? } do
expose :deployment_status, as: :status
expose :persisted_environment, as: :environment, with: EnvironmentEntity
expose :persisted_environment, as: :environment do |build, options|
options.merge(except: [{ last_deployment: [:commit] }]).yield_self do |opts|
EnvironmentEntity.represent(build.persisted_environment, opts)
end
end
end

expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/projects/jobs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def get_index(**extra_params)
expect(json_response.dig('deployment_status', 'status')).to eq 'creating'
expect(json_response.dig('deployment_status', 'environment')).not_to be_nil
expect(json_response.dig('deployment_status', 'environment', 'last_deployment')).not_to be_nil
expect(json_response.dig('deployment_status', 'environment', 'last_deployment'))
.not_to include('commit')
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/serializers/build_details_entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,29 @@

it { is_expected.to include(failure_reason: 'unmet_prerequisites') }
end

context 'when a build has environment with latest deployment' do
let(:build) do
create(:ci_build, :running, environment: environment.name, pipeline: pipeline)
end

let(:environment) do
create(:environment, project: project, name: 'staging', state: :available)
end

before do
create(:deployment, :success, environment: environment, project: project)

allow(request).to receive(:project).and_return(project)
end

it 'does not serialize latest deployment commit' do
response = subject.with_indifferent_access

response.dig(:deployment_status, :environment, :last_deployment).tap do |deployment|
expect(deployment).not_to include(:commit)
end
end
end
end
end

0 comments on commit 412a385

Please sign in to comment.