BigW Consortium Gitlab

build_serializer_spec.rb 1.19 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe BuildSerializer do
  let(:user) { create(:user) }

  let(:serializer) do
7
    described_class.new(current_user: user)
8 9 10 11 12
  end

  subject { serializer.represent(resource) }

  describe '#represent' do
Shinya Maeda committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    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
28 29 30 31
  end

  describe '#represent_status' do
    context 'when represents only status' do
32 33
      let(:resource) { create(:ci_build) }
      let(:status) { resource.detailed_status(double('user')) }
34 35

      subject { serializer.represent_status(resource) }
36 37

      it 'serializes only status' do
Shinya Maeda committed
38 39 40
        expect(subject[:text]).to eq(status.text)
        expect(subject[:label]).to eq(status.label)
        expect(subject[:icon]).to eq(status.icon)
41
        expect(subject[:favicon]).to eq("/assets/ci_favicons/#{status.favicon}.ico")
42 43 44 45
      end
    end
  end
end