Sha256: 7cb8f986a4a4219398d8d00b9e90448090cd6a26178a8f702c98b9a5397ccf48

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe HexValidator do

  context "HEX 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

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-1.0.0 spec/lib/hex_validator_spec.rb
flash_validators-0.0.1 spec/lib/hex_validator_spec.rb