Sha256: c6b2e836f5f1c394dd4bd5abda1b3dfc31521f90d5589b346d13be93a219df8c

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

require 'spec_helper'

describe Grape::Validations::MultipleAttributesIterator do
  describe '#each' do
    subject(:iterator) { described_class.new(validator, scope, params) }
    let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
    let(:validator) { double(attrs: %i[first second third]) }

    context 'when params is a hash' do
      let(:params) do
        { first: 'string', second: 'string' }
      end

      it 'yields the whole params hash without the list of attrs' do
        expect { |b| iterator.each(&b) }.to yield_with_args(params)
      end
    end

    context 'when params is an array' do
      let(:params) do
        [{ first: 'string1', second: 'string1' }, { first: 'string2', second: 'string2' }]
      end

      it 'yields each element of the array without the list of attrs' do
        expect { |b| iterator.each(&b) }.to yield_successive_args(params[0], params[1])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/validations/multiple_attributes_iterator_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/validations/multiple_attributes_iterator_spec.rb
grape-1.2.5 spec/grape/validations/multiple_attributes_iterator_spec.rb