Commit Graph

569 Commits

Author SHA1 Message Date
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
Andrew White
90520d2eee Remove deprecated method Numeric#to_formatted_s 2016-11-14 12:03:48 +00:00
Andrew White
7c848e6dd4 Remove deprecated method alias_method_chain 2016-11-14 11:57:30 +00:00
Andrew White
8e43fc5ace Remove deprecated constant MissingSourceFIle 2016-11-14 11:25:52 +00:00
Andrew White
b93a257186 Remove deprecated Module.qualified_const_get/set/defined? 2016-11-14 08:11:21 +00:00
Andrew White
213f0d63a5 Update CHANGELOG 2016-11-13 23:25:05 +00:00
Andrew White
8931916f4a Ensure duration parsing is consistent across DST changes
Previously `ActiveSupport::Duration.parse` used `Time.current` and
`Time#advance` to calculate the number of seconds in the duration
from an arbitrary collection of parts. However as `advance` tries to
be consistent across DST boundaries this meant that either the
duration was shorter or longer depending on the time of year.

This was fixed by using an absolute reference point in UTC which
isn't subject to DST transitions. An arbitrary date of Jan 1st, 2000
was chosen for no other reason that it seemed appropriate.

Additionally, duration parsing should now be marginally faster as we
are no longer creating instances of `ActiveSupport::TimeWithZone`
every time we parse a duration string.

Fixes #26941.
2016-10-31 17:25:43 +00:00
Prathamesh Sonpatki
69a3fa1efc
Use Hash#compact and Hash#compact! from Ruby 2.4
- Ruby 2.4 has added Hash#compact and Hash#compact! so we can use it
  now.
- Reference: https://bugs.ruby-lang.org/issues/11818 and https://bugs.ruby-lang.org/issues/12863.
2016-10-23 20:54:39 +05:30
denisovlev
07ffe7a621 Fix ActiveSupport::TimeZone#strptime cannot parse timestamps (%Q, %s) 2016-10-21 13:19:08 +03:00
Josua Schmid
fc72d6815a
Fix copy_time_to: Copy nsec instead of usec
`copy_time_to` is a helper function for date and time calculations.
It's being used by `prev_week`, `next_week` and `prev_weekday` to keep
the time fraction when jumping around between days.

Previously the nanoseconds part was lost during the operation. This
lead to problems in practice if you were using the `end_of_day`
calculation. Resulting in the time fraction of `end_of_day` not being
the same as next week's `end_of_day`.

With this fix `copy_time_to` doesn't forget the `nsec` digits.
2016-10-20 10:49:59 +02:00
Andrew White
6c1dac00df Revert "Merge pull request #26677 from tbalthazar/26644"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 9ce2d1b1a43fc4ef3db59849b7412d30583a4074, reversing
changes made to 53ede1aff2025d4391d0e05ba471fdaf3110a99c.
2016-10-02 17:00:18 +01:00
Thomas Balthazar
607a6c7a9a Fix ActiveSupport::TimeWithZone#localtime
Previously memoization in `localtime` wasn't taking the `utc_offset`
parameter into account when returning a cached value. It now caches the
computed value depending on the `utc_offset` parameter, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,5,2,11)
    # => Mon, 02 May 2016 11:00:00 EDT -04:00

    t.localtime(-7200)
    # => 2016-05-02 13:00:00 -0200

    t.localtime(-3600)
    # => 2016-05-02 14:00:00 -0100
2016-10-01 13:38:43 +02:00
Thomas Balthazar
76c2553b88 Fix ActiveSupport::TimeWithZone#in
Previously calls to `in` were being sent to the non-DST aware
method `Time#since` via `method_missing`. It is now aliased to
the DST aware `ActiveSupport::TimeWithZone#+` which handles
transitions across DST boundaries, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,11,6,1)
    # => Sun, 06 Nov 2016 01:00:00 EDT -05:00

    t.in(1.hour)
    # => Sun, 06 Nov 2016 01:00:00 EST -05:00
2016-09-24 09:39:51 +02:00
Rafael Mendonça França
32e25e812d
Merge pull request #25628 from ysksn/options
Remove parameter "options = nil" for #clear
2016-08-17 02:55:58 -03:00
Vipul A M
8b984161d6
Pass over changelogs [ci skip] 2016-08-10 09:33:13 +05:30
Yves Senn
e9852c92bf Merge pull request #25681 from willnet/fix-thread_mattr_accessor
Fix `thread_mattr_accessor` share variable superclass with subclass
2016-08-08 12:35:29 +02:00
willnet
3529e58efd Fix thread_mattr_accessor share variable superclass with subclass
The current implementation of `thread_mattr_accessor` set variable
sharing superclass with subclass. So the method doesn't work as documented.

