diff --git a/Gemfile b/Gemfile index f3f63bc42c8287d7a0ba448f6b98e8f0664daaf9..ce3192a4743cc2fa5a888d16356fae73bbb60193 100644 --- a/Gemfile +++ b/Gemfile @@ -92,7 +92,7 @@ gem 'net-ldap', '~> 0.16.3' # API gem 'grape', '~> 1.5.2' -gem 'grape-entity', '~> 0.7.1' +gem 'grape-entity', '~> 0.9.0' gem 'rack-cors', '~> 1.0.6', require: 'rack/cors' # GraphQL API diff --git a/Gemfile.lock b/Gemfile.lock index 806ee347fdcc15d864e9ac9e7885045552d448aa..34a0fe708a124a7b8b618e9512cc4f0246475461 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -538,8 +538,8 @@ GEM mustermann-grape (~> 1.0.0) rack (>= 1.3.0) rack-accept - grape-entity (0.7.1) - activesupport (>= 4.0) + grape-entity (0.9.0) + activesupport (>= 3.0.0) multi_json (>= 1.3.2) grape-path-helpers (1.6.3) activesupport @@ -1471,7 +1471,7 @@ DEPENDENCIES google-protobuf (~> 3.15.8) gpgme (~> 2.0.19) grape (~> 1.5.2) - grape-entity (~> 0.7.1) + grape-entity (~> 0.9.0) grape-path-helpers (~> 1.6.3) grape_logging (~> 1.7) graphiql-rails (~> 1.4.10) diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb index a37011d01006a2fd071f375ba1583c0984b1e24c..08a939e86c5b7a4d5c30d187379128c79c0baeeb 100644 --- a/app/serializers/deployment_entity.rb +++ b/app/serializers/deployment_entity.rb @@ -38,7 +38,7 @@ class DeploymentEntity < Grape::Entity expose :commit, using: CommitEntity, if: -> (*) { include_details? } expose :manual_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? } expose :scheduled_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? } - expose :playable_build, expose_nil: false, if: -> (*) { include_details? && can_create_deployment? } do |deployment, options| + expose :playable_build, if: -> (deployment) { include_details? && can_create_deployment? && deployment.playable_build } do |deployment, options| JobEntity.represent(deployment.playable_build, options.merge(only: [:play_path, :retry_path])) end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index 6835d1390652343a1418b2b96aad0a5b39c6fb80..6105b52fbda373135211a005380dc93a473bb366 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -21,7 +21,7 @@ class EnvironmentEntity < Grape::Entity expose :stop_action_available?, as: :has_stop_action expose :rollout_status, if: -> (*) { can_read_deploy_board? }, using: RolloutStatusEntity - expose :upcoming_deployment, expose_nil: false do |environment, ops| + expose :upcoming_deployment, if: -> (environment) { environment.upcoming_deployment } do |environment, ops| DeploymentEntity.represent(environment.upcoming_deployment, ops.merge(except: UNNECESSARY_ENTRIES_FOR_UPCOMING_DEPLOYMENT)) end diff --git a/app/serializers/issue_board_entity.rb b/app/serializers/issue_board_entity.rb index d27e40963906ca6a82ddc8f6d8511a1c97e755fd..17a36f5fb0735beb99b6cca24efcd9763460768c 100644 --- a/app/serializers/issue_board_entity.rb +++ b/app/serializers/issue_board_entity.rb @@ -20,7 +20,7 @@ class IssueBoardEntity < Grape::Entity API::Entities::Project.represent issue.project, only: [:id, :path] end - expose :milestone, expose_nil: false do |issue| + expose :milestone, if: -> (issue) { issue.milestone } do |issue| API::Entities::Milestone.represent issue.milestone, only: [:id, :title] end diff --git a/ee/app/serializers/dashboard_environment_entity.rb b/ee/app/serializers/dashboard_environment_entity.rb index ec49d2301110d1cb9c0db52f1634e3d6105bd00f..ffe580890efeab366a08b690024c742112cb911c 100644 --- a/ee/app/serializers/dashboard_environment_entity.rb +++ b/ee/app/serializers/dashboard_environment_entity.rb @@ -11,13 +11,13 @@ class DashboardEnvironmentEntity < Grape::Entity expose :external_url - expose :last_visible_deployment, as: :last_deployment, expose_nil: false do |environment| + expose :last_visible_deployment, as: :last_deployment, if: ->(environment) { environment.last_visible_deployment } do |environment| DeploymentEntity.represent(environment.last_visible_deployment, options.merge(request: request_with_project, except: unnecessary_deployment_fields)) end - expose :last_visible_pipeline, as: :last_pipeline, expose_nil: false do |environment| + expose :last_visible_pipeline, as: :last_pipeline, if: ->(environment) { environment.last_visible_pipeline } do |environment| PipelineDetailsEntity.represent(environment.last_visible_pipeline, options.merge(request: request_with_project, only: required_pipeline_fields)) diff --git a/spec/serializers/ci/pipeline_entity_spec.rb b/spec/serializers/ci/pipeline_entity_spec.rb index 58b28de09b13a7065ec8f9c4a7787c4ea580a7ee..054406e4e65a8c31ef258f403a366560fc6ab394 100644 --- a/spec/serializers/ci/pipeline_entity_spec.rb +++ b/spec/serializers/ci/pipeline_entity_spec.rb @@ -239,23 +239,23 @@ end context 'when pipeline has failed builds' do - let_it_be(:pipeline) { create(:ci_pipeline, user: user) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) } let_it_be(:build) { create(:ci_build, :success, pipeline: pipeline) } let_it_be(:failed_1) { create(:ci_build, :failed, pipeline: pipeline) } let_it_be(:failed_2) { create(:ci_build, :failed, pipeline: pipeline) } context 'when the user can retry the pipeline' do - it 'exposes these failed builds' do - allow(entity).to receive(:can_retry?).and_return(true) + before do + project.add_maintainer(user) + end + it 'exposes these failed builds' do expect(subject[:failed_builds].map { |b| b[:id] }).to contain_exactly(failed_1.id, failed_2.id) end end context 'when the user cannot retry the pipeline' do it 'is nil' do - allow(entity).to receive(:can_retry?).and_return(false) - expect(subject[:failed_builds]).to be_nil end end