CHANGELOG.md 16.5 KB
Newer Older
R
Rafael Mendonça França 已提交
1 2
## Rails 4.0.0 (unreleased) ##

3 4 5 6
*   Fix skipping of filters defined by objects in `ActiveSupport::Callbacks::Callback`.

    *Ben McRedmond*

7 8 9 10 11 12
*   An `ActiveSupport::Subscriber` class has been extracted from
    `ActiveSupport::LogSubscriber`, allowing you to use the event attachment
    API for other kinds of subscribers.

    *Daniel Schierbeck*

13 14 15 16 17 18
*   `Class#class_attribute` accepts an `instance_predicate` option which
    defaults to `true`. If set to `false` the predicate method will not
    be defined.

    *Agis Anastasopoulos*

A
Agis Anastasopoulos 已提交
19
*   `fast_xs` support has been removed.  Use `String#encode(xml: :attr)`.
20

21 22
*   `ActiveSupport::Notifications::Instrumenter#instrument` should
    yield its payload.
23 24 25

    *stopdropandrew*

26 27 28 29 30
*   `ActiveSupport::TimeWithZone` raises `NoMethodError` in proper context.
    Fixes #9772.

    *Yves Senn*

31
*   Fix deletion of empty directories in `ActiveSupport::Cache::FileStore`.
32

S
Steve Klabnik 已提交
33
    *Charles Jones*
R
Rafael Mendonça França 已提交
34

35
## Rails 4.0.0.beta1 (February 25, 2013) ##
36

37 38 39 40 41 42 43 44 45 46 47 48 49
*   Improve singularizing a singular for multiple cases.
    Fixes #2608 #1825 #2395.

    Example:

        # Before
        'address'.singularize # => 'addres'

        # After
        'address'.singularize # => 'address'

    *Mark McSpadden*

50 51 52 53 54
*   Prevent `DateTime#change` from truncating the second fraction, when seconds
    do not need to be changed.

    *Chris Baynes*

55 56
*   Added `ActiveSupport::TimeWithZone#to_r` for `Time#at` compatibility.

57 58 59 60 61 62 63 64 65 66 67 68
    Before this change:

        Time.zone = 'Tokyo'
        time = Time.zone.now
        time == Time.at(time) # => false

    After the change:

        Time.zone = 'Tokyo'
        time = Time.zone.now
        time == Time.at(time) # => true

69 70
    *stopdropandrew*

71
*   `ActiveSupport::NumberHelper#number_to_human` returns the number unaltered when
72 73 74
    the given units hash does not contain the needed key, e.g. when the number provided
    is less than the largest key provided.
    Fixes #9269.
75 76 77

    Examples:

78 79
        number_to_human(123, units: {}) # => 123
        number_to_human(123, units: { thousand: 'k' }) # => 123
80 81 82

    *Michael Hoffman*

83
*   Added `beginning_of_minute` support to core ext calculations for `Time` and `DateTime`.
84 85 86

    *Gagan Awhad*

87 88 89 90
*   Add `:nsec` date format.

    *Jamie Gaskins*

91
*   `ActiveSupport::Gzip.compress` allows two optional arguments for compression
B
Beyond 已提交
92 93 94 95
    level and strategy.

    *Beyond*

96 97
*   Modify `TimeWithZone#as_json` to include 3 decimal places of sub-second accuracy
    by default, which is optional as per the ISO8601 spec, but extremely useful. Also
98
    the default behaviour of `Date#toJSON()` in recent versions of Chrome, Safari and
99 100
    Firefox.

101 102
    *James Harton*

103 104
*   Improve `String#squish` to handle Unicode whitespace. *Antoine Lyset*

105
*   Standardise on `to_time` returning an instance of `Time` in the local system timezone
106 107 108 109
    across `String`, `Time`, `Date`, `DateTime` and `ActiveSupport::TimeWithZone`.

    *Andrew White*

110
*   Extract `ActiveSupport::Testing::Performance` into https://github.com/rails/rails-perftest
111
    You can add the gem to your `Gemfile` to keep using performance tests.
