rails--rails/actionview
Andrew White 75924c4517 Deprecate implicit coercion of `ActiveSupport::Duration`
Currently `ActiveSupport::Duration` implicitly converts to a seconds
value when used in a calculation except for the explicit examples of
addition and subtraction where the duration is the receiver, e.g:

    >> 2 * 1.day
    => 172800

This results in lots of confusion especially when using durations
with dates because adding/subtracting a value from a date treats
integers as a day and not a second, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 2 * 1.day
    => Mon, 10 Apr 2490

To fix this we're implementing `coerce` so that we can provide a
deprecation warning with the intent of removing the implicit coercion
in Rails 5.2, e.g:

    >> 2 * 1.day
    DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration
    to a Numeric is deprecated and will raise a TypeError in Rails 5.2.
    => 172800

In Rails 5.2 it will raise `TypeError`, e.g:

    >> 2 * 1.day
    TypeError: ActiveSupport::Duration can't be coerced into Integer

This is the same behavior as with other types in Ruby, e.g:

    >> 2 * "foo"
    TypeError: String can't be coerced into Integer
    >> "foo" * 2
    => "foofoo"

As part of this deprecation add `*` and `/` methods to `AS::Duration`
so that calculations that keep the duration as the receiver work
correctly whether the final receiver is a `Date` or `Time`, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 1.day * 2
    => Fri, 03 Mar 2017

Fixes #27457.
2017-03-02 08:00:22 +00:00
..
app/assets/javascripts Move rails-ujs README and LICENCE to actionview 2017-02-22 13:49:27 -05:00
bin
lib Remove `encode_special_chars` option from `strip_tags` 2017-02-27 14:17:17 -08:00
test Deprecate implicit coercion of `ActiveSupport::Duration` 2017-03-02 08:00:22 +00:00
.gitignore
CHANGELOG.md Remove `encode_special_chars` option from `strip_tags` 2017-02-27 14:17:17 -08:00
MIT-LICENSE
README.rdoc
RUNNING_UJS_TESTS.rdoc
RUNNING_UNIT_TESTS.rdoc
Rakefile Test rails-ujs in our travis matrix 2017-02-22 13:49:28 -05:00
actionview.gemspec use rails-html-sanitizer >= 1.0.3 2017-01-27 13:53:13 +09:00
blade.yml
coffeelint.json Test rails-ujs in our travis matrix 2017-02-22 13:49:28 -05:00
package.json Update package.json 2017-02-23 15:03:20 -05:00

README.rdoc

= Action View

Action View is a framework for handling view template lookup and rendering, and provides
view helpers that assist when building HTML forms, Atom feeds and more.
Template formats that Action View handles are ERB (embedded Ruby, typically
used to inline short Ruby snippets inside HTML), and XML Builder.

== Download and installation

The latest version of Action View can be installed with RubyGems:

  $ gem install actionview

Source code can be downloaded as part of the Rails project on GitHub

* https://github.com/rails/rails/tree/master/actionview


== License

Action View is released under the MIT license:

* http://www.opensource.org/licenses/MIT


== Support

API documentation is at

* http://api.rubyonrails.org

Bug reports can be filed for the Ruby on Rails project here:

* https://github.com/rails/rails/issues

Feature requests should be discussed on the rails-core mailing list here:

* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core