Sha256: 861a31498882294891f72880aa7e35e90a86c8c30b73bb812e353eda1195987a

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe DirtySeed::Assigners::Type::Integer do
  let(:attribute) { build_attribute(:integer) }
  let(:assigner) { described_class.new(attribute) }

  describe '#value' do
    context 'when there are no validators' do
      it 'returns an integer' do
        10.times { expect(assigner.value).to be_an Integer }
      end
    end

    context 'when there is greater_than validator' do
      it 'returns an integer greater than the requirement' do
        attribute.validators = [
          ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1_000)
        ]
        10.times { expect(assigner.value).to be >= 1_000 }
      end
    end

    context 'when there is less_than validator' do
      it 'returns an integer less than the requirement' do
        attribute.validators = [
          ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, less_than: -1_000)
        ]
        10.times { expect(assigner.value).to be < -1_000 }
      end
    end

    context 'when there are less_than and greater_than validators' do
      it 'returns an integer greater than and less than the requirements' do
        attribute.validators = [
          ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1, less_than: 5)
        ]
        10.times { expect(assigner.value).to be_between(1, 5).exclusive }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dirty_seed-0.2.1 spec/lib/dirty_seed/assigners/type/integer_spec.rb
dirty_seed-0.2.0 spec/lib/dirty_seed/assigners/type/integer_spec.rb