require "abstract_unit" class ActiveModelHelperTest < ActionView::TestCase tests ActionView::Helpers::ActiveModelHelper silence_warnings do Post = Struct.new(:author_name, :body, :updated_at) do 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.errors[:updated_at] << "bar" @post.author_name = "" @post.body = "Back to the hill and over it again!" @post.updated_at = Date.new(2004, 6, 15) 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_select_with_errors assert_dom_equal( %(), select("post", "author_name", [:a, :b]) ) end def test_select_with_errors_and_blank_option expected_dom = %() assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], include_blank: "Choose one...")) assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], prompt: "Choose one...")) end def test_date_select_with_errors assert_dom_equal( %(