Skip to content

Commit

Permalink
Merge pull request #1650 from tiarly/add_boolean_specs
Browse files Browse the repository at this point in the history
Add extra specs for Boolean type field
  • Loading branch information
dblock committed Jul 3, 2017
2 parents 108dc5c + a6ba585 commit ee5de31
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* [#1635](https://github.com/ruby-grape/grape/pull/1635): Instrument validators with ActiveSupport::Notifications - [@ktimothy](https://github.com/ktimothy).
* [#1646](https://github.com/ruby-grape/grape/pull/1646): Add ability to include an array of modules as helpers - [@pablonahuelgomez](https://github.com/pablonahuelgomez).
* [#1623](https://github.com/ruby-grape/grape/pull/1623): Removed `multi_json` and `multi_xml` dependencies - [@dblock](https://github.com/dblock).
* [#1650](https://github.com/ruby-grape/grape/pull/1650): Add extra specs for Boolean type field - [@tiarly](https://github.com/tiarly).
* Your contribution here.

#### Fixes
Expand Down
37 changes: 37 additions & 0 deletions spec/grape/validations/validators/coerce_spec.rb
Expand Up @@ -280,6 +280,43 @@ class User
expect(last_response.body).to eq('TrueClass')
end

it 'Boolean' do
subject.params do
optional :boolean, type: Boolean, default: true
end
subject.get '/boolean' do
params[:boolean].class
end

get '/boolean'
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('TrueClass')

get '/boolean', boolean: true
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('TrueClass')

get '/boolean', boolean: false
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('FalseClass')

get '/boolean', boolean: 'true'
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('TrueClass')

get '/boolean', boolean: 'false'
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('FalseClass')

get '/boolean', boolean: 123
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('boolean is invalid')

get '/boolean', boolean: '123'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('boolean is invalid')
end

it 'Rack::Multipart::UploadedFile' do
subject.params do
requires :file, type: Rack::Multipart::UploadedFile
Expand Down

0 comments on commit ee5de31

Please sign in to comment.