Precondition

    class Account
      thread_mattr_accessor :user
    end

    class Customer < Account
    end

    Account.user = "DHH"
    Account.user  #=> "DHH"
    Customer.user = "Rafael"
    Customer.user # => "Rafael"

Documented behavior

    Account.user  # => "DHH"

Actual behavior

    Account.user  # => "Rafael"

Current implementation set variable statically likes `Thread[:attr_Account_user]`,
and customer also use it.

Make variable name dynamic to use own thread-local variable.
2016-08-04 10:11:06 +09:00
Andrew White
0e762ecdc3 Add :weeks to the list of variable duration parts
Since 434df00 week durations are no longer converted to days. This means
we need to add :weeks to the parts that ActiveSupport::TimeWithZone will
consider being of variable duration to take account of DST transitions.

Fixes #26039.
2016-08-03 14:45:09 +01:00
David Heinemeier Hansson
afc9a82567 Revert "Adds not_in? onto Object" 2016-07-29 14:45:20 -07:00
Rafael França
0020f1a4c9 Merge pull request #25914 from jmccartie/jm/not_in
Adds `not_in?` onto Object
2016-07-22 19:48:46 -03:00
Xavier Noria
9256bbbbd7 the infamous typo only seen in GitHub's diff [ci skip] 2016-07-22 00:27:39 +02:00
Jon McCartie
4db6ac29f2 Adds not_in? onto Object 2016-07-21 17:23:33 -05:00
Xavier Noria
575dbeeefc define Range#match? if Ruby < 2.4
See the rationale in the documentation included in this patch.

We are going to gradually introduce this predicate in the code base.
2016-07-22 00:15:52 +02:00
Bart de Water
d4ea18a8cb
Allow MessageEncryptor to take advantage of authenticated encryption modes
AEAD modes like `aes-256-gcm` provide both confidentiality and data authenticity, eliminating the need to use MessageVerifier to check if the encrypted data has been tampered with.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-07-21 10:38:33 -07:00
Genadi Samokovarov
16f24cd10f Introduce assert_changes and assert_no_changes
Those are assertions that I really do miss from the standard
`ActiveSupport::TestCase`. Think of those as a more general version of
`assert_difference` and `assert_no_difference` (those can be implemented
by assert_changes, should this change be accepted).

Why do we need those? They are useful when you want to check a
side-effect of an operation. `assert_difference` do cover a really
common case, but we `assert_changes` gives us more control. Having a
global error flag? You can test it easily with `assert_changes`. In
fact, you can be really specific about the initial state and the
terminal one.

```ruby
error = Error.new(:bad)
assert_changes -> { Error.current }, from: nil, to: error do
  expected_bad_operation
end
```

`assert_changes` follows `assert_difference` and a string can be given
for evaluation as well.

```ruby
error = Error.new(:bad)
assert_changes 'Error.current', from: nil, to: error do
  expected_bad_operation
end
```

Check out the test cases if you wanna see more examples.

🍻
2016-07-17 12:58:57 +03:00
oss92
b937c24edc Added :fallback_string option to Array#to_sentence 2016-07-13 20:19:26 +02:00
John Gesimondo
424e961be7 Raise ArgumentError for bad strptime arguments 2016-07-11 20:49:21 -07:00
Vipul A M
919e705362
travel/travel_to travel time helpers, now raise on nested calls,
as this can lead to confusing time stubbing.

     Instead of:

         travel_to 2.days.from_now do
           # 2 days from today
           travel_to 3.days.from_now do
             # 5 days from today
           end
         end

     preferred way to achieve above is:

         travel_to 2.days.from_now
         # 2 days from today

         travel_back
         travel_to 5.days.from_now
         # 5 days from today

Closes #24690
Fixes #24689
2016-07-02 15:09:34 -07:00
Yosuke Kabuto
b76f82d714 Update CHANGELOG.md for #25628 [ci skip]
Move new CHANGELOG entry top [ci skip]

