summaryrefslogtreecommitdiff
path: root/spec/serializers/label_serializer_spec.rb
blob: 40249450f7fda7785b4a5ce0643fd8902821644d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe LabelSerializer do
  let(:user) { create(:user) }

  let(:serializer) do
    described_class.new(user: user)
  end

  subject { serializer.represent(resource) }

  describe '#represent' do
    context 'when a single object is being serialized' do
      let(:resource) { create(:label) }

      it 'serializes the label object' do
        expect(subject[:id]).to eq resource.id
      end
    end

    context 'when multiple objects are being serialized' do
      let(:num_labels) { 2 }
      let(:resource) { create_list(:label, num_labels) }

      it 'serializes the array of labels' do
        expect(subject.size).to eq(num_labels)
      end
    end
  end

  describe '#represent_appearance' do
    context 'when represents only appearance' do
      let(:resource) { create(:label) }

      subject { serializer.represent_appearance(resource) }

      it 'serializes only attributes used for appearance' do
        expect(subject.keys).to eq([:id, :title, :color, :project_id, :text_color])
        expect(subject[:id]).to eq(resource.id)
        expect(subject[:title]).to eq(resource.title)
        expect(subject[:color]).to eq(resource.color)
        expect(subject[:text_color]).to eq(resource.text_color)
        expect(subject[:project_id]).to eq(resource.project_id)
      end
    end
  end
end