Sha256: 6616103f7ef91d6ccc0313d85be14674ed9bc614965270007ca5673bdcf56990

Contents?: true

Size: 970 Bytes

Versions: 17

Compression:

Stored size: 970 Bytes

Contents

require 'spec_helper'

describe IpValidator do

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

    subject { klass.new }

    it { should allow_value("0.0.0.0").for(:ip) }
    it { should allow_value("127.0.0.1").for(:ip) }
    it { should allow_value("99.39.240.31").for(:ip) }

    it { should_not allow_value('').for(:ip) }
    it { should_not allow_value(' ').for(:ip) }
    it { should_not allow_value(nil).for(:ip) }
    it { should_not allow_value("0 0 0 0").for(:ip) }
    it { should_not allow_value("0.0.0.0:3000").for(:ip) }
    it { should_not allow_value("22.22.333.22").for(:ip) }
    it { should_not allow_value("! \#$%\`|").for(:ip) }
    it { should_not allow_value("<>@[]\`|").for(:ip) }

    it { should ensure_valid_ip_format_of(:ip) }
    it { should_not ensure_valid_ip_format_of(:name) }
  end

end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
active_validation-1.0.0 spec/lib/ip_validator_spec.rb
yukonisuru-1.0.0 spec/lib/ip_validator_spec.rb
yukonisuru-0.0.1 spec/lib/ip_validator_spec.rb
flash_validators-3.0.12 spec/lib/ip_validator_spec.rb
flash_validators-3.0.11 spec/lib/ip_validator_spec.rb
flash_validators-3.0.10 spec/lib/ip_validator_spec.rb
flash_validators-3.0.9 spec/lib/ip_validator_spec.rb
flash_validators-3.0.8 spec/lib/ip_validator_spec.rb
flash_validators-3.0.7 spec/lib/ip_validator_spec.rb
flash_validators-3.0.6 spec/lib/ip_validator_spec.rb
flash_validators-3.0.5 spec/lib/ip_validator_spec.rb
flash_validators-3.0.4 spec/lib/ip_validator_spec.rb
flash_validators-3.0.3 spec/lib/ip_validator_spec.rb
flash_validators-3.0.2 spec/lib/ip_validator_spec.rb
flash_validators-3.0.1 spec/lib/ip_validator_spec.rb
flash_validators-3.0.0 spec/lib/ip_validator_spec.rb
flash_validators-1.1.0 spec/lib/ip_validator_spec.rb