From 371a5f2d73f73243ec2440305fdfab64088f35a3 Mon Sep 17 00:00:00 2001 From: Nikolay Shebanov Date: Fri, 22 Feb 2013 02:22:27 +0400 Subject: [PATCH] Fix #9360 regression in content_for --- actionpack/CHANGELOG.md | 2 ++ actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- actionpack/test/template/capture_helper_test.rb | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 94eb876db5..5f68fbc608 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -999,4 +999,6 @@ * `ActionView::Helpers::TextHelper#highlight` now defaults to the HTML5 `mark` element. *Brian Cardarella* +* Fixed `ActionView::Helpers::CaptureHelper#content_for` regression (described in #9360). *Nikolay Shebanov* + Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md) for previous changes. diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 4ec860d69a..1bad82159a 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -156,7 +156,7 @@ def content_for(name, content = nil, options = {}, &block) end nil else - @view_flow.get(name) + @view_flow.get(name).presence end end diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index 234ac3252d..938f1c3e54 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -137,6 +137,10 @@ def test_content_for_returns_nil_when_writing assert_equal 'bar', content_for(:title) end + def test_content_for_returns_nil_when_content_missing + assert_equal nil, content_for(:some_missing_key) + end + def test_content_for_question_mark assert ! content_for?(:title) content_for :title, 'title'