Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression with optional parameters #1307

Closed
dblock opened this issue Mar 7, 2016 · 2 comments
Closed

Regression with optional parameters #1307

dblock opened this issue Mar 7, 2016 · 2 comments

Comments

@dblock
Copy link
Member

dblock commented Mar 7, 2016

Regression from #1263

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

Passes in 0.14.0, fails on HEAD (0.15.0)

Grape::Endpoint
  get
    responds without ext (FAILED - 1)
    responds with ext
  put
    responds (FAILED - 2)

Failures:

  1) Grape::Endpoint get responds without ext
     Failure/Error: expect(last_response.status).to eq 200

       expected: 200
            got: 405

       (compared using ==)
     # ./spec/grape/integration/methods_with_options_spec.rb:25:in `block (3 levels) in <top (required)>'

  2) Grape::Endpoint put responds
     Failure/Error: expect(last_response.status).to eq 200

       expected: 200
            got: 405

       (compared using ==)
     # ./spec/grape/integration/methods_with_options_spec.rb:39:in `block (3 levels) in <top (required)>'

Finished in 0.16979 seconds (files took 0.67914 seconds to load)
3 examples, 2 failures

Failed examples:

rspec ./spec/grape/integration/methods_with_options_spec.rb:23 # Grape::Endpoint get responds without ext
rspec ./spec/grape/integration/methods_with_options_spec.rb:37 # Grape::Endpoint put responds
@dblock
Copy link
Member Author

dblock commented Mar 7, 2016

Another much simpler spec not fixed above.

require 'spec_helper'

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

  def app
    subject
  end

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

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

  context 'get' do
    it 'responds' do
      get '/api/foo'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq 'foo'
    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

@dblock dblock reopened this Mar 7, 2016
@dblock dblock closed this as completed in c40ef2e Mar 7, 2016
@dblock
Copy link
Member Author

dblock commented Mar 8, 2016

Another one:

require 'spec_helper'

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

  def app
    subject
  end

  before do
    subject.namespace :me do
      namespace :pending do
        get '/' do
          'banana'
        end
      end
      put ':id' do
        params[:id]
      end
    end
  end

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant