spec/grape/api/custom_validations_spec.rb in grape-1.2.5 vs spec/grape/api/custom_validations_spec.rb in grape-1.3.0
- old
+ new
@@ -1,16 +1,18 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Grape::Validations do
context 'using a custom length validator' do
before do
module CustomValidationsSpec
class DefaultLength < Grape::Validations::Base
def validate_param!(attr_name, params)
@option = params[:max].to_i if params.key?(:max)
return if params[attr_name].length <= @option
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long"
+ raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long")
end
end
end
end
subject do
@@ -85,11 +87,11 @@
context 'using a custom validator with message_key' do
before do
module CustomValidationsSpec
class WithMessageKey < Grape::Validations::PresenceValidator
def validate_param!(attr_name, _params)
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: :presence
+ raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: :presence)
end
end
end
end
subject do
@@ -124,10 +126,10 @@
return unless request.params.key? @attrs.first
# check if admin flag is set to true
return unless @option
# check if user is admin or not
# as an example get a token from request and check if it's admin or not
- raise Grape::Exceptions::Validation, params: @attrs, message: 'Can not set Admin only field.' unless request.headers['X-Access-Token'] == 'admin'
+ raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers['X-Access-Token'] == 'admin'
end
end
end
end
subject do