From 459cc1ecb84aea273ecf8183fb791f61e26c19b0 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Sun, 7 Oct 2007 19:50:30 +0000
Subject: error_messages_for and friends also work with local variables. Closes
#9699.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7779 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
---
.../test/template/active_record_helper_test.rb | 23 +++++++++++++++++++++-
actionpack/test/template/form_helper_test.rb | 19 ++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index 4a85ae1751..4630cbc1f3 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -181,6 +181,11 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
assert_dom_equal "can't be empty
", error_message_on(:post, :author_name)
end
+ def test_error_message_on_no_instance_variable
+ other_post = @post
+ assert_dom_equal "can't be empty
", error_message_on(other_post, :author_name)
+ end
+
def test_error_message_on_should_use_options
assert_dom_equal "beforecan't be emptyafter
", error_message_on(:post, :author_name, "before", "after", "differentError")
end
@@ -203,7 +208,23 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
# should space object name
assert_dom_equal %(2 errors prohibited this chunky bacon from being saved There were problems with the following fields:
User email can't be empty Author name can't be empty ), error_messages_for(:user, :post, :object_name => "chunky_bacon")
end
-
+
+ def test_error_messages_for_non_instance_variable
+ actual_user = @user
+ actual_post = @post
+ @user = nil
+ @post = nil
+
+ #explicitly set object
+ assert_dom_equal %(1 error prohibited this post from being saved There were problems with the following fields:
Author name can't be empty ), error_messages_for("post", :object => actual_post)
+
+ #multiple objects
+ assert_dom_equal %(2 errors prohibited this user from being saved There were problems with the following fields:
User email can't be empty Author name can't be empty ), error_messages_for("user", "post", :object => [actual_user, actual_post])
+
+ #nil object
+ assert_equal '', error_messages_for('user', :object => nil)
+ end
+
def test_form_with_string_multipart
assert_dom_equal(
%(
),
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 1c842fc307..32529c66f7 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -527,6 +527,25 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
+
+ def test_default_form_builder_no_instance_variable
+ post = @post
+ @post = nil
+
+ _erbout = ''
+ form_for(:post, post) do |f|
+ _erbout.concat f.error_message_on('author_name')
+ _erbout.concat f.error_messages
+ end
+
+ expected = %() +
+ %(can't be empty
) +
+ %(1 error prohibited this post from being saved There were problems with the following fields:
Author name can't be empty ) +
+ %( )
+
+ assert_dom_equal expected, _erbout
+
+ end
# Perhaps this test should be moved to prototype helper tests.
def test_remote_form_for_with_labelled_builder
--
cgit v1.2.3