Sha256: 3542f94beb2667425e7a7c6bfd8b8c047dc2bf17191f7a6063d09616f2e13edc

Contents?: true

Size: 819 Bytes

Versions: 21

Compression:

Stored size: 819 Bytes

Contents

require 'spec_helper'

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

  def app
    subject
  end

  before do
    subject.namespace :api do
      get ':id(/:ext)' do
        [params[:id], params[:ext]].compact.join('/')
      end

      put ':id' do
        params[:id]
      end
    end
  end

  context 'get' do
    it 'responds without ext' do
      get '/api/foo'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'foo'
    end

    it 'responds with ext' do
      get '/api/foo/bar'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'foo/bar'
    end
  end

  context 'put' do
    it 'responds' do
      put '/api/foo'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'foo'
    end
  end
end

Version data entries

21 entries across 21 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/optional_parameters_in_route_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.5 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.4 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.3 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.2 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.1 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.2.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.1.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.0.3 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.0.2 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.0.1 spec/grape/api/optional_parameters_in_route_spec.rb
grape-1.0.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.19.2 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.19.1 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.19.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.18.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.17.0 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.16.2 spec/grape/api/optional_parameters_in_route_spec.rb
grape-0.16.1 spec/grape/api/optional_parameters_in_route_spec.rb