112 113 114 115 116

        gem 'rails-perftest'

    *Yves Senn*

117 118
*   `Hash.from_xml` raises when it encounters `type="symbol"` or `type="yaml"`.
    Use `Hash.from_trusted_xml` to parse this XML.
119 120 121 122 123

    CVE-2013-0156

    *Jeremy Kemper*

124 125 126 127 128
*   Deprecate `assert_present` and `assert_blank` in favor of
    `assert object.blank?` and `assert object.present?`

    *Yves Senn*

129
*   Change `String#to_date` to use `Date.parse`. This gives more consistent error
130 131 132 133 134 135 136
    messages and allows the use of partial dates.

        "gibberish".to_date => Argument Error: invalid date
        "3rd Feb".to_date => Sun, 03 Feb 2013

    *Kelly Stannard*

137
*   It's now possible to compare `Date`, `DateTime`, `Time` and `TimeWithZone`
138
    with `Float::INFINITY`. This allows to create date/time ranges with one infinite bound.
139 140 141 142 143 144 145 146 147 148 149
    Example:

        range = Range.new(Date.today, Float::INFINITY)

    Also it's possible to check inclusion of date/time in range with conversion.

        range.include?(Time.now + 1.year)     # => true
        range.include?(DateTime.now + 1.year) # => true

    *Alexander Grebennik*

150 151 152 153
*   Remove meaningless `ActiveSupport::FrozenObjectError`, which was just an alias of `RuntimeError`.

    *Akira Matsuda*

154
*   Introduce `assert_not` to replace warty `assert !foo`.  *Jeremy Kemper*
155

156 157 158 159 160 161 162 163 164
*   Prevent `Callbacks#set_callback` from setting the same callback twice.

        before_save :foo, :bar, :foo

    will at first call `bar`, then `foo`. `foo` will no more be called
    twice.

    *Dmitriy Kiriyenko*

165
*   Add `ActiveSupport::Logger#silence` that works the same as the old `Logger#silence` extension.
166 167 168

    *DHH*

169
*   Remove surrogate unicode character encoding from `ActiveSupport::JSON.encode`
170
    The encoding scheme was broken for unicode characters outside the basic multilingual plane;
171
    since json is assumed to be UTF-8, and we already force the encoding to UTF-8,
172
    simply pass through the un-encoded characters.
173 174

    *Brett Carter*
S
Steve Klabnik 已提交
175

176
*   Deprecate `Time.time_with_date_fallback`, `Time.utc_time` and `Time.local_time`.
177
    These methods were added to handle the limited range of Ruby's native `Time`
178 179 180 181 182
    implementation. Those limitations no longer apply so we are deprecating them in 4.0
    and they will be removed in 4.1.

    *Andrew White*

183 184
*   Deprecate `Date#to_time_in_current_zone` and add `Date#in_time_zone`. *Andrew White*

185
*   Add `String#in_time_zone` method to convert a string to an `ActiveSupport::TimeWithZone`. *Andrew White*
A
Andrew White 已提交
186

187
*   Deprecate `ActiveSupport::BasicObject` in favor of `ActiveSupport::ProxyObject`.
188
    This class is used for proxy classes. It avoids confusion with Ruby's `BasicObject`
189 190 191 192
    class.

    *Francesco Rodriguez*

193 194 195
*   Patched `Marshal#load` to work with constant autoloading. Fixes autoloading
    with cache stores that rely on `Marshal` (`MemCacheStore` and `FileStore`).
    Fixes #8167.
196 197 198

    *Uriel Katz*

199 200
*   Make `Time.zone.parse` to work with JavaScript format date strings. *Andrew White*

201 202 203 204 205 206 207 208 209
*   Add `DateTime#seconds_until_end_of_day` and `Time#seconds_until_end_of_day`
    as a complement for `seconds_from_midnight`; useful when setting expiration
    times for caches, e.g.:

        <% cache('dashboard', expires_in: Date.current.seconds_until_end_of_day) do %>
          ...

    *Olek Janiszewski*

210
*   No longer proxy `ActiveSupport::Multibyte#class`. *Steve Klabnik*
211

