Commit Graph

7080 Commits

Author SHA1 Message Date
Michael Stock ec9fffd3e0 Move HashWithIndifferentAccess tests to separate file 2017-03-30 00:05:40 -05:00
Matt Casper 0117810cda Add aliases for reverse_merge to with_defaults
In the context of controller parameters, reverse_merge is commonly used
to provide defaults for user input. Having an alias to reverse_merge
called with_defaults feels more idiomatic for Rails.
2017-03-29 15:55:09 -05:00
Rafael Mendonça França d046390c32
Use keyword arguments instead of hash 2017-03-28 18:02:00 -04:00
Rafael Mendonça França 0875256fe9
Merge pull request #28480 from mubashirhanif/add_keep_id_suffix_option_to_humanize_new
Add keep id suffix option to humanize new
2017-03-28 17:57:17 -04:00
Rafael Mendonça França d55f7fee81
starts_with? is removed in Ruby 2.4 2017-03-28 16:01:35 -04:00
Rafael Mendonça França 8d50b45159
Merge pull request #1 from radiospiel/tickets/26955-listen-paths
No longer listens to dirs outside of the app directory.
2017-03-28 15:52:21 -04:00
Andrew White d28c482435 Return unmapped timezones from `country_zones`
If a country doesn't exist in the MAPPINGS hash then create a new
`ActiveSupport::Timezone` instance using the supplied timezone id.

Fixes #28431.
2017-03-28 13:33:32 +01:00
Yves Senn 40ba03adaa minor CHANGELOG formatting changes. [ci skip] 2017-03-26 12:14:11 +02:00
yuuji.yaginuma af2e39f3d5 Fix doc format for `duplicable?` [ci skip] 2017-03-25 19:55:28 +09:00
Vipul A M c07cc2986c
Remove unnecessary ruby version comments [ci skip] 2017-03-24 17:59:49 +05:30
Vipul A M 7045e03dee
Fix duplicable? for Ratiional and Complex on ruby master, since they are now duplicable 2017-03-23 17:34:30 +05:30
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
Mubashir Hanif f0c8f1b085 Added options hash to titleize method and keep_id_suffix option to humanize
some documentation

remove extra whitespace.

Added id in the middle test case and corrected some testcases.

Some Coding standard guidelines corrections as suggested by codeclimate.

Some more corrections suggested by codeclimate.
2017-03-21 22:55:17 +01:00
Jon Moss 9bcc021286 Merge pull request #28446 from y-yagi/move_new_changelog_entry_to_the_top
Move new CHANGELOG entry to the top [ci skip]
2017-03-18 21:39:50 -04:00
Vipul A M 0a4d1c3cde Cleanup documentation fixes (#28460) 2017-03-17 17:33:35 +05:30
Vipul A M d5c32f8711 Merge pull request #28445 from denniszelada/feature-documentation-with_options
Add documentation to use with_options anywhere in the same class [ci
2017-03-17 12:20:22 +05:30
Dennis Zelada 4ac5f90e92 Add documentation to use with_options in the same class [ci skip] 2017-03-16 18:15:36 +01:00
yuuji.yaginuma 41f8a9a03a Move new CHANGELOG entry to the top [ci skip] 2017-03-16 21:35:37 +09:00
Andrew White b9c399de22 Fix test warnings 2017-03-16 09:16:20 +00:00
Andrew White 5055370828 Move `to_time` to `DateTime` compatibility.rb file
We are overriding it in `Time` and `ActiveSupport::TimeWithZone` so
there's no point in having it in the `DateAndTime::Compatibility`
module. Also add some docs for the `to_time` implementations.
2017-03-16 09:14:13 +00: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
Jon Moss bd3f0e706c Tweak 28412
PR was merged before I could finished reviewing 😬

[ci skip]
2017-03-15 13:10:11 -04:00
Andrew White 8efbfba248 Merge pull request #28425 from rails/remove-duration-deprecation
Remove implicit coercion deprecation of durations
2017-03-15 15:46:55 +00:00
Rafael França 401d3ad56c Merge pull request #28412 from benoittgt/add_doc_for_message_encryptor_new
Add documentation about signature_key for MessageEncryptor.new [ci skip]
2017-03-15 11:32:23 -04:00
Andrew White de5eb9ed98 Restore 5.minutes changed in #28204 2017-03-15 14:56:27 +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
Benoit Tigeot 9a79201fd4 Add documentation about signature_key for MessageEncryptor.new [ci skip] 2017-03-15 08:56:44 +01:00
Jon Moss 0713efb509 Lint activesupport/CHANGELOG.md
[ci skip]
2017-03-13 19:45:35 -04:00
Vipul A M 5b0841ecea AS:Cache:MemoryStore doc fixes [ci skip] (#28389) 2017-03-12 14:35:43 +05:30
Vipul A M 254b831edd Merge pull request #27051 from devonestes/adding-cache-clear-docs
Add missing documentation for MemoryStore#clear [ci skip]
2017-03-12 14:20:06 +05:30
Ryuta Kamizono 2e752d18b3 Fix indentation and formatting in CHANGELOGs [ci skip] 2017-03-11 17:31:25 +09:00
Lin Jen-Shin e63fb2407a Make sure local cache cleared even it's throwing:
We (GitLab) hit into an issue that somewhere in the middleware
chain was throwing `:warden`, which was caught in the wrapping
middleware, but `LocalCache::Middleware` was not aware of it.
It should look like:

``` ruby
result = catch(:warden) do
  @app.call(env)
end
```

Source: 090ed153db/lib/warden/manager.rb (L35-L37)

Using `ensure` could make sure that we would always do the cleanup,
and better yet, avoid `rescue Exception` which we all should know
that could cause some issues which could be very hard to debug.

Please check the discussion thread for more context:
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1402#note_25128108
2017-03-10 17:34:54 +00: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 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