Sha256: 4a4867fe3c68696c90201755f5f9c4b3960c14ce5ba1d19b34edc25cec7f1d87

Contents?: true

Size: 1.11 KB

Versions: 30

Compression:

Stored size: 1.11 KB

Contents

RSpec.describe NilValidator do
  subject(:nil_validator) do
    described_class.new(
        :attributes => attributes
    )
  end

  let(:attribute) do
    :nil_thing
  end

  let(:attributes) do
    [
        attribute
    ]
  end

  context '#validate_each' do
    subject(:validate_each) do
      nil_validator.validate_each(record, attribute, value)
    end

    let(:record) do
      record_class.new
    end

    let(:record_class) do
      # capture attribute for Class.new scope
      attribute = self.attribute

      Class.new do
        include ActiveModel::Validations

        #
        # Validations
        #

        validates attribute,
                  :nil => true
      end
    end

    context 'with value' do
      let(:value) do
        ''
      end

      it 'should record error on attribute' do
        validate_each

        expect(record.errors[attribute]).to include('must be nil')
      end
    end

    context 'without value' do
      let(:value) do
        nil
      end

      it 'should not record any error' do
        validate_each

        expect(record.errors).to be_empty
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
metasploit-model-5.0.2 spec/app/validators/nil_validator_spec.rb
metasploit-model-5.0.1 spec/app/validators/nil_validator_spec.rb
metasploit-model-5.0.0 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.6 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.5 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.4 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.3 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.2 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.1 spec/app/validators/nil_validator_spec.rb
metasploit-model-4.0.0 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.1.4 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.1.3 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.1.2 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.1.1 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.1.0 spec/app/validators/nil_validator_spec.rb
metasploit-model-3.0.0 spec/app/validators/nil_validator_spec.rb
metasploit-model-2.0.4 spec/app/validators/nil_validator_spec.rb
metasploit-model-2.0.3 spec/app/validators/nil_validator_spec.rb
metasploit-model-2.0.2 spec/app/validators/nil_validator_spec.rb
metasploit-model-2.0.1 spec/app/validators/nil_validator_spec.rb