diff --git a/UPGRADING.md b/UPGRADING.md index 4b4ed33..34c2416 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,5 +1,7 @@ ## HEAD +* No longer raises `Pavlov::ValidationError, "Missing arguments:` when an argument is nil but adds an error. + # 0.1.8 * Let custom validations use errors.add instead of raising exceptions diff --git a/lib/pavlov/operation.rb b/lib/pavlov/operation.rb index 3d02276..4ec3949 100644 --- a/lib/pavlov/operation.rb +++ b/lib/pavlov/operation.rb @@ -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? + errors.add(attribute.name.to_s, "can't be blank") + end end end diff --git a/spec/regression/case2_spec.rb b/spec/regression/case2_spec.rb index 834886b..89570c9 100755 --- a/spec/regression/case2_spec.rb +++ b/spec/regression/case2_spec.rb @@ -28,7 +28,7 @@ def list def members_to_remove list.zrange(0, -1).select do |id| activity = Activity[id] - ! valid(activity) + !valid(activity) end end diff --git a/spec/regression/case4_spec.rb b/spec/regression/case4_spec.rb index 21599cf..3b0ada0 100644 --- a/spec/regression/case4_spec.rb +++ b/spec/regression/case4_spec.rb @@ -15,7 +15,7 @@ class Interactors::ExampleModule::FollowUser arguments :user_name, :user_to_follow_user_name def authorized? - (!! pavlov_options[:current_user]) && (pavlov_options[:current_user].username == user_name) + (!!pavlov_options[:current_user]) && (pavlov_options[:current_user].username == user_name) end def user diff --git a/spec/regression/case5_spec.rb b/spec/regression/case5_spec.rb index df7e33a..35f3352 100644 --- a/spec/regression/case5_spec.rb +++ b/spec/regression/case5_spec.rb @@ -15,7 +15,7 @@ class Interactors::ExampleModule::Followers arguments :user_name, :skip, :take def authorized? - !! pavlov_options[:current_user] + !!pavlov_options[:current_user] end def validate