Commit Graph

175 Commits

Author SHA1 Message Date
Xavier Noria
52ce6ece8c adds coverage for throwing while autoloading
References #24205.
2016-03-15 23:46:05 +01:00
Sruli Rapps
1cfeab5314 Dependencies clean up
Cleans up four items I came across in ActiveSupport::Dependencies:

- DependenciesTest#
  test_dependency_which_raises_exception_isnt_added_to_loaded_set:
  Fixes current implementation which will pass no matter what since the
  filepath is never added to "loaded" or "history" without being
  expanded first.
- Remove DependenciesTest#test_unhook. Seems leftover from when
  alias_method_chain was used in Loadable and ModuleConstMissing.
  The test will always pass since Module never responds to those methods
- WatchStack#new_constants documentation: update self to @stack.
  Looks like self was leftover from when WatchStack inherited from Hash
- Remove ActiveSupport namespace from call to
  Dependencies.constant_watch_stack.watching? since the namespace is not
  needed, Dependencies is called two other times in the same method
  without it (even on the same line) and it brings the line to within
  80 characters
2016-02-19 16:15:45 +02:00
Ronak Jangir
2f28e5b641 Removed use of mocha in active_support 2015-07-10 01:58:46 +05:30
Kasper Timm Hansen
afb6a2c08d Avoid E constant clashing with Minitest defined version.
Minitest sets an E constant to an empty string to save GC time.
This clashes with autoloading tests which define an E constant.
2015-05-22 23:30:08 +02:00
Josef Stribny
097ac2045a Do not depend on Rails git repository layout in ActiveSupport tests 2015-04-02 17:09:24 +02:00
claudiob
36effd916c Remove LoadError#path hack for Ruby 1.9
Now that Rails requires Ruby >= 2.0 there is need to skip the
`test_depend_on_path` test.
2015-01-04 15:54:21 -03:00
Rafael Mendonça França
48deeab90a Merge pull request #8740 from amatsuda/missing_source_file
replace use of MissingSourceFile with LoadError

Conflicts:
	activesupport/test/core_ext/load_error_test.rb
2015-01-02 19:19:59 -03:00
Xavier Noria
0ed6ebcf90 dependencies.rb: keep the decorated #load and #require private [closes #17553] 2014-11-10 14:29:29 -08:00
Yves Senn
00ae750b23 Merge pull request #15956 from zuhao/refactor_activesupport_dependencies_test
Cleanup loaded features and constants after dependency tests.
2014-11-05 15:40:37 +01:00
Xavier Noria
ae07806858 fixes circularity check in dependencies
The check for circular loading should depend on a stack of files being
loaded at the moment, rather than the collection of loaded files.

This showed up indirectly in #16468, where a misspelled helper would
incorrectly result in a circularity error message.

References #16468
2014-10-25 14:06:33 +02:00
Guo Xiang Tan
6e0f273dfd Use safe_constantize.
Fixes https://github.com/rails/rails/issues/9933.
2014-09-02 00:41:00 +08:00
Akira Matsuda
6e440a0147 Reset ActiveSupport::Dependencies.mechanism to make tests order independent 2014-08-13 21:25:11 +09:00
Akira Matsuda
fe873dfae2 Duplicated method in the test helper 2014-08-13 21:25:11 +09:00
Zuhao Wan
d75f4dcb0e Cleanup loaded features and constants after dependency tests. 2014-06-28 17:57:27 +08:00
Yuki Nishijima
98f0cab396 Fix a bug where NameError#name returns a qualified name in string
Ruby's original behaviour is that :

  * It only returns a const name, not a qualified aname
  * It returns a symbol, not a string
