aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorSam Umbach <sam@thinkrelevance.com>2011-12-03 09:41:03 -0500
committerSam Umbach <sam@thinkrelevance.com>2011-12-03 11:52:25 -0500
commit93580f49361210903a4e9cfa34a89da8ddb15815 (patch)
tree79ef1e9d890e1aa3686c796549c78a7da80322d5 /activesupport
parentbaa93a1c2ef5fd09203fe6ecd8eaddd79178bbbc (diff)
downloadrails-93580f49361210903a4e9cfa34a89da8ddb15815.tar.gz
rails-93580f49361210903a4e9cfa34a89da8ddb15815.tar.bz2
rails-93580f49361210903a4e9cfa34a89da8ddb15815.zip
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
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/dependencies_test.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index fe8f51e11a..6dc303ea86 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -258,6 +258,53 @@ class DependenciesTest < Test::Unit::TestCase
$:.replace(original_path)
end
+ def test_require_returns_true_when_file_not_yet_required
+ path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
+ original_path = $:.dup
+ original_features = $".dup
+ $:.push(path)
+
+ with_loading('autoloading_fixtures/load_path') do
+ assert_equal true, require('loaded_constant')
+ end
+ ensure
+ remove_constants(:LoadedConstant)
+ $".replace(original_features)
+ $:.replace(original_path)
+ end
+
+ def test_require_returns_true_when_file_not_yet_required_even_when_no_new_constants_added
+ path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
+ original_path = $:.dup
+ original_features = $".dup
+ $:.push(path)
+
+ with_loading('autoloading_fixtures/load_path') do
+ Object.module_eval "module LoadedConstant; end"
+ assert_equal true, require('loaded_constant')
+ end
+ ensure
+ remove_constants(:LoadedConstant)
+ $".replace(original_features)
+ $:.replace(original_path)
+ end
+
+ def test_require_returns_false_when_file_already_required
+ path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
+ original_path = $:.dup
+ original_features = $".dup
+ $:.push(path)
+
+ with_loading('autoloading_fixtures/load_path') do
+ require 'loaded_constant'
+ assert_equal false, require('loaded_constant')
+ end
+ ensure
+ remove_constants(:LoadedConstant)
+ $".replace(original_features)
+ $:.replace(original_path)
+ end
+
def failing_test_access_thru_and_upwards_fails
with_autoloading_fixtures do
assert ! defined?(ModuleFolder)