Commit Graph

3420 Commits

Author SHA1 Message Date
Rafael França
40b7d93c5b
Merge pull request #38576 from Edouard-chin/ec-activejob-deprecation
Fix AJ wrong deprecation message on `after_callbacks_if_terminated`:
2020-03-03 15:28:50 -05:00
Edouard CHIN
06dd162fb3 ActiveSupport::Calbacks#halted_callback_hook receive callback name:
- The `halted_callback_hook` method is called whenever the
  `terminator` halt the callback execution.
  Usually, this translate to when a `before` callback throw
  an `:abort`.

  <details>
    <summary> Example </summary>

    ```ruby
      class Foo
        include ActiveSupport::Callbacks

	define_callbacks :save
	set_callback(:save, :before) { throw(:abort) }

	def run
	  run_callbacks(:save) do
	    'hello'
	  end
	end

	def halted_callback_hook(filter)
	  # filter is the proc passed to `set_callback` above
	end
      end
    ```
  </details>

  ### Problem

  When a class has multiple callbacks, (i.e. `save`, `validate` ...),
  it's impossible to tell in the halted_callback_hook which type of
  callback halted the execution.
  This is useful to take different action based on the callback.

  <details>
    <summary> Use Case </summary>

    ```ruby
      class Foo
        include ActiveSupport::Callbacks

	define_callbacks :save
	define_callbacks :validate

	set_callback(:save, :before) { throw(:abort) }
	set_callback(:validate, :before) { throw(:abort) }

	def run
	  run_callbacks(:validate) do
	    ...
	  end

	  run_callbacks(:save) do
	    ...
	  end
	end

	def halted_callback_hook(filter)
	  Rails.logger.warn("Couldn't save the record, the ??? callback halted the execution")
	end
      end
    ```
  </details>

  ### Solution

  Allow `halted_callback_hook` to receive a second argument which is
  the name of the callback being run.
2020-03-03 16:17:55 -04:00
Abhay Nikam
339d1cdc27 Fixes TypeError raised for parameter filter if the json data has key as integer 2020-02-28 17:27:58 +09:00
Ryuta Kamizono
12e48544cf Fix delegate_missing_to to allow keyword arguments 2020-02-28 04:20:01 +09:00
Kasper Timm Hansen
51d73fb84b
Merge pull request #37624
Closes #37624
2020-02-17 01:32:23 +01:00
Hrvoje Šimić
074265a6c1
Update assert_changes and assert_no_changes to use assert_equal
This provides better more specific diffs when comparing complex objects.

Reverts bbe437faecca5fd6bdc2327a4bc7a31ba21afe2e.

Closes #37507. Closes #38220.

Co-authored-by: michdsouza <michd2005@gmail.com>
Co-authored-by: Rahul Purohit <rahulpuroht@gmail.com>
Co-authored-by: Nicholas Koh <nkohwl@gmail.com>
2020-02-17 01:30:50 +01:00
Elia Schito
1dedf07af9
Prepend class methods of prepended concerns 2020-02-14 18:11:50 +01:00
Ryuta Kamizono
76ae3dbed3 Revert "Merge pull request #22780 from pauloancheta/master"
This reverts commit 7aa047b57237f691540afc3e22b91f73df7e5bc4, reversing
changes made to c9b36dd67a1c8fe40ad76301e3929e47b0b23e1d.

This is a right example for singular names.
2020-02-13 11:41:15 +09:00
Edouard CHIN
afb0220436 Cast ConfigurationFile#content_path to a string:
- This is required when we assign the `ERB#filename` in case
  of a Pathname.
2020-02-10 19:12:33 -04:00
Edouard CHIN
ec1b3d70ca
Add the filename when building ERB:
- If an error occurs when rendering ERB (other than a Psych's
  SyntaxError), it's impossible to know in which file the error
  occured.

  This commit fixes that
2020-02-10 23:06:30 +01:00
Kasper Timm Hansen
9e4354a017
Give us some space please 2020-02-10 02:39:16 +01:00
Jason Karns
54ecc90d90
More tests for concerning 2020-02-10 02:23:43 +01:00
Jason Karns
ba2bea5e07
Concerns learn to be prepended 2020-02-10 02:23:33 +01:00
Jason Karns
6e2ca1a186
Make tests safer
Using a class variable here makes the tests susceptible to phantom
greens because (depending on the order of the tests), the class variable
could have been set by a prior test. (Test polution)

