Commit Graph

5824 Commits

Author SHA1 Message Date
Rafael França
9cf7217909 Merge pull request #29140 from notEthan/log_subscribed_avoid_rescuing
Log subscriber - avoid rescuing certain exceptions
2017-06-16 13:36:04 -04:00
yuuji.yaginuma
9231d2a0b4 Fix Message::Encryptor default cipher [ci skip]
Follow up of #29263
2017-06-12 07:47:13 +09:00
Kasper Timm Hansen
6d402c6bfa Merge pull request #29263 from assain/default_message_encryptor_to_gcm
Default Message Encryptor Cipher to AES-256-GCM From AES-256-CBC
2017-06-11 21:45:35 +02:00
Assain
7440bf44ba set message_encryptor default cipher to aes-256-gcm
- Introduce a method to select default cipher, and maintain backward compatibility
2017-06-12 00:29:16 +05:30
Eugene Kenny
52f90044a1
Cache: test coverage for cleanup behavior with local cache strategy
No need to pass `#cleanup` options through to `LocalCache#clear`.

Fixes #29081. References #25628.
2017-06-10 14:48:20 -07:00
Jeremy Daer
816a3763d9
Revert #25628. Incomplete change + needs a deprecation cycle.
See https://github.com/rails/rails/issues/29067#issuecomment-301342084
for rationale.

This reverts commit b76f82d714e590c20370e72fa36fa574c4f17650.

Fixes #29067. Fixes #29081.
2017-06-10 11:04:34 -07:00
Guillermo Iguaran
831ef696b1 Merge pull request #29386 from y-yagi/remove_unreachable_code
Remove unreachable code
2017-06-07 19:36:46 -05:00
yuuji.yaginuma
d93317534c Remove unreachable code
`Time.find_zone!` raise `ArgumentError` if invalid value is specified.
379a0b42da/activesupport/lib/active_support/core_ext/time/zones.rb (L97..L99)

