-
Notifications
You must be signed in to change notification settings - Fork 4
Add error when attribute is present but value is nil and has no default #78
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -51,13 +51,15 @@ def raise_unauthorized(message = 'Unauthorized') | |
end | ||
|
||
def check_validation | ||
fail Pavlov::ValidationError, "Missing arguments: #{missing_arguments.inspect}" if missing_arguments.any? | ||
check_missing_arguments | ||
validate | ||
end | ||
|
||
def missing_arguments | ||
attribute_set.select do |attribute| | ||
!attribute.options.key?(:default) && send(attribute.name).nil? | ||
def check_missing_arguments | ||
attribute_set.each do |attribute| | ||
if !attribute.options.key?(:default) && send(attribute.name).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. isn't there a way which checks whether the argument was passed in? This way you cannot pass in nil anywhere (except when this is an explicit default). That's no missing argument. We might want to check for nils as well, but I'm not totally sure. If there is no other way to check missing arguments this is fine though. 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. When I originally wrote this code I couldn't find any way, but maybe the newer Virtus has more support for this. If nothing else, we could hook into the initializer now, and set all non-passed-in attributes to a |
||
errors.add(attribute.name.to_s, "can't be blank") | ||
end | ||
end | ||
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.
We probably want a line in UPGRADING to inform people that we will no longer raise this exact exception.