Skip to content

Commit 109d1a5

Browse files
committed
Add specs for String coercion
1 parent 43fd676 commit 109d1a5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spec/grape/validations/validators/coerce_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ def self.parsed?(value)
180180
expect(last_response.body).to eq(integer_class_name)
181181
end
182182

183+
it 'String' do
184+
subject.params do
185+
requires :string, coerce: String
186+
end
187+
subject.get '/string' do
188+
params[:string].class
189+
end
190+
191+
get '/string', string: 45
192+
expect(last_response.status).to eq(200)
193+
expect(last_response.body).to eq('String')
194+
195+
get '/string', string: nil
196+
expect(last_response.status).to eq(200)
197+
expect(last_response.body).to eq('NilClass')
198+
end
199+
183200
it 'is a custom type' do
184201
subject.params do
185202
requires :uri, coerce: SecureURIOnly

0 commit comments

Comments
 (0)