Better to have the variable be tied to the instance.
2020-02-10 02:23:33 +01:00
Jason Karns
8543974afa
concerning learns how to prepend the concern
In rare instances, a module needs to be prepended into the ancestor
hierarchy, not simply included. In cases where this is necessary, and it
is desirable to use an inline concern, it would be beneficial to be able
to instruct `concerning` that the concern should be prepended.

This is now possible, by providing `prepend: true` kwarg to
`concerning`. (It is false by default.)
2020-02-10 02:23:33 +01:00
Ryuta Kamizono
a55620f3fa Fix with_options to allow string key options 2020-02-05 17:22:25 +09:00
T.J. Schuck
6af50a9067 Change all "can not"s to the correct "cannot"
It's been 6 years since [the original](https://github.com/rails/rails/pull/13584), so we're overdue for a sequel.

The correct word is "cannot", one word, not "can not", two words.
2020-02-04 16:46:55 -05:00
Ryuta Kamizono
5aae2b2783 Simplify RUBY_VERSION checking in tests 2020-01-29 09:31:00 +09:00
John Hawthorn
5ff5e5f638 Parallelize activesupport test suite 2020-01-24 09:54:55 -08:00
John Hawthorn
1301063c2c Allow cache tests to be run in parallel
This initializes our caches with a random namespace which should ensure
that we can run the tests in parallel without interfering with each
other.

One compromise is that we can never actually call cache.clear on the
memcache client, since that would clear the cache for all namespaces. We
can work around this for the one test that needs to do a clear to
stub flush_all on the client and replace it with a delete.
2020-01-24 09:54:55 -08:00
John Hawthorn
132ed0a909 Force encoding of cache keys 2020-01-24 09:54:01 -08:00
John Hawthorn
5b5c37eaf7 Add tests for empty fetch 2020-01-24 09:54:01 -08:00
John Hawthorn
cdfcf555af Allow encrypted_file_test to work in parallel 2020-01-24 09:54:01 -08:00
John Hawthorn
0373152f43 Allow automic file test to be parallelized 2020-01-24 09:54:01 -08:00
John Hawthorn
7d858752a6 Unique temp paths for encrypted_config_test 2020-01-24 09:54:01 -08:00
John Hawthorn
2afc230053 Use random tmp dir for FileStoreTest 2020-01-24 09:54:01 -08:00
Ryuta Kamizono
3a85ced1a0 Fix deprecate_methods to not expand positional argument hash 2020-01-20 01:48:23 +09:00
Cliff Pruitt
10754f79f3 Allow ActiveSupport deprecation warnings to be configured as disallowed
This allows deprecation messages to be matched by substring, symbol (treated as
substring), or regular expression. If a warning is matched, the behaviors
configured for disallowed deprecations will be used. The default behavior for
disallowed deprecation warnings is `:raise`.

Also adds `ActiveSupport::Deprecation.allow` for thread-local, block level ignoring of deprecation warnings which would otherwise be disallowed by ActiveSupport::Deprecation.disallowed_warnings.
2020-01-15 13:28:11 -05:00
Ian Fleeton
684ae07e2f Don't encourage using octals for dates and times
This could result in confusing errors or inconsistency for 08 and 09
2020-01-15 10:57:38 +00:00
Akihito Tsukamoto
fd2bc5cee6 Fix NoMethodError on ActiveSupport::Cache::RedisCacheStore#clear with Redis::Distributed 2020-01-10 17:57:59 +09:00
Jean Boussier
0309179fb6 Do not define instance predicate if the instance reader isn't as well
This regressed in 49d1b5a98dc50ca59bbfb817f90eb5c2c2645d30.

I didn't notice it because the method would be defined but would
raise a NoMethodError.
2020-01-09 10:35:14 +01:00
Ryuta Kamizono
67e18160e6 Fix deprecation warnings in Active Support tests 2020-01-09 04:01:14 +09:00
Vishal Telangre
740bb178d9
Deprecate using Range#include? to check the inclusion of a value in a date time range
Use `Range#cover?` instead of `Range#include?` to check the inclusion of a value in a date time range.
2020-01-08 20:28:02 +05:30
John Hawthorn
80d98450c3
Merge pull request #38144 from jhawthorn/mattr_location
Define mattr_* methods at caller's location
2020-01-06 09:00:37 -08:00
tom-lord
7905bdfd8b Add :round_mode parameter support to number helpers
Support handling a `round_mode` in `ActiveSupport::NumberHelper::RoundingHelper`

