aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2013-06-09 23:48:28 -0700
committerSteve Klabnik <steve@steveklabnik.com>2013-06-09 23:48:28 -0700
commitcbfcd9ddf1c964829307a8ce4b483c50252898a7 (patch)
tree73c25e049f42333dbaff3a1a95c0153ccacbd11f
parentf5e133e830940731b74c4e12118eab90054d32ec (diff)
parenta548792aa0beef4330a3d47eb75dd2fe741013bc (diff)
downloadrails-cbfcd9ddf1c964829307a8ce4b483c50252898a7.tar.gz
rails-cbfcd9ddf1c964829307a8ce4b483c50252898a7.tar.bz2
rails-cbfcd9ddf1c964829307a8ce4b483c50252898a7.zip
Merge pull request #10795 from atambo/master
Don't blindly call blame_file! on exceptions in ActiveSupport::Dependes::Loadable
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/dependencies.rb2
-rw-r--r--activesupport/test/dependencies/raises_exception_without_blame_file.rb5
-rw-r--r--activesupport/test/dependencies_test.rb8
4 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 5a1c14683e..0f9399f4d6 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fix `ActiveSupport::Dependencies::Loadable#load_dependency` calling
+ `#blame_file!` on Exceptions that do not have the Blamable mixin
+
+ *Andrew Kreiling*
+
* Override `Time.at` to support the passing of Time-like values when called with a single argument.
*Andrew White*
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index fff4c776a9..d38e4b0732 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -213,7 +213,7 @@ module ActiveSupport #:nodoc:
yield
end
rescue Exception => exception # errors from loading file
- exception.blame_file! file
+ exception.blame_file! file if exception.respond_to? :blame_file!
raise
end
diff --git a/activesupport/test/dependencies/raises_exception_without_blame_file.rb b/activesupport/test/dependencies/raises_exception_without_blame_file.rb
new file mode 100644
index 0000000000..4b2da6ff30
--- /dev/null
+++ b/activesupport/test/dependencies/raises_exception_without_blame_file.rb
@@ -0,0 +1,5 @@
+exception = Exception.new('I am not blamable!')
+class << exception
+ undef_method(:blame_file!)
+end
+raise exception
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 4b1426bb2e..68b6cc6e8c 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -76,6 +76,14 @@ class DependenciesTest < ActiveSupport::TestCase
end
end
+ def test_dependency_which_raises_doesnt_blindly_call_blame_file!
+ with_loading do
+ filename = 'dependencies/raises_exception_without_blame_file'
+
+ assert_raises(Exception) { require_dependency filename }
+ end
+ end
+
def test_warnings_should_be_enabled_on_first_load
with_loading 'dependencies' do
old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true