Sha256: d656428d6b5ef580bc49ba6e0a32a96e577c029a1f53753b9f1ead221c75fbb5

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe Grape::Validations::SingleAttributeIterator 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 params and every single attribute from the list' do
        expect { |b| iterator.each(&b) }
          .to yield_successive_args([params, :first], [params, :second], [params, :third])
      end
    end

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

      it 'yields every single attribute from the list for each of the array elements' do
        expect { |b| iterator.each(&b) }.to yield_successive_args(
          [params[0], :first], [params[0], :second], [params[0], :third],
          [params[1], :first], [params[1], :second], [params[1], :third]
        )
      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/single_attribute_iterator_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/validations/single_attribute_iterator_spec.rb
grape-1.2.5 spec/grape/validations/single_attribute_iterator_spec.rb