require 'test/unit' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper' # require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper' class ActiveRecordHelperTest < Test::Unit::TestCase include ActionView::Helpers::FormHelper include ActionView::Helpers::ActiveRecordHelper include ActionView::Helpers::TextHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on) Column = Struct.new("Column", :type, :name, :human_name) def setup @post = Post.new def @post.errors Class.new { def on(field) field == "author_name" || field == "body" end def empty?() false end def count() 1 end def full_messages() [ "Author name can't be empty" ] end }.new end def @post.new_record?() true end def @post.column_for_attribute(attr_name) Post.content_columns.select { |column| column.name == attr_name }.first end def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end @post.title = "Hello World" @post.author_name = "" @post.body = "Back to the hill and over it again!" @post.secret = 1 @post.written_on = Date.new(2004, 6, 15) @controller = Class.new do def url_for(options, *parameters_for_method_reference) options[:action] end end @controller = @controller.new end def test_generic_input_tag assert_equal( %(), input("post", "title") ) end def test_text_area_with_errors assert_equal( %(
), text_area("post", "body") ) end def test_text_field_with_errors assert_equal( %(
), text_field("post", "author_name") ) end def test_form_with_string assert_equal( %(


\n


), form("post") ) end def test_form_with_date def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end assert_equal( %(


\n\n\n

), form("post") ) end def test_form_with_datetime def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end @post.written_on = Time.gm(2004, 6, 15, 16, 30) assert_equal( %(


\n\n\n — \n : \n

), form("post") ) end def test_error_for_block assert_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

), error_messages_for("post") assert_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1") end end