Skip to content

Commit a29fa63

Browse files
authored
Merge pull request #1543 from ruby-grape/support-ruby-2.4
Support ruby 2.4
2 parents 0033f1d + 96fd175 commit a29fa63

14 files changed

+146
-81
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ sudo: false
44

55
matrix:
66
include:
7-
- rvm: 2.3.3
7+
- rvm: 2.4.0
88
script:
99
- bundle exec danger
10+
- rvm: 2.4.0
11+
gemfile: Gemfile
12+
- rvm: 2.4.0
13+
gemfile: gemfiles/rack_edge.gemfile
14+
- rvm: 2.4.0
15+
gemfile: gemfiles/rack_1.5.2.gemfile
16+
- rvm: 2.4.0
17+
gemfile: gemfiles/rails_edge.gemfile
18+
- rvm: 2.4.0
19+
gemfile: gemfiles/rails_5.gemfile
1020
- rvm: 2.3.3
1121
gemfile: Gemfile
1222
- rvm: 2.3.3

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
#### 0.19.1 (Next)
1+
### 0.19.1 (Next)
2+
3+
#### Features
24

35
* [#1536](https://github.com/ruby-grape/grape/pull/1536): Updates `invalid_versioner_option` translation - [@Lavode](https://github.com/Lavode).
6+
* [#1543](https://github.com/ruby-grape/grape/pull/1543): Support ruby 2.4 - [@LeFnord](https://github.com/LeFnord), [@namusyaka](https://github.com/namusyaka).
7+
* Your contribution here.
8+
9+
#### Fixes
10+
411
* Your contribution here.
512

613
### 0.19.0 (12/18/2016)

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [Include Missing](#include-missing)
3333
- [Parameter Validation and Coercion](#parameter-validation-and-coercion)
3434
- [Supported Parameter Types](#supported-parameter-types)
35+
- [Integer/Fixnum and Coercions](#integerfixnum-and-coercions)
3536
- [Custom Types and Coercions](#custom-types-and-coercions)
3637
- [Multipart File Parameters](#multipart-file-parameters)
3738
- [First-Class `JSON` Types](#first-class-json-types)
@@ -799,6 +800,28 @@ The following are all valid types, supported out of the box by Grape:
799800
* Rack::Multipart::UploadedFile (alias `File`)
800801
* JSON
801802

803+
### Integer/Fixnum and Coercions
804+
805+
Please be aware that the behavior differs between Ruby 2.4 and earlier versions.
806+
In Ruby 2.4, values consisting of numbers are converted to Integer, but in earlier versions it will be treated as Fixnum.
807+
808+
```ruby
809+
params do
810+
requires :integers, type: Hash do
811+
requires :int, coerce: Integer
812+
end
813+
end
814+
get '/int' do
815+
params[:integers][:int].class
816+
end
817+
818+
...
819+
820+
get '/int' integers: { int: '45' }
821+
#=> Integer in ruby 2.4
822+
#=> Fixnum in earlier ruby versions
823+
```
824+
802825
### Custom Types and Coercions
803826

804827
Aside from the default set of supported types listed above, any class can be
@@ -2878,7 +2901,7 @@ end
28782901
The behaviour is then:
28792902

28802903
```bash
2881-
GET /123 # 'Fixnum'
2904+
GET /123 # 'Integer'
28822905
GET /foo # 400 error - 'blah is invalid'
28832906
```
28842907

lib/grape/dsl/inside_route.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def status(status = nil)
122122
when Symbol
123123
raise ArgumentError, "Status code :#{status} is invalid." unless Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status)
124124
@status = Rack::Utils.status_code(status)
125-
when Fixnum
125+
when Integer
126126
@status = status
127127
when nil
128128
return @status if @status
@@ -135,7 +135,7 @@ def status(status = nil)
135135
200
136136
end
137137
else
138-
raise ArgumentError, 'Status code must be Fixnum or Symbol.'
138+
raise ArgumentError, 'Status code must be Integer or Symbol.'
139139
end
140140
end
141141

spec/grape/api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ class DummyFormatClass
925925
end
926926

927927
get '/', id: '32'
928-
expect(last_response.body).to eql 'first 32:Fixnum second'
928+
expect(last_response.body).to eql "first 32:#{integer_class_name} second"
929929
end
930930

931931
it 'adds a after filter' do
@@ -2506,7 +2506,7 @@ def static
25062506
end
25072507
end
25082508
describe 'status' do
2509-
it 'can be set to arbitrary Fixnum value' do
2509+
it 'can be set to arbitrary Integer value' do
25102510
subject.get '/foo' do
25112511
status 210
25122512
end

spec/grape/dsl/inside_route_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ def initialize
126126
.to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
127127
end
128128

129-
it 'accepts unknown Fixnum status codes' do
129+
it 'accepts unknown Integer status codes' do
130130
expect { subject.status 210 }.to_not raise_error
131131
end
132132

133-
it 'raises error if status is not a fixnum or symbol' do
133+
it 'raises error if status is not a integer or symbol' do
134134
expect { subject.status Object.new }
135-
.to raise_error(ArgumentError, 'Status code must be Fixnum or Symbol.')
135+
.to raise_error(ArgumentError, 'Status code must be Integer or Symbol.')
136136
end
137137
end
138138

spec/grape/dsl/request_response_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def self.imbue(key, value)
131131
end
132132

133133
it 'abort if :with option value is not Symbol, String or Proc' do
134-
expect { subject.rescue_from :all, with: 1234 }.to raise_error(ArgumentError, 'with: Fixnum, expected Symbol, String or Proc')
134+
expect { subject.rescue_from :all, with: 1234 }.to raise_error(ArgumentError, "with: #{integer_class_name}, expected Symbol, String or Proc")
135135
end
136136

137137
it 'abort if both :with option and block are passed' do

spec/grape/validations/validators/allow_blank_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class API < Grape::API
5757
get '/allow_float_blank'
5858

5959
params do
60-
requires :val, type: Fixnum, allow_blank: true
60+
requires :val, type: Integer, allow_blank: true
6161
end
62-
get '/allow_fixnum_blank'
62+
get '/allow_integer_blank'
6363

6464
params do
6565
requires :val, type: Symbol, allow_blank: true
@@ -173,9 +173,9 @@ class API < Grape::API
173173
get '/allow_float_blank'
174174

175175
params do
176-
requires :val, type: Fixnum, allow_blank: true
176+
requires :val, type: Integer, allow_blank: true
177177
end
178-
get '/allow_fixnum_blank'
178+
get '/allow_integer_blank'
179179

180180
params do
181181
requires :val, type: Symbol, allow_blank: true
@@ -345,8 +345,8 @@ def app
345345
expect(last_response.status).to eq(200)
346346
end
347347

348-
it 'accepts empty when fixnum allow_blank' do
349-
get '/custom_message/allow_fixnum_blank', val: ''
348+
it 'accepts empty when integer allow_blank' do
349+
get '/custom_message/allow_integer_blank', val: ''
350350
expect(last_response.status).to eq(200)
351351
end
352352
end
@@ -483,8 +483,8 @@ def app
483483
expect(last_response.status).to eq(200)
484484
end
485485

486-
it 'accepts empty when fixnum allow_blank' do
487-
get '/allow_fixnum_blank', val: ''
486+
it 'accepts empty when integer allow_blank' do
487+
get '/allow_integer_blank', val: ''
488488
expect(last_response.status).to eq(200)
489489
end
490490
end

spec/grape/validations/validators/coerce_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class User
175175

176176
get '/int', int: '45'
177177
expect(last_response.status).to eq(200)
178-
expect(last_response.body).to eq('Fixnum')
178+
expect(last_response.body).to eq(integer_class_name)
179179
end
180180

181181
context 'Array' do
@@ -189,7 +189,7 @@ class User
189189

190190
get '/array', arry: %w(1 2 3)
191191
expect(last_response.status).to eq(200)
192-
expect(last_response.body).to eq('Fixnum')
192+
expect(last_response.body).to eq(integer_class_name)
193193
end
194194

195195
it 'Array of Bools' do
@@ -238,7 +238,7 @@ class User
238238

239239
get '/set', set: Set.new([1, 2, 3, 4]).to_a
240240
expect(last_response.status).to eq(200)
241-
expect(last_response.body).to eq('Fixnum')
241+
expect(last_response.body).to eq(integer_class_name)
242242
end
243243

244244
it 'Set of Bools' do
@@ -326,7 +326,7 @@ class User
326326

327327
get '/int', integers: { int: '45' }
328328
expect(last_response.status).to eq(200)
329-
expect(last_response.body).to eq('Fixnum')
329+
expect(last_response.body).to eq(integer_class_name)
330330
end
331331
end
332332

@@ -525,11 +525,11 @@ class User
525525

526526
get '/', splines: '{"x":"1","y":"woof"}'
527527
expect(last_response.status).to eq(200)
528-
expect(last_response.body).to eq('Fixnum.String')
528+
expect(last_response.body).to eq("#{integer_class_name}.String")
529529

530530
get '/', splines: '[{"x":1,"y":2},{"x":1,"y":"quack"}]'
531531
expect(last_response.status).to eq(200)
532-
expect(last_response.body).to eq('Fixnum.Fixnum')
532+
expect(last_response.body).to eq("#{integer_class_name}.#{integer_class_name}")
533533

534534
get '/', splines: '{"x":"4","y":"woof"}'
535535
expect(last_response.status).to eq(400)
@@ -576,7 +576,7 @@ class User
576576

577577
get '/', a: '5'
578578
expect(last_response.status).to eq(200)
579-
expect(last_response.body).to eq('Fixnum')
579+
expect(last_response.body).to eq(integer_class_name)
580580

581581
get '/', a: 'anything else'
582582
expect(last_response.status).to eq(200)

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
RSpec.configure do |config|
1818
config.include Rack::Test::Methods
19+
config.include Spec::Support::Helpers
1920
config.raise_errors_for_deprecations!
2021

2122
config.before(:each) { Grape::Util::InheritableSetting.reset_global! }

0 commit comments

Comments
 (0)