Skip to content

Commit

Permalink
Add spec for ruby-grape#1263
Browse files Browse the repository at this point in the history
  • Loading branch information
namusyaka committed Mar 9, 2016
1 parent c50b565 commit 2368d61
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,72 @@ def subject.enable_root_route!
expect(last_response.headers['Content-Type']).to eql 'text/plain'
end

describe 'adds an OPTIONS route that' do
before do
subject.before { header 'X-Custom-Header', 'foo' }
subject.get 'example' do
'example'
end
subject.route :any, '*path' do
error! :not_found, 404
end
options '/example'
end

it 'returns a 204' do
expect(last_response.status).to eql 204
end

it 'has an empty body' do
expect(last_response.body).to be_blank
end

it 'has an Allow header' do
expect(last_response.headers['Allow']).to eql 'OPTIONS, GET, HEAD'
end

it 'has a X-Custom-Header' do
expect(last_response.headers['X-Custom-Header']).to eql 'foo'
end

it 'has no Content-Type' do
expect(last_response.content_type).to be_nil
end

it 'has no Content-Length' do
expect(last_response.content_length).to be_nil
end
end

describe 'adds a 405 Not Allowed route that' do
before do
subject.before { header 'X-Custom-Header', 'foo' }
subject.post :example do
'example'
end
subject.route :any, '*path' do
error! :not_found, 404
end
get '/example'
end

it 'returns a 405' do
expect(last_response.status).to eql 405
end

it 'contains error message in body' do
expect(last_response.body).to eq '405 Not Allowed'
end

it 'has an Allow header' do
expect(last_response.headers['Allow']).to eql 'OPTIONS, POST'
end

it 'has a X-Custom-Header' do
expect(last_response.headers['X-Custom-Header']).to eql 'foo'
end
end

context 'allows HEAD on a GET request that' do
before do
subject.get 'example' do
Expand Down

0 comments on commit 2368d61

Please sign in to comment.