require 'abstract_unit' class ActiveModelHelperTest < ActionView::TestCase tests ActionView::Helpers::ActiveModelHelper silence_warnings do class Post < Struct.new(:author_name, :body) include ActiveModel::Conversion include ActiveModel::Validations def persisted? false end end end def setup super @post = Post.new @post.errors[:author_name] << "can't be empty" @post.errors[:body] << "foo" @post.author_name = "" @post.body = "Back to the hill and over it again!" end def test_text_area_with_errors assert_dom_equal( %(
), text_area("post", "body") ) end def test_text_field_with_errors assert_dom_equal( %(
), text_field("post", "author_name") ) end def test_hidden_field_does_not_render_errors assert_dom_equal( %(), hidden_field("post", "author_name") ) end def test_field_error_proc old_proc = ActionView::Base.field_error_proc ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| %(
#{html_tag} #{[instance.error_message].join(', ')}
).html_safe end assert_dom_equal( %(
can't be empty
), text_field("post", "author_name") ) ensure ActionView::Base.field_error_proc = old_proc if old_proc end end