aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-25 08:53:24 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-25 08:53:24 -0700
commitdcb2bee35e773192f8a78065c193156b7d3da6ec (patch)
tree2ffa67a03e2ab280177a7df34bf8f16737b3e249 /actionpack
parentb76a96320e967d158d5979b613f8cabad28b7034 (diff)
parent4b1985578a2b27b170358e82e72e00d23fdaf087 (diff)
downloadrails-dcb2bee35e773192f8a78065c193156b7d3da6ec.tar.gz
rails-dcb2bee35e773192f8a78065c193156b7d3da6ec.tar.bz2
rails-dcb2bee35e773192f8a78065c193156b7d3da6ec.zip
Merge pull request #7446 from nashby/backport-fix-issue-7431
backport #7435
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb7
-rw-r--r--actionpack/test/template/date_helper_test.rb24
3 files changed, 34 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 99ff1c1ede..3f91ba64f5 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.9 (unreleased) ##
+* Fix handling of date selects when using both disabled and discard options.
+ Fixes #7431.
+
+ *Vasiliy Ermolovich*
+
* Fix select_tag when option_tags is nil.
Fixes #7404.
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index c26f0d4911..87e2332c42 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -915,12 +915,15 @@ module ActionView
# build_hidden(:year, 2008)
# => "<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="2008" />"
def build_hidden(type, value)
- (tag(:input, {
+ select_options = {
:type => "hidden",
:id => input_id_from_type(type),
:name => input_name_from_type(type),
:value => value
- }.merge(@html_options.slice(:disabled))) + "\n").html_safe
+ }.merge(@html_options.slice(:disabled))
+ select_options.merge!(:disabled => 'disabled') if @options[:disabled]
+
+ tag(:input, select_options) + "\n".html_safe
end
# Returns the name attribute for the input tag.
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index 584d1830eb..cf707e1de5 100644
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -2533,6 +2533,30 @@ class DateHelperTest < ActionView::TestCase
assert_dom_equal expected, datetime_select("post", "updated_at", :discard_minute => true)
end
+ def test_datetime_select_disabled_and_discard_minute
+ @post = Post.new
+ @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35)
+
+ expected = %{<select id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]">\n}
+ 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) }
+ expected << "</select>\n"
+ expected << %{<select id="post_updated_at_2i" disabled="disabled" name="post[updated_at(2i)]">\n}
+ 1.upto(12) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 6}>#{Date::MONTHNAMES[i]}</option>\n) }
+ expected << "</select>\n"
+ expected << %{<select id="post_updated_at_3i" disabled="disabled" name="post[updated_at(3i)]">\n}
+ 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 15}>#{i}</option>\n) }
+ expected << "</select>\n"
+
+ expected << " &mdash; "
+
+ expected << %{<select id="post_updated_at_4i" disabled="disabled" name="post[updated_at(4i)]">\n}
+ 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) }
+ expected << "</select>\n"
+ expected << %{<input type="hidden" id="post_updated_at_5i" disabled="disabled" name="post[updated_at(5i)]" value="16" />\n}
+
+ assert_dom_equal expected, datetime_select("post", "updated_at", :discard_minute => true, :disabled => true)
+ end
+
def test_datetime_select_invalid_order
@post = Post.new
@post.updated_at = Time.local(2004, 6, 15, 15, 16, 35)