Commit Graph

615 Commits

Author SHA1 Message Date
Julian Nadeau
35fac87123
Add action_controller_api, action_controller_base on_load hook 2017-04-10 19:34:48 -04:00
Josh Pencheon
2144e70a86 Implement fetch_values for HashWithIndifferentAccess (#28316)
`fetch_values` was added to Hash in Ruby 2.3.0:
  https://bugs.ruby-lang.org/issues/10017

This patch adds an implemention for instances of HWAI, in line
with the existing definitions of `fetch` and `values_at`.
2017-04-10 10:20:13 +09:30
Yves Senn
40ba03adaa minor CHANGELOG formatting changes. [ci skip] 2017-03-26 12:14:11 +02:00
Rafael Mendonça França
25473baf40
No need to have an entry that was included in 5.1 in 5.2
[ci skip]
2017-03-22 19:28:01 -04:00
Dominic Cleal
f53a3005f5
Add AS::Deprecation::DeprecatedConstantAccessor
An alternative to DeprecatedConstantProxy which works more transparently
with exceptions because it returns the object that the new constant
refers to rather than a proxy. This is then compatible with
`rescue OldException`.
2017-03-22 16:21:40 +00:00
Matthew Draper
6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
yuuji.yaginuma
41f8a9a03a Move new CHANGELOG entry to the top [ci skip] 2017-03-16 21:35:37 +09:00
Andrew White
ee33b9e93a Merge pull request #28147 from kmcphillips/master-time-freeze
Allow Time#to_time on frozen objects. Return frozen time rather than "RuntimeError: can't modify frozen Time"
2017-03-16 08:53:12 +00:00
Andrew White
a91ea1d510 Remove implicit coercion deprecation of durations
In #28204 we deprecated implicit conversion of durations to a
numeric which represented the number of seconds in the duration
because of unwanted side effects with calculations on durations
and dates. This unfortunately had the side effect of forcing a
explicit cast when configuring third-party libraries like
expiration in Redis, e.g:

    redis.expire("foo", 5.minutes)

To work around this we've removed the deprecation and added a
private class that wraps the numeric and can perform calculation
involving durations and ensure that they remain a duration
irrespective of the order of operations.
2017-03-15 14:56:27 +00:00
Jon Moss
0713efb509 Lint activesupport/CHANGELOG.md
[ci skip]
2017-03-13 19:45:35 -04:00
Ryuta Kamizono
2e752d18b3 Fix indentation and formatting in CHANGELOGs [ci skip] 2017-03-11 17:31:25 +09:00
Kevin McPhillips
92fc8ec663 Handle #to_time and memoization taking into account memoization, frozen state, and preserve_timezone flag. 2017-03-06 18:08:31 -05:00
yuuji.yaginuma
b9fa0fd2f1 Fix typo titlelize -> titleize [ci skip] 2017-03-07 08:08:19 +09:00
Andrew White
48b37f127f Update titlelize regex to allow apostrophes
In 4b685aa the regex in `titlelize` was updated to not match
apostrophes to better reflect the nature of the transformation.
Unfortunately this had the side effect of breaking capitalization
on the first word of a sub-string, e.g:

  >> "This was 'fake news'".titleize
  => "This Was 'fake News'"

This is fixed by extending the look-behind to also check for a
word character on the other side of the apostrophe.

Fixes #28312.
2017-03-06 17:51:03 +00:00
Andrew White
f0aeecda14 Add rfc3339 aliases to xmlschema
For naming consistency when using the RFC 3339 profile
of ISO 8601 in applications.
2017-03-03 21:53:13 +00:00
Andrew White
08e05d4a49 Add Time.rfc3339 parsing method
The `Time.xmlschema` and consequently its alias `iso8601` accepts
timestamps without a offset in contravention of the RFC 3339
standard. This method enforces that constraint and raises an
`ArgumentError` if it doesn't.
2017-03-03 21:53:13 +00:00
Andrew White
f61062c70f Add ActiveSupport::TimeZone.rfc3339 parsing method
Previously there was no way to get a RFC 3339 timestamp
into a specific timezone without either using `parse` or
chaining methods. The new method allows parsing directly
into the timezone, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.rfc3339("1999-12-31T14:00:00Z")
    => Fri, 31 Dec 1999 14:00:00 HST -10:00

This new method has stricter semantics than the current
`parse` method and will raise an `ArgumentError`
instead of returning nil, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.rfc3339("foobar")
    ArgumentError: invalid date
    >> Time.zone.parse("foobar")
    => nil

It will also raise an `ArgumentError` when either the
time or offset components are missing, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.rfc3339("1999-12-31")
    ArgumentError: invalid date
    >> Time.zone.rfc3339("1999-12-31T14:00:00")
    ArgumentError: invalid date
2017-03-03 21:53:13 +00:00
Andrew White
4974b1a483 Add ActiveSupport::TimeZone.iso8601 parsing method
Previously there was no way to get a ISO 8601 timestamp into a specific
timezone without either using `parse` or chaining methods. The new method
allows parsing directly into the timezone, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.iso8601("1999-12-31T14:00:00Z")
    => Fri, 31 Dec 1999 14:00:00 HST -10:00

If the timestamp is a ISO 8601 date (YYYY-MM-DD) then the time is set
to midnight, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.iso8601("1999-12-31")
    => Fri, 31 Dec 1999 00:00:00 HST -10:00

This new method has stricter semantics than the current `parse` method
and will raise an `ArgumentError` instead of returning nil, e.g:

    >> Time.zone = "Hawaii"
    => "Hawaii"
    >> Time.zone.iso8601("foobar")
    ArgumentError: invalid date
    >> Time.zone.parse("foobar")
    => nil
2017-03-03 21:53:12 +00:00
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
Andrew White
b5af751508 Update DateTime#change to support usec and nsec
Adding support for these options now allows us to update the
`DateTime#end_of` methods to match the equivalent `Time#end_of`
methods, e.g:

    datetime = DateTime.now.end_of_day
    datetime.nsec == 999999999 # => true

Fixes #21424.
2017-03-02 06:02:41 +00:00
Nick Johnstone
2d84a6bc74
Add Duration#before and #after as aliases for #ago and #since
It's common in test cases at my job to have code like this:

    let(:today) { customer_start_date + 2.weeks }
    let(:earlier_date) { today - 5.days }

With this change, we can instead write

    let(:today) { 2.weeks.after(customer_start_date) }
    let(:earlier_date) { 5.days.before(today) }

Closes #27721
2017-02-26 01:18:51 -07:00
Vipul A M
e842db501f
AS CHANGELOG Pass [ci skip] 2017-02-26 10:19:48 +05:30
Ryuta Kamizono
dd3adc5a04 Fix typo HashWithIndifferentAcces to HashWithIndifferentAccess [ci skip] 2017-02-25 11:17:01 +09:00
Matthew Draper
9099cf064f Merge pull request #28157 from robin850/hwia-soft-deprecation
Soft-deprecate the `HashWithIndifferentAccess` constant
2017-02-25 10:53:03 +10:30
Rafael Mendonça França
feea081199
Merge pull request #28006 from fareastside/master
Allow ActiveSupport::MarshalWithAutoloading#load to take a Proc
2017-02-24 19:17:01 -05:00
Rafael Mendonça França
ccb0095116
Fix CHANGELOG entry position [ci skip] 2017-02-24 19:01:42 -05:00
Robin Dupret
e690a92b44 Soft-deprecate the top-level HashWithIndifferentAccess class
Since using a `ActiveSupport::Deprecation::DeprecatedConstantProxy`
would prevent people from inheriting this class and extending it
from the `ActiveSupport::HashWithIndifferentAccess` one would break
the ancestors chain, that's the best option we have here.
2017-02-25 00:29:43 +01:00
Dylan Thacker-Smith
29c02709cd Add missing gzip footer check in ActiveSupport::Gzip.decompress
A gzip file has a checksum and length for the decompressed data in its
footer which isn't checked by just calling Zlib::GzipReader#read.
Calling Zlib::GzipReader#close must be called after reading to the end
of the file causes this check to be done, which is done by
Zlib::GzipReader.wrap after its block is called.
2017-02-24 17:33:36 -05:00
Jeff Latz
a72498f776 add optional second argument to ActiveSupport core extension for Marshal#load so it can take a proc 2017-02-24 12:12:07 -05:00
Rafael Mendonça França
f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
Andrew White
240e32bbbf Add CHANGELOG entry for #28104 2017-02-22 08:29:58 +00:00
Kasper Timm Hansen
507c9970ab Revert "Merge pull request #27925 from robin850/hwia-removal"
Pointed out by @matthewd that the HWIA subclass changes the
AS scoped class and top-level HWIA hierarchies out from under
existing classes.

This reverts commit 71da39097b67114329be6d8db7fe6911124531af, reversing
changes made to 41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.
2017-02-20 22:15:31 +01:00
Robin Dupret
e532531939 Deprecate the top-level HashWithIndifferentAccess contant
This constant was kept for the sake of backward compatibility; it
is still available under `ActiveSupport::HashWithIndifferentAccess`.

Furthermore, since Ruby 2.5 (https://bugs.ruby-lang.org/issues/11547)
won't support top level constant lookup, people would have to update
their code anyway.
2017-02-19 22:06:12 +01:00
yuuji.yaginuma
4e63ce53fc deprecate halt_callback_chains_on_return_false instead of halt_and_display_warning_on_return_false
`halt_and_display_warning_on_return_false` is not a public API and
application is using `halt_callback_chains_on_return_false`.

https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt#L29
https://github.com/rails/rails/blob/5-0-stable/activesupport/lib/active_support.rb#L86..L88

Therefore, deprecate messages should be issued for
`halt_callback_chains_on_return_false` instead of
`halt_and_display_warning_on_return_false`.
2017-02-08 17:18:55 +09:00
Rafael Mendonça França
9e98f3f7e6
Deprecate halt_and_display_warning_on_return_false 2017-02-07 12:24:46 -03:00
Rafael Mendonça França
3a25cdca3e
Remove deprecated behavior that halts callbacks when the return is false 2017-02-07 12:19:37 -03:00
Ryuta Kamizono
09525527a5 Deprecate passing string to :if and :unless conditional options on set_callback and skip_callback 2017-02-04 20:48:29 +09:00
Ryuta Kamizono
f8d3fed167 Remove deprecated passing string to define callback
And raise `ArgumentError` when passing string to define callback.
2017-02-04 20:48:29 +09:00
Fumiaki MATSUSHIMA
bdcfdef214 Update Unicode Version to 9.0.0
9.0.0 was released on June 21, 2016

http://blog.unicode.org/2016/06/announcing-unicode-standard-version-90.html

http://www.unicode.org/versions/Unicode9.0.0/

There are some changes about grapheme cluster in Unicode 9.0.0:

http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules

------------

I noticed that `unpack_graphemes` returns [Other] when the argument is Other ÷ Prepend
(it must be [Other, Prepend]).
But in [Unicode 8.0.0's Prepend has no characters](http://www.unicode.org/reports/tr29/tr29-27.html#Prepend)
so we don't have to backport following patch:

```diff
should_break =
+ if pos == eoc
+   true
```
2017-01-28 16:57:36 +09:00
Kevin McPhillips
5da6a9d684 CHANGELOG: Raise ArgumentError when calling transliterate on anything other than a string 2017-01-16 14:40:54 -05:00
Akira Matsuda
b99014bf44 AS::StringInquirer#respond_to_missing? should fallback to super
in case String or any other ancestor class' respond_to_missing? was defined.
2017-01-15 03:38:06 +09:00
Akira Matsuda
d5fbb04fab AS::ArrayInquirer#respond_to_missing? should fallback to super
in case Array or any other ancestor class' respond_to_missing? was defined.
2017-01-15 02:44:03 +09:00
Andrey Novikov
cb9d0e4864
Fix inconsistent results when parsing large durations and constructing durations from code
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.
2017-01-09 23:04:48 +03:00
utilum
83d3b0dbf1 Fix Complex and Rational are duplicable?
See [this test](https://gist.github.com/utilum/78918f1b64f8b61ee732cb266db7c43a).
2016-12-21 17:50:14 +01:00
yuuji.yaginuma
2cb8558120 change return value of duplicable? with Ruby 2.4+
`NilClass`, `FalseClass`, `TrueClass`, `Symbol` and `Numeric` can dup
with Ruby 2.4+.

Ref: https://bugs.ruby-lang.org/issues/12979
2016-12-13 07:35:36 +09:00
yuuji.yaginuma
7d1e104f66 remove duplicated changelog entry [ci skip] 2016-11-15 07:43:21 +09:00
Andrew White
e491b2c063 Merge pull request #27035 from rails/remove-active-support-deprecations
Remove Active Support deprecations
2016-11-14 19:59:43 +00:00
Rafael Mendonça França
7c1566b278
Revert "Merge pull request #25811 from oss92/to_sentence_fallback_string"
This reverts commit bad3a120f1690f393d8f6204b3ceee60f0ce707b, reversing
changes made to 2384317465ccb1dfca456a2b7798714b99f32711.

Reason: Adding a new option in the API for something that can be done
with a `#presence` check could do.
2016-11-14 13:16:00 -05:00
Andrew White
0d7bd2031b Remove deprecated class ActiveSupport::Concurrency::Latch 2016-11-14 12:44:19 +00:00
Andrew White
0189f4db6f Remove deprecated separator argument from parameterize 2016-11-14 12:14:23 +00:00