-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix blank error message when allow_blank is false and value is blank #934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,16 @@ def self.raise_if_missing_params | |
|
||
# check if value is valid | ||
def valid?(value) | ||
if param_description.is_a?(Apipie::ParamDescription) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some time param_description to be i will fix if test code is bad |
||
if (param_description.options[:allow_nil] == false) && value.nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pass when param_description.options[:allow_nil] value is nil, only false |
||
@error_value = nil | ||
return false | ||
elsif (param_description.options[:allow_blank] == false) && value.blank? | ||
@error_value = 'blank' | ||
return false | ||
end | ||
end | ||
|
||
if self.validate(value) | ||
@error_value = nil | ||
true | ||
|
@@ -480,6 +490,9 @@ def self.validate(value) | |
end | ||
|
||
class BooleanValidator < BaseValidator | ||
def valid?(value) | ||
validate(value) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much value putting this in multiple validator ? |
||
|
||
def validate(value) | ||
%w[true false 1 0].include?(value.to_s) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
class CustomBoolValidator < Apipie::Validator::BaseValidator | ||
def valid?(value) | ||
validate(value) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. method alias or do without entirely? |
||
|
||
def validate(value) | ||
value.in?([true, false]) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we can remove the
!allow_nil
check and theblank_forbidden?
check.I think they were added for a reason...
I don't understand what problem we are trying to fix here.