212
*   Deprecate `ActiveSupport::TestCase#pending` method, use `skip` from minitest instead. *Carlos Antonio da Silva*
213

214 215 216 217 218 219 220 221 222 223 224 225 226
*   `XmlMini.with_backend` now may be safely used with threads:

        Thread.new do
          XmlMini.with_backend("REXML") { rexml_power }
        end
        Thread.new do
          XmlMini.with_backend("LibXML") { libxml_power }
        end

    Each thread will use it's own backend.

    *Nikita Afanasenko*

227
*   Dependencies no longer trigger `Kernel#autoload` in `remove_constant`. Fixes #8213. *Xavier Noria*
228

229
*   Simplify `mocha` integration and remove monkey-patches, bumping `mocha` to 0.13.0. *James Mead*
230

231
*   `#as_json` isolates options when encoding a hash. Fixes #8182.
232 233 234

    *Yves Senn*

235
*   Deprecate `Hash#diff` in favor of minitest's #diff. *Steve Klabnik*
S
Steve Klabnik 已提交
236

237
*   `Kernel#capture` can catch output from subprocesses. *Dmitry Vorotilin*
238

239 240 241 242
*   `to_xml` conversions now use builder's `tag!` method instead of explicit invocation of `method_missing`.

    *Nikita Afanasenko*

243 244
*   Fixed timezone mapping of the Solomon Islands. *Steve Klabnik*

245 246
*   Make callstack attribute optional in `ActiveSupport::Deprecation::Reporting`
    methods `warn` and `deprecation_warning`.
247 248 249

    *Alexey Gaziev*

250
*   Implement `HashWithIndifferentAccess#replace` so `key?` works correctly. *David Graham*
251

252 253
*   Handle the possible permission denied errors `atomic.rb` might trigger due to its `chown`
    and `chmod` calls.
254

255 256 257
    *Daniele Sluijters*

*   `Hash#extract!` returns only those keys that present in the receiver.
258

259
        {a: 1, b: 2}.extract!(:a, :x) # => {:a => 1}
260 261 262

    *Mikhail Dieterle*

263 264
*   `Hash#extract!` returns the same subclass, that the receiver is. I.e.
    `HashWithIndifferentAccess#extract!` returns a `HashWithIndifferentAccess` instance.
265 266 267

    *Mikhail Dieterle*

268
*   Optimize `ActiveSupport::Cache::Entry` to reduce memory and processing overhead. *Brian Durand*
269

270 271 272 273 274 275 276
*   Tests tag the Rails log with the current test class and test case:

        [SessionsControllerTest] [test_0002_sign in] Processing by SessionsController#create as HTML
        [SessionsControllerTest] [test_0002_sign in] ...

    *Jeremy Kemper*

277
*   Add `logger.push_tags` and `.pop_tags` to complement `logger.tagged`:
278 279 280 281 282 283 284 285 286 287 288 289 290

        class Job
          def before
            Rails.logger.push_tags :jobs, self.class.name
          end

          def after
            Rails.logger.pop_tags 2
          end
        end

    *Jeremy Kemper*

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
*   Allow delegation to the class using the `:class` keyword, replacing
    `self.class` usage:

        class User
          def self.hello
           "world"
          end

          delegate :hello, to: :class
        end

    *Marc-Andre Lafortune*

*   `Date.beginning_of_week` thread local and `beginning_of_week` application
    config option added (default is Monday).

    *Innokenty Mikhailov*
308

309 310 311 312
*   An optional block can be passed to `config_accessor` to set its default value

        class User
          include ActiveSupport::Configurable
313

314 315 316 317 318 319 320 321 322
          config_accessor :hair_colors do
            [:brown, :black, :blonde, :red]
          end
        end

        User.hair_colors # => [:brown, :black, :blonde, :red]

    *Larry Lv*

323
*   `ActiveSupport::Benchmarkable#silence` has been deprecated due to its lack of
324 325 326 327 328 329
    thread safety. It will be removed without replacement in Rails 4.1.

    *Steve Klabnik*

