show restriction errors in Rails test mode by default.

or always if not using Rails
This commit is contained in:
Adam Meehan 2010-08-03 18:28:00 +10:00
parent 048bf3ba6c
commit 81030a6ed8
2 changed files with 6 additions and 10 deletions

View File

@ -128,20 +128,16 @@ The value should be an array of 3 values being year, month and day in that order
=== TEMPORAL RESTRICTION ERRORS:
When using the validation temporal restrictions there are times when the restriction
value itself may be invalid. Normally this will add an error to the model such as
'restriction :before value was invalid'. These can be annoying if you are using
procs or methods as restrictions and don't care if they don't evaluate properly
and you want the validation to complete. In these situations you turn them off.
option value itself may be invalid. This will add an error to the model such as
'Error occurred validating birth_date for :before restriction'. These can be annoying
in development or production as you most likely just want to skip the option if no
valid value was returned. By default these errors are displayed in Rails test mode.
To turn them off:
To turn them on/off:
# in the setup block
config.ignore_restriction_errors = true
A word of warning though, as this may hide issues with the model and make those
corner cases a little harder to test. In general if you are using procs or
model methods and you only care when they return a value, then they should
return nil in all other situations. Restrictions are skipped if they are nil.
=== DISPLAY INVALID VALUES IN DATE/TIME SELECT HELPERS:

View File

@ -24,7 +24,7 @@ module ValidatesTimeliness
# Ignore errors when restriction options are evaluated
mattr_accessor :ignore_restriction_errors
@@ignore_restriction_errors = false
@@ignore_restriction_errors = defined?(Rails) ? !Rails.env.test? : false
# Setup method for plugin configuration
def self.setup