Add default value to locale file

Update inline documentation with new parameter option

Update CHANGELOG

Add round_mode examples to all the tests

Add I18n test

Simplify logic

Further simpification
2020-01-05 21:23:02 +00:00
John Hawthorn
b5b1b02087 Error if mattr_accessor is called on singleton 2020-01-04 18:01:48 -08:00
Nicolas Dular
97d428b790 Return unfrozen strings from to_sentence 2019-12-28 21:56:46 +01:00
Jean Boussier
49d1b5a98d
Optimize class_attribute instance accessors 2019-12-22 23:33:59 +01:00
Abhishek Sarkar
c9bc6d66cb Remove week from iso8601 parts
It converts the week part into days and removes it from the final result.

```
duration = ActiveSupport::Duration.build(1000000) # 1 week, 4 days, 13 hours, 46 minutes, and 40.0 seconds

duration_iso = duration.iso8601 # P11DT13H46M40S

ActiveSupport::Duration.parse(duration_iso) # 11 days, 13 hours, 46 minutes, and 40 seconds
```
2019-12-20 22:15:15 +08:00
Michael Grosser
203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
Rafael França
f741f56da3
Merge pull request #37865 from hectorbus/number-to-currency-negative-zero-fix
number_to_currency negative zero fix
2019-12-17 12:30:57 -03:00
Ryuta Kamizono
2193c0ac67 Should keep the original parts for zero duration
Follow up to https://github.com/rails/rails/pull/37849#issuecomment-560557239.

Without this, `0.days` is considered as `0.seconds` due to #31310.
We should not lose the original parts.
2019-12-04 22:59:21 +09:00
Hector Bustillos
92fea7a574 number_to_currency negative zero fix 2019-12-02 23:18:26 -07:00
Ryuta Kamizono
aa93e3cb20 Fix since and ago with a duration which has empty parts
Related #37839.

Sometimes divisions of `ActiveSupport::Duration` makes the instance's
parts attribute empty, but it has a value actually (e.g. `(1.minute /
60) # => @value=1 (second), but empty parts`).

In that case we should respect `value` as the source of seconds.
2019-12-02 18:13:51 +09:00
Tsukuru Tanimichi
f468b91a15 The return value of ActiveSupport::Duration#inspect is wrong when its parts are empty
```ruby
(1.day / 24).inspect   #=> "0 seconds"
(1.day / 24).to_i      #=> 3600
(1.day / 24) == 1.hour #=> true
(1.hour).inspect       #=> "1 hour"
(1.hour).parts         #=> {:hours=>1}
(1.day / 24).parts     #=> {}
```

Sometimes divisions of `ActiveSupport::Duration` make the instance's `parts` attribute empty. But these instances are not always 0 seconds.

Related to #31310 and #31302
2019-11-30 16:32:57 +09:00
Ryuta Kamizono
d558febe32 Auto-correct rubocop offences 2019-11-24 09:54:47 +09:00
Kasper Timm Hansen
aa457920cc
Merge pull request #37496
Closes #37496
2019-11-10 20:02:20 +01:00
Tim Masliuchenko
21f907bb51
Accept block in travel_back time helper 2019-11-10 20:02:09 +01:00
George Claghorn
974ce9c333
Fix configuring a cache store with ActiveSupport::OrderedOptions
9845cd6 broke configuring a cache store like so:

    config.cache_store = :redis_cache_store, config_for("redis/cache")

Rails::Application#config_for returns an ActiveSupport::OrderedOptions. By default, the Array#extract_options! core extension won't extract instances of Hash subclasses. Add ActiveSupport::OrderedOptions#extractable_options? and have it return true to fix.
2019-11-08 17:32:55 -05:00
John Hawthorn
063b028190
Merge pull request #37590 from jhawthorn/deprecation_threadsafe
Make AS::Deprecation.silence block thread-local
2019-11-08 12:32:28 -08:00