Remove parameter "options = nil" for #clear
2016-07-02 23:58:14 +09:00
Godfrey Chan
ffded19faf Clearify CHANGELOG for #23011 [ci skip] 2016-06-27 08:37:06 -07:00
Godfrey Chan
3a9428df91 Merge pull request #23011 from arnvald/bugfix/correctly_parse_date
Use correct timezone when parsing date in json
2016-06-25 12:02:07 +08:00
Kevin McPhillips
b081633efa Update changelog for #25341 2016-06-22 20:42:54 -04:00
Rafael Mendonça França
4a7cd700b4
Remove deprecated arguments in assert_nothing_raised 2016-06-13 12:05:33 -04:00
Sean Griffin
2c5a8ba6f6 Don't blank pad day of the month when formatting dates
We are currently using `%e` which adds a space before the result if the
digit is a single number. This leads to strings like `February  2, 2016`
which is undesireable. I've opted to replace with 0 padding instead of
removing the padding entirely, to preserve compatibility for those
relying on the fact that the width is constant, and to be consistent
with time formatting.

Fixes #25251.
2016-06-02 11:47:22 -04:00
Rafael Mendonça França
9a0e09696a
Merge pull request #23930 from gsamokovarov/module-delegate-missing-to
Introduce Module#delegate_missing_to
2016-05-24 18:33:41 -03:00
Jeremy Daer
e35b98e6f5
Action Mailer: Declarative exception handling with rescue_from.
Follows the same pattern as controllers and jobs. Exceptions raised in
delivery jobs (enqueued by `#deliver_later`) are also delegated to the
mailer's rescue_from handlers, so you can handle the DeserializationError
raised by delivery jobs:

```ruby
class MyMailer < ApplicationMailer
  rescue_from ActiveJob::DeserializationError do
    …
  end
```

ActiveSupport::Rescuable polish:
* Add the `rescue_with_handler` class method so exceptions may be
  handled at the class level without requiring an instance.
* Rationalize `exception.cause` handling. If no handler matches the
  exception, fall back to the handler that matches its cause.
* Handle exceptions raised elsewhere. Pass `object: …` to execute
  the `rescue_from` handler (e.g. a method call or a block to
  instance_exec) against a different object. Defaults to `self`.
2016-05-15 18:44:16 -07:00
Rafael Mendonça França
8ecc5ab1d8 Start Rails 5.1 development 🎉 2016-05-10 03:46:56 -03:00
Rafael Mendonça França
fbdcf5221a Preparing for 5.0.0.rc1 release 2016-05-06 16:54:40 -05:00
Jeremy Daer
3136b17b7f
AS::Duration changelog polish
Use the updated changelog from the first merge: 7254517

References #22806, #24762.

[ci skip]
2016-04-29 13:12:00 -07:00
Andrey Novikov
434df0016e
Change 1.week to create 1 week durations instead of 7 days durations.
This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
2016-04-28 03:45:05 +03:00
eileencodes
f7a986012a Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
Jeremy Daer
c1ad19c92f
Revert "Change 1.week to create 1 week durations instead of 7 days durations."
Regression: adding minutes/hours to a time would change its time zone

This reverts commit 1bf9fe75a6473cb7501cae544cab772713e68cef.
2016-04-27 14:36:22 -05:00
Alexey Shein
420730b10b
Do not cache ActiveSupport::TimeZone#utc_offset
This can be an issue when TZInfo::TimeZone#current_period is refreshed
due to timezone period transition, but it's not reflected in
ActiveSupport::TimeZone object.

For example, on Sun, 26 Oct 2014 22:00 UTC, Moscow changed its TZ from
MSK +04:00 to MSK +03:00 (-1 hour). If ActiveSupport::TimeZone['Moscow']
happens to be initialized just before the timezone transition, it will
cache its stale utc_offset even after the timezone transition.

This commit removes cache and fixes this issue.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-25 20:55:33 -05:00
Vipul A M
abeabdbc88 Follow up of c9c5788a52
[ci skip]
2016-04-24 01:18:15 +05:30
Andrew White
ee5e476aad Make getlocal and getutc always return instances of Time
Previously these methods could return either a DateTime or a Time
depending on how the ActiveSupport::TimeWithZone instance had
been constructed. Changing to always return an instance of Time
eliminates a possible stack level too deep error in to_time where
it was wrapping a DateTime instance.

As a consequence of this the internal time value is now always an
instance of Time in the UTC timezone, whether that's as the UTC
time directly or a representation of the local time in the timezone.

There should be no consequences of this internal change and if
there are it's a bug due to leaky abstractions.
2016-04-23 19:34:54 +01:00
Andrew White
a424bbb242 Add DateTime#subsec
Mirrors the Time#subsec method by returning the fraction
of the second as a Rational.
2016-04-23 19:18:38 +01:00
Andrew White
dbc7a7cb50 Add additional aliases for DateTime#utc 2016-04-23 18:01:38 +01:00