From eb23754ebbfbf2d465cc0f900720704fb3703633 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 17 Apr 2013 00:06:11 +0200 Subject: Move template tests from actionpack to actionview --- .../test/template/active_model_helper_test.rb | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 actionview/test/template/active_model_helper_test.rb (limited to 'actionview/test/template/active_model_helper_test.rb') diff --git a/actionview/test/template/active_model_helper_test.rb b/actionview/test/template/active_model_helper_test.rb new file mode 100644 index 0000000000..86bccdfade --- /dev/null +++ b/actionview/test/template/active_model_helper_test.rb @@ -0,0 +1,99 @@ +require 'abstract_unit' + +class ActiveModelHelperTest < ActionView::TestCase + tests ActionView::Helpers::ActiveModelHelper + + silence_warnings do + class Post < Struct.new(:author_name, :body, :updated_at) + 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( + %(
\n\n\n
), + date_select("post", "updated_at", :discard_month => true, :discard_day => true, :start_year => 2004, :end_year => 2005) + ) + end + + def test_datetime_select_with_errors + assert_dom_equal( + %(
\n\n\n\n : \n
), + datetime_select("post", "updated_at", :discard_year => true, :discard_month => true, :discard_day => true, :minute_step => 60) + ) + end + + def test_time_select_with_errors + assert_dom_equal( + %(
\n\n\n\n : \n
), + time_select("post", "updated_at", :minute_step => 60) + ) + 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 -- cgit v1.2.3