2017-03-06 15:09:48 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BuildSerializer do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:serializer) do
|
2017-05-09 04:15:34 +00:00
|
|
|
described_class.new(current_user: user)
|
2017-03-06 15:09:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { serializer.represent(resource) }
|
|
|
|
|
|
|
|
describe '#represent' do
|
2017-03-11 14:30:25 +00:00
|
|
|
context 'when a single object is being serialized' do
|
|
|
|
let(:resource) { create(:ci_build) }
|
|
|
|
|
|
|
|
it 'serializers the pipeline object' do
|
|
|
|
expect(subject[:id]).to eq resource.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple objects are being serialized' do
|
|
|
|
let(:resource) { create_list(:ci_build, 2) }
|
|
|
|
|
|
|
|
it 'serializers the array of pipelines' do
|
|
|
|
expect(subject).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
2017-03-10 15:16:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#represent_status' do
|
2018-04-05 21:04:42 +00:00
|
|
|
context 'for a failed build' do
|
|
|
|
let(:resource) { create(:ci_build, :failed) }
|
|
|
|
let(:status) { resource.detailed_status(double('user')) }
|
|
|
|
|
|
|
|
subject { serializer.represent_status(resource) }
|
|
|
|
|
|
|
|
it 'serializes only status' do
|
|
|
|
expect(subject[:text]).to eq(status.text)
|
|
|
|
expect(subject[:label]).to eq('failed')
|
|
|
|
expect(subject[:tooltip]).to eq('failed <br> (unknown failure)')
|
|
|
|
expect(subject[:icon]).to eq(status.icon)
|
|
|
|
expect(subject[:favicon]).to match_asset_path("/assets/ci_favicons/#{status.favicon}.ico")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for any other type of build' do
|
|
|
|
let(:resource) { create(:ci_build, :success) }
|
2017-03-21 13:21:13 +00:00
|
|
|
let(:status) { resource.detailed_status(double('user')) }
|
2017-03-10 15:16:48 +00:00
|
|
|
|
|
|
|
subject { serializer.represent_status(resource) }
|
2017-03-06 15:09:48 +00:00
|
|
|
|
|
|
|
it 'serializes only status' do
|
2017-03-11 14:30:25 +00:00
|
|
|
expect(subject[:text]).to eq(status.text)
|
2018-04-05 21:04:42 +00:00
|
|
|
expect(subject[:label]).to eq('passed')
|
|
|
|
expect(subject[:tooltip]).to eq('passed')
|
2017-03-11 14:30:25 +00:00
|
|
|
expect(subject[:icon]).to eq(status.icon)
|
2017-10-03 14:47:56 +00:00
|
|
|
expect(subject[:favicon]).to match_asset_path("/assets/ci_favicons/#{status.favicon}.ico")
|
2017-03-06 15:09:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|