Sha256: ee6876e690af7f50a560408ea9cba312fce8d0db1a4d67a71c8da7e631494a00

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe HexValidator do

  context "has a valid value" do
    let(:klass) do
      Class.new do
        include ActiveModel::Validations
        attr_accessor :color, :name
        validates :color, hex: true
      end
    end

    subject { klass.new }

    it { should allow_value("#aaa").for(:color) }
    it { should allow_value("#aaaaaa").for(:color) }
    it { should allow_value("#999").for(:color) }
    it { should allow_value("#999999").for(:color) }
    it { should allow_value("#a9a").for(:color) }
    it { should allow_value("#a9a9a9").for(:color) }
    it { should allow_value("aaa").for(:color) }
    it { should allow_value("aaaaaa").for(:color) }
    it { should allow_value("999").for(:color) }
    it { should allow_value("999999").for(:color) }
    it { should allow_value("a9a").for(:color) }
    it { should allow_value("a9a9a9").for(:color) }

    it { should_not allow_value('').for(:color) }
    it { should_not allow_value(' ').for(:color) }
    it { should_not allow_value(nil).for(:color) }
    it { should_not allow_value("#").for(:color) }
    it { should_not allow_value("#9").for(:color) }
    it { should_not allow_value("#9a").for(:color) }
    it { should_not allow_value("#hhh").for(:color) }
    it { should_not allow_value("#9h9").for(:color) }
    it { should_not allow_value("#9a9a").for(:color) }
    it { should_not allow_value("#9a9a9").for(:color) }
    it { should_not allow_value("#9a9a9a9").for(:color) }
    it { should_not allow_value(" #9a9").for(:color) }
    it { should_not allow_value(" #9a9 ").for(:color) }
    it { should_not allow_value("#9a9 ").for(:color) }
    it { should_not allow_value(" 9a9").for(:color) }
    it { should_not allow_value(" 9a9 ").for(:color) }
    it { should_not allow_value("9a9 ").for(:color) }
    it { should_not allow_value("! \#$%\`|").for(:color) }
    it { should_not allow_value("<>@[]\`|").for(:color) }

    it { should ensure_valid_hex_format_of(:color) }
    it { should_not ensure_valid_hex_format_of(:name) }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flash_validators-1.1.0 spec/lib/hex_validator_spec.rb