Sha256: 1b9ea2b134980d66497483550c24d833921d6ec97e4c89c478c54f6a6f0693f0

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

  describe '#value' do
    context 'when there are no validators' do
      it 'returns a float' do
        10.times { expect(assigner.value).to be_a Float }
      end
    end

    context 'when there is greater_than validator' do
      it 'returns a float 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 a float 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 is greater_and less_than validators' do
      it 'returns a float greater than and less than the requirements' do
        attribute.validators = [
          ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 0, less_than: 1)
        ]
        10.times { expect(assigner.value).to be_between(0, 1).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/float_spec.rb
dirty_seed-0.2.0 spec/lib/dirty_seed/assigners/type/float_spec.rb