Skip to content

Commit

Permalink
Spec for ruby-grape#1276.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock authored and przbadu committed Apr 5, 2016
1 parent c266b7c commit 4766f66
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/grape/api/invalid_format_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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(MultiJson.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(MultiJson.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(MultiJson.dump(id: 'foo', format: 'invalid'))
end
end
end

0 comments on commit 4766f66

Please sign in to comment.