2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-05 18:47:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe LabelSerializer do
|
2017-05-05 18:47:32 -04:00
|
|
|
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
|
2020-10-14 05:08:46 -04:00
|
|
|
expect(subject.keys).to eq([:id, :title, :color, :project_id, :text_color])
|
2017-05-05 18:47:32 -04:00
|
|
|
expect(subject[:id]).to eq(resource.id)
|
|
|
|
expect(subject[:title]).to eq(resource.title)
|
2022-03-02 19:20:18 -05:00
|
|
|
expect(subject[:color]).to be_color(resource.color)
|
2017-05-05 18:47:32 -04:00
|
|
|
expect(subject[:text_color]).to eq(resource.text_color)
|
2020-10-14 05:08:46 -04:00
|
|
|
expect(subject[:project_id]).to eq(resource.project_id)
|
2017-05-05 18:47:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|