aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-07 19:50:30 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-07 19:50:30 +0000
commit459cc1ecb84aea273ecf8183fb791f61e26c19b0 (patch)
tree7457f38b749ba5668f87593a6c28bfde8435d75c /actionpack/test
parentc79dfd36dc0002f7647781aacfb7fa8965852e08 (diff)
downloadrails-459cc1ecb84aea273ecf8183fb791f61e26c19b0.tar.gz
rails-459cc1ecb84aea273ecf8183fb791f61e26c19b0.tar.bz2
rails-459cc1ecb84aea273ecf8183fb791f61e26c19b0.zip
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
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/template/active_record_helper_test.rb23
-rw-r--r--actionpack/test/template/form_helper_test.rb19
2 files changed, 41 insertions, 1 deletions
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 "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
end
+ def test_error_message_on_no_instance_variable
+ other_post = @post
+ assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
+ end
+
def test_error_message_on_should_use_options
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", 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 %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), 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 %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post)
+
+ #multiple objects
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), 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(
%(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
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 = %(<form action='http://www.example.com' method='post'>) +
+ %(<div class='formError'>can't be empty</div>) +
+ %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
+ %(</form>)
+
+ assert_dom_equal expected, _erbout
+
+ end
# Perhaps this test should be moved to prototype helper tests.
def test_remote_form_for_with_labelled_builder