From 024d3b9fcc684367b1a329c8b89c227b6470520e Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Mon, 19 Dec 2011 21:55:37 +0300 Subject: add failing tests for issue #3487 --- .../test/template/active_model_helper_test.rb | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb index 8530a72a82..52be0f1762 100644 --- a/actionpack/test/template/active_model_helper_test.rb +++ b/actionpack/test/template/active_model_helper_test.rb @@ -4,7 +4,7 @@ class ActiveModelHelperTest < ActionView::TestCase tests ActionView::Helpers::ActiveModelHelper silence_warnings do - class Post < Struct.new(:author_name, :body) + class Post < Struct.new(:author_name, :body, :updated_at) include ActiveModel::Conversion include ActiveModel::Validations @@ -20,9 +20,11 @@ class ActiveModelHelperTest < ActionView::TestCase @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 @@ -39,6 +41,27 @@ class ActiveModelHelperTest < ActionView::TestCase ) 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( %(), -- cgit v1.2.3 From 92088131ac15734f2227e9d85ea751e3f89b0116 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Tue, 20 Dec 2011 20:25:56 +0300 Subject: fix adding field_with_errors to date selects, closes #3487 --- actionpack/lib/action_view/helpers/active_model_helper.rb | 5 ----- actionpack/lib/action_view/helpers/date_helper.rb | 14 +++++++++----- actionpack/lib/action_view/helpers/form_helper.rb | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 96c3eec337..56f15604a6 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -1,4 +1,3 @@ -require 'action_view/helpers/form_helper' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/enumerable' require 'active_support/core_ext/object/blank' @@ -47,9 +46,5 @@ module ActionView options['type'] != 'hidden' end end - - class InstanceTag - include ActiveModelInstanceTag - end end end diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index dd2b59cb0a..2806348337 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -422,7 +422,7 @@ module ActionView end # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. - # The datetime can be either a +Time+ or +DateTime+ object or an integer. + # The datetime can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the :field_name option, 'second' by default. # # ==== Examples @@ -448,7 +448,7 @@ module ActionView # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. # Also can return a select tag with options by minute_step from 0 through 59 with the 00 minute - # selected. The datetime can be either a +Time+ or +DateTime+ object or an integer. + # selected. The datetime can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the :field_name option, 'minute' by default. # # ==== Examples @@ -473,7 +473,7 @@ module ActionView end # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. - # The datetime can be either a +Time+ or +DateTime+ object or an integer. + # The datetime can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the :field_name option, 'hour' by default. # # ==== Examples @@ -868,7 +868,7 @@ module ActionView tag_options = { :value => value } tag_options[:selected] = "selected" if selected == i text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value - text = options[:ampm] ? AMPM_TRANSLATION[i] : text + text = options[:ampm] ? AMPM_TRANSLATION[i] : text select_options << content_tag(:option, text, tag_options) end (select_options.join("\n") + "\n").html_safe @@ -974,7 +974,7 @@ module ActionView end end - class InstanceTag #:nodoc: + module DateHelperInstanceTag def to_date_select_tag(options = {}, html_options = {}) datetime_selector(options, html_options).select_date.html_safe end @@ -1030,6 +1030,10 @@ module ActionView end end + class InstanceTag #:nodoc: + include DateHelperInstanceTag + end + class FormBuilder def date_select(method, options = {}, html_options = {}) @template.date_select(@object_name, method, objectify_options(options), html_options) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ccb2275329..ffb5a729ed 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -2,6 +2,7 @@ require 'cgi' require 'action_view/helpers/date_helper' require 'action_view/helpers/tag_helper' require 'action_view/helpers/form_tag_helper' +require 'action_view/helpers/active_model_helper' require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/method_names' @@ -963,7 +964,7 @@ module ActionView end class InstanceTag - include Helpers::TagHelper, Helpers::FormTagHelper + include Helpers::ActiveModelInstanceTag, Helpers::TagHelper, Helpers::FormTagHelper attr_reader :object, :method_name, :object_name -- cgit v1.2.3