diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-10-03 15:17:12 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-10-03 15:17:12 +0900 |
commit | 137f74b56396bc8feee87ead9c827ccc0fb47cd2 (patch) | |
tree | a5a4f6d2efdaffdbcf7ee5f92d77604e0b107ed6 | |
parent | 66b3bd5e2689c735675dc192746c972ebf627a97 (diff) | |
download | gitlab-ce-137f74b56396bc8feee87ead9c827ccc0fb47cd2.tar.gz |
Add job_entity_spec
-rw-r--r-- | app/serializers/job_entity.rb | 10 | ||||
-rw-r--r-- | spec/serializers/job_entity_spec.rb | 12 |
2 files changed, 21 insertions, 1 deletions
diff --git a/app/serializers/job_entity.rb b/app/serializers/job_entity.rb index dd6c2fa1a6d..0b19cb16955 100644 --- a/app/serializers/job_entity.rb +++ b/app/serializers/job_entity.rb @@ -24,8 +24,12 @@ class JobEntity < Grape::Entity path_to(:play_namespace_project_job, build) end + expose :unschedule_path, if: -> (*) { scheduled? } do |build| + path_to(:unschedule_namespace_project_job, build) + end + expose :playable?, as: :playable - expose :scheduled_at + expose :scheduled_at, if: -> (*) { scheduled? } expose :created_at expose :updated_at expose :detailed_status, as: :status, with: DetailedStatusEntity @@ -48,6 +52,10 @@ class JobEntity < Grape::Entity build.playable? && can?(request.current_user, :update_build, build) end + def scheduled? + build.scheduled? + end + def detailed_status build.detailed_status(request.current_user) end diff --git a/spec/serializers/job_entity_spec.rb b/spec/serializers/job_entity_spec.rb index 8e1ca3f308d..5fc27da4906 100644 --- a/spec/serializers/job_entity_spec.rb +++ b/spec/serializers/job_entity_spec.rb @@ -109,6 +109,18 @@ describe JobEntity do end end + context 'when job is scheduled' do + let(:job) { create(:ci_build, :scheduled) } + + it 'contains path to unschedule action' do + expect(subject).to include(:unschedule_path) + end + + it 'contains scheduled_at' do + expect(subject[:scheduled_at]).to eq(job.scheduled_at) + end + end + context 'when job is generic commit status' do let(:job) { create(:generic_commit_status, target_url: 'http://google.com') } |