Sha256: fe4bfebd9bc9f6de71234255d7f1e5a8b308f6a3d2ef55632d2e14562abf47d9

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

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

describe 'validate_presence_of' do
  include ModelBuilder

  # Defines a model, create a validation and returns a raw matcher
  def define_and_validate(options={})
    @model = define_model :product, :title => :string, :size => :string, :category => :string do
      validates_presence_of :title, :size, options
    end

    validate_presence_of(:title, :size)
  end

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

    it 'should contain a description' do
      @matcher.description.should == 'require title and size to be set'
    end

    it 'should set allow_nil? message' do
      @matcher = validate_presence_of(:category)
      @matcher.matches?(@model)
      @matcher.failure_message.should == 'Expected Product to require category to be set'
      @matcher.negative_failure_message.should == 'Did not expect Product to require category to be set'
    end
  end

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

      it { should validate_presence_of(:size)         }
      it { should validate_presence_of(:title)        }
      it { should validate_presence_of(:title, :size) }
      it { should_not validate_presence_of(:category) }
    end

    create_message_specs(self)
  end

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

    should_validate_presence_of(:size)
    should_validate_presence_of(:title)
    should_validate_presence_of(:size, :title)
    should_not_validate_presence_of(:category)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
remarkable_activerecord-3.0.10 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.2 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.3 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.4 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.5 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.6 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.7 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.8 spec/validate_presence_of_matcher_spec.rb
remarkable_activerecord-3.0.9 spec/validate_presence_of_matcher_spec.rb