Sha256: 25a2cf25958a7aae553e026f38c0b8e66d8c851e10dc370ef4f6307c77cc31df

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'
require 'integration/format_validator/spec_helper'

describe DataMapper::Validate::Fixtures::BillOfLading do
  def valid_attributes
    { :id => 1, :doc_no => 'A1234', :email => 'user@example.com', :url => 'http://example.com' }
  end

  describe "with doc no with value of 'BAD CODE :)'" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'BAD CODE :)'))
    end

    it_should_behave_like 'invalid model'

    it "has meaningful error message on invalid field" do
      @model.errors.on(:doc_no).should == [ 'Doc no has an invalid format' ]
    end
  end

  describe "with doc no with value of 'A1234'" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'A1234'))
    end

    it_should_behave_like 'valid model'
  end

  describe "with doc no with value of 'B123456X12'" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'B123456X12'))
    end

    it_should_behave_like 'valid model'
  end

  describe "with missing url" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.except(:url))
    end

    it_should_behave_like 'invalid model'
  end

  describe "with blank name" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:username => ''))
    end

    it_should_behave_like 'valid model'
  end

  describe "with blank email" do
    before :all do
      @model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:email => ''))
    end

    it_should_behave_like 'valid model'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-validations-0.10.1 spec/integration/format_validator/format_validator_spec.rb
dm-validations-0.10.0 spec/integration/format_validator/format_validator_spec.rb