Skip to content

Commit

Permalink
Merge pull request #953 from dabrorius/allow_all_fixnum_statuses
Browse files Browse the repository at this point in the history
Allow all Fixnum statuses
  • Loading branch information
dm1try committed Mar 10, 2015
2 parents 514a2e5 + ca49961 commit cf4aac1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/grape/dsl/inside_route.rb
Expand Up @@ -102,11 +102,7 @@ def status(status = nil)
fail ArgumentError, "Status code :#{status} is invalid."
end
when Fixnum
if Rack::Utils::HTTP_STATUS_CODES.keys.include?(status)
@status = status
else
fail ArgumentError, "Status code #{status} is invalid."
end
@status = status
when nil
return @status if @status
case request.request_method.to_s.upcase
Expand Down
16 changes: 16 additions & 0 deletions spec/grape/api_spec.rb
Expand Up @@ -2031,6 +2031,22 @@ def static
expect(route.route_settings[:custom]).to eq(key: 'value')
end
end
describe 'status' do
it 'can be set to arbitrary Fixnum value' do
subject.get '/foo' do
status 210
end
get '/foo'
expect(last_response.status).to eq 210
end
it 'can be set with a status code symbol' do
subject.get '/foo' do
status :see_other
end
get '/foo'
expect(last_response.status).to eq 303
end
end
end

context 'desc' do
Expand Down
5 changes: 2 additions & 3 deletions spec/grape/dsl/inside_route_spec.rb
Expand Up @@ -118,9 +118,8 @@ def initialize
.to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
end

it 'raises error if unknow status code is passed' do
expect { subject.status 210 }
.to raise_error(ArgumentError, 'Status code 210 is invalid.')
it 'accepts unknown Fixnum status codes' do
expect { subject.status 210 }.to_not raise_error
end

it 'raises error if status is not a fixnum or symbol' do
Expand Down

0 comments on commit cf4aac1

Please sign in to comment.