From 17927cbddcd4da278c93ec68815eec5d74650e61 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Wed, 13 Jun 2007 01:34:16 +0000
Subject: Improve UrlRewriter tests. Improve helper test coverage. Closes
#7207, #7208, #7212.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7013 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
---
.../test/template/active_record_helper_test.rb | 38 +++++++++++++++-------
1 file changed, 27 insertions(+), 11 deletions(-)
(limited to 'actionpack/test/template')
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index 5eab1c8525..4a85ae1751 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -28,7 +28,16 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
@post = Post.new
def @post.errors
Class.new {
- def on(field) field == "author_name" || field == "body" end
+ def on(field)
+ case field.to_s
+ when "author_name"
+ "can't be empty"
+ when "body"
+ true
+ else
+ false
+ end
+ end
def empty?() false end
def count() 1 end
def full_messages() [ "Author name can't be empty" ] end
@@ -52,7 +61,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
@post.secret = 1
@post.written_on = Date.new(2004, 6, 15)
end
-
+
def setup_user
@user = User.new
def @user.errors
@@ -95,7 +104,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
%( ), input("post", "title")
)
end
-
+
def test_text_area_with_errors
assert_dom_equal(
%(
),
@@ -109,7 +118,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
text_field("post", "author_name")
)
end
-
+
def test_form_with_string
assert_dom_equal(
%(
),
@@ -129,7 +138,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
form("post")
)
end
-
+
def test_form_with_date
silence_warnings do
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
@@ -152,26 +161,30 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
form("post")
)
end
-
+
def test_error_for_block
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")
assert_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", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
assert_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", :class => nil, :id => "errorDeathById", :header_tag => "h1")
assert_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", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
end
-
+
def test_error_messages_for_handles_nil
assert_equal "", error_messages_for("notthere")
end
-
+
def test_error_message_on_handles_nil
assert_equal "", error_message_on("notthere", "notthere")
end
-
+
def test_error_message_on
- assert error_message_on(:post, :author_name)
+ assert_dom_equal "can't be empty
", error_message_on(: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
-
+
def test_error_messages_for_many_objects
assert_dom_equal %(2 errors prohibited this post from being saved There were problems with the following fields:
Author name can't be empty User email can't be empty ), error_messages_for("post", "user")
@@ -186,6 +199,9 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
# any default works too
assert_dom_equal %(2 errors prohibited this monkey 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 => "monkey")
+
+ # 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_form_with_string_multipart
--
cgit v1.2.3