Sha256: 58515a148b283f9de8447c04039bac5d01d52e7ba6b6c1f7a50b73cb97aca8fb

Contents?: true

Size: 918 Bytes

Versions: 13

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

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

13 entries across 13 versions & 2 rubygems

Version Path
grape-1.6.2 spec/grape/api/parameters_modification_spec.rb
grape-1.6.1 spec/grape/api/parameters_modification_spec.rb
grape-1.6.0 spec/grape/api/parameters_modification_spec.rb
grape-1.5.3 spec/grape/api/parameters_modification_spec.rb
grape-1.5.2 spec/grape/api/parameters_modification_spec.rb
grape-1.5.1 spec/grape/api/parameters_modification_spec.rb
grape-1.5.0 spec/grape/api/parameters_modification_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/spec/grape/api/parameters_modification_spec.rb
grape-1.4.0 spec/grape/api/parameters_modification_spec.rb
grape-1.3.3 spec/grape/api/parameters_modification_spec.rb
grape-1.3.2 spec/grape/api/parameters_modification_spec.rb
grape-1.3.1 spec/grape/api/parameters_modification_spec.rb
grape-1.3.0 spec/grape/api/parameters_modification_spec.rb