Sha256: cc509a6293d90ee549ecf44237f252cbe2ebe2052bc8eb3732ba5c67c3747273

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

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

11 entries across 11 versions & 2 rubygems

Version Path
grape-1.6.0 spec/grape/api/invalid_format_spec.rb
grape-1.5.3 spec/grape/api/invalid_format_spec.rb
grape-1.5.2 spec/grape/api/invalid_format_spec.rb
grape-1.5.1 spec/grape/api/invalid_format_spec.rb
grape-1.5.0 spec/grape/api/invalid_format_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/spec/grape/api/invalid_format_spec.rb
grape-1.4.0 spec/grape/api/invalid_format_spec.rb
grape-1.3.3 spec/grape/api/invalid_format_spec.rb
grape-1.3.2 spec/grape/api/invalid_format_spec.rb
grape-1.3.1 spec/grape/api/invalid_format_spec.rb
grape-1.3.0 spec/grape/api/invalid_format_spec.rb