Skip to content

Commit

Permalink
Add specs for String coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
stanhu committed Mar 17, 2020
1 parent 43fd676 commit 109d1a5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/grape/validations/validators/coerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ def self.parsed?(value)
expect(last_response.body).to eq(integer_class_name)
end

it 'String' do
subject.params do
requires :string, coerce: String
end
subject.get '/string' do
params[:string].class
end

get '/string', string: 45
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('String')

get '/string', string: nil
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('NilClass')
end

it 'is a custom type' do
subject.params do
requires :uri, coerce: SecureURIOnly
Expand Down

0 comments on commit 109d1a5

Please sign in to comment.