diff options
Diffstat (limited to 'activemodel/lib/active_model')
| -rw-r--r-- | activemodel/lib/active_model/errors.rb | 15 | ||||
| -rw-r--r-- | activemodel/lib/active_model/gem_version.rb | 2 | ||||
| -rw-r--r-- | activemodel/lib/active_model/type.rb | 2 | ||||
| -rw-r--r-- | activemodel/lib/active_model/type/decimal.rb | 12 | ||||
| -rw-r--r-- | activemodel/lib/active_model/validations/clusivity.rb | 7 | ||||
| -rw-r--r-- | activemodel/lib/active_model/validator.rb | 4 | 
6 files changed, 28 insertions, 14 deletions
| diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index ef6141a51d..836201535f 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -110,7 +110,7 @@ module ActiveModel      #   person.errors.include?(:name) # => true      #   person.errors.include?(:age)  # => false      def include?(attribute) -      messages[attribute].present? +      messages.key?(attribute) && messages[attribute].present?      end      alias :has_key? :include?      alias :key? :include? @@ -160,6 +160,15 @@ module ActiveModel      #      #   person.errors[:name]  # => ["cannot be nil"]      #   person.errors['name'] # => ["cannot be nil"] +    # +    # Note that, if you try to get errors of an attribute which has +    # no errors associated with it, this method will instantiate +    # an empty error list for it and +keys+ will return an array +    # of error keys which includes this attribute. +    # +    #   person.errors.keys    # => [] +    #   person.errors[:name]  # => [] +    #   person.errors.keys    # => [:name]      def [](attribute)        messages[attribute.to_sym]      end @@ -318,7 +327,7 @@ module ActiveModel      #   # => {:base=>[{error: :name_or_email_blank}]}      def add(attribute, message = :invalid, options = {})        message = message.call if message.respond_to?(:call) -      detail  = normalize_detail(attribute, message, options) +      detail  = normalize_detail(message, options)        message = normalize_message(attribute, message, options)        if exception = options[:strict]          exception = ActiveModel::StrictValidationFailed if exception == true @@ -493,7 +502,7 @@ module ActiveModel        end      end -    def normalize_detail(attribute, message, options) +    def normalize_detail(message, options)        { error: message }.merge(options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS))      end    end diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb index 94514a0657..62862aa4e9 100644 --- a/activemodel/lib/active_model/gem_version.rb +++ b/activemodel/lib/active_model/gem_version.rb @@ -8,7 +8,7 @@ module ActiveModel      MAJOR = 5      MINOR = 0      TINY  = 0 -    PRE   = "beta2" +    PRE   = "beta3"      STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")    end diff --git a/activemodel/lib/active_model/type.rb b/activemodel/lib/active_model/type.rb index bec851594f..6ec3452478 100644 --- a/activemodel/lib/active_model/type.rb +++ b/activemodel/lib/active_model/type.rb @@ -47,7 +47,7 @@ module ActiveModel      register(:binary, Type::Binary)      register(:boolean, Type::Boolean)      register(:date, Type::Date) -    register(:date_time, Type::DateTime) +    register(:datetime, Type::DateTime)      register(:decimal, Type::Decimal)      register(:float, Type::Float)      register(:immutable_string, Type::ImmutableString) diff --git a/activemodel/lib/active_model/type/decimal.rb b/activemodel/lib/active_model/type/decimal.rb index d19d8baada..11ea327026 100644 --- a/activemodel/lib/active_model/type/decimal.rb +++ b/activemodel/lib/active_model/type/decimal.rb @@ -29,12 +29,12 @@ module ActiveModel            end          end -        scale ? casted_value.round(scale) : casted_value +        apply_scale(casted_value)        end        def convert_float_to_big_decimal(value)          if precision -          BigDecimal(value, float_precision) +          BigDecimal(apply_scale(value), float_precision)          else            value.to_d          end @@ -47,6 +47,14 @@ module ActiveModel            precision.to_i          end        end + +      def apply_scale(value) +        if scale +          value.round(scale) +        else +          value +        end +      end      end    end  end diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb index bad9e4f9a9..d49af603bb 100644 --- a/activemodel/lib/active_model/validations/clusivity.rb +++ b/activemodel/lib/active_model/validations/clusivity.rb @@ -30,14 +30,15 @@ module ActiveModel          @delimiter ||= options[:in] || options[:within]        end -      # In Ruby 1.9 <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all +      # In Ruby 2.2 <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. +      # endpoints, which is fast but is only accurate on Numeric, Time, Date, +      # or DateTime ranges.        def inclusion_method(enumerable)          if enumerable.is_a? Range            case enumerable.first -          when Numeric, Time, DateTime +          when Numeric, Time, DateTime, Date              :cover?            else              :include? diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 1d2888a818..109bf038b0 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -163,10 +163,6 @@ module ActiveModel      # +ArgumentError+ when invalid options are supplied.      def check_validity!      end - -    def should_validate?(record) # :nodoc: -      !record.persisted? || record.changed? || record.marked_for_destruction? -    end    end    # +BlockValidator+ is a special +EachValidator+ which receives a block on initialization | 
