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

Header versioning does not play nicely with Crepe::API.mount #1

Open
davidcelis opened this issue Apr 23, 2015 · 1 comment
Open

Header versioning does not play nicely with Crepe::API.mount #1

davidcelis opened this issue Apr 23, 2015 · 1 comment

Comments

@davidcelis
Copy link
Member

Here's a failing spec:

RSpec.describe Crepe::API, 'versioning' do
  context 'with header' do
    app do
      version with: :header, vendor: :pancake, default: :v2

      version :v1 do
        mount Proc.new { [200, {'Content-Type' => 'text/plain'}, ['v1']] }
      end

      version :v2 do
        mount Proc.new { [200, {'Content-Type' => 'text/plain'}, ['v2']] }
      end

      mount Proc.new { [200, {'Content-Type' => 'text/plain'}, ['v3']] }, at: :v3
    end

    it 'routes to several versions at the same path' do
      get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.pancake-v2+json'
      expect(last_response.body).to include 'v2'

      get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.pancake-v1+json'
      expect(last_response.body).to include 'v1'

      expect(get('/v3').body).to include 'v3'
    end

    it 'defaults to the specified version' do
      expect(get('/').body).to include 'v2'
    end
  end
end

By using mount with a proc or Rack application from within a version declaration, the requested endpoints become 404s instead of routing to an app.

@davidcelis
Copy link
Member Author

Adding method: 'GET' to those first two mounts fix the 404s, but then requesting /v3 goes to the v2 Proc.

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

No branches or pull requests

1 participant