*   An optional block can be passed to `Hash#deep_merge`. The block will be invoked
    for each duplicated key and used to resolve the conflict.
330

331
    *Pranas Kiziela*
332

333
*   `ActiveSupport::Deprecation` is now a class. It is possible to create an instance
334 335 336 337
    of deprecator. Backwards compatibility has been preserved.

    You can choose which instance of the deprecator will be used.

338
        deprecate :method_name, deprecator: deprecator_instance
339

340
    You can use `ActiveSupport::Deprecation` in your gem.
341

342 343
        require 'active_support/deprecation'
        require 'active_support/core_ext/module/deprecation'
344

345 346 347 348
        class MyGem
          def self.deprecator
            ActiveSupport::Deprecation.new('2.0', 'MyGem')
          end
349

350 351
          def old_method
          end
352

353 354
          def new_method
          end
355

356
          deprecate old_method: :new_method, deprecator: deprecator
357
        end
358

359 360
        MyGem.new.old_method
        # => DEPRECATION WARNING: old_method is deprecated and will be removed from MyGem 2.0 (use new_method instead). (called from <main> at file.rb:18)
361 362 363

    *Piotr Niełacny & Robert Pankowecki*

364 365
*   `ERB::Util.html_escape` encodes single quote as `#39`. Decimal form has better support in old browsers. *Kalys Osmonov*

366
*   `ActiveSupport::Callbacks`: deprecate monkey patch of object callbacks.
367
    Using the `filter` method like this:
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387

        before_filter MyFilter.new

        class MyFilter
          def filter(controller)
          end
        end

    Is now deprecated with recommendation to use the corresponding filter type
    (`#before`, `#after` or `#around`):

        before_filter MyFilter.new

        class MyFilter
          def before(controller)
          end
        end

    *Bogdan Gusiev*

388 389
*   An optional block can be passed to `HashWithIndifferentAccess#update` and `#merge`.
    The block will be invoked for each duplicated key, and used to resolve the conflict,
390
    thus replicating the behaviour of the corresponding methods on the `Hash` class.
391 392 393

    *Leo Cassarani*

394 395 396 397 398 399
*   Remove `j` alias for `ERB::Util#json_escape`.
    The `j` alias is already used for `ActionView::Helpers::JavaScriptHelper#escape_javascript`
    and both modules are included in the view context that would confuse the developers.

    *Akira Matsuda*

400
*   Replace deprecated `memcache-client` gem with `dalli` in `ActiveSupport::Cache::MemCacheStore`.
401 402 403

    *Guillermo Iguaran*

404 405 406 407 408
*   Add default values to all `ActiveSupport::NumberHelper` methods, to avoid
    errors with empty locales or missing values.

    *Carlos Antonio da Silva*

409 410
*   `ActiveSupport::JSON::Variable` is deprecated. Define your own `#as_json` and
    `#encode_json` methods for custom JSON string literals.
411 412 413

    *Erich Menge*

414
*   Add `String#indent`. *fxn & Ace Suares*
415 416 417 418 419 420

*   Inflections can now be defined per locale. `singularize` and `pluralize`
    accept locale as an extra argument.

    *David Celis*

421
*   `Object#try` will now return `nil` instead of raise a `NoMethodError` if the
422 423 424 425 426
    receiving object does not implement the method, but you can still get the
    old behavior by using the new `Object#try!`.

    *DHH*

M
Mark Turner 已提交
427
*   `ERB::Util.html_escape` now escapes single quotes. *Santiago Pastorino*
428

429
*   `Time#change` now works with time values with offsets other than UTC or the local time zone. *Andrew White*
430

431
*   `ActiveSupport::Callbacks`: deprecate usage of filter object with `#before` and `#after` methods as `around` callback. *Bogdan Gusiev*
432

433
*   Add `Time#prev_quarter` and `Time#next_quarter` short-hands for `months_ago(3)` and `months_since(3)`. *SungHee Kang*
434

435 436
*   Remove obsolete and unused `require_association` method from dependencies. *fxn*

