Commit Graph

7043 Commits

Author SHA1 Message Date
Erol Fornoles
ee2979b905
Use method from Hash 2017-03-06 15:32:02 +08:00
Erol Fornoles
7b633857dd
Make the order of Hash#reverse_merge! consistent with HashWithIndifferentAccess 2017-03-06 15:32:01 +08: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
fd8da71118 Fix typo in comment 2017-03-03 13:51:22 +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
Lukas Zapletal
4c484a69e2 Use DEFAULT_CIPHER constant in MessageEncryptor 2017-03-01 13:57:54 +01: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
ac57a3ee0e Add few tests for the top level HashWithIndifferentAccess
This ensures that if we try to hard-deprecate it again in the future,
we won't break these behaviors.
2017-02-25 00:38:41 +01: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
Pavel Pravosud
b74c7e939a Make HWIA#compact not return nil when no nils 2017-02-23 15:24:22 -08:00
Rafael Mendonça França
f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
Godfrey Chan
135c5d5928 🙈 :nodoc: AS::Duration::ISO8601Serializer
This class should not be used directly, the public API is `AS::Duration#iso8601`.
2017-02-23 10:55:06 -08:00
Andrew White
a92bd65e37 Add more missing requires
Further missing requires for Timeout exposed due to Bundler 1.14.5
2017-02-22 14:05:37 +00:00
Andrew White
ac1862972c Add missing requires
Bundler 1.14.5 moved to lazily loading 'rubygems/spec_fetcher' which
revealed some missing requires from the JSON encoding test file.
2017-02-22 13:25:44 +00:00
Andrew White
240e32bbbf Add CHANGELOG entry for #28104 2017-02-22 08:29:58 +00:00
Adam Rice
6560448b46 Preload to_datetime before freezing a TimeWithZone instance 2017-02-22 14:16:59 +11:00
Kasper Timm Hansen
ff326e7456 Merge pull request #27941 from y-yagi/prevent_multiple_values_being_set_to_run_via
Prevent multiple values being set to `run_via`
2017-02-20 22:20:14 +01: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
Matthew Draper
e9abbb700a Merge pull request #27863 from robin850/api-improvements
Some improvements to the API site's sidebar
2017-02-21 05:33:32 +10:30
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
f38a660a60 Prevent multiple values being set to run_via
When executing the test via rake, since `rake` is set for `run_via`, `ruby` should not be set.
Related 2cb6c27310452da11b93d729c3b760ce988106e1
2017-02-18 09:49:57 +09:00
kenta-s
642880819b Fix doc in Multibyte::Chars [ci skip] 2017-02-17 08:07:37 +09:00
kenta-s
e07ebc13f4 Remove redundant namespaces from sample code of deprecated_method_warning [ci skip] 2017-02-15 19:31:33 +09:00
Mario Uher
3f79ee4862 Not ants were harmed! 🐜 2017-02-14 12:05:21 +01:00
kenta-s
6f032275c9 Fix the return of deprecate_methods in doc [ci skip] 2017-02-14 09:24:05 +09:00
Ryuta Kamizono
416d85b65e
Remove unused require
These files are not using `strip_heredoc`.

Closes #27976
2017-02-12 19:38:49 -07:00
Edouard CHIN
5b2b6282f5 Also not needed on this file, call to mattr_accessor got removed in 9e98f3f7e6 (diff-1ecd313ff0ab827af30014553cf8918dL76) 2017-02-12 20:00:54 -05:00
Andrew White
acdbe70a02 Merge pull request #27973 from kenta-s/add-missing-test-for-time-blank
Add Time#blank? to blank_test
2017-02-12 13:17:30 +00:00
Ryuta Kamizono
16ee3ccc9c Add Style/EmptyLinesAroundMethodBody in .rubocop.yml and remove extra empty lines 2017-02-12 20:44:15 +09:00
kenta-s
d632535df6 Add Time#blank? to blank_test 2017-02-12 11:02:50 +09: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
6599e07674
Remove unused code now that the deprecated file was removed 2017-02-07 15:07:15 -03: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
Robin Dupret
b7dbfe1b4d Avoid documenting private or external classes
There are a lot of monkey patches inside the code base but there's
no need to document external constants so let's remove them from
the documentation

Also, since there are monkey patches for some test cases classes,
there were sometimes both documented and sneaked under the wrong
section in the sidebar.

Finally, for future references, the `active_support/vendor`
folder has been originally ignored in https://git.io/vDqfA but
no longer exists.

[ci skip]
2017-02-07 16:16:38 +01:00
Rafael Mendonça França
64f4930afc
Document that string in if and unless option of callbacks are deprecated 2017-02-07 10:46:16 -03:00
Rafael Mendonça França
9b19861ec0
Improve the exception message to direct people to all the possible values 2017-02-07 10:41:44 -03:00
Rafael França
d7bbe075f9 Merge pull request #27608 from kamipo/remove_deprecated_passing_string_to_define_callback
Remove deprecated passing string to define callback
2017-02-07 10:33:28 -03:00
Arthur Nogueira Neves
e3afc83631 Merge pull request #27919 from bf4/correct_spelling
Correct spelling
2017-02-06 11:12:52 -05:00