Commit Graph

21 Commits

Author SHA1 Message Date
Xavier Noria af27a25f19 Remove DependenciesTestHelpers 2021-04-03 19:24:12 +02: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
Keenan Brock a930f5ba06 Fix safe_constantize to not raise a LoadError.
### Summary

There was an issues when using `safe_constantize` on a string that has
the wrong case.

File `em.rb` defines `EM`.
`"Em".safe_constantize` causes a little confusion with the autoloader.
The autoloader finds file "em.rb",
expecting it to define `Em`, but `Em` is not defined.
The autoloader raises a `LoadError`, which is good,
But `safe_constantize` is defined to return `nil` when a class is not found.

### Before

```
"Em".safe_constantize
LoadError: Unable to autoload constant Em, \
expected rails/activesupport/test/autoloading_fixtures/em.rb to define it
```

### After

```
"Em".safe_constantize
# => nil
```
2019-01-09 14:52:46 -05:00
Koichi ITO ac717d65a3 [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment` 2017-07-11 13:12:32 +09:00
Kir Shatrov 72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03: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
Xavier Noria a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Yves Senn 2aad0b4168 Merge pull request #21250 from ronakjangir47/safe_const
safe_constantize - Added Object scoped missing test cases
2015-09-07 08:52:36 +02:00
Ronak Jangir f96c7d963c safe_constantize - Added Object scoped missing test cases 2015-09-06 13:34:24 +05:30
Guo Xiang Tan 6e0f273dfd Use `safe_constantize`.
Fixes https://github.com/rails/rails/issues/9933.
2014-09-02 00:41:00 +08:00
Aditya Kapoor 885ebda266 Add Missing Test Cases for the constantize 2014-06-07 23:58:38 +05:30
Nikolay Shebanov 7fd36f307a Fix #10932. Treat "" and "::" as invalid on constantize 2013-06-14 11:20:15 +04:00
Aaron Patterson 4a7679ebca cleaning up constantize tests 2012-11-07 17:13:17 +09:00
Andrew White 3d0e4895cd Handle case where ancestor is not the end of the chain 2012-05-19 15:47:35 +01:00
Marc-Andre Lafortune eb09411460 Fix constantize so top level constants are looked up properly. 2012-05-19 15:47:35 +01:00
Marc-Andre Lafortune 99e9a733c8 Make constantize look down the ancestor chain (excluding Object) 2012-05-19 15:47:35 +01:00
Alex Tambellini 7598284c0b safe_constantize should handle wrong constant name NameErrors Fixes #4710 2012-01-26 14:19:49 -05:00
José Valim b2f34d1e35 Ensure that constantize just rescues NameError that applies to the constant being currently loaded. 2011-09-23 16:21:49 +02:00
Ryan Oblak 310565f537 Added ActiveSupport::Inflector.safe_constantize and String#safe_constantize; refactored common constantize tests into ConstantizeTestCases 2011-09-23 15:36:33 +02:00