From 5c7bb86a1bafbc6f067452768f37e566d6020918 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 30 Mar 2012 11:39:18 -0300 Subject: Remove the leading \n added by textarea on assert_select --- actionpack/CHANGELOG.md | 2 ++ actionpack/lib/action_dispatch/testing/assertions/selector.rb | 1 + actionpack/test/controller/assert_select_test.rb | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b0e7890512..ed3135f384 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 3.2.3 (unreleased) ## +* Remove the leading \n added by textarea on assert_select. *Santiago Pastorino* + * Fix #5632, render :inline set the proper rendered format. *Santiago Pastorino* * Fix textarea rendering when using plugins like HAML. Such plugins encode the first newline character in the content. This issue was introduced in https://github.com/rails/rails/pull/5191 *James Coleman* diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index b4555f4f59..afbd869152 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -269,6 +269,7 @@ module ActionDispatch end end text.strip! unless NO_STRIP.include?(match.name) + text.sub!(/\A\n/, '') if match.name == "textarea" unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s) content_mismatch ||= build_message(message, " expected but was\n.", match_with, text) true diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index 5eef8a32d7..97200cb6db 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -135,6 +135,13 @@ class AssertSelectTest < ActionController::TestCase assert_raise(Assertion) { assert_select "pre", :html=>text } end + def test_strip_textarea + render_html %Q{} + assert_select "textarea", "\nfoo\n" + render_html %Q{} + assert_select "textarea", "foo" + end + def test_counts render_html %Q{
foo
foo
} assert_nothing_raised { assert_select "div", 2 } -- cgit v1.2.3