Sha256: 2e3136b97d6bcca10e10024d11efa078894498160e63747c2746a05493e7d652

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe Vanguard::DSL, '#validates_length_of' do
  include Spec::Shared::DSL

  describe 'with fixnum :length option' do
    before do
      builder.validates_length_of attribute_name, :length => 3
    end

    describe 'when validated attribute value is expected length' do
      let(:attribute_value) { 'foo' }

      it_should_be_a_valid_instance
    end

    describe 'when validated attribute value is not expected length' do
      let(:attribute_value) { 'barz' }

      it_should_be_an_invalid_instance
    end
  end

  describe 'with  :maximum option' do
    before do
      builder.validates_length_of attribute_name, :maximum => 3
    end

    describe 'when validated attribute value is at most expected length' do
      let(:attribute_value) { 'foo' }

      it_should_be_a_valid_instance
    end

    describe 'when validated attribute value is more than expected length' do
      let(:attribute_value) { 'barz' }

      it_should_be_an_invalid_instance
    end
  end

  describe 'with :minimum option' do
    before do
      builder.validates_length_of attribute_name, :minimum => 3
    end

    describe 'when validated attribute value is at least expected length' do
      let(:attribute_value) { 'foo' }

      it_should_be_a_valid_instance
    end

    describe 'when validated attribute value is less than expected length' do
      let(:attribute_value) { 'bz' }

      it_should_be_an_invalid_instance
    end
  end

  describe 'with range :length options' do
    before do
      builder.validates_length_of attribute_name, :length => 2..3
    end

    describe 'when validated attribute value length is within expected range' do
      let(:attribute_value) { 'foo' }

      it_should_be_a_valid_instance
    end

    describe 'when validated attribute value length is not within expected range' do
      let(:attribute_value) { 'barz' }

      it_should_be_an_invalid_instance
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vanguard-0.0.5 spec/integration/vanguard/dsl/validates_length_of_spec.rb
vanguard-0.0.4 spec/integration/vanguard/dsl/validates_length_of_spec.rb
vanguard-0.0.3 spec/integration/vanguard/dsl/validates_length_of_spec.rb