Welcome to mirror list, hosted at ThFree Co, Russian Federation.

color_spec.rb « type « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84fd8d0bbce1750ae8e5e8ec01fd33828d44579a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Gitlab::Database::Type::Color do
  subject(:type) { described_class.new }

  let(:color) { ::Gitlab::Color.of('red') }

  it 'serializes by calling #to_s' do
    expect(type.serialize(color)).to eq(color.to_s)
  end

  it 'serializes nil to nil' do
    expect(type.serialize(nil)).to be_nil
  end

  it 'casts by calling Color::new' do
    expect(type.cast('#fff')).to eq(::Gitlab::Color.new('#fff'))
  end

  it 'accepts colors as arguments to cast' do
    expect(type.cast(color)).to eq(color)
  end

  it 'allows nil database values' do
    expect(type.cast(nil)).to be_nil
  end

  it 'tells us what is serializable' do
    [nil, 'foo', color].each do |value|
      expect(type.serializable?(value)).to be true
    end
  end

  it 'tells us what is not serializable' do
    [0, 3.2, true, Time.current, { some: 'hash' }].each do |value|
      expect(type.serializable?(value)).to be false
    end
  end
end