437 438 439 440 441 442 443 444 445 446 447 448
*   Add `:instance_accessor` option for `config_accessor`.

        class User
          include ActiveSupport::Configurable
          config_accessor :allowed_access, instance_accessor: false
        end

        User.new.allowed_access = true # => NoMethodError
        User.new.allowed_access        # => NoMethodError

    *Francesco Rodriguez*

449 450 451 452 453
*   `ActionView::Helpers::NumberHelper` methods have been moved to `ActiveSupport::NumberHelper` and are now available via
    `Numeric#to_s`.  `Numeric#to_s` now accepts the formatting options `:phone`, `:currency`, `:percentage`, `:delimited`,
    `:rounded`, `:human`, and `:human_size`.

    *Andrew Mutz*
454

455
*   Add `Hash#transform_keys`, `Hash#transform_keys!`, `Hash#deep_transform_keys`, and `Hash#deep_transform_keys!`. *Mark McSpadden*
456

457
*   Changed XML type `datetime` to `dateTime` (with upper case letter `T`). *Angelo Capilleri*
458

459 460
*   Add `:instance_accessor` option for `class_attribute`. *Alexey Vakhov*

461 462
*   `constantize` now looks in the ancestor chain. *Marc-Andre Lafortune & Andrew White*

463
*   Adds `Hash#deep_stringify_keys` and `Hash#deep_stringify_keys!` to convert all keys from a `Hash` instance into strings. *Lucas Húngaro*
464

465
*   Adds `Hash#deep_symbolize_keys` and `Hash#deep_symbolize_keys!` to convert all keys from a `Hash` instance into symbols. *Lucas Húngaro*
466

467
*   `Object#try` can't call private methods. *Vasiliy Ermolovich*
468

469 470
*   `AS::Callbacks#run_callbacks` remove `key` argument. *Francesco Rodriguez*

471
*   `deep_dup` works more expectedly now and duplicates also values in `Hash` instances and elements in `Array` instances. *Alexey Gaziev*
472

473
*   Inflector no longer applies ice -> ouse to words like "slice", "police", etc. *Wes Morgan*
J
José Valim 已提交
474

475
*   Add `ActiveSupport::Deprecations.behavior = :silence` to completely ignore Rails runtime deprecations. *twinturbo*
476

477
*   Make `Module#delegate` stop using `send` - can no longer delegate to private methods. *dasch*
D
Daniel Schierbeck 已提交
478

479
*   `ActiveSupport::Callbacks`: deprecate `:rescuable` option. *Bogdan Gusiev*
480

481
*   Adds `Integer#ordinal` to get the ordinal suffix string of an integer. *Tim Gildea*
482

483
*   `ActiveSupport::Callbacks`: `:per_key` option is no longer supported. *Bogdan Gusiev*
484

485
*   `ActiveSupport::Callbacks#define_callbacks`: add `:skip_after_callbacks_if_terminated` option. *Bogdan Gusiev*
486

487
*   Add `html_escape_once` to `ERB::Util`, and delegate the `escape_once` tag helper to it. *Carlos Antonio da Silva*
488

489 490
*   Deprecates the compatibility method `Module#local_constant_names`,
    use `Module#local_constants` instead (which returns symbols). *Xavier Noria*
491

492 493
*   Deletes the compatibility method `Module#method_names`,
    use `Module#methods` from now on (which returns symbols). *Xavier Noria*
494

495 496
*   Deletes the compatibility method `Module#instance_method_names`,
    use `Module#instance_methods` from now on (which returns symbols). *Xavier Noria*
497

498 499
*   `BufferedLogger` is deprecated. Use `ActiveSupport::Logger`, or the logger
    from the Ruby standard library.
500

501
    *Aaron Patterson*
502

503
*   Unicode database updated to 6.1.0. *Norman Clarke*
504

505 506
*   Adds `encode_big_decimal_as_string` option to force JSON serialization of `BigDecimal` as numeric instead
    of wrapping them in strings for safety.
507

508 509
*   Optimize log subscribers to check log level before doing any processing. *Brian Durand*

X
Xavier Noria 已提交
510
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activesupport/CHANGELOG.md) for previous changes.