Therefore, the return value never becomes nil.
2017-06-08 08:45:04 +09:00
Jeremy Daer
2b96d5822b Cache: write_multi (#29366)
Rails.cache.write_multi foo: 'bar', baz: 'qux'

Plus faster `fetch_multi` with stores that implement `write_multi_entries`.
Keys that aren't found may be written to the cache store in one shot
instead of separate writes.

The default implementation simply calls `write_entry` for each entry.
Stores may override if they're capable of one-shot bulk writes, like
Redis `MSET`.
2017-06-06 16:39:20 -07:00
Kasper Timm Hansen
704209b017 Merge pull request #29294 from gsamokovarov/attributes-default
Introduce mattr_accessor default option
2017-06-04 16:12:40 +02:00
Vipul A M
3168da0af7
Don't create extra assignment, just return 2017-06-04 15:42:16 +05:30
Genadi Samokovarov
b6b0c99ff3 Use mattr_accessor default: option throughout the project 2017-06-03 13:52:48 +03:00
Genadi Samokovarov
a5b0c60714 Implement mattr_acessor :default option 2017-06-03 13:52:35 +03:00
Shota Iguchi
3fbe657e9b Add next occur and previous occurred day of week API (#26600) 2017-05-30 13:13:29 +02:00
Ryuta Kamizono
0a9522a8b3 Add missing "not" in the doc for assert_no_changes [ci skip] 2017-05-30 05:53:07 +09:00
David Heinemeier Hansson
1c275d812f Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute

* Convert to using class_attribute default rather than explicit setter

* Removed instance_accessor option by mistake

* False is a valid default value

* Documentation
2017-05-29 18:01:50 +02:00
Eileen M. Uchitelle
edc90c858d Merge pull request #26628 from mjhoy/fix-number-to-human-25742
round before calculating exponent in number_to_human_converter
2017-05-29 10:43:54 -04:00
Kasper Timm Hansen
87eae9ffa6 Merge pull request #29074 from kamipo/remove_returning_true_in_internal_callbacks
Remove returning true in internal callbacks
2017-05-28 17:10:21 +02:00
Matthew Draper
352865d0f8 Merge pull request #29097 from EilisHamilton/fix_uncountable_pluralization_locale
Fix pluralization of uncountables when given a locale
2017-05-28 22:54:54 +09:30
Kasper Timm Hansen
85211ea1ef Clear all current instances before a reload.
If users added an attribute or otherwise changed a CurrentAttributes subclass
they'd see exceptions on the next page load.

Because `ActiveSupport::CurrentAttributes.current_instances` would keep
references to the old instances from the previous request.

We can fix this by clearing out the `current_attributes` before we unload
constants. Then any change to the model can be autoloaded again since its
slot isn't taken by an old instance.

We'll still have to call reset before we clear so external collaborators,
like Time.zone, won't linger with their current value throughout other code.
2017-05-28 10:47:17 +02:00
Kasper Timm Hansen
3cacbc1ef0 Remove double Thread.current storage.
Since we're generating a key through the class name we can combine
the two Thread.current calls into a single hash version.
2017-05-28 10:17:36 +02:00
Kasper Timm Hansen
fcc47bcfcc Use non-raising finder.
`find` raises when it can't find a record, so we'll never reach the
else. Switch to `find_by` which returns nil when no record can be
found.
2017-05-27 14:36:18 +02:00
Kasper Timm Hansen
3a131b6c00 [ci skip] Fix spelling that's a bit of an overreach. 2017-05-27 14:34:53 +02:00
David Heinemeier Hansson
24a864437e ActiveSupport::CurrentAttributes provides a thread-isolated attributes singleton (#29180)
* Add ActiveSupport::CurrentAttributes to provide a thread-isolated attributes singleton

* Need to require first

* Move stubs into test namespace.

Thus they won't conflict with other Current and Person stubs.

* End of the line for you, whitespace!

* Support super in attribute methods.

Define instance level accessors in an included module such that
`super` in an overriden accessor works, akin to Active Model.

* Spare users the manual require.

Follow the example of concerns, autoload in the top level Active Support file.

* Add bidelegation support

* Rename #expose to #set. Simpler, clearer

* Automatically reset every instance.

Skips the need for users to actively embed something that resets
their CurrentAttributes instances.

* Fix test name; add tangible name value when blank.

* Try to ensure we run after a request as well.

* Delegate all missing methods to the instance

This allows regular `delegate` to serve, so we don't need bidelegate.

* Properly test resetting after execution cycle.

Also remove the stale puts debugging.

* Update documentation to match new autoreset
2017-05-26 20:00:27 +02:00
Matthew Draper
4cfcf1ee54 Merge pull request #29176 from bogdanvlviv/define-path-with__dir__
Define path with __dir__
2017-05-26 12:24:43 +09:30
Ethan
1c5f5af8c9 check that logger is defined in log subscriber rescue before logging 2017-05-24 12:54:27 -07:00
Ethan
8300234f9f lob subscriber should only rescue StandardError, not Exception 2017-05-24 12:53:52 -07:00
Koichi ITO
bef95d372f Fix a RuboCop offences using rubocop -a 2017-05-24 15:21:17 +09:00
bogdanvlviv
40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df003a96f0e490c43559747618d10f5f
2017-05-23 00:53:51 +03:00
Andrew White
36d53f557d Merge pull request #29163 from rails/fix-scalar-duration-calculation
Fix implicit calculations with scalars and durations
2017-05-21 17:12:54 +01:00
Andrew White
28938dd64c Fix implicit calculations with scalars and durations
Previously calculations where the scalar is first would be converted
to a duration of seconds but this causes issues with dates being
converted to times, e.g:

    Time.zone = "Beijing"           # => Asia/Shanghai
    date = Date.civil(2017, 5, 20)  # => Mon, 20 May 2017
    2 * 1.day                       # => 172800 seconds
    date + 2 * 1.day                # => Mon, 22 May 2017 00:00:00 CST +08:00

Now the `ActiveSupport::Duration::Scalar` calculation methods will try
to maintain the part structure of the duration where possible, e.g:

    Time.zone = "Beijing"           # => Asia/Shanghai
    date = Date.civil(2017, 5, 20)  # => Mon, 20 May 2017
    2 * 1.day                       # => 2 days
    date + 2 * 1.day                # => Mon, 22 May 2017

Fixes #29160, #28970.
2017-05-20 16:36:25 +01:00
David Heinemeier Hansson
dccfcbfdaf Remove unused mismatch payload attribute 2017-05-20 16:43:31 +02:00
David Heinemeier Hansson
aa8749eb52 Add cache_key_with_version and use it in ActiveSupport::Cache.expand_cache_key
This retains the existing behavior of
ActiveSupport::Cache.expand_cache_key (as used by etaging) where the
cache key includes the version.
2017-05-19 14:09:09 +02:00
Eilis Hamilton
7c45146b15 Fix pluralization of uncountables when given a locale
Previously apply_inflections would only use the :en uncountables
rather then the ones for the locale that was passed to pluralize or
singularize.

This changes apply_inflections to take a locale which it will use to
find the uncountables.
2017-05-19 13:58:19 +12:00
David Heinemeier Hansson
75fa8dd309 Use recyclable cache keys (#29092) 2017-05-18 18:12:32 +02:00
Kasper Timm Hansen
7cc526beb5 Merge pull request #29086 from mikeycgto/message-encryptor-auth-tag-check
Message encryptor auth tag check

Fixes MessageEncryptor when used in AEAD mode. Specifically, we need to check if the `auth_tag` is nil. This may arise when an AEAD encryptor is used to decrypt a ciphertext generated from a different mode, such as CBC-HMAC. Basically, the number of double dashes will differ and `auth_tag` may be nil in this case.
2017-05-15 21:20:12 +02:00
Michael Coyne
71fb6def5f Fix for AEAD auth_tag check in MessageEncryptor
When MessageEncryptor tries to +decrypt_and_verify+ ciphertexts
generated in a different mode (such CBC-HMAC), the +auth_tag+ may be
+nil+ and must explicitly check for it.

See the discussion here:
https://github.com/rails/rails/pull/28132#discussion_r116388462
2017-05-15 08:54:39 +00:00
Eugene Kenny
db9ae5f1e1 Don't cache locally if unless_exist was passed
Some cache backends support the `unless_exist` option, which tells them
not to overwrite an existing entry. The local cache currently always
stores the new value, even though the backend may have rejected it.

Since we can't tell which value will end up in the backend cache, we
should delete the key from the local cache, so that the next read for
that key will go to the backend and pick up the correct value.
2017-05-14 23:24:37 +01:00
Ryuta Kamizono
0584e21ac0 Remove returning true in internal callbacks
`display_deprecation_warning_for_false_terminator` was removed since
3a25cdc.
2017-05-14 03:42:17 +09:00
Peter McCracken
4fc2ea1181 handle loops in the cause chain in Rescuable#rescue_with_handler 2017-05-10 13:33:46 -04:00
T.J. Schuck
aa91328058 Assorted delegate_missing_to doc fixes
* Fix rdoc code formatting — `tt`, not backticks

* Fix/simplify sentence grammar — should at least just be “and the like”, not “likes”, but this is just general tightening up.

* Add note that delegated methods must be public.  Tested here: 7ff5ccae94/activesupport/test/core_ext/module_test.rb (L359-L365)

* Simplify example code for delegate_missing_to. The example had complexity that wasn’t necessary for demonstrating `delegate_missing_to`.  This gets rid of a bunch of cruft so the example is more obvious about what’s going on regarding the feature itself.

[ci skip]
2017-05-04 16:29:00 -04:00
Ryuta Kamizono
4e6d84f555 Use flat_map rather than map(&:...).flatten 2017-04-29 23:30:38 +09:00
Eugene Kenny
001fc80d87 Add missing require for remove_possible_method
5055370828
added a call to `remove_possible_method`, but didn't require the file
that defines it.
2017-04-28 10:18:55 -07:00
Ryuta Kamizono
ca9ac31002 respond_to_missing? should be private
Follow up of 03d3f036.

Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036.
But the visibility is still public. It should be private.
2017-04-22 23:11:15 +09:00
Jon Moss
32431b3770 Add comma
[ci skip]
2017-04-20 18:40:26 -04:00
Rafael França
e88636f733 Merge pull request #28582 from sbull/activejob-error-logging
Add error logging to Active Job
2017-04-20 18:01:57 -04:00
Josh Nussbaum
62b1b17221 Fixes Hash.from_xml with frozen strings for all backends 2017-04-20 16:31:50 -04:00
Marion Bouguet
ba2e9e0911 Remove outdated comment
Since 3aee9126aa6309538ee64064dcabcd34d7cc7d26, this class hasn't inherited from Array.
2017-04-20 16:20:00 +09:00
Willem van Bergen
0bdf6d757b Send deprecation horizon and gem name as arguments to deprecation heavier handler, and make sure they are used for the ActiveSupport::Notifications message. 2017-04-19 18:23:28 -04:00
Rafael França
48c5139ae3 Merge pull request #28790 from tjschuck/require_as_time_in_testing_time_helpers
Explicitly require AS::Time in AS::Testing::TimeHelpers
2017-04-18 17:25:19 -04:00