gitlab-org--gitlab-foss/spec/serializers/environment_serializer_spec.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

2016-10-28 08:32:07 -04:00
require 'spec_helper'
describe EnvironmentSerializer do
let(:serializer) do
described_class
.new(user: user, project: project)
.represent(resource)
2016-10-28 08:32:07 -04:00
end
2016-11-04 05:16:30 -04:00
let(:json) { serializer.as_json }
let(:user) { create(:user) }
let(:project) { create(:project) }
2016-10-28 08:32:07 -04:00
context 'when there is a single object provided' do
before do
create(:ci_build, :manual, name: 'manual1',
pipeline: deployable.pipeline)
end
let(:deployment) do
create(:deployment, deployable: deployable,
user: user,
project: project,
sha: project.commit.id)
end
let(:deployable) { create(:ci_build) }
let(:resource) { deployment.environment }
2016-10-28 08:32:07 -04:00
it 'it generates payload for single object' do
2016-11-04 05:16:30 -04:00
expect(json).to be_an_instance_of Hash
2016-10-28 08:32:07 -04:00
end
it 'contains important elements of environment' do
2016-11-04 05:16:30 -04:00
expect(json)
.to include(:name, :external_url, :environment_url, :last_deployment)
end
it 'contains relevant information about last deployment' do
2016-11-04 05:16:30 -04:00
last_deployment = json.fetch(:last_deployment)
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
let(:project) { create(:empty_project) }
2016-10-28 08:32:07 -04:00
let(:resource) { create_list(:environment, 2) }
it 'contains important elements of environment' do
2016-11-04 05:16:30 -04:00
expect(json.first)
.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