spec/grape/validations/validators/presence_spec.rb in grape-1.2.5 vs spec/grape/validations/validators/presence_spec.rb in grape-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Grape::Validations::PresenceValidator do
subject do
Class.new(Grape::API) do
@@ -265,8 +267,36 @@
expect(last_response.body).to eq('Hello optional'.to_json)
get '/optional', name: 'Bob'
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('Hello optional'.to_json)
+ end
+ end
+
+ context 'with a custom type' do
+ it 'does not validate their type when it is missing' do
+ class CustomType
+ def self.parse(value)
+ return if value.blank?
+
+ new
+ end
+ end
+
+ subject.params do
+ requires :custom, type: CustomType
+ end
+ subject.get '/custom' do
+ 'custom'
+ end
+
+ get 'custom'
+
+ expect(last_response.status).to eq(400)
+ expect(last_response.body).to eq('{"error":"custom is missing"}')
+
+ get 'custom', custom: 'filled'
+
+ expect(last_response.status).to eq(200)
end
end
end