Sha256: a08302f947ae9a21300e7a9c5e336a3fe1ebab99d6df2fe94552d99489fa8ac7

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

require File.dirname(__FILE__) + "/spec_helper"

describe Validatable::ValidatesConfirmationOf do
  
  before(:all) do
    class Cow

      include DataMapper::CallbacksHelper
      include DataMapper::Validations
      
      attr_accessor :name, :name_confirmation, :age
    end
  end
  
  it 'should pass validation' do
    class Cow
      validations.clear
      validates_confirmation_of :name, :event => :save
    end
    
    betsy = Cow.new
    betsy.valid?.should == true

    betsy.name = 'Betsy'
    betsy.name_confirmation = ''
    betsy.valid?(:save).should == false
    betsy.errors.full_messages.first.should == 'Name does not match the confirmation'

    betsy.name = ''
    betsy.name_confirmation = 'Betsy'
    betsy.valid?(:save).should == false
    betsy.errors.full_messages.first.should == 'Name does not match the confirmation'

    betsy.name = 'Betsy'
    betsy.name_confirmation = 'Betsy'
    betsy.valid?(:save).should == true
  end
  
  it 'should allow allow a custom error message' do
    class Cow
      validations.clear
      validates_confirmation_of :name, :event => :save, :message => 'You confirm name NOW or else.'
    end
    
    betsy = Cow.new
    betsy.valid?.should == true

    betsy.name = 'Betsy'
    betsy.name_confirmation = ''
    betsy.valid?(:save).should == false

    betsy.errors.full_messages.first.should == 'You confirm name NOW or else.'
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datamapper-0.2.4 spec/validates_confirmation_of_spec.rb
datamapper-0.2.5 spec/validates_confirmation_of_spec.rb
datamapper-0.3.0 spec/validates_confirmation_of_spec.rb
datamapper-0.3.1 spec/validates_confirmation_of_spec.rb
datamapper-0.3.2 spec/validates_confirmation_of_spec.rb