Sha256: 6e37c21b6b50d3f9583f160dcaba34f0515d2f5dd702d0f770cd6224c02e660e

Contents?: true

Size: 994 Bytes

Versions: 13

Compression:

Stored size: 994 Bytes

Contents

require 'spec_helper'

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

  def app
    subject
  end

  before do
    subject.namespace do
      format :json
      content_type :json, 'application/json'
      params do
        requires :id, desc: 'Identifier.'
      end
      get ':id' do
        {
          id: params[:id],
          format: params[:format]
        }
      end
    end
  end

  context 'get' do
    it 'no format' do
      get '/foo'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: nil))
    end
    it 'json format' do
      get '/foo.json'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: 'json'))
    end
    it 'invalid format' do
      get '/foo.invalid'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: 'invalid'))
    end
  end
end

Version data entries

13 entries across 13 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/invalid_format_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/api/invalid_format_spec.rb
grape-1.2.5 spec/grape/api/invalid_format_spec.rb
grape-1.2.4 spec/grape/api/invalid_format_spec.rb
grape-1.2.3 spec/grape/api/invalid_format_spec.rb
grape-1.2.2 spec/grape/api/invalid_format_spec.rb
grape-1.2.1 spec/grape/api/invalid_format_spec.rb
grape-1.2.0 spec/grape/api/invalid_format_spec.rb
grape-1.1.0 spec/grape/api/invalid_format_spec.rb
grape-1.0.3 spec/grape/api/invalid_format_spec.rb
grape-1.0.2 spec/grape/api/invalid_format_spec.rb
grape-1.0.1 spec/grape/api/invalid_format_spec.rb
grape-1.0.0 spec/grape/api/invalid_format_spec.rb