Sha256: adee5b028e321a5f68ec71c861599fb3777b87be421e9242f229d2c1543a5413

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'validate_confirmation_of' do
  include ModelBuilder

  # Defines a model, create a validation and returns a raw matcher
  def define_and_validate(options={})
    @model = define_model :user, :name => :string, :email => :string, :age => :string do
      validates_confirmation_of :name, :email, options
    end

    validate_confirmation_of(:name, :email)
  end

  describe 'messages' do
    before(:each){ @matcher = define_and_validate }

    it 'should contain a description' do
      @matcher.description.should == 'require name and email to be confirmed'
    end

    it 'should set responds_to_confirmation? message' do
      @matcher = validate_confirmation_of(:age)
      @matcher.matches?(@model)
      @matcher.failure_message.should == 'Expected User instance responds to age_confirmation'
    end

    it 'should set confirms? message' do
      @model.instance_eval{ def age_confirmation=(*args); end }
      @matcher = validate_confirmation_of(:age)
      @matcher.matches?(@model)
      @matcher.failure_message.should == 'Expected User to be valid only when age is confirmed'
    end

  end

  describe 'matchers' do

    describe 'without options' do
      before(:each){ define_and_validate }

      it { should validate_confirmation_of(:name) }
      it { should validate_confirmation_of(:name, :email) }
      it { should_not validate_confirmation_of(:name, :age) }
    end

    create_message_specs(self)
  end

  describe 'macros' do
    before(:each){ define_and_validate }

    should_validate_confirmation_of :name
    should_validate_confirmation_of :name, :email
    should_not_validate_confirmation_of :name, :age
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
remarkable_activerecord-3.0.0 spec/validate_confirmation_of_matcher_spec.rb
remarkable_activerecord-3.0.1 spec/validate_confirmation_of_matcher_spec.rb