1. 03 7月, 2016 1 次提交
    • V
      `travel/travel_to` travel time helpers, now raise on nested calls, · 919e7053
      Vipul A M 提交于
           as this can lead to confusing time stubbing.
      
           Instead of:
      
               travel_to 2.days.from_now do
                 # 2 days from today
                 travel_to 3.days.from_now do
                   # 5 days from today
                 end
               end
      
           preferred way to achieve above is:
      
               travel_to 2.days.from_now
               # 2 days from today
      
               travel_back
               travel_to 5.days.from_now
               # 5 days from today
      
      Closes #24690
      Fixes #24689
      919e7053
  2. 27 6月, 2016 1 次提交
  3. 23 6月, 2016 1 次提交
  4. 14 6月, 2016 1 次提交
  5. 02 6月, 2016 1 次提交
    • S
      Don't blank pad day of the month when formatting dates · 2c5a8ba6
      Sean Griffin 提交于
      We are currently using `%e` which adds a space before the result if the
      digit is a single number. This leads to strings like `February  2, 2016`
      which is undesireable. I've opted to replace with 0 padding instead of
      removing the padding entirely, to preserve compatibility for those
      relying on the fact that the width is constant, and to be consistent
      with time formatting.
      
      Fixes #25251.
      2c5a8ba6
  6. 16 5月, 2016 1 次提交
    • J
      Action Mailer: Declarative exception handling with `rescue_from`. · e35b98e6
      Jeremy Daer 提交于
      Follows the same pattern as controllers and jobs. Exceptions raised in
      delivery jobs (enqueued by `#deliver_later`) are also delegated to the
      mailer's rescue_from handlers, so you can handle the DeserializationError
      raised by delivery jobs:
      
      ```ruby
      class MyMailer < ApplicationMailer
        rescue_from ActiveJob::DeserializationError do
          …
        end
      ```
      
      ActiveSupport::Rescuable polish:
      * Add the `rescue_with_handler` class method so exceptions may be
        handled at the class level without requiring an instance.
      * Rationalize `exception.cause` handling. If no handler matches the
        exception, fall back to the handler that matches its cause.
      * Handle exceptions raised elsewhere. Pass `object: …` to execute
        the `rescue_from` handler (e.g. a method call or a block to
        instance_exec) against a different object. Defaults to `self`.
      e35b98e6
  7. 10 5月, 2016 1 次提交
  8. 07 5月, 2016 1 次提交
  9. 30 4月, 2016 1 次提交
  10. 28 4月, 2016 3 次提交
  11. 26 4月, 2016 1 次提交
    • A
      Do not cache ActiveSupport::TimeZone#utc_offset · 420730b1
      Alexey Shein 提交于
      This can be an issue when TZInfo::TimeZone#current_period is refreshed
      due to timezone period transition, but it's not reflected in
      ActiveSupport::TimeZone object.
      
      For example, on Sun, 26 Oct 2014 22:00 UTC, Moscow changed its TZ from
      MSK +04:00 to MSK +03:00 (-1 hour). If ActiveSupport::TimeZone['Moscow']
      happens to be initialized just before the timezone transition, it will
      cache its stale utc_offset even after the timezone transition.
      
      This commit removes cache and fixes this issue.
      Signed-off-by: NJeremy Daer <jeremydaer@gmail.com>
      420730b1
  12. 24 4月, 2016 6 次提交
  13. 23 4月, 2016 1 次提交
  14. 20 4月, 2016 1 次提交
  15. 19 4月, 2016 3 次提交
    • J
      92d7a4e3
    • J
      Ruby 2.4: compat with new Array#sum · 7ad4690b
      Jeremy Daer 提交于
      Ruby 2.4 introduces `Array#sum`, but it only supports numeric elements,
      breaking our `Enumerable#sum` which supports arbitrary `Object#+`.
      To fix, override `Array#sum` with our compatible implementation.
      
      Native Ruby 2.4:
      
          %w[ a b ].sum
          # => TypeError: String can't be coerced into Fixnum
      
      With `Enumerable#sum` shim:
      
          %w[ a b ].sum
          # => 'ab'
      
      We tried shimming the fast path and falling back to the compatible path
      if it fails, but that ends up slower even in simple causes due to the cost
      of exception handling. Our only choice is to override the native `Array#sum`
      with our `Enumerable#sum`.
      7ad4690b
    • A
      `ActiveSupport::Duration` supports ISO8601 formatting and parsing. · 04c512da
      Arnau Siches, Andrey Novikov 提交于
      ```ruby
      ActiveSupport::Duration.parse('P3Y6M4DT12H30M5S')
      
      (3.years + 3.days).iso8601
      ```
      
      Inspired by Arnau Siches' [ISO8601 gem](https://github.com/arnau/ISO8601/)
      and rewritten by Andrey Novikov with suggestions from Andrew White. Test
      data from the ISO8601 gem redistributed under MIT license.
      
      (Will be used to support the PostgreSQL interval data type.)
      04c512da
  16. 18 4月, 2016 2 次提交
  17. 09 4月, 2016 1 次提交
  18. 04 4月, 2016 2 次提交
    • S
      Match `String#to_time`'s behaviour to ruby · 9c2c677d
      Siim Liiser 提交于
      Previously `String#to_time` returned the midnight of the current date
      in some cases where there was no relavant information in the string.
      Now the method returns `nil` instead in those cases.
      
      Fixes #22958.
      9c2c677d
    • A
      Call super instead of returning nil for DateTime#<=> · 08073125
      Andrew White 提交于
      The native DateTime#<=> implementation can be used to compare instances
      with numeric values being considered as astronomical julian day numbers
      so we should call that instead of returning nil.
      
      Fixes #24228.
      08073125
  19. 02 4月, 2016 1 次提交
    • P
      `number_to_phone` formats number with regexp · 4e977da5
      Pan GaoYong 提交于
      By default, this method formats US number. This commit extends its
      functionality to format number for other countries with a custom regular
      expression.
      
          number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/)
          # => 188-1234-5678
      
      The output phone number is divided into three groups, so the regexp
      should also match three groups of numbers.
      4e977da5
  20. 01 4月, 2016 1 次提交
  21. 25 3月, 2016 1 次提交
  22. 22 3月, 2016 1 次提交
  23. 11 3月, 2016 1 次提交
    • O
      Prevent `Marshal.load` from looping infinitely · aa0fad51
      Olek Janiszewski 提交于
      Fix a bug in `Marshal.load` that caused it to loop indefinitely when
      trying to autoload a constant that resolved to a different name.
      
      This could occur when marshalling an ActiveRecord 4.0 object (e.g. into
      memcached) and then trying to unmarshal it with Rails 4.2. The
      marshalled payload contains a reference to
      `ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column`, which in
      Rails 4.2 resolves to
      `ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column`.
      aa0fad51
  24. 03 3月, 2016 1 次提交
  25. 01 3月, 2016 2 次提交
  26. 28 2月, 2016 1 次提交
    • G
      Introduce Module#delegate_missing_to · 335fcc21
      Genadi Samokovarov 提交于
      When building decorators, a common pattern may emerge:
      
          class Partition
            def initialize(first_event)
              @events = [ first_event ]
            end
      
            def people
              if @events.first.detail.people.any?
                @events.collect { |e| Array(e.detail.people) }.flatten.uniq
              else
                @events.collect(&:creator).uniq
              end
            end
      
            private
              def respond_to_missing?(name, include_private = false)
                @events.respond_to?(name, include_private)
              end
      
              def method_missing(method, *args, &block)
                @events.send(method, *args, &block)
              end
          end
      
      With `Module#delegate_missing_to`, the above is condensed to:
      
          class Partition
            delegate_missing_to :@events
      
            def initialize(first_event)
              @events = [ first_event ]
            end
      
            def people
              if @events.first.detail.people.any?
                @events.collect { |e| Array(e.detail.people) }.flatten.uniq
              else
                @events.collect(&:creator).uniq
              end
            end
          end
      
      David suggested it in #23824.
      335fcc21
  27. 26 2月, 2016 1 次提交
  28. 25 2月, 2016 1 次提交