Sha256: 8de6408bed95910e96e32cefe6e4ffe604157dee45dcfc541d225a941bdead19

Contents?: true

Size: 973 Bytes

Versions: 2

Compression:

Stored size: 973 Bytes

Contents

require 'spec_helper'

describe IpValidator do

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

2 entries across 2 versions & 1 rubygems

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