Sha256: ed3da15768530a96ddc8a41246147ba3bebb088c9bf9ff0f7b2b681ff107b8cd

Contents?: true

Size: 953 Bytes

Versions: 1

Compression:

Stored size: 953 Bytes

Contents

require 'spec_helper'

describe CnpjValidator do
  context "when cnpj is invalid" do
    before :each do
      @company = Company.new(:cnpj => "12345")
      I18n.stub(:t).with("activerecord.errors.models.company.attributes.cnpj.invalid").and_return("is invalid")
    end

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

    it "should set an error on attribute" do
      @company.valid?
      @company.errors[:cnpj].should == ['is invalid']
    end
  end

  context "when cnpj is valid" do
    before :each do
      @company = Company.new(:cnpj => "37525685000108")
    end

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

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

  it "should accept a nil value" do
    @company = Company.new(:cnpj => nil)
    @company.valid?.should be_true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_cnpj-1.1.0 spec/validates_cnpj_spec.rb