Skip to content

Commit af4b654

Browse files
committed
Merge pull request rails#10642 from LTe/invalid-load-error
Show real LoadError on helpers require
2 parents 261da32 + e0438b1 commit af4b654

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

actionpack/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Fix an issue where rails raise exception about missing helper where it
2+
should throw `LoadError`. When helper file exists and only loaded file from
3+
this helper does not exist rails should throw LoadError instead of
4+
`MissingHelperError`.
5+
6+
*Piotr Niełacny*
7+
18
* Fix `ActionDispatch::ParamsParser#parse_formatted_parameters` to rewind body input stream on
29
parsing json params.
310

actionpack/lib/abstract_controller/helpers.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ def initialize(error, path)
150150
@error = error
151151
@path = "helpers/#{path}.rb"
152152
set_backtrace error.backtrace
153-
super("Missing helper file helpers/%s.rb" % path)
153+
154+
if error.path =~ /^#{path}(\.rb)?$/
155+
super("Missing helper file helpers/%s.rb" % path)
156+
else
157+
raise error
158+
end
154159
end
155160
end
156161

12 KB
Binary file not shown.

actionpack/test/abstract/helper_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class AbstractHelpersBlock < ControllerWithHelpers
4848
end
4949
end
5050

51+
class AbstractInvalidHelpers < AbstractHelpers
52+
include ActionController::Helpers
53+
54+
path = File.join(File.expand_path('../../fixtures', __FILE__), "helpers_missing")
55+
$:.unshift(path)
56+
self.helpers_path = path
57+
end
58+
5159
class TestHelpers < ActiveSupport::TestCase
5260
def setup
5361
@controller = AbstractHelpers.new
@@ -97,5 +105,17 @@ def test_includes_controller_default_helper
97105
assert_equal "Hello Default", @controller.response_body
98106
end
99107
end
108+
109+
class InvalidHelpersTest < ActiveSupport::TestCase
110+
def test_controller_raise_error_about_real_require_problem
111+
e = assert_raise(LoadError) { AbstractInvalidHelpers.helper(:invalid_require) }
112+
assert_equal "No such file to load -- very_invalid_file_name", e.message
113+
end
114+
115+
def test_controller_raise_error_about_missing_helper
116+
e = assert_raise(Helpers::ClassMethods::MissingHelperError) { AbstractInvalidHelpers.helper(:missing) }
117+
assert_equal "Missing helper file helpers/missing_helper.rb", e.message
118+
end
119+
end
100120
end
101121
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'very_invalid_file_name'
2+
3+
module InvalidRequireHelper
4+
end
5+

0 commit comments

Comments
 (0)