Sha256: 977679023e1050a77f1cca2e0a5a239ca9e442dcdcc12514385132948f6108e3

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

require 'spec_helper'

describe SubnetValidator do
  context "when subnet is invalid" do
    before :each do
      @subnet = Subnet.new(:value => "127.0.0")
      I18n.stub(:t).with(:"activerecord.errors.models.subnet.attributes.value.invalid",
                         :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
    end

    it "should set object as invalid" do
      @subnet.valid?.should be_false
    end

    it "should set an error" do
      @subnet.valid?
      @subnet.errors[:value].should == ['is invalid']
    end
  end

  context "when subnet is valid" do
    before :each do
      @subnet = Subnet.new(:value => "10.10.10.1/28")
    end

    it "should set object as valid" do
      @subnet.valid?.should be_true
    end

    it "should not set an error on attribute" do
      @subnet.valid?
      @subnet.errors[:value].should be_blank
    end
  end

  it "should be valid with a nil value" do
    @subnet = Subnet.new(:value => nil)
    @subnet.valid?.should be_true
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validates_host-1.0.0 spec/validates_host/subnet_validator_spec.rb
validates_host-0.3.1 spec/validates_host/subnet_validator_spec.rb
validates_host-0.3.0 spec/validates_host/subnet_validator_spec.rb