Permalink
Browse files

Merge pull request #10642 from LTe/invalid-load-error

Show real LoadError on helpers require
Conflicts:
	actionpack/CHANGELOG.md

Closes #12055.
  • Loading branch information...
1 parent ea01b54 commit 78624ffedbf98c49743a60e00aa1351c9a48f54b @senny senny committed Jul 10, 2013
@@ -1,5 +1,12 @@
## unreleased ##
+* Fix an issue where rails raise exception about missing helper where it
+ should throw `LoadError`. When helper file exists and only loaded file from
+ this helper does not exist rails should throw LoadError instead of
+ `MissingHelperError`.
+
+ *Piotr Niełacny*
+
* Only cache template digests if `config.cache_template_loading` is true.
*Josh Lauer*, *Justin Ridgewell*
@@ -150,7 +150,12 @@ def initialize(error, path)
@error = error
@path = "helpers/#{path}.rb"
set_backtrace error.backtrace
- super("Missing helper file helpers/%s.rb" % path)
+
+ if error.path =~ /^#{path}(\.rb)?$/
+ super("Missing helper file helpers/%s.rb" % path)
+ else
+ raise error
+ end
end
end
Binary file not shown.
@@ -48,6 +48,14 @@ class AbstractHelpersBlock < ControllerWithHelpers
end
end
+ class AbstractInvalidHelpers < AbstractHelpers
+ include ActionController::Helpers
+
+ path = File.join(File.expand_path('../../fixtures', __FILE__), "helpers_missing")
+ $:.unshift(path)
+ self.helpers_path = path
+ end
+
class TestHelpers < ActiveSupport::TestCase
def setup
@controller = AbstractHelpers.new
@@ -97,5 +105,17 @@ def test_includes_controller_default_helper
assert_equal "Hello Default", @controller.response_body
end
end
+
+ class InvalidHelpersTest < ActiveSupport::TestCase
+ def test_controller_raise_error_about_real_require_problem
+ e = assert_raise(LoadError) { AbstractInvalidHelpers.helper(:invalid_require) }
+ assert_equal "No such file to load -- very_invalid_file_name", e.message
+ end
+
+ def test_controller_raise_error_about_missing_helper
+ e = assert_raise(Helpers::ClassMethods::MissingHelperError) { AbstractInvalidHelpers.helper(:missing) }
+ assert_equal "Missing helper file helpers/missing_helper.rb", e.message
+ end
+ end
end
end
@@ -0,0 +1,5 @@
+require 'very_invalid_file_name'
+
+module InvalidRequireHelper
+end
+

0 comments on commit 78624ff

Please sign in to comment.