Skip to content

Commit

Permalink
Merge pull request ruby-grape#1320 from dblock/invalid-format-spec
Browse files Browse the repository at this point in the history
Spec for ruby-grape#1276.
  • Loading branch information
dblock committed Mar 14, 2016
2 parents 044bd00 + dbf39c5 commit 41808e3
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 41808e3

Please sign in to comment.