Commit Graph

7244 Commits

Author SHA1 Message Date
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
kenta-s
9140720dcf Add tests for blank? 2017-02-06 23:27:50 +09:00
Benjamin Fleischer
c8b5d828e7 Correct spelling
```
go get -u github.com/client9/misspell/cmd/misspell
misspell  -w -error -source=text .
```
2017-02-05 19:00:18 -06: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
Jared Beck
e014042bad Docs: Correction: Module::DelegationError
When the delegation target is nil and the allow_nil option is not
in use, a Module::DelegationError is raised.

    class C
      delegate :a, to: :b
        def b
          nil
        end
      end
    C.new.a
    # => Module::DelegationError: C#a delegated to b.a, but b is nil

[ci skip]
2017-02-03 17:27:04 -05:00
Arthur Nogueira Neves
c98e08df7a explicitly require listen in EventedFileUpdateCheckerTest (#27867)
Currently, executing the `test_initialize_raises_an_ArgumentError_if_no_block_given`
test alone will result in an error.

```
$ ./bin/test test/evented_file_update_checker_test.rb -n test_initialize_raises_an_ArgumentError_if_no_block_given
Run options: -n test_initialize_raises_an_ArgumentError_if_no_block_given --seed 6692

# Running:

E

Error:
EventedFileUpdateCheckerTest#test_initialize_raises_an_ArgumentError_if_no_block_given:
NameError: uninitialized constant EventedFileUpdateCheckerTest::Listen
    rails/activesupport/test/evented_file_update_checker_test.rb:21:in `teardown'
```

This is because if do not specify a file or directory for
`EventedFileUpdateChecker`, do not require `listen`, and using listen
method in teardown.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/evented_file_update_checker.rb#L53..L65

Therefore, added listen's require to avoid errors.
2017-02-01 13:45:56 -05:00
yuuji.yaginuma
725058fc09 explicitly require listen in EventedFileUpdateCheckerTest
Currently, executing the `test_initialize_raises_an_ArgumentError_if_no_block_given`
test alone will result in an error.

```
$ ./bin/test test/evented_file_update_checker_test.rb -n test_initialize_raises_an_ArgumentError_if_no_block_given
Run options: -n test_initialize_raises_an_ArgumentError_if_no_block_given --seed 6692

# Running:

E

Error:
EventedFileUpdateCheckerTest#test_initialize_raises_an_ArgumentError_if_no_block_given:
NameError: uninitialized constant EventedFileUpdateCheckerTest::Listen
    rails/activesupport/test/evented_file_update_checker_test.rb:21:in `teardown'
```

This is because if do not specify a file or directory for
`EventedFileUpdateChecker`, do not require `listen`, and using listen
method in teardown.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/evented_file_update_checker.rb#L53..L65

Therefore, added listen's require to avoid errors.
2017-02-01 08:43:39 +09:00
yuuji.yaginuma
11d994724e remove unused variable
This removes the following warnings.

```
activesupport/test/file_update_checker_shared_tests.rb:279: warning: assigned but unused variable - checker
```
2017-02-01 08:20:13 +09:00
Rafael Mendonça França
3f2b7d60a5
Remove deprecated callbacks from ActionDispatch middlewares 2017-01-31 15:52:12 -05:00
Eileen M. Uchitelle
3488f08ce1 Merge pull request #27857 from kenta-s/add-test-for-variable_size_secure_compare
Add test for `variable_size_secure_compare`
2017-01-31 08:33:48 -05:00
kenta-s
02bb4c55fd Add test for variable_size_secure_compare 2017-01-31 20:41:14 +09:00
kenta-s
20435f3547 Remove redundant right parentheses in number_helper [ci skip] 2017-01-31 20:13:03 +09:00
Rafael Mendonça França
44901ca903
Raise in the initialize not in the execute 2017-01-31 01:15:07 -05:00
Rafael França
6d8fdd136b Merge pull request #27824 from kenta-s/raise-an-error-if-no-block-given
Raise an error if FileUpdateChecker#execute is called with no block
2017-01-31 00:54:01 -05:00
Arthur Nogueira Neves
543f19626b Merge pull request #27797 from y-yagi/correctly_check_error_message
correctly check error message
2017-01-30 20:16:30 -05:00
Jeremy Daer
1fc995577f Merge pull request #27822 from mtsmfm/bump-unicode-version
Update Unicode Version to 9.0.0
2017-01-30 13:16:02 -07:00
Akira Matsuda
6b7bfece37 Ruby constant look-up no longer falls back to top-level since 2.5
This behavior used to warn until 2.4, and raises since 2.5.
The test here was intentinally named not to start with "test_" and so it used not to be executed because this never passes,
but now is should pass in trunk.

https://bugs.ruby-lang.org/issues/11547
44a2576f79

closes #19897
2017-01-30 16:52:54 +09:00
Akira Matsuda
17848036ad Missing require 'active_support/core_ext/hash/keys'
Without this, the test causes a "method redefined" warning because
* first it loads I18n and defines Hash#deep_symbolize_keys inside I18n's lib/i18n/core_ext/hash.rb
* then it loads AS/core_ext/hash/keys.rb afterwards
2017-01-29 08:41:06 +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
kenta-s
3585155f1b Raise an error if FileUpdateChecker#execute is called with no block 2017-01-28 00:53:32 +09:00
kenta-s
221489a6e9 Fix broken sample code for EventedFileUpdateChecker [ci skip] 2017-01-28 00:23:14 +09:00
Akira Matsuda
442daca3c4 Uninterned Symbol can be duped since ruby 2.4.1
11e6bd5ac2

Leaving the 2.4.0 conditional for now, in order never to forget backporting r57407 to 2.4.1
2017-01-26 06:37:50 +09:00
kenta-s
19fc419925 Fix grammar 'an hyphen' -> 'a hyphen' [ci skip] 2017-01-25 23:50:20 +09:00
Akira Matsuda
ed7a3cde67 This seems to be working on JRuby 9K
% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 +jit [darwin-x86_64]
"\u307B\u3052"

% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64]
"\u307B\u3051\u3099"

% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin14]
"\u307B\u3051\u3099"
2017-01-25 18:27:52 +09:00
Richard Schneeman
1107c85876 Merge pull request #27798 from yui-knk/give_message_to_test_duplicable
Give a message to `#test_duplicable` assertion
2017-01-25 02:53:49 -06:00
Jeremy Evans
7da8d76206
Change ActionView ERB Handler from Erubis to Erubi
Erubi offers the following advantages for Rails:

* Works with ruby's --enable-frozen-string-literal option
* Has 88% smaller memory footprint
* Does no freedom patching (Erubis adds a method to Kernel)
* Has simpler internals (1 file, <150 lines of code)
* Has an open development model (Erubis doesn't have a
  public source control repository or bug tracker)
* Is not dead (Erubis hasn't been updated since 2011)

Erubi is a simplified fork of Erubis that contains just the
parts that are generally needed (which includes the parts
that Rails uses).  The only intentional difference in
behavior is that it does not include support for <%=== tags
for debug output.  That could be added to the ActionView ERB
handler if it is desired.

The Erubis template handler remains in a deprecated state
so that code that accesses it directly does not break.  It
can be removed after Rails 5.1.
2017-01-25 01:41:27 -07:00
yui-knk
2aac4e4392 Give a message to #test_duplicable assertion
Giving a message helps us to know what happened
when we look at Travis CI.
2017-01-25 13:57:31 +09:00
yuuji.yaginuma
c42bd31977 correctly check error message
`assert_raise` does not check error message. However, in some tests,
it seems like expecting error message checking with `assert_raise`.
Instead of specifying an error message in `assert_raise`, modify to use
another assert to check the error message.
2017-01-25 09:58:15 +09:00
kenta-s
5db8d7308b Fix sample code for expand_cache_key usage [ci skip] 2017-01-24 20:28:20 +09:00
kenta-s
d1c546ff2a Add module name to BacktraceCleaner usage example [ci skip] 2017-01-22 19:19:13 +09:00
bogdanvlviv
ec3933e14c add missing comment out [ci skip] 2017-01-20 15:41:23 +02:00
yuuji.yaginuma
58156a803e add missing comment out [ci skip] 2017-01-20 16:39:03 +09:00
Jean Boussier
b9bda7fd89 Allocation free Integer#to_s 2017-01-19 15:24:41 +01:00
Akira Matsuda
044f8bdf62 Unused class for testing since 93559da4826546d07014f8cfa399b64b4a143127 2017-01-18 17:30:46 +09:00
Akira Matsuda
45d1b69140 rm rm_f that is not in use 2017-01-18 17:30:46 +09:00
Corey Ward
1d3ddac7b8 Adjust Module.parent_name to work when frozen; fixes #27637 2017-01-17 22:18:36 -06:00
Corey Ward
307065f959 Use appropriate assertion based on expectation
This resolves a stern Minitest “warning” about an upcoming
behavior change in MiniTest 6 that will result in the test failing.

https://github.com/seattlerb/minitest/issues/666
2017-01-17 14:25:41 -06:00
Akira Matsuda
146e928800 Don't pollute Object with rubinius_skip and jruby_skip
we call them only in the tests
2017-01-17 18:51:50 +09:00
Akira Matsuda
4ad1a52f5a All currently supported rubies already have LoadError#path 2017-01-17 18:16:21 +09:00
Akira Matsuda
8e2feedd31 else + if = elsif 2017-01-17 18:02:52 +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
Kevin McPhillips
f90a08c193 Raise ArgumentError if attempting to transliterate anything that is not a string 2017-01-16 14:40:41 -05:00
Akira Matsuda
88daf5dee4 Should do nothing here 2017-01-16 12:33:37 +09:00
Kasper Timm Hansen
7c3a99eeca Revert "Merge pull request #27686 from koic/friendly_bigdecimal_inspect"
The exact inspect output of a BigDecimal is out of scope for what we're trying
to communicate about `dup` and `duplicable?` here.

Adding two examples distracts is disctracting, so keep the docs from before
since our minimal version is Ruby 2.2.2.

[ Koichi ITO, Jon Moss, Kasper Timm Hansen ]

This reverts commit 2163874dedaf83e67599c2930c2686caa165fbad, reversing
changes made to 46fdbc5290335ed38fa9fe2b6b0ef8abe4eccb1b.
2017-01-15 19:49:34 +01:00
Koichi ITO
7b3d663b4d Several representation of BigDecimal has changed in Ruby 2.4.0+ [ci skip]
cf. https://github.com/ruby/bigdecimal/pull/42
2017-01-15 12:01:55 +09:00
Akira Matsuda
764bbb801e It would be safer not to totally undef core classes' respond_to_missing?
instead, rewrite them to no-op
2017-01-15 04:42:03 +09: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
b89316fed3 This test wasn't actually an effective regression test 2017-01-15 03:31:24 +09:00
Akira Matsuda
a3afd05384 Unused &block parameter 2017-01-15 02:44:03 +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
Akira Matsuda
3d91649654 Constant look-up would no longer fall back to top-level constant since ruby 2.5
See: 44a2576f79
9df88e9cae
2017-01-13 16:38:30 +09:00
Akira Matsuda
9360b6be63 class Foo < Struct.new(:x) creates an extra unneeded anonymous class
because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
2017-01-13 15:13:47 +09:00
Andrew White
9ae511f550 Add duration constructors for use in Numeric extensions
The Numeric extensions like 1.day, 1.month, etc. shouldn't know
how the internals of ActiveSupport::Duration works.
2017-01-12 10:05:16 +00:00
Andrew White
2a5ae2b714 Add additional tests for #27610
Since 1.month no longer equals 30.days add some tests to ensure that
addition maintains the same day in the month or is the last day in
the month if the month has less days than the current day. Also add
a test for the behaviour of 12.months == 1.year.
2017-01-12 10:05:16 +00:00
Akira Matsuda
b70fc698e1 Reduce string objects by using \ instead of + or << for concatenating strings
(I personally prefer writing one string in one line no matter how long it is, though)
2017-01-12 17:45:37 +09:00
Andrew White
033f654027 Merge pull request #27610 from Envek/fix_and_speed_up_duration_parsing
Fix inconsistent parsing of Durations with both months and years
2017-01-12 07:20:28 +00:00
Akira Matsuda
c82fa18514 Use Encoding::UTF_8 constant for default_{internal,external} in the tests 2017-01-11 17:48:00 +09:00
Jonas Nicklas
3d78949c74 Make time travel work with subclasses of Time/Date/Datetime
Closes #27614

Previously when calling `now` on a subclass of e.g. `Time` it would return an instance of `Time` instead of returning an instance of the subclass. This way, we always return the correct class.
2017-01-10 11:43:26 +01: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
Sean Griffin
98c6e4e56c Merge pull request #27392 from y-yagi/use_same_class_on_compact
ensure `#compact` of HWIDA to return HWIDA
2017-01-06 06:23:24 -05:00
yuuji.yaginuma
d97ba34472 ensure #compact of HWIDA to return HWIDA
`Hash#compact` of Ruby native returns new hash.
Therefore, in order to return HWIDA as in the past version, need to
define own `#compact` to HWIDA.

Related: #26868
2017-01-06 17:49:18 +09:00
Akira Matsuda
5473e390d3 self. is not needed when calling its own instance method
Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
2017-01-05 19:58:52 +09:00
Rafael Mendonça França
209bfc0a5c
Fix style guide violations 2017-01-05 00:40:24 -05:00
Rafael Mendonça França
46bb76acad
Make sure we generate keys that can be used with the cipher
We use aes-256-cbc cipher by default and it only accepts keys with 32
bytes at max.

Closes #27576.

[ci skip]
2017-01-04 23:54:03 -05:00
Rafael França
d66789fa0e Merge pull request #26480 from tbrisker/fix-26461
Clarify that mattr_* creates public methods
2017-01-04 23:39:11 -05:00
Akira Matsuda
24bacb3e95 There's no such module 2017-01-05 01:37:36 +09:00
Jon Moss
bb8f57ec30 Remove unnecessary require statements
Should have been removed via 8e43fc5ace8039370f233570863b34821a3be46f.
2017-01-03 20:30:02 -05:00
Sean Griffin
a194ec88fe Merge pull request #27363 from amatsuda/refined_array_sum
Refining Array#sum monkey-patch using Refinements
2017-01-03 13:50:57 -05:00
Rafael França
3e8fa248b1 Merge pull request #27520 from prathamesh-sonpatki/merge-uncountable-tests-for-inflector
Make the tests for uncountability of ascii and non-ascii words uniform
2017-01-01 15:43:10 -05:00
Kasper Timm Hansen
c6c3b130e1 Fix Symbol#duplicable? for Ruby 2.4.0.
Ruby 2.4.0 has trouble duplicating certain symbols created from
strings via `to_sym`.

It didn't happen with `'symbol'.to_sym.dup` for some reason, but
works fine with the longer string sample.

Once a newer Ruby version with a fix is released we'll get have
a failing test case we can fix.

Ref: #27532
2017-01-01 13:41:24 +01:00
Jon Moss
37d956f45f Bump license years for 2017
Per https://www.timeanddate.com/counters/firstnewyear.html, it's already
2017 in a lot of places, so we should bump the Rails license years to
2017.

[ci skip]
2016-12-31 08:34:08 -05:00
Prathamesh Sonpatki
11b6f9e06a
Make the tests for uncountability of ascii and non-ascii words uniform 2016-12-31 09:51:43 +05:30
Matthew Draper
c3ff36815c Merge pull request #12509 from eitoball/pluralize_for_non_ascii_character_words
Fix ActiveSupport::Inflector.pluralize behavior for words that consist of non-ASCII characters

(test only; the original bug was fixed by 1bf50badd943e684a56a03392ef0ddafefca0ad7)
2016-12-31 11:47:24 +10:30
Matthew Draper
ee669ab36f Prefer Regexp#match? over Regexp#=== 2016-12-31 11:42:16 +10:30
Matthew Draper
afe057ebc2 Only add regexes for the new words 2016-12-31 11:42:16 +10:30
Rafael Mendonça França
010e246756
Fix Rubocop violations and fix documentation visibility
Some methods were added to public API in
5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of
the public API.
2016-12-28 21:53:51 -05:00
Akira Matsuda
a46b2f8911 assert_equal takes expectation first 2016-12-26 11:04:56 +09:00
Akira Matsuda
019cc5960d "Use assert_nil if expecting nil from ...:in `...'. This will fail in minitest 6." 2016-12-25 13:15:56 +09:00
Akira Matsuda
4ba9e61d99 Expectation first 2016-12-25 13:15:56 +09:00
Akira Matsuda
630cc857c9 "Use assert_nil if expecting nil from ...:in `...'. This will fail in MT6." 2016-12-25 09:59:16 +09:00
Akira Matsuda
e8ba0c0f21 "Use assert_nil if expecting nil. This will fail in minitest 6." 2016-12-25 02:29:52 +09:00
Akira Matsuda
a43e7706be Privatize unneededly protected methods in Active Support 2016-12-24 11:39:05 +09:00
Akira Matsuda
4db99eb87b No need to nodoc private methods 2016-12-24 11:36:51 +09:00
Akira Matsuda
3fe6a5d510 Privatize unneededly protected methods in Active Support tests 2016-12-24 00:22:29 +09:00
Akira Matsuda
21e5fd4a2a Describe what we are protecting 2016-12-23 23:48:54 +09: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
Akira Matsuda
3582f58a75 protected here doesn't protect anything
there aren't any instance method defined in this class
2016-12-19 17:50:29 +09:00
Matthew Draper
3b055d2ca4 Merge pull request #27366 from utilum/avoid_fixnum_warning
Fix Fixnum deprecated warning in Ruby 2.4+
2016-12-18 14:27:28 +10:30
Matthew Draper
a47efcfcae Merge pull request #27368 from matthewd/doubled-callbacks
Support double-yield inside an around callback
2016-12-16 23:14:46 +10:30
utilum
598f10c000 Fix Fixnum deprecated warning in Ruby 2.4+ 2016-12-16 10:57:19 +01:00
Matthew Draper
833ea903a9 Support double-yield inside an around callback
It's questionable whether this is a good thing -- it forces any later/
inner callback to handle multiple invocations, along with the actual
wrapped action. But it worked prior to 871ca21f6a1d65c0ec78cb5a9641411e2210460b,
so we shouldn't break it unintentionally.
2016-12-15 19:23:10 +10:30
Akira Matsuda
571f0f32c6 Refining Array#sum monkey-patch using Refinements
Because we don't want to see our ugly orig_sum method outside of this file
2016-12-15 05:48:23 +09:00
Jean Boussier
11e05defec Fix constantize edge case involving prepend, autoloading and name conflicts
In the following situation:

```ruby
class Bar
end

module Baz
end

class Foo
  prepend Baz
end

class Foo::Bar
end
```

Running `Inflector.constantize('Foo::Bar')` would blow up with a NameError.

What is happening is that `constatize` was written before the introduction
of prepend, and wrongly assume that `klass.ancestors.first == klass`.

So it uses `klass.ancestors.inject` without arguments, as a result
a prepended module is used in place of the actual class.
2016-12-14 14:25:43 +01:00
yuuji.yaginuma
2f6105e494 fix new warning in ruby 2.4
This fixes the following warning.

```
test/caching_test.rb:986: warning: parentheses after method name is interpreted as
test/caching_test.rb:986: warning: an argument list, not a decomposed argument

test/cases/adapters/mysql2/reserved_word_test.rb:146: warning: parentheses after method name is interpreted as
test/cases/adapters/mysql2/reserved_word_test.rb:146: warning: an argument list, not a decomposed argument
```

Ref: 65e27c8b13
2016-12-14 08:58:39 +09: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
Akira Matsuda
5d07e8a326 💅 2016-12-13 00:48:14 +09:00
Akira Matsuda
bd9e134b01 nil, true, 1, etc. don't raise on #dup since Ruby 2.4
https://bugs.ruby-lang.org/issues/12979
2016-12-13 00:43:56 +09:00
Akira Matsuda
b87619f945 Keep AS::XmlMini::PARSING["decimal"].call('') returning 0
BigDecimal('an invalid string') has changed its behavior to raise an ArgumentError since 1.3.0
https://bugs.ruby-lang.org/issues/10286
2016-12-13 00:06:08 +09:00
Toshimaru
d9ff835b99 split DELEGATION_RESERVED_METHOD_NAMES in half 2016-12-09 05:21:11 +09:00
yuuji.yaginuma
d71f289fb2 stop using removed render :text
Follow up to 79a5ea9eadb4d43b62afacedc0706cbe88c54496
2016-12-03 15:28:59 +09:00
Sean Griffin
4e73ffa9b4 Exclude singleton classes from subclasses and descendants
This behavior changed in Ruby starting with 2.3.0, as a result of
https://bugs.ruby-lang.org/issues/11360. This results in a change in
behavior of these methods which is likely undesirable.

Fixes #27238
2016-12-01 14:53:31 -05:00
Matthew Draper
f9592e1631 Merge pull request #27206 from kirs/fix-testing-isolation-2
Fix arguments passing in testing isolation
2016-12-01 05:57:18 +10:30
Kir Shatrov
4b3cd4b0fe Fix arguments passing in testing isolation
The issue affects MRI 2.2.5, MRI 2.3.3, JRuby 9.1.6.0. It can be reproduced by:

```
$ cd activemodel
$ NO_FORK=1 bundle exec rake test
```

If we wrap original arguments in quotes, it will be considered as a one big single argument.
Later, [`rake/rake_test_loader.rb`](https://github.com/ruby/rake/blob/7863b97/lib/rake/rake_test_loader.rb#L15)
will iterate over ARGS and try to require that huge single "argument" (which is a list of multiple .rb files).
This leads to an exception:

```
/Users/kir/Project
s/opensource/rails/vendor/bundle/gems/rake-11.3.0/lib/rake/rake_test_loader.rb:15:in `require': cannot load such file -- /Users/kir/Projects/opensource/rails/activemodel/test/cases/
attribute_assignment_test.rb [stripped] /Users/kir/Projects/opensource/rails/activemodel/test/cases/validations/with_validation_test.rb /Users/kir/Projects/opensource/rails/activemodel/test/cases/validations_test
.rb (LoadError)

        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/rake-11.3.0/lib/rake/rake_test_loader.rb:15:in `block in <main>'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/rake-11.3.0/lib/rake/rake_test_loader.rb:4:in `select'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/rake-11.3.0/lib/rake/rake_test_loader.rb:4:in `<main>'
```

Originally quotes were introduced in https://github.com/rails/rails/pull/19819 to fix MRI 2.2.2.

The fix solves issue on all affected platforms: MRI 2.2.5, MRI 2.3.3, JRuby 9.1.6.0.
2016-11-30 14:02:02 -05:00
Akira Matsuda
7e73145b39 Missing require 'active_support/notifications' 2016-11-30 11:28:34 +09:00
Sean Griffin
32f215c301 Treat combined durations as a single unit
Prior to this commit, `3.months - 3.months` would result in a duration
that has the "parts" of `[[:months, 3], [:months, -3]]`. This would mean
that it was subtly different than `2.months - 2.months`. When applied to
a time, the date might actually change if the resulting day doesn't
exist however many months in the future, even though in both cases we
just wanted to add `0`, which should always be an identity operation.

With this change, we now store the parts as a hash, so `3.months -
3.months` is simply stored as `{ months: 0 }`.
2016-11-29 13:02:14 -05:00
yuuji.yaginuma
32225387c1 use public Module#include instead of send :include
Follow up to #18767
2016-11-27 22:20:52 +09:00
Matthew Draper
f243e7f0d0 Merge pull request #26874 from tgxworld/fix_broadcast_logger
`Broadcast#silence` breaks custom loggers that do not include `Logg…
2016-11-25 15:57:50 +10:30
Ryuta Kamizono
d99b3848bb Fix require_dependency message format
`depend_on` message format is `"No such file to load -- %s.rb"`.
But `require_dependency` message is missing `.rb` suffix.

```
% git grep -n 'No such file to load'
actionview/test/actionpack/abstract/helper_test.rb:112:        assert_equal "No such file to load -- very_invalid_file_name.rb", e.message
activesupport/lib/active_support/dependencies.rb:245:      def require_dependency(file_name, message = "No such file to load -- %s.rb")
activesupport/lib/active_support/dependencies.rb:333:    def depend_on(file_name, message = "No such file to load -- %s.rb")
```
2016-11-25 06:56:05 +09:00
Yves Senn
2b4a9735d8 update bin/test scripts to prevent double runs.
The test runner was updated to make use of autorun. This caused the
`bin/test` scripts to run Minitest twice.
2016-11-21 17:25:12 +01:00
Kasper Timm Hansen
6d6249b1c1 ✂️ needless lines beneath private. 2016-11-20 17:58:36 +01:00
Jon Moss
8e3901b5e6 Move tests to a module, include in subclasses, style linting
This fixes an error where the test runner would try and run
XMLMiniEngineTest like a normal test class, except it's abstract. Now,
to circumvent this, we don't include any of the actual tests in
XMLMiniEngineTest; they are wrapped in a module that is included in
subclass when they inherit from XMLMiniEngineTest. Pretty neat, huh?
2016-11-20 10:46:16 -05:00
Jon Moss
0ab54f4a49 Create XMLMiniEngineTest; base class for all tests 2016-11-20 10:46:16 -05:00
Jon Moss
2bdc4ddc06 Code styling cleanup 2016-11-20 10:45:58 -05:00
Jon Moss
305e2922a4 Create CommonXMLMiniAdapterTest; common tests module
Created a new module (a la Action Cable subscription adapter's test
suite) to be included in all sub class test to ensure compatability and
reduce duplicated code.
2016-11-20 10:45:09 -05:00
Jon Moss
1d18b9b2fb Do not include ActiveSupport into test classes
Will help get rid of errors like the following:

```
  1) Error:
JDOMEngineTest#test_order=:
ArgumentError: wrong number of arguments (0 for 1)
    /Users/jon/code/rails/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb:106:in `test_order='
```
2016-11-19 10:30:57 -05:00
Rafael França
76c273868e Merge pull request #27070 from jonhyman/patch-raw-true
Removes 'raw: true' from MemCacheStore#read_multi
2016-11-17 18:18:34 -05:00
Sean Griffin
7a3be90dce Refactor the handling of fallback exception handlers 2016-11-17 15:03:57 -05:00
Sean Griffin
f48bb1b4ad Call fallback exception handlers with the right exception
The issue presented in #26246 showed a deeper underlying problem. When
we fell back to the exception handler for an exceptions cause, we were
calling that handler with the outer raised exception. This breaks the
calling code's expectations, especially if the exception has methods on
it behond those from `StandardError`.
2016-11-17 14:50:41 -05:00
Jonathan Hyman
226b845113 Removes 'raw: true' from MemCacheStore#read_multi, per https://github.com/rails/rails/issues/27066. 2016-11-16 15:42:31 -05:00
Kir Shatrov
3261470452 Fix testing isolation
AS::Testing::Isolation has two ways to isolate the process:
forking and subprocessing. The second way is used on JRuby and other
platforms that don't support forking.

The way how subprocessing works is that we prepare a command to run a
new process:

```
/opt/rubies/2.3.0/bin/ruby -I{skipped_load_path} test/initializable_test.rb '' -nInitializableTests::Basic#test_Initializer_provides_context's_class_name
```

As you see, there's unescaped quote at the end of the line.
It leads to:

```
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
```

This fixes tests on MRI + NO_FORK variable and on JRuby 🎉
2016-11-15 15:56:32 -05:00
Devon Estes
355bdeb54e Add missing documentation for MemoryStore#clear [ci skip]
We were missing some form of documentation for this method, so I've gone ahead
and added some!
2016-11-15 14:23:29 +01: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
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
Rafael França
f1c5b0bd0a Merge pull request #26222 from vipulnsward/26134-fix
Format and send logs to logger.fatal from DebugExceptions
2016-11-13 22:50:30 -05:00
Andrew White
213f0d63a5 Update CHANGELOG 2016-11-13 23:25:05 +00:00
Andrew White
dadba9ae57 Remove deprecated :prefix option 2016-11-13 23:09:03 +00:00
Andrew White
2ff2b98032 Remove deprecated new_from_hash_copying_default 2016-11-13 23:09:03 +00:00
Andrew White
0e8d297301 Remove deprecated time marshal core_ext file 2016-11-13 23:09:03 +00:00
Andrew White
73b18eccdf Remove deprecated struct core_ext file 2016-11-13 23:09:02 +00:00
Vipul A M
546ff50d82
Remove warning from access to Bignum class, 2**64 is already a known bignum value. See also http://patshaughnessy.net/2014/1/9/how-big-is-a-bignum for smallest bignum value 2016-11-13 18:08:57 -05:00
Andrew White
2ae41d24b9 Remove deprecated module method_transplanting file 2016-11-13 22:29:18 +00:00
Andrew White
c32ccd837e Remove deprecated local_constants 2016-11-13 22:28:18 +00:00
Andrew White
c9458c74e0 Remove deprecated kernel debugger file 2016-11-13 22:27:52 +00:00
Andrew White
3641cd3f3d Remove deprecated namespaced_key 2016-11-13 22:17:37 +00:00
Andrew White
8b646041be Remove deprecated set_cache_value 2016-11-13 22:16:54 +00:00
Andrew White
efdb785d7f Remove deprecated escape_key 2016-11-13 22:15:45 +00:00
Andrew White
08260c2373 Remove deprecated key_file_path 2016-11-13 22:14:31 +00:00
Andrew White
89071400b4 Fix typo in constant reference 2016-11-13 15:59:13 +00:00
Andrew White
60d82fa141 It's a NAN not Infinity 2016-11-13 15:57:42 +00:00
Andrew White
d2890f76d4 Use literal values in assertions
Using the method you're testing to generate expected
values can lead to bugs being masked.
2016-11-13 15:31:05 +00:00
Andrew White
c85d305a67 Merge pull request #26933 from prathamesh-sonpatki/fix-26877
Fix an issue with JSON encoding of "Infinity" and "NaN" values
2016-11-13 14:46:21 +00:00
Andrew White
0ef5b6c163 Merge pull request #26905 from bogdanvlviv/docs
Add missing `+` around a some literals.
2016-11-13 14:09:30 +00:00
Vipul A M
89fab56597
Format and send logs to logger.fatal from DebugExceptions instead of calling fatal multiple times. Expose tags_text from TaggedLogging to be used for log formatting
Fixes #26134
2016-11-12 15:47:39 -05:00
eno
5cadcc7479 No longer listens to dirs inside of installed gems
rails5 uses the listen gem to watch for changes from autoload directories
and from i18n directories. Changes there would be reflected by the 
running app, in development mode usually.

However, files outside of the application directory or locally installed
gems should not change during development, and rails does not need to 
reflect changes there if they do.

This change makes sure only those paths that do not originate from 
the app itself are watched. This can help especially with the situation on 
OSX, where rb-fsevent - which implements file watching - is quite a
resource hog.
2016-11-08 08:45:35 +01:00
Akira Matsuda
a3478f1685 Tweaking some test data due to sprintf behavior change in 2.4
2.3: sprintf('%0.1f', 5.55)  #=> "5.5"
2.4: sprintf('%0.1f', 5.55)  #=> "5.6"

see: 6ed8c79ddb and
295f60b94d
2016-11-05 16:19:17 +09:00
Akira Matsuda
51e991f0b2 Less method invocation 2016-11-05 15:35:40 +09:00
Arthur Nogueira Neves
db8b40b7f5 Merge pull request #26536 from y-yagi/change_increment_and_decrement_to_public_api
change `MemCacheStore#increment` and `MemCacheStore#decrement` to public API [ci skip]
2016-11-04 10:27:55 -04: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
8776f15b44
Fix an issue with JSON encoding of "Infinity" and "NaN" values
- When `as_json` returns `Infinity` or `NaN` as the value of any of the key,
  we don't used to call `as_json` on it as it was treated as primitive.
- This used to pass `Infinity` or `NaN` to `JSON.generate` and Ruby used
  to throw an error for `Infinity/NaN not allowed in JSON.`
- This patch changes the code to call `as_json` on these primitives so
  that they are converted to proper values before being passed to
  `JSON.generate`.
- Fixes #26877.
2016-10-30 20:08:55 +05:30
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Xavier Noria
56832e791f let Regexp#match? be globally available
Regexp#match? should be considered to be part of the Ruby core library. We are
emulating it for < 2.4, but not having to require the extension is part of the
illusion of the emulation.
2016-10-27 09:13:55 +02:00
bogdanvlviv
5faa9a235c Add missing + around a some literals.
Mainly around `nil`

[ci skip]
2016-10-27 00:27:47 +03:00
yui-knk
c51a9b975f Ensure #transform_values of HWIDA to return HWIDA
On Ruby 2.4, naitive `Hash#transform_values` is implemented.
`Hash#transform_values` uses an instance of Hash (`rb_hash_new`) to
collect returned values of a block.
For ensuring `#transform_values` of HWIDA to return HWIDA, we should
define `#transform_values` on HWIDA.
2016-10-26 11:18:10 +09:00
Rafael Mendonça França
c5d46a8a4e
Whitespace 2016-10-25 14:54:25 -02:00
Rafael França
3cc30db12c Merge pull request #26868 from prathamesh-sonpatki/use-hash-compact-from-ruby-24
Use Hash#compact and Hash#compact! from Ruby 2.4
2016-10-24 23:56:09 -02:00
Guo Xiang Tan
308e84e982 Broadcast#silence breaks custom loggers that does not include LoggerSilence. 2016-10-24 18:26:13 +08: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
claudiob
fbda46758b Revert #26826 and add documentation
This reverts commit a01cf703 as explained in the comment to #26826:

Realized that this PR caused the following warning in Travis CI:

```
/home/travis/build/rails/rails/activesupport/lib/active_support/dependencies.rb:293: warning: loading in progress, circular require considered harmful - /home/travis/build/rails/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
```

Indeed, `active_support/core_ext/hash/indifferent_access.rb` **needs** to require `active_support/hash_with_indifferent_access.rb` in order to access the class `ActiveSupport::HashWithIndifferentAccess`.

The other way around, though, is not _strictly_ required, unless someone tries (like I did in the [gist above](https://gist.github.com/claudiob/43cc7fe77ff95951538af2825a71e5ec)) to use `ActiveSupport::HashWithIndifferentAccess` by only requiring `active_support/hash_with_indifferent_access.rb` without first requiring `active_support/core_ext/hash/indifferent_access.rb`.

I think the solution to this is to revert this PR and instead change the documentation to explicitly state that **developers should not require 'active_support/hash_with_indifferent_access'** if all they want is to use `ActiveSupport::HashWithIndifferentAccess` – instead they should require `active_support/core_ext/hash/indifferent_access.rb`.
2016-10-21 22:55:51 -07:00
Rafael França
7bbd3e68ed Merge pull request #26843 from denisovlev/strptime_timestamps
Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s)
2016-10-22 00:12:47 -03:00
Claudio B
397025db76 Merge pull request #26826 from claudiob/add-require
Add missing require in active_support/hash_with_indifferent_access.rb
2016-10-21 18:08:34 -07:00
Aaron Patterson
b6f935bbf9
Use on_load to trigger commandline processing code
We need to use on_load so that plugins will get the same functionality
2016-10-21 14:44:17 -07:00
Charles Oliver Nutter
9531e69f99 Skip test that depends on RubyVM when it is not available (JRuby). 2016-10-21 14:36:51 -05:00
Charles Oliver Nutter
2674392058 Additional fix for argument-splat ordering differences.
See #26854
2016-10-21 10:16:58 -05:00
Charles Oliver Nutter
5f382d41c3 Explicitly unpack the expanded args to avoid execution order diff.
In https://bugs.ruby-lang.org/issues/12860 I argue that MRI's
execution order here is incorrect. The splatting of the 'c' args
should happen before the shift, but it happens after. On JRuby, it
behaves the way you would expect, leading to the 'c' args splat
still containing the block and producing an error like "cannot
convert proc to symbol" when the send attempts to coerce
it.

This patch makes the unpacking order explicit with a multi-assign,
which behaves properly on all implementations I tested.
2016-10-21 09:33:25 -05:00
denisovlev
07ffe7a621 Fix ActiveSupport::TimeZone#strptime cannot parse timestamps (%Q, %s) 2016-10-21 13:19:08 +03:00
Andrew White
f2c6db41ba Merge pull request #26839 from renuo/fix-missing-nsec-transfer
Fix copy_time_to: Copy nsec instead of usec
2016-10-21 07:03:32 +01:00
Yves Senn
dce4751a74 doc, hide non-public methods form the api docs. [ci skip]
This is a follow up to #25681, specifically this comment:
https://github.com/rails/rails/pull/25681#issuecomment-238294002

The way the thread local variable is stored is an implementation detail
and subject to change. It makes no sense to only generate a reader or
writer as you'd have to know where to read from or where it writes to.
2016-10-20 21:21:55 +02:00
Rafael Mendonça França
b10227728b
Merge pull request #26830 from headius/mask_forking_fsevent_test_on_jruby
Mask forking filesystem event on JRuby.
2016-10-20 10:42:50 -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
Aaron Patterson
cd5e4188ee
Merge pull request #26829 from headius/wait_for_events_in_listen_tests
Wait for file events to propagated for slower Listen backends.
2016-10-19 15:00:38 -07:00
claudiob
a01cf703e2 Add missing require 2016-10-19 11:48:43 -07:00
Rafael Mendonça França
bd8b50d2e5
Add comment to remove code when we are in Ruby 2.4 2016-10-14 23:57:03 -03:00
Jesús Burgos
e84ed4fd17 Use built-in #transform_values when available.
The methods Hash#transform_values and Hash#transform_values! have been
implemented in Ruby and they'll be available as part of the standard
library.

Here's the link to the discussion in Ruby's issue tracker:
https://bugs.ruby-lang.org/issues/12512

These methods are implemented in C so they're expected to perform
better.
2016-10-14 14:27:27 +02:00
Rafael França
3c8f26ac14 Merge pull request #26531 from y-yagi/remove_unused_benchmark
remove unused require `benchmark`
2016-10-10 22:04:00 -03:00
Matthew Draper
cb0452e9a5 Fixnum and Bignum are deprecated in Ruby trunk
https://bugs.ruby-lang.org/issues/12739
2016-10-08 08:13:11 +10:30
Matthew Draper
0464b728e2 Merge pull request #26359 from maclover7/jm-speed-up-time
Speed up Time.zone.now
2016-10-06 02:35:35 +10:30
Matthew Draper
4d6feef792 Merge pull request #26684 from matthewd/executor-serial
Avoid bumping the class serial when invoking executor
2016-10-05 05:23:48 +10:30
Matthew Draper
6ecb14715e Merge pull request #26686 from matthewd/deprecation-caller
Correct caller tracking in delegated deprecation methods
2016-10-05 05:23:20 +10:30
Matthew Draper
e8b36e7711 Avoid bumping the class serial when invoking executor 2016-10-03 13:35:51 +10:30
Jon Moss
353122c9da Speed up Time.zone.now
@amatsuda, during his RailsConf talk this past year, presented a
benchmark that showed `Time.zone.now` (an Active Support joint)
performing 24.97x slower than Ruby's `Time.now`. Rails master appears to
be a _bit_ faster than that, currently clocking in at 18.25x slower than
`Time.now`. Here's the exact benchmark data for that:

```
Warming up --------------------------------------
            Time.now   127.923k i/100ms
       Time.zone.now    10.275k i/100ms
Calculating -------------------------------------
            Time.now      1.946M (± 5.9%) i/s -      9.722M in   5.010236s
       Time.zone.now    106.625k (± 4.3%) i/s -    534.300k in   5.020343s

Comparison:
            Time.now:  1946220.1 i/s
       Time.zone.now:   106625.5 i/s - 18.25x slower
```

What if I told you we could make `Time.zone.now` _even_ faster? Well,
that's exactly what this patch accomplishes. When creating `ActiveSupport::TimeWithZone`
objects, we try to convert the provided time to be in a UTC format. All
this patch does is, in the method where we convert a provided time to
UTC, check if the provided time is already UTC, and is a `Time` object
and then return early if that is the case, This sidesteps having to continue on,
and create a new `Time` object from scratch. Here's the exact benchmark
data for my patch:

```
Warming up --------------------------------------
            Time.now   124.136k i/100ms
       Time.zone.now    26.260k i/100ms
Calculating -------------------------------------
            Time.now      1.894M (± 6.4%) i/s -      9.434M in   5.000153s
       Time.zone.now    301.654k (± 4.3%) i/s -      1.523M in   5.058328s

Comparison:
            Time.now:  1893958.0 i/s
       Time.zone.now:   301653.7 i/s - 6.28x slower
```

With this patch, we go from `Time.zone.now` being 18.25x slower than
`Time.now` to only being 6.28x slower than `Time.now`. I'd obviously love some
verification on this patch, since these numbers sound pretty interesting... :)

This is the benchmark-ips report I have been using while working on this:

```ruby
require 'benchmark/ips'

Time.zone = 'Eastern Time (US & Canada)'

Benchmark.ips do |x|
  x.report('Time.now') {
    Time.now
  }

  x.report('Time.zone.now') {
    Time.zone.now
  }

  x.compare!
end
```

cc @amatsuda
cc performance folks @tenderlove and @schneems

![Pretty... pretty... pretty good.](https://media.giphy.com/media/bWeR8tA1QV4cM/giphy.gif)
2016-10-02 15:12:46 -04:00
Matthew Draper
62ed56135b Correct caller tracking in delegated deprecation methods 2016-10-03 05:22:28 +10:30
Andrew White
9128ba5cd4 Cache to_time to improve performance when comparing
In #25880 we tried to cache localtime to fix the performance
regression but that proved to be difficult due to the fact that
localtime/getlocal can take a utc_offset argument. We tried
caching based on the argument but since the argument can be nil
sometimes that meant that if the TZ environment variable changed
then the cached value for nil became invalid. By moving the
caching to DateAndTime#compatibility we don't have to worry about
arguments since it doesn't take any.

There is a possible edge condition where preserve_timezone is set
to false and the system timezone changes then it could result in
a cached value being incorrect but the only way to fix this would
be to remove all caching and live with the performance issue.
2016-10-02 17:15:44 +01:00
Andrew White
bd8f0871c2 Revert "Merge pull request #25880 from ryandv/fix_performance_regression_in_timewithzone_to_time"
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 3132fa6b7d9585e04eb44b25b55d298391b040b5, reversing
changes made to 6949f8e5e7dc901d4e04ebab6c975afb33ca44c9.
2016-10-02 17:02:27 +01: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
Andrew White
9ce2d1b1a4 Merge pull request #26677 from tbalthazar/26644
Fix `ActiveSupport::TimeWithZone#localtime`
2016-10-01 21:30:02 +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
Matthew Draper
871ca21f6a Tighten the backtrace pollution from passing through callbacks
Callbacks are everywhere, so it's better if we can avoid making a mess
of the backtrace just because we've passed through a callback hook.

I'm making no effort to the before/after invocations: those only affect
backtraces while they're running. The calls that matter are the ones
that remain on the call stack after run_callbacks yields: around
callbacks, and internal book-keeping around the before/afters.
2016-09-30 06:57:43 +09:30
Akira Matsuda
b18f8b9d77 Merge pull request #26402 from mtsmfm/remove-dead-constants
Remove dead constants
2016-09-29 18:52:39 +09:00
Jon Moss
c93b80d53d Merge pull request #26654 from Neodelf/activesupport_1
[ci skip] Remove not necessary whitespace
2016-09-28 17:02:22 -04:00
Andrey Molchanov
1ba3ee4dd1 [ci skip] Use class name instead of path to file 2016-09-28 23:31:54 +03:00
Andrey Molchanov
05eb2c0835 [ci skip] Remove not necessary whitespace 2016-09-28 23:24:26 +03:00
yuuji.yaginuma
34a313aa35 fix typo in DateAndTime::Calculations#all_week doc [ci skip]
`Date.week_start` does not exist. `Date.beginning_of_week` seems to be correct.
Ref: #5339
2016-09-27 12:23:52 +09:00
Kasper Timm Hansen
0dfc467587 fffffff, Add code missing in 29f0fbd 2016-09-25 20:38:12 +02:00
Kasper Timm Hansen
29f0fbd5db Revise setting of run_with_rails_extension.
The Rails test runner supports three ways to run tests: directly, via rake, or ruby.

When Running with Ruby ala `ruby -Itest test/models/post_test.rb` our test file would
be evaluated first, requiring `test_helper` and then `active_support/testing/autorun`
that would then require the test file (which it hadn't been before) thus reevaluating
it. This caused exceptions if using Active Support's declarative syntax.

Fix this by shifting around when we set the how we're run to closer mimick the require
order.

If we're running with `bin/rails test` the test command file is run first and we then
set `run_with_rails_extension`, later we hit `active_support/testing/autorun` and do
nothing — because we've been run elsewhere.

If we at this point haven't set `run_with_rails_extension` we've been running with
`ruby` this whole time and thus we set that.

We should always trigger `Minitest.autorun` as it doesn't hurt to call it twice.

Consolidate the two methods into a single one that better brings out the intent of
why they're there.
2016-09-25 20:36:30 +02:00