CHANGELOG.md 5.9 KB
Newer Older
1 2 3 4 5 6
*   Remove unused parameter `options = nil` for `#clear` of
    `ActiveSupport::Cache::Strategy::LocalCache::LocalStore` and
    `ActiveSupport::Cache::Strategy::LocalCache`.

    *Yosuke Kabuto*

7
*   Fix `thread_mattr_accessor` subclass no longer overwrites parent.
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    Assigning a value to a subclass using `thread_mattr_accessor` no
    longer changes the value of the parent class. This brings the
    behavior inline with the documentation.

    Given:

        class Account
          thread_mattr_accessor :user
        end

        class Customer < Account
        end

        Account.user = "DHH"
        Customer.user = "Rafael"

    Before:

        Account.user  # => "Rafael"

    After:

        Account.user  # => "DHH"
32 33 34

    *Shinichi Maeshima*

35 36 37 38 39 40 41 42
*   Since weeks are no longer converted to days, add `:weeks` to the list of
    parts that `ActiveSupport::TimeWithZone` will recognize as possibly being
    of variable duration to take account of DST transitions.

    Fixes #26039.

    *Andrew White*

X
Xavier Noria 已提交
43
*   Defines `Regexp.match?` for Ruby versions prior to 2.4. The predicate
44
    has the same interface, but it does not have the performance boost. Its
X
Xavier Noria 已提交
45 46 47 48
    purpose is to be able to write 2.4 compatible code.

    *Xavier Noria*

V
Vipul A M 已提交
49
*   Allow `MessageEncryptor` to take advantage of authenticated encryption modes.
50 51

    AEAD modes like `aes-256-gcm` provide both confidentiality and data
V
Vipul A M 已提交
52
    authenticity, eliminating the need to use `MessageVerifier` to check if the
53 54 55 56 57
    encrypted data has been tampered with. This speeds up encryption/decryption
    and results in shorter cipher text.

    *Bart de Water*

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
*   Introduce `assert_changes` and `assert_no_changes`.

    `assert_changes` is a more general `assert_difference` that works with any
    value.

        assert_changes 'Error.current', from: nil, to: 'ERR' do
          expected_bad_operation
        end

    Can be called with strings, to be evaluated in the binding (context) of
    the block given to the assertion, or a lambda.

        assert_changes -> { Error.current }, from: nil, to: 'ERR' do
          expected_bad_operation
        end

    The `from` and `to` arguments are compared with the case operator (`===`).

        assert_changes 'Error.current', from: nil, to: Error do
          expected_bad_operation
        end

    This is pretty useful, if you need to loosely compare a value. For example,
    you need to test a token has been generated and it has that many random
    characters.

        user = User.start_registration
        assert_changes 'user.token', to: /\w{32}/ do
          user.finish_registration
        end

    *Genadi Samokovarov*

91 92 93 94 95 96
*   Add `:fallback_string` option to `Array#to_sentence`. If an empty array
    calls the function and a fallback string option is set then it returns the
    fallback string other than an empty string.

    *Mohamed Osama*

97 98 99 100 101 102 103 104 105
*   Fix `ActiveSupport::TimeZone#strptime`. Now raises `ArgumentError` when the
    given time doesn't match the format. The error is the same as the one given
    by Ruby's `Date.strptime`. Previously it raised
    `NoMethodError: undefined method empty? for nil:NilClass.` due to a bug.

    Fixes #25701.

    *John Gesimondo*

X
Xavier Noria 已提交
106
*   `travel/travel_to` travel time helpers, now raise on nested calls,
107
     as this can lead to confusing time stubbing.
108

109
     Instead of:
110

111 112 113 114
         travel_to 2.days.from_now do
           # 2 days from today
           travel_to 3.days.from_now do
             # 5 days from today
115
           end
116 117 118 119
         end

     preferred way to achieve above is:

X
Xavier Noria 已提交
120
         travel 2.days do
121 122
           # 2 days from today
         end
123 124 125 126 127

         travel 5.days do
           # 5 days from today
         end

128 129
     *Vipul A M*

130 131 132 133 134 135
*   Support parsing JSON time in ISO8601 local time strings in
    `ActiveSupport::JSON.decode` when `parse_json_times` is enabled.
    Strings in the format of `YYYY-MM-DD hh:mm:ss` (without a `Z` at
    the end) will be parsed in the local timezone (`Time.zone`). In
    addition, date strings (`YYYY-MM-DD`) are now parsed into `Date`
    objects.
136 137 138

    *Grzegorz Witek*

K
Kevin McPhillips 已提交
139 140 141 142 143 144
*   Fixed `ActiveSupport::Logger.broadcast` so that calls to `#silence` now
    properly delegate to all loggers. Silencing now properly suppresses logging
    to both the log and the console.

    *Kevin McPhillips*

145 146 147 148
*   Remove deprecated arguments in `assert_nothing_raised`.

    *Rafel Mendonça França*

149 150 151 152 153 154 155
*   `Date.to_s` doesn't produce too many spaces. For example, `to_s(:short)`
    will now produce `01 Feb` instead of ` 1 Feb`.

    Fixes #25251.

    *Sean Griffin*

V
Vipul A M 已提交
156
*   Introduce `Module#delegate_missing_to`.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

    When building a decorator, a common pattern emerges:

        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

    *Genadi Samokovarov*, *DHH*

203 204 205 206
*   Rescuable: If a handler doesn't match the exception, check for handlers
    matching the exception's cause.

    *Jeremy Daer*
207

208
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activesupport/CHANGELOG.md) for previous changes.