Sha256: 94ef6ef6c5d92a63f2625350c62728eb725c8ccc6927f4c9274578c945e47bfe

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require "spec_helper"

describe ".validates_ip_address" do
  subject { User.new }

  context "IPv4" do
    it "should be valid" do
      User.validates_ip_address :url, :only => :v4
      subject.url = "192.168.1.2"
      subject.should be_valid
    end

    it "should not be valid" do
      User.validates_ip_address :url, :only => :v4
      subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
      subject.should_not be_valid
      subject.errors[:url].should == ["is not a valid IPv4 address"]
    end
  end

  context "IPv6" do
    it "should be valid" do
      User.validates_ip_address :url, :only => :v6
      subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
      subject.should be_valid
    end

    it "should not be valid" do
      User.validates_ip_address :url, :only => :v6
      subject.url = "192.168.1.2"
      subject.should_not be_valid
      subject.errors[:url].should == ["is not a valid IPv6 address"]
    end
  end

  it "should be valid with IPv4" do
    User.validates_ip_address :url
    subject.url = "192.168.1.2"
    subject.should be_valid
  end

  it "should be valid with IPv6" do
    User.validates_ip_address :url
    subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
    subject.should be_valid
  end

  it "should allow blank values" do
    User.validates_ip_address :url, :allow_blank => true
    subject.url = ""
    subject.should be_valid
  end

  it "should allow nil values" do
    User.validates_ip_address :url, :allow_nil => true
    subject.url = nil
    subject.should be_valid
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
validators-2.1.0 spec/validators/validates_ip_address_spec.rb
validators-2.0.0 spec/validators/validates_ip_address_spec.rb
validators-1.0.0 spec/validators/validates_ip_address_spec.rb
validators-0.1.3 spec/validators/validates_ip_address_spec.rb
validators-0.1.2 spec/validators/validates_ip_address_spec.rb
validators-0.1.1 spec/validators/validates_ip_address_spec.rb