2014-06-24 10:13:17 -07:00
Arthur Neves
bd3fde0931
Add regression test for NameError#name 2014-06-20 09:55:41 -04:00
Noah Lindner
4fa8c8b52f Fixed an issue where reloading of removed dependencies would cause an unexpected circular dependency error 2014-02-08 15:59:08 -08:00
Carlos Antonio da Silva
c5b76b5362 Prefer assert_raise instead of flunk + rescue to test for exceptions
Change most tests to make use of assert_raise returning the raised
exception rather than relying on a combination of flunk + rescue to
check for exception types/messages.
2013-12-19 09:20:51 -02:00
Carlos Antonio da Silva
d799b9c1cf Fix asserting the correct exception message in dependencies test
In Minitest, the second argument of assert_raise(s) accepts a string as
the message that should be shown in case of a failure in the assertion
(eg nothing was raised when it should), and not the exception message to
be matched.

To do that we need to save the exception returned from assert_raise(s)
into a local variable and check for the exception message using it.
2013-12-19 08:47:09 -02:00
Xavier Noria
01c9782fa2 better error message for constants autoloaded from anonymous modules [fixes #13204]
load_missing_constant is a private method that basically plays the role of const_missing.
This method has an error condition that is surprising: it raises if the class or module
already has the missing constant. How is it possible that if the class of module has
the constant Ruby has called const_missing in the first place?

The answer is that the from_mod argument is self except for anonymous modules, because
const_missing passes down Object in such case (see the comment in the source code of the
patch for the rationale).

But then, it is better to pass down Object *if Object is also missing the constant* and
otherwise err with an informative message right away.
2013-12-06 19:18:10 +01:00
Xavier Noria
2254615bff Merge pull request #12412 from bf4/allow_pathname_for_require_dependency
Allow Pathname for require dependency
2013-09-30 23:22:11 -07:00
Benjamin Fleischer
0b0beb71d6 require_dependency should allow Pathname-like objects, not just String 2013-09-30 19:57:03 -05:00
Simon Coffey
b4a9668626 Ensure all-caps nested consts marked as autoloaded
Previously, an autoloaded constant `HTML::SomeClass` would not be marked
as autoloaded by AS::Dependencies. This is because the
`#loadable_constants_for_path` method uses `String#camelize` on the
inferred file path, which in turn means that, unless otherwise directed,
AS::Dependencies watches for loaded constants in the `Html` namespace.

By passing the original qualified constant name to `#load_or_require`,
this inference step is avoided, and the new constant is picked up in the
correct namespace.
2013-08-27 08:20:33 +01:00
Andrew Kreiling
a548792aa0 Don't blindly call blame_file! on exceptions in ActiveSupport::Dependencies::Loadable
It is possible under some environments to receive an Exception that is
not extended with Blamable (e.g. JRuby).
ActiveSupport::Dependencies::Loadable#load_dependency blindly call
blame_file! on the exception which throws it's own NoMethodError
exception and hides the original Exception.

This commit fixes #9521
2013-06-09 18:20:10 -04:00
Vipul A M
6944dfb5d0 remove redundant var 2013-05-09 18:23:27 +05:30
Carlos Antonio da Silva
466ff9310a Merge pull request #9681 from vipulnsward/fix_typo_in_module_name
Fix typo in DependenciesTestHelpers module name
2013-03-12 03:55:30 -07:00
Vipul A M
8778e1c4af Fix typo in DependenciesTestHelpers module name 2013-03-12 10:33:32 +05:30
Vipul A M
647a9abb02 Cleanup tests for unused variables 2013-03-11 16:03:10 +05:30
Akira Matsuda
70ae89c321 Remove unnecessary begin..rescue..end, use only rescue 2013-01-06 15:41:14 +09:00
Akira Matsuda
370bfda55f replace use of MissingSourceFile with LoadError 2013-01-04 16:46:22 +09:00
Xavier Noria
26c024e959 silences "possibly useless use of :: in void context" warnings
The AS utility silence_warnings does not really silence this
one, because it is issued at parse-time. It seemed to in
some places because the constant was the only expression in
the block and therefore it was its return value, that could
potentially be used by silence_warnings are return value of
the yield call.

To bypass the warning we assign to a variable. The chosen
variable is "_" because it is special-cased in parse.c not
to issue an "assigned but unused variable" warning in turn.
2012-12-24 21:16:16 +01:00
kennyj
180e2e5e9e silence warning: possibly useless use of a constant in void context 2012-12-06 01:10:03 +09:00
Uriel Katz
9ee0ffb360 Patched Marshal#load to work with constant autoloading (active_support/dependecies.rb) (issue #8167) 2012-12-01 14:00:16 +02:00
Xavier Noria
46ebce6b49 prevent Dependencies#remove_const from autoloading parents [fixes #8301] 2012-11-28 00:13:14 +01:00
Xavier Noria
a8c3ea90f1 let remove_constant still delete Kernel#autoload constants [rounds #8213]
The method #remove_const does not load the file, so we
can still remove the constant.
2012-11-15 11:10:03 +01:00
Xavier Noria
bff4d8d165 dependencies no longer trigger Kernel#autoload in remove_const [fixes #8213] 2012-11-15 04:36:36 +01:00
Carlos Antonio da Silva
d46f9e3731 Fix some assert_raise calls containing messages in Active Support 2012-10-28 17:54:24 -02:00
Xavier Noria
b33700f558 detect circular constant autoloading
Nowadays circular autoloads do not work, but the user gets a NameError
that says some constant is undefined. That's puzzling, because he is
normally trying to autoload a constant he knows can be autoloaded.
With this check we can give a better error message.
2012-08-28 20:34:39 +02:00
Francesco Rodriguez
cc14a3b2c1 Fix ActiveSupport tests that depend on run order 2012-08-23 16:00:58 -05:00
Aaron Patterson
56a1bb2f10 raise the same exception in order to keep path info
Ruby 2.0.0 implements LoadError#path, but newly raised load errors will
not contain the path information.  Replace the error message, copy
blame, and rereaise the same exception object
2012-06-12 16:19:51 -07:00
Xavier Noria
d3a99c32d1 removes the obsolete require_association method from dependencies
This is an obsolete method from the very early days,
apparently it was used circa 2004 because STI support
was not smart enough. This method is not public
interface, and we are heading a major version, so
removal seems right.
2012-06-10 00:38:40 +02:00
Aaron Patterson
b8d8c50785 use AS::TestCase as the base class 2012-01-05 17:12:46 -08:00
Sam Umbach
cfc467f73e Simplify load and require tests
- These tests don't use autoloading so there's no need to add anything to autoload_paths
2011-12-03 13:11:02 -05:00
Sam Umbach
2a9f063082 Test that require and load raise LoadError if file not found 2011-12-03 13:08:18 -05:00
Sam Umbach
0a485309a0 Test return value of ActiveSupport::Dependencies::Loadable#load 2011-12-03 12:58:41 -05:00
Sam Umbach
93580f4936 Test return value of ActiveSupport::Dependencies::Loadable#require
- Add tests to protect from regressions in require's return value behavior
- See a10606c490471d8e1483acb3b31d7f2d51e9ebbe (require needs to return true or false) for the original bug fix
2011-12-03 11:52:25 -05:00
Jonathan del Strother
e0714ee005 Fix autoload_once_paths when using Pathnames & ruby 1.9
Under ruby 1.9.2 -
  "/var/log".starts_with?(Pathname.new("/var"))  # => false

so setting config.autoload_once_paths with Pathnames would not work
2011-08-24 18:14:25 +01:00
Arun Agrawal
ec7457ed2a Removing extra requires from the test. Already loaded in abstract_unit. 2011-07-31 23:36:21 +05:30
Andrew White
cf3364a03c Raise NameError instead of ArgumentError in ActiveSupport::Dependencies
ActiveSupport::Dependencies now raises NameError if it finds an existing
constant in load_missing_constant. This better reflects the nature of
the error which is usually caused by calling constantize on a nested constant.

Closes #1423
2011-06-01 01:16:20 +01:00
José Valim
a6e945554d Fix failing tests. 2011-05-22 13:21:47 +02:00
Aaron Patterson
69e348013b adding deprecation noticies to deprecated class cache methods 2011-03-02 09:31:40 -08:00
Aaron Patterson
66245441d4 adding backwards compat for class cache references. <3<3 2011-03-02 09:18:05 -08:00
Aaron Patterson
7b6bfe84f3 refactor Reference to a ClassCache object, fix lazy lookup in Middleware so that anonymous classes are supported 2011-03-01 17:20:35 -08:00
Andrew White
f1966337fa Add before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants!
Signed-off-by: Xavier Noria <fxn@hashref.com>
2010-09-01 22:32:41 +02:00
wycats
dbe08026e1 Sadly, this segv's in 1.8 :( 2010-08-17 16:51:35 -07:00
Santiago Pastorino
4ea1753fc2 This is for making sure const_missing is triggered without warnings 2010-07-26 12:51:52 -03:00
wycats
1b97701e51 Fix a bug where requires inside of autoloads were being added to the autoloaded_constants list, causing mayhem. [#5165 state:resolved] 2010-07-26 00:59:54 -07:00
Santiago Pastorino
e1d4e78b15 Removes unused vars
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-24 01:19:44 +02:00
Santiago Pastorino
80cf6559ed Makes restore previosly saved warnings_on_first_load value and avoid warning
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-24 01:19:43 +02:00
Xavier Noria
6f83a5036d renames load_(once_)paths to autoload_(once_)paths in dependencies and config 2010-06-24 00:17:28 +02:00
Jeremy Kemper
fd1a504136 ActiveSupport::Dependencies.constantize shortcut for caching named constant lookups 2010-06-05 22:05:58 -07:00
wycats
a6b3942843 Optimize LookupContext 2010-06-04 20:11:06 -07:00
Santiago Pastorino
aacf2581cd refactor evals and adds some __FILE__ and __LINE__
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-20 15:18:57 +02:00
Santiago Pastorino and Sebastian Martinez
e7276a9f09 Make dependencies_test pass running standalone [#4215 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-03-18 17:50:28 -07:00
Yehuda Katz
4da45060a2 Simplify dependencies.rb some. Remove alias of Kernel::Foo to Object::Foo as it was not used and breaks Ruby semantics. 2010-02-14 10:48:06 -08:00
Yehuda Katz
77f630d317 Since require_dependency cannot be cleared, remove the dependencies 2010-02-10 15:06:42 -08:00
Xavier Noria
cf9a52a7b6 removes Module#as_load_path, which is no longer used 2010-02-07 23:06:15 +01:00
Xavier Noria
1979e9c855 Symbol#to_proc is not needed for Ruby >= 1.8.7 2009-11-09 22:16:51 +01:00
Jeremy Kemper
87e2c1895f Fix failing dependencies test relying on . being in LOAD_PATH 2009-08-09 12:40:16 -07:00
Jeremy Kemper
d0bcf51191 Extract repetitive method 2009-08-09 12:14:25 -07:00
Jeremy Kemper
635f68dca9 Uses &:foo 2009-08-09 12:11:50 -07:00
Jeremy Kemper
f28bd9557c Fix dependencies revealed by testing in isolation 2009-04-22 18:54:13 -07:00
Jeremy Kemper
f5d720fb96 Opt in to Dependencies 2009-04-22 16:42:14 -07:00
Jeremy Kemper
1c36172c13 Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
[#1617 state:resolved]
2009-03-08 13:11:58 -07:00
Jeremy Kemper
cbb38bbdba Only track new constant definitions when we're reloading dependencies 2008-11-10 22:21:09 -08:00
Pratik Naik
a5cdb7a813 Remove stuff that was deprecated in 2-1-stable 2008-10-21 11:34:56 +01:00
Jeremy Kemper
a1eb4e11c2 Get rid of 'Object#send!'. It was originally added because it's in Ruby 1.9, but it has since been removed from 1.9.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>

Conflicts:

	actionpack/test/controller/layout_test.rb
2008-08-31 13:20:15 -07:00
Joshua Peek
3fd9036fc5 Added config.dependency_loading to enable or disable the dependency loader after initialization 2008-07-24 11:58:26 -05:00
Joshua Peek
c08547d226 Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [#238 state:resolved] 2008-06-03 13:32:53 -05:00
Tom Ward
77e45352e7 Fixed Dependencies so load errors are not masked behind a 'Expected x.rb to define X' message when mechanism is not set to :load [#87 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2008-05-31 13:33:38 -07:00
Tom Ward
ebb642fa3a Fix Dependencies watch_frames collection. [#24 state:resolved]
Previously, the code collecting watch_frames could fail leaving
watch_frames defined but nil. The cleanup code checks watch_frames
is defined, but not that it holds a value, raising an undefined method
on NilClass error rather than the original cause.  This can make
debugging the underlying cause a total pain.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2008-05-20 11:44:23 +01:00
Jeremy Kemper
f8c12301bb remove some more absolute requires
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8567 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-05 13:32:48 +00:00
Jeremy Kemper
f6d8526659 require abstract_unit directly since test is in load path
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8563 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-05 13:31:04 +00:00
Jeremy Kemper
5f4d121798 Dependencies Ruby 1.9 compat
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-09-27 11:01:20 +00:00
Nicholas Seckar
4eec5f4fbb Update Dependencies to ignore constants inherited from ancestors. Closes #6951.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6426 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-03-14 23:27:28 +00:00
Jeremy Kemper
0a06ffc08e tighten test_load_once_paths_should_behave_when_recursively_loading
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5816 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-01-01 00:25:30 +00:00
Jeremy Kemper
cbe0c3c54f Check for nil name also. Closes #6561.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5814 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-12-31 23:53:05 +00:00
Nicholas Seckar
91b71ed30c Fix Dependencies.autoloaded? to ignore anonymous modules. Closes #6561.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5811 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-12-31 18:53:58 +00:00
Nicholas Seckar
1e170da30d Checkin failing test case related to load once paths
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5781 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-12-24 14:41:29 +00:00
Nicholas Seckar
6a485c3100 Fix remove_constant to correctly handle constant names of the form "::A::...". References #6720.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5710 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-12-09 05:21:33 +00:00
Jeremy Kemper
615d05f5de Test autoloading nested subclass of parent.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5541 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-16 22:50:46 +00:00
Nicholas Seckar
ad06514257 Update dependencies to delete partially loaded constants.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5464 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-07 20:45:36 +00:00
Jeremy Kemper
e1140f876e Update failing autoload tests.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5463 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-07 20:29:50 +00:00
Nicholas Seckar
a7d0e0e011 Fix warning and incorrect test trigger
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5444 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-06 23:45:39 +00:00
Jeremy Kemper
07c51829ab Failing test for autoloading shadowed exceptions.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5440 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-06 19:23:30 +00:00
Nicholas Seckar
5cc682da07 Update dependencies to allow constants to be defined alongside their siblings.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5386 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-11-01 23:21:13 +00:00
Nicholas Seckar
497b5dcf19 Add 'unloadable', a method used to mark any constant as requiring an unload after each request.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5307 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-10-15 23:32:31 +00:00
Nicholas Seckar
93659978d5 Fix loadable_constants_for_path to handle load paths that do not end with a slash.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5053 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-09-06 20:31:28 +00:00
Nicholas Seckar
7441b19d0c Fix logic error in determining what was loaded by a given file. Closes #6039.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5035 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-09-05 23:36:14 +00:00
Nicholas Seckar
1d554b84f8 Equate Kernel.const_missing with Object.const_missing. Fixes #5988.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5023 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-09-05 22:36:28 +00:00