Skip to content

Commit cf4aac1

Browse files
committed
Merge pull request #953 from dabrorius/allow_all_fixnum_statuses
Allow all Fixnum statuses
2 parents 514a2e5 + ca49961 commit cf4aac1

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lib/grape/dsl/inside_route.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ def status(status = nil)
102102
fail ArgumentError, "Status code :#{status} is invalid."
103103
end
104104
when Fixnum
105-
if Rack::Utils::HTTP_STATUS_CODES.keys.include?(status)
106-
@status = status
107-
else
108-
fail ArgumentError, "Status code #{status} is invalid."
109-
end
105+
@status = status
110106
when nil
111107
return @status if @status
112108
case request.request_method.to_s.upcase

spec/grape/api_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,22 @@ def static
20312031
expect(route.route_settings[:custom]).to eq(key: 'value')
20322032
end
20332033
end
2034+
describe 'status' do
2035+
it 'can be set to arbitrary Fixnum value' do
2036+
subject.get '/foo' do
2037+
status 210
2038+
end
2039+
get '/foo'
2040+
expect(last_response.status).to eq 210
2041+
end
2042+
it 'can be set with a status code symbol' do
2043+
subject.get '/foo' do
2044+
status :see_other
2045+
end
2046+
get '/foo'
2047+
expect(last_response.status).to eq 303
2048+
end
2049+
end
20342050
end
20352051

20362052
context 'desc' do

spec/grape/dsl/inside_route_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ def initialize
118118
.to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
119119
end
120120

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

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

0 commit comments

Comments
 (0)