mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Show real LoadError on helpers require
When helper try to require missing file rails will throw exception about missing helper. # app/helpers/my_helper.rb require 'missing' module MyHelper end And when we try do load helper class ApplicationController helper :my end Rails will throw exception. This is wrong because there is a helper file. Missing helper file helpers/my_helper.rb Now when helper try to require non-existed file rails will throw proper exception. No such file to load -- missing
This commit is contained in:
parent
cd0d5902dd
commit
e0438b1c07
5 changed files with 38 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
* 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*
|
||||||
|
|
||||||
* Fix `ActionDispatch::ParamsParser#parse_formatted_parameters` to rewind body input stream on
|
* Fix `ActionDispatch::ParamsParser#parse_formatted_parameters` to rewind body input stream on
|
||||||
parsing json params.
|
parsing json params.
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,12 @@ module AbstractController
|
||||||
@error = error
|
@error = error
|
||||||
@path = "helpers/#{path}.rb"
|
@path = "helpers/#{path}.rb"
|
||||||
set_backtrace error.backtrace
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
BIN
actionpack/test/abstract/.helper_test.rb.swp
Normal file
BIN
actionpack/test/abstract/.helper_test.rb.swp
Normal file
Binary file not shown.
|
@ -48,6 +48,14 @@ module AbstractController
|
||||||
end
|
end
|
||||||
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
|
class TestHelpers < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
@controller = AbstractHelpers.new
|
@controller = AbstractHelpers.new
|
||||||
|
@ -97,5 +105,17 @@ module AbstractController
|
||||||
assert_equal "Hello Default", @controller.response_body
|
assert_equal "Hello Default", @controller.response_body
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
5
actionpack/test/fixtures/helpers_missing/invalid_require_helper.rb
vendored
Normal file
5
actionpack/test/fixtures/helpers_missing/invalid_require_helper.rb
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
require 'very_invalid_file_name'
|
||||||
|
|
||||||
|
module InvalidRequireHelper
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue