Sha256: 58d8873cb8ceef7244f7c983b43a5850ce9b339bd7522eed530448659de71e79

Contents?: true

Size: 1.71 KB

Versions: 13

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe Grape::Extensions::Hashie::Mash::ParamBuilder do
  subject { Class.new(Grape::API) }

  def app
    subject
  end

  describe 'in an endpoint' do
    context '#params' do
      before do
        subject.params do
          build_with Grape::Extensions::Hashie::Mash::ParamBuilder
        end

        subject.get do
          params.class
        end
      end

      it 'should be of type Hashie::Mash' do
        get '/'
        expect(last_response.status).to eq(200)
        expect(last_response.body).to eq('Hashie::Mash')
      end
    end
  end

  describe 'in an api' do
    before do
      subject.send(:include, Grape::Extensions::Hashie::Mash::ParamBuilder)
    end

    context '#params' do
      before do
        subject.get do
          params.class
        end
      end

      it 'should be Hashie::Mash' do
        get '/'
        expect(last_response.status).to eq(200)
        expect(last_response.body).to eq('Hashie::Mash')
      end
    end

    context 'in a nested namespace api' do
      before do
        subject.namespace :foo do
          get do
            params.class
          end
        end
      end

      it 'should be Hashie::Mash' do
        get '/foo'
        expect(last_response.status).to eq(200)
        expect(last_response.body).to eq('Hashie::Mash')
      end
    end

    it 'is indifferent to key or symbol access' do
      subject.params do
        build_with Grape::Extensions::Hashie::Mash::ParamBuilder
        requires :a, type: String
      end
      subject.get '/foo' do
        [params[:a], params['a']]
      end

      get '/foo', a: 'bar'
      expect(last_response.status).to eq(200)
      expect(last_response.body).to eq('["bar", "bar"]')
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.5 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.4 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.3 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.2 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.1 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.2.0 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.1.0 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.0.3 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.0.2 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.0.1 spec/grape/extensions/param_builders/hashie/mash_spec.rb
grape-1.0.0 spec/grape/extensions/param_builders/hashie/mash_spec.rb