diff options
author | Adam Keys <adam@therealadam.com> | 2009-08-08 16:35:03 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 23:42:18 +0100 |
commit | 5632b36701ad9514d596c558877cd74c14c1d54b (patch) | |
tree | 5f8bd9d896c63cde9e73cb65b1f33a71b08f3c1d /activemodel/lib | |
parent | bee3e099bd3f4038f8a4122ad48446a232cbf21a (diff) | |
download | rails-5632b36701ad9514d596c558877cd74c14c1d54b.tar.gz rails-5632b36701ad9514d596c558877cd74c14c1d54b.tar.bz2 rails-5632b36701ad9514d596c558877cd74c14c1d54b.zip |
Fix exclusive range patch to use begin/end instead of min/max. [#2981 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 3e76796355..e91841bd1c 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -66,10 +66,14 @@ module ActiveModel validates_each(attrs, options) do |record, attr, value| value = options[:tokenizer].call(value) if value.kind_of?(String) - if value.nil? or value.size < option_value.begin - record.errors.add(attr, :too_short, :default => custom_message || options[:too_short], :count => option_value.begin) - elsif value.size > option_value.end - record.errors.add(attr, :too_long, :default => custom_message || options[:too_long], :count => option_value.end) + + min, max = option_value.begin, option_value.end + max = max - 1 if option_value.exclude_end? + + if value.nil? || value.size < min + record.errors.add(attr, :too_short, :default => custom_message || options[:too_short], :count => min) + elsif value.size > max + record.errors.add(attr, :too_long, :default => custom_message || options[:too_long], :count => max) end end when :is, :minimum, :maximum |