aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/form_helper_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-01-26 03:38:23 +0000
committerMichael Koziarski <michael@koziarski.com>2007-01-26 03:38:23 +0000
commit768b60e60d19b8940138d5f412fa79f074b5c123 (patch)
tree1a9bc75f299c71014d580f16d4aa0b5a2aadb19f /actionpack/test/template/form_helper_test.rb
parent92af8014652c7e28fa5a26682e81b974b9dbfaef (diff)
downloadrails-768b60e60d19b8940138d5f412fa79f074b5c123.tar.gz
rails-768b60e60d19b8940138d5f412fa79f074b5c123.tar.bz2
rails-768b60e60d19b8940138d5f412fa79f074b5c123.zip
Add error_messages and error_message_on to the default FormBuilder. Closes #6939 [nik.wakelin]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6040 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template/form_helper_test.rb')
-rw-r--r--actionpack/test/template/form_helper_test.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 4796e3d35d..14a41f69e2 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -6,6 +6,7 @@ class FormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::ActiveRecordHelper
silence_warnings do
Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on, :cost)
@@ -18,8 +19,14 @@ class FormHelperTest < Test::Unit::TestCase
def setup
@post = Post.new
- def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
-
+ def @post.errors()
+ Class.new{
+ def on(field); "can't be empty" if field == "author_name"; end
+ def empty?() false end
+ def count() 1 end
+ def full_messages() [ "Author name can't be empty" ] end
+ }.new
+ end
def @post.id; 123; end
def @post.id_before_type_cast; 123; end
@@ -447,6 +454,23 @@ class FormHelperTest < Test::Unit::TestCase
ensure
ActionView::Base.default_form_builder = old_default_form_builder
end
+
+ def test_default_form_builder_with_active_record_helpers
+
+ _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