Sha256: 7c21f9711e9859b2b1b47cb6a4c0bc5aa7ab65fa09053f151a5d41a5c51e8730

Contents?: true

Size: 930 Bytes

Versions: 10

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Grape::Validations::Types::ArrayCoercer do
  subject { described_class.new(type) }

  describe '#call' do
    context 'an array of primitives' do
      let(:type) { Array[String] }

      it 'coerces elements in the array' do
        expect(subject.call([10, 20])).to eq(%w[10 20])
      end
    end

    context 'an array of arrays' do
      let(:type) { Array[Array[Integer]] }

      it 'coerces elements in the nested array' do
        expect(subject.call([%w[10 20]])).to eq([[10, 20]])
        expect(subject.call([['10'], ['20']])).to eq([[10], [20]])
      end
    end

    context 'an array of sets' do
      let(:type) { Array[Set[Integer]] }

      it 'coerces elements in the nested set' do
        expect(subject.call([%w[10 20]])).to eq([Set[10, 20]])
        expect(subject.call([['10'], ['20']])).to eq([Set[10], Set[20]])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
grape-1.6.2 spec/grape/validations/types/array_coercer_spec.rb
grape-1.6.1 spec/grape/validations/types/array_coercer_spec.rb
grape-1.6.0 spec/grape/validations/types/array_coercer_spec.rb
grape-1.5.3 spec/grape/validations/types/array_coercer_spec.rb
grape-1.5.2 spec/grape/validations/types/array_coercer_spec.rb
grape-1.5.1 spec/grape/validations/types/array_coercer_spec.rb
grape-1.5.0 spec/grape/validations/types/array_coercer_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/spec/grape/validations/types/array_coercer_spec.rb
grape-1.4.0 spec/grape/validations/types/array_coercer_spec.rb
grape-1.3.3 spec/grape/validations/types/array_coercer_spec.rb