-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A PathResolver method that extracts the handler and format was broken since the re-arrangement of the extensions. It was no longer properly extracting the format of the template. The symptom was the layout file was no longer being looked up properly (#22). The sequence is as follows: - look up the template users/index - take the template and extract the handler and format, the format is seen as null - set the template format as the new format to use - lookup the layout file with the new format to match the template - no layout file is found The fix is to monkey patch the `ActionView::PathResolver#extract_handler_and_format` method. It will now make an additional attempt to lookup the types with another part of the extension if it exists. It is not ideal to monkey patch Rails methods, but in this case I think it is necessary. The `extract_handler_and_format` method uses knowledge of the constants set about the ‘registered details’ to extract the extension data and since we’ve modified the registered details, we need to modify the function as well.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require './test/test_helper' | ||
|
||
class ViewAdditionsTest < ActiveSupport::TestCase | ||
setup do | ||
@resolver = ActionView::PathResolver.new | ||
end | ||
|
||
test "it retrieves the correct handler and format when only hanlder and format are present" do | ||
handler, format = @resolver.extract_handler_and_format('application.html.erb', nil) | ||
assert_equal format.to_s, 'text/html' | ||
end | ||
|
||
test "it retrieves the correct handler and format when only hanlder, format and version are present" do | ||
handler, format = @resolver.extract_handler_and_format('application.json.v1.jbuilder', nil) | ||
assert_equal format.to_s, 'application/json' | ||
end | ||
|
||
test "it retrieves the correct handler and format when only hanlder, format and locale are present" do | ||
handler, format = @resolver.extract_handler_and_format('application.en.json.jbuilder', nil) | ||
assert_equal format.to_s, 'application/json' | ||
end | ||
|
||
test "it retrieves the correct handler and format when only hanlder, format, locale and version are present" do | ||
handler, format = @resolver.extract_handler_and_format('application.en.json.v1.jbuilder', nil) | ||
assert_equal format.to_s, 'application/json' | ||
end | ||
end |