diff options
author | Akira Matsuda <ronnie@dio.jp> | 2013-10-23 22:01:14 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2013-10-23 22:10:15 +0900 |
commit | 68db6bc431fbff0b2291f1f60ccf974b4eece596 (patch) | |
tree | 83e3ceeaa83e20ed65071aea33637826026d3464 /activemodel/lib/active_model/validations | |
parent | dc8a20677d820aa09413c6a3e25c9d70ba24561a (diff) | |
download | rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.tar.gz rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.tar.bz2 rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.zip |
Let validates_inclusion_of accept Time and DateTime ranges
fixes 4.0.0 regression introduced in 0317b93c17a46d7663a8c36edc26ad0ba3d75f85
Diffstat (limited to 'activemodel/lib/active_model/validations')
-rw-r--r-- | activemodel/lib/active_model/validations/clusivity.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb index 1c35cb7c35..fd6cc1edb4 100644 --- a/activemodel/lib/active_model/validations/clusivity.rb +++ b/activemodel/lib/active_model/validations/clusivity.rb @@ -30,12 +30,18 @@ module ActiveModel @delimiter ||= options[:in] || options[:within] end - # In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the - # range for equality, which is slower but more accurate. <tt>Range#cover?</tt> uses - # the previous logic of comparing a value with the range endpoints, which is fast - # but is only accurate on numeric ranges. + # In Ruby 1.9 <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all + # possible values in the range for equality, which is slower but more accurate. + # <tt>Range#cover?</tt> uses the previous logic of comparing a value with the range + # endpoints, which is fast but is only accurate on Numeric, Time, or DateTime ranges. def inclusion_method(enumerable) - (enumerable.is_a?(Range) && enumerable.first.is_a?(Numeric)) ? :cover? : :include? + return :include? unless enumerable.is_a?(Range) + case enumerable.first + when Numeric, Time, DateTime + :cover? + else + :include? + end end end end |