1. 10 1月, 2017 1 次提交
    • A
      Fix inconsistent results when parsing large durations and constructing durations from code · cb9d0e48
      Andrey Novikov 提交于
          ActiveSupport::Duration.parse('P3Y') == 3.years # It should be true
      
      Duration parsing made independent from any moment of time:
      Fixed length in seconds is assigned to each duration part during parsing.
      
      Changed duration of months and years in seconds to more accurate and logical:
      
       1. The value of 365.2425 days in Gregorian year is more accurate
          as it accounts for every 400th non-leap year.
      
       2. Month's length is bound to year's duration, which makes
          sensible comparisons like `12.months == 1.year` to be `true`
          and nonsensical ones like `30.days == 1.month` to be `false`.
      
      Calculations on times and dates with durations shouldn't be affected as
      duration's numeric value isn't used in calculations, only parts are used.
      
      Methods on `Numeric` like `2.days` now use these predefined durations
      to avoid duplicating of duration constants through the codebase and
      eliminate creation of intermediate durations.
      cb9d0e48
  2. 22 12月, 2016 1 次提交
  3. 13 12月, 2016 1 次提交
  4. 15 11月, 2016 2 次提交
  5. 14 11月, 2016 7 次提交
  6. 01 11月, 2016 1 次提交
    • A
      Ensure duration parsing is consistent across DST changes · 8931916f
      Andrew White 提交于
      Previously `ActiveSupport::Duration.parse` used `Time.current` and
      `Time#advance` to calculate the number of seconds in the duration
      from an arbitrary collection of parts. However as `advance` tries to
      be consistent across DST boundaries this meant that either the
      duration was shorter or longer depending on the time of year.
      
      This was fixed by using an absolute reference point in UTC which
      isn't subject to DST transitions. An arbitrary date of Jan 1st, 2000
      was chosen for no other reason that it seemed appropriate.
      
      Additionally, duration parsing should now be marginally faster as we
      are no longer creating instances of `ActiveSupport::TimeWithZone`
      every time we parse a duration string.
      
      Fixes #26941.
      8931916f
  7. 23 10月, 2016 1 次提交
  8. 21 10月, 2016 1 次提交
  9. 20 10月, 2016 1 次提交
    • J
      Fix copy_time_to: Copy nsec instead of usec · fc72d681
      Josua Schmid 提交于
      `copy_time_to` is a helper function for date and time calculations.
      It's being used by `prev_week`, `next_week` and `prev_weekday` to keep
      the time fraction when jumping around between days.
      
      Previously the nanoseconds part was lost during the operation. This
      lead to problems in practice if you were using the `end_of_day`
      calculation. Resulting in the time fraction of `end_of_day` not being
      the same as next week's `end_of_day`.
      
      With this fix `copy_time_to` doesn't forget the `nsec` digits.
      fc72d681
  10. 03 10月, 2016 1 次提交
  11. 01 10月, 2016 1 次提交
    • T
      Fix `ActiveSupport::TimeWithZone#localtime` · 607a6c7a
      Thomas Balthazar 提交于
      Previously memoization in `localtime` wasn't taking the `utc_offset`
      parameter into account when returning a cached value. It now caches the
      computed value depending on the `utc_offset` parameter, e.g:
      
          Time.zone = "US/Eastern"
      
          t = Time.zone.local(2016,5,2,11)
          # => Mon, 02 May 2016 11:00:00 EDT -04:00
      
          t.localtime(-7200)
          # => 2016-05-02 13:00:00 -0200
      
          t.localtime(-3600)
          # => 2016-05-02 14:00:00 -0100
      607a6c7a
  12. 24 9月, 2016 1 次提交
    • T
      Fix ActiveSupport::TimeWithZone#in · 76c2553b
      Thomas Balthazar 提交于
      Previously calls to `in` were being sent to the non-DST aware
      method `Time#since` via `method_missing`. It is now aliased to
      the DST aware `ActiveSupport::TimeWithZone#+` which handles
      transitions across DST boundaries, e.g:
      
          Time.zone = "US/Eastern"
      
          t = Time.zone.local(2016,11,6,1)
          # => Sun, 06 Nov 2016 01:00:00 EDT -05:00
      
          t.in(1.hour)
          # => Sun, 06 Nov 2016 01:00:00 EST -05:00
      76c2553b
  13. 10 8月, 2016 1 次提交
  14. 04 8月, 2016 1 次提交
    • W
      Fix `thread_mattr_accessor` share variable superclass with subclass · 3529e58e
      willnet 提交于
      The current implementation of `thread_mattr_accessor` set variable
      sharing superclass with subclass. So the method doesn't work as documented.
      
      Precondition
      
          class Account
            thread_mattr_accessor :user
          end
      
          class Customer < Account
          end
      
          Account.user = "DHH"
          Account.user  #=> "DHH"
          Customer.user = "Rafael"
          Customer.user # => "Rafael"
      
      Documented behavior
      
          Account.user  # => "DHH"
      
      Actual behavior
      
          Account.user  # => "Rafael"
      
      Current implementation set variable statically likes `Thread[:attr_Account_user]`,
      and customer also use it.
      
      Make variable name dynamic to use own thread-local variable.
      3529e58e
  15. 03 8月, 2016 1 次提交
  16. 30 7月, 2016 1 次提交
  17. 22 7月, 2016 4 次提交
  18. 17 7月, 2016 1 次提交
    • G
      Introduce `assert_changes` and `assert_no_changes` · 16f24cd1
      Genadi Samokovarov 提交于
      Those are assertions that I really do miss from the standard
      `ActiveSupport::TestCase`. Think of those as a more general version of
      `assert_difference` and `assert_no_difference` (those can be implemented
      by assert_changes, should this change be accepted).
      
      Why do we need those? They are useful when you want to check a
      side-effect of an operation. `assert_difference` do cover a really
      common case, but we `assert_changes` gives us more control. Having a
      global error flag? You can test it easily with `assert_changes`. In
      fact, you can be really specific about the initial state and the
      terminal one.
      
      ```ruby
      error = Error.new(:bad)
      assert_changes -> { Error.current }, from: nil, to: error do
        expected_bad_operation
      end
      ```
      
      `assert_changes` follows `assert_difference` and a string can be given
      for evaluation as well.
      
      ```ruby
      error = Error.new(:bad)
      assert_changes 'Error.current', from: nil, to: error do
        expected_bad_operation
      end
      ```
      
      Check out the test cases if you wanna see more examples.
      
      🍻
      16f24cd1
  19. 14 7月, 2016 1 次提交
  20. 12 7月, 2016 1 次提交
  21. 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
  22. 02 7月, 2016 1 次提交
  23. 27 6月, 2016 1 次提交
  24. 23 6月, 2016 1 次提交
  25. 14 6月, 2016 1 次提交
  26. 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
  27. 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
  28. 10 5月, 2016 1 次提交
  29. 07 5月, 2016 1 次提交
  30. 30 4月, 2016 1 次提交