2016-10-28 08:32:07 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EnvironmentSerializer do
|
2017-01-27 07:02:59 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
let(:json) do
|
2016-11-03 07:54:10 -04:00
|
|
|
described_class
|
|
|
|
.new(user: user, project: project)
|
2016-11-02 09:36:21 -04:00
|
|
|
.represent(resource)
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a single object provided' do
|
2016-11-03 08:42:22 -04:00
|
|
|
before do
|
|
|
|
create(:ci_build, :manual, name: 'manual1',
|
|
|
|
pipeline: deployable.pipeline)
|
|
|
|
end
|
|
|
|
|
2016-11-03 07:54:10 -04:00
|
|
|
let(:deployment) do
|
|
|
|
create(:deployment, deployable: deployable,
|
2016-11-03 10:13:57 -04:00
|
|
|
user: user,
|
|
|
|
project: project,
|
|
|
|
sha: project.commit.id)
|
2016-11-03 07:54:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:deployable) { create(:ci_build) }
|
|
|
|
let(:resource) { deployment.environment }
|
2016-10-28 08:32:07 -04:00
|
|
|
|
2016-11-03 09:01:35 -04:00
|
|
|
it 'contains important elements of environment' do
|
2016-11-04 05:16:30 -04:00
|
|
|
expect(json)
|
2016-11-17 10:08:05 -05:00
|
|
|
.to include(:name, :external_url, :environment_path, :last_deployment)
|
2016-11-03 09:01:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains relevant information about last deployment' do
|
2016-11-04 05:16:30 -04:00
|
|
|
last_deployment = json.fetch(:last_deployment)
|
2016-11-03 09:01:35 -04:00
|
|
|
|
|
|
|
expect(last_deployment)
|
|
|
|
.to include(:ref, :user, :commit, :deployable, :manual_actions)
|
|
|
|
end
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a collection of objects provided' do
|
2016-11-03 07:54:10 -04:00
|
|
|
let(:project) { create(:empty_project) }
|
2016-10-28 08:32:07 -04:00
|
|
|
let(:resource) { create_list(:environment, 2) }
|
|
|
|
|
2016-11-03 09:01:35 -04:00
|
|
|
it 'contains important elements of environment' do
|
2016-11-04 05:16:30 -04:00
|
|
|
expect(json.first)
|
2016-11-03 09:01:35 -04:00
|
|
|
.to include(:last_deployment, :name, :external_url)
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates payload for collection' do
|
2016-11-04 05:16:30 -04:00
|
|
|
expect(json).to be_an_instance_of Array
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|