Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any key in Renderer environment hash #26786

Merged
merged 1 commit into from Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,8 @@
* Allow keys not found in RACK_KEY_TRANSLATION for setting the environment when rendering
arbitrary templates.

*Sammy Larbi*

* Remove deprecated support to non-keyword arguments in `ActionDispatch::IntegrationTest#process`,
`#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`.

Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/renderer.rb
Expand Up @@ -102,7 +102,9 @@ def normalize_keys(env)
method: ->(v) { v.upcase },
}

def rack_key_for(key); RACK_KEY_TRANSLATION[key]; end
def rack_key_for(key)
RACK_KEY_TRANSLATION.fetch(key, key.to_s)
end

def rack_value_for(key, value)
RACK_VALUE_TRANSLATION.fetch(key, IDENTITY).call value
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/renderer_test.rb
Expand Up @@ -60,6 +60,14 @@ class RendererTest < ActiveSupport::TestCase
assert_equal "true", content
end

test "rendering with custom env using a key that is not in RACK_KEY_TRANSLATION" do
value = "warden is here"
renderer = ApplicationController.renderer.new warden: value
content = renderer.render inline: "<%= request.env['warden'] %>"

assert_equal value, content
end

test "rendering with defaults" do
renderer = ApplicationController.renderer.new https: true
content = renderer.render inline: "<%= request.ssl? %>"
Expand Down