Sha256: 93311367b05f43c6ed2c197e312354efe91a154f57c717c10fe722f88c812af6

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe Grape::Middleware::Versioner::Path do
  let(:app) { lambda{|env| [200, env, env['api.version']]} }
  subject { Grape::Middleware::Versioner::Path.new(app, @options || {}) }

  it 'should set the API version based on the first path' do
    subject.call('PATH_INFO' => '/v1/awesome').last.should == 'v1'
  end

  it 'should cut the version out of the path' do
    subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO'].should == '/awesome'
  end

  it 'should provide a nil version if no path is given' do
    subject.call('PATH_INFO' => '/').last.should be_nil
  end

  context 'with a pattern' do
    before{ @options = {:pattern => /v./i} }
    it 'should set the version if it matches' do
      subject.call('PATH_INFO' => '/v1/awesome').last.should == 'v1'
    end

    it 'should ignore the version if it fails to match' do
      subject.call('PATH_INFO' => '/awesome/radical').last.should be_nil
    end
  end

  context 'with specified versions' do
    before{ @options = {:versions => ['v1', 'v2']}}
    it 'should throw an error if a non-allowed version is specified' do
      catch(:error){subject.call('PATH_INFO' => '/v3/awesome')}[:status].should == 404
    end

    it 'should allow versions that have been specified' do
      subject.call('PATH_INFO' => '/v1/asoasd').last.should == 'v1'
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
grape-0.2.1.1 spec/grape/middleware/versioner/path_spec.rb
grape-0.2.3 spec/grape/middleware/versioner/path_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/spec/grape/middleware/versioner/path_spec.rb
grape-0.2.2 spec/grape/middleware/versioner/path_spec.rb
grape-0.2.1 spec/grape/middleware/versioner/path_spec.rb
grape-0.2.0 spec/grape/middleware/versioner/path_spec.rb