Commit d03e6878 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Rename BuildEntity to JobEntity

parent 0a80e504
class BuildDetailsEntity < BuildEntity class BuildDetailsEntity < JobEntity
expose :coverage, :erased_at, :duration expose :coverage, :erased_at, :duration
expose :tag_list, as: :tags expose :tag_list, as: :tags
......
class BuildSerializer < BaseSerializer class BuildSerializer < BaseSerializer
entity BuildEntity entity JobEntity
def represent_status(resource) def represent_status(resource)
data = represent(resource, { only: [:status] }) data = represent(resource, { only: [:status] })
......
...@@ -24,6 +24,6 @@ class DeploymentEntity < Grape::Entity ...@@ -24,6 +24,6 @@ class DeploymentEntity < Grape::Entity
expose :user, using: UserEntity expose :user, using: UserEntity
expose :commit, using: CommitEntity expose :commit, using: CommitEntity
expose :deployable, using: BuildEntity expose :deployable, using: JobEntity
expose :manual_actions, using: BuildEntity expose :manual_actions, using: JobEntity
end end
class BuildEntity < Grape::Entity class JobEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :id expose :id
expose :name expose :name
expose :build_path do |build| expose :build_path do |build|
build.external_url || path_to(:namespace_project_job, build) build.target_url || path_to(:namespace_project_job, build)
end end
expose :retry_path, if: -> (*) { retryable? } do |build| expose :retry_path, if: -> (*) { retryable? } do |build|
......
...@@ -4,7 +4,7 @@ class JobGroupEntity < Grape::Entity ...@@ -4,7 +4,7 @@ class JobGroupEntity < Grape::Entity
expose :name expose :name
expose :size expose :size
expose :detailed_status, as: :status, with: StatusEntity expose :detailed_status, as: :status, with: StatusEntity
expose :jobs, with: BuildEntity expose :jobs, with: JobEntity
private private
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe BuildDetailsEntity do describe BuildDetailsEntity do
set(:user) { create(:admin) } set(:user) { create(:admin) }
it 'inherits from BuildEntity' do it 'inherits from JobEntity' do
expect(described_class).to be < BuildEntity expect(described_class).to be < JobEntity
end end
describe '#as_json' do describe '#as_json' do
......
require 'spec_helper' require 'spec_helper'
describe BuildEntity do describe JobEntity do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:build) { create(:ci_build) } let(:job) { create(:ci_build) }
let(:project) { build.project } let(:project) { job.project }
let(:request) { double('request') } let(:request) { double('request') }
before do before do
...@@ -12,12 +12,12 @@ describe BuildEntity do ...@@ -12,12 +12,12 @@ describe BuildEntity do
end end
let(:entity) do let(:entity) do
described_class.new(build, request: request) described_class.new(job, request: request)
end end
subject { entity.as_json } subject { entity.as_json }
it 'contains paths to build page action' do it 'contains paths to job page action' do
expect(subject).to include(:build_path) expect(subject).to include(:build_path)
end end
...@@ -27,7 +27,7 @@ describe BuildEntity do ...@@ -27,7 +27,7 @@ describe BuildEntity do
end end
it 'contains whether it is playable' do it 'contains whether it is playable' do
expect(subject[:playable]).to eq build.playable? expect(subject[:playable]).to eq job.playable?
end end
it 'contains timestamps' do it 'contains timestamps' do
...@@ -41,7 +41,7 @@ describe BuildEntity do ...@@ -41,7 +41,7 @@ describe BuildEntity do
context 'when build is retryable' do context 'when build is retryable' do
before do before do
build.update(status: :failed) job.update(status: :failed)
end end
it 'contains cancel path' do it 'contains cancel path' do
...@@ -51,7 +51,7 @@ describe BuildEntity do ...@@ -51,7 +51,7 @@ describe BuildEntity do
context 'when build is cancelable' do context 'when build is cancelable' do
before do before do
build.update(status: :running) job.update(status: :running)
end end
it 'contains cancel path' do it 'contains cancel path' do
...@@ -59,7 +59,7 @@ describe BuildEntity do ...@@ -59,7 +59,7 @@ describe BuildEntity do
end end
end end
context 'when build is a regular build' do context 'when job is a regular job' do
it 'does not contain path to play action' do it 'does not contain path to play action' do
expect(subject).not_to include(:play_path) expect(subject).not_to include(:play_path)
end end
...@@ -69,8 +69,8 @@ describe BuildEntity do ...@@ -69,8 +69,8 @@ describe BuildEntity do
end end
end end
context 'when build is a manual action' do context 'when job is a manual action' do
let(:build) { create(:ci_build, :manual) } let(:job) { create(:ci_build, :manual) }
context 'when user is allowed to trigger action' do context 'when user is allowed to trigger action' do
before do before do
...@@ -99,4 +99,25 @@ describe BuildEntity do ...@@ -99,4 +99,25 @@ describe BuildEntity do
end end
end end
end end
context 'when job is generic commit status' do
let(:job) { create(:generic_commit_status, target_url: 'http://google.com') }
it 'contains paths to target action' do
expect(subject).to include(:build_path)
end
it 'does not contain paths to other action paths' do
expect(subject).not_to include(:retry_path, :cancel_path, :play_path)
end
it 'contains timestamps' do
expect(subject).to include(:created_at, :updated_at)
end
it 'contains details' do
expect(subject).to include :status
expect(subject[:status]).to include :icon, :favicon, :text, :label
end
end
end end
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