Sha256: cefca36e35336f60de8a3439173afb0c2e9002d00784d662785d39ea5c9b010d

Contents?: true

Size: 886 Bytes

Versions: 18

Compression:

Stored size: 886 Bytes

Contents

require 'spec_helper'

describe Grape::Endpoint do
  subject { Class.new(Grape::API) }

  def app
    subject
  end

  before do
    subject.namespace :test do
      params do
        optional :foo, default: '-abcdef'
      end
      get do
        params[:foo].slice!(0)
        params[:foo]
      end
    end
  end

  context 'when route modifies param value' do
    it 'param default should not change' do
      get '/test'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'abcdef'

      get '/test'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'abcdef'

      get '/test?foo=-123456'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq '123456'

      get '/test'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'abcdef'
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/api/parameters_modification_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/api/parameters_modification_spec.rb
grape-1.2.5 spec/grape/api/parameters_modification_spec.rb
grape-1.2.4 spec/grape/api/parameters_modification_spec.rb
grape-1.2.3 spec/grape/api/parameters_modification_spec.rb
grape-1.2.2 spec/grape/api/parameters_modification_spec.rb
grape-1.2.1 spec/grape/api/parameters_modification_spec.rb
grape-1.2.0 spec/grape/api/parameters_modification_spec.rb
grape-1.1.0 spec/grape/api/parameters_modification_spec.rb
grape-1.0.3 spec/grape/api/parameters_modification_spec.rb
grape-1.0.2 spec/grape/api/parameters_modification_spec.rb
grape-1.0.1 spec/grape/api/parameters_modification_spec.rb
grape-1.0.0 spec/grape/api/parameters_modification_spec.rb
grape-0.19.2 spec/grape/api/parameters_modification_spec.rb
grape-0.19.1 spec/grape/api/parameters_modification_spec.rb
grape-0.19.0 spec/grape/api/parameters_modification_spec.rb
grape-0.18.0 spec/grape/api/parameters_modification_spec.rb
grape-0.17.0 spec/grape/api/parameters_modification_spec.rb