Cleanup duplicates in deploymentEntityDetailed and add small spec tests

This commit is contained in:
Pawel Chojnacki 2017-04-20 12:21:24 +02:00
parent 4469946105
commit e8f2daae8e
3 changed files with 31 additions and 24 deletions

View file

@ -1,15 +1,5 @@
class DeploymentEntityDetailed < Grape::Entity
include RequestAwareEntity
expose :id
expose :iid
expose :sha
class DeploymentEntityDetailed < DeploymentEntity
expose :ref do
expose :name do |deployment|
deployment.ref
end
expose :ref_path do |deployment|
namespace_project_tree_path(
deployment.project.namespace,
@ -18,9 +8,6 @@ class DeploymentEntityDetailed < Grape::Entity
end
end
expose :created_at
expose :tag
expose :last?
expose :user, using: UserEntity
expose :commit, using: CommitEntity
expose :deployable, using: BuildEntity

View file

@ -0,0 +1,26 @@
require 'spec_helper'
describe DeploymentEntityDetailed do
let(:user) { create(:user) }
let(:request) { double('request') }
let(:deployment) { create(:deployment) }
let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json }
before do
allow(request).to receive(:user).and_return(user)
end
it 'exposes internal deployment id' do
expect(subject).to include(:iid)
end
it 'exposes nested information about branch' do
expect(subject[:ref][:name]).to eq 'master'
expect(subject[:ref][:ref_path]).not_to be_empty
end
it 'exposes creation date' do
expect(subject).to include(:created_at)
end
end

View file

@ -1,28 +1,22 @@
require 'spec_helper'
describe DeploymentEntityDetailed do
describe DeploymentEntity do
let(:user) { create(:user) }
let(:request) { double('request') }
let(:deployment) { create(:deployment) }
let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json }
before do
allow(request).to receive(:user).and_return(user)
end
let(:entity) do
described_class.new(deployment, request: request)
end
let(:deployment) { create(:deployment) }
subject { entity.as_json }
it 'exposes internal deployment id' do
expect(subject).to include(:iid)
end
it 'exposes nested information about branch' do
expect(subject[:ref][:name]).to eq 'master'
expect(subject[:ref][:ref_path]).not_to be_empty
end
it 'exposes creation date' do