spec/grape/api/custom_validations_spec.rb in grape-0.13.0 vs spec/grape/api/custom_validations_spec.rb in grape-0.14.0
- old
+ new
@@ -1,12 +1,13 @@
require 'spec_helper'
describe Grape::Validations do
before do
- class DefaultLength < Grape::Validations::Base
- def validate_param!(attr_name, params)
- @option = params[:max].to_i if params.key?(:max)
- unless params[attr_name].length <= @option
+ 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
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long"
end
end
end
end