Skip to content

Commit

Permalink
Merge pull request #26786 from codeodor/patch-1
Browse files Browse the repository at this point in the history
Allow any key in Renderer environment hash
  • Loading branch information
eileencodes committed Oct 15, 2016
2 parents 10781f3 + 6fccd7b commit 28ce091
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 28ce091

Please sign in to comment.