Sha256: e6b88e25cf83bb08f4713cf769239d81683bde030f599b25a38e24a6bda9af39

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Volt::TypeValidator do
  subject { Volt::TypeValidator.validate(*use_params) }
  let(:use_params) { [model, field_name, options] }

  let(:model) { Volt::Model.new count: count }
  let(:field_name) { :count }
  let(:name) { 'John Doe' }

  describe '.validate' do
    describe 'when options is a Numeric' do
      let(:options) { Numeric }

      describe 'when count is a Numeric' do
        let(:count) { 5 }
        it { expect(subject).to eq({}) }
      end

      describe 'when count is a string' do
        let(:count) { 'Cats' }
        it do
          expect(subject).to eq({count: ['must be of type Numeric']})
        end
      end
    end

    describe 'when options is a Hash' do
      let(:options) do
        { type: Numeric, message: 'must be a number' }
      end

      describe 'when count is a Numeric' do
        let(:count) { 5 }
        it { expect(subject).to eq({}) }
      end

      describe 'when count is a string' do
        let(:count) { 'Cats' }
        it do
          expect(subject).to eq(count: ['must be a number'])
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
volt-0.9.5.pre4 spec/models/validators/type_validator_spec.rb
volt-0.9.5.pre3 spec/models/validators/type_validator_spec.rb
volt-0.9.5.pre2 spec/models/validators/type_validator_spec.rb
volt-0.9.5.pre1 spec/models/validators/type_validator_spec.rb
volt-0.9.4 spec/models/validators/type_validator_spec.rb
volt-0.9.4.pre5 spec/models/validators/type_validator_spec.rb
volt-0.9.4.pre3 spec/models/validators/type_validator_spec.rb
volt-0.9.4.pre2 spec/models/validators/type_validator_spec.rb
volt-0.9.4.pre1 spec/models/validators/type_validator_spec.rb