Sha256: 7a9540b0c769d5fb5cfed62cabb005c9de82033a6c7f5851367adfa38b45c30b

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe BooleanValidator do

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

    subject { klass.new }

    it { should allow_value(true).for(:active) }
    it { should allow_value(false).for(:active) }
    it { should allow_value(1).for(:active) }
    it { should allow_value(0).for(:active) }

    it { should_not allow_value('').for(:active) }
    it { should_not allow_value(' ').for(:active) }
    it { should_not allow_value(nil).for(:active) }
    it { should_not allow_value("true").for(:active) }
    it { should_not allow_value("false").for(:active) }
    it { should_not allow_value("1").for(:active) }
    it { should_not allow_value("0").for(:active) }
    it { should_not allow_value("! \#$%\`|").for(:active) }
    it { should_not allow_value("<>@[]\`|").for(:active) }

    it { should ensure_valid_boolean_format_of(:active) }
    it { should_not ensure_valid_boolean_format_of(:name) }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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