From 130fe2b172afb81979e72fbf30edf945147cb78f Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Thu, 23 Aug 2012 21:59:22 +0300 Subject: [PATCH] correct handling of date selects when using both disabled and discard options we should take disabled option not only from `html_options` hash but from `options` hash too like `build_select` method does it. So datetime_select("post", "updated_at", { :discard_minute => true }, { :disabled => true }) datetime_select("post", "updated_at", :discard_minute => true , :disabled => true) both these variants work now closes #7431 --- actionpack/CHANGELOG.md | 5 ++++ .../lib/action_view/helpers/date_helper.rb | 7 ++++-- actionpack/test/template/date_helper_test.rb | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4aaa9bcd23..3c8a0f48ab 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* Fix handling of date selects when using both disabled and discard options. + Fixes #7431. + + *Vasiliy Ermolovich* + * `ActiveRecord::SessionStore` is extracted out of Rails into a gem `activerecord-session_store`. Setting `config.session_store` to `:active_record_store` will no longer work and will break if the `activerecord-session_store` gem isn't available. *Prem Sichanugrist* diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 096ad12892..795440cacc 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -963,12 +963,15 @@ def prompt_option_tag(type, options) # build_hidden(:year, 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 c13878af98..a4da7cd4b0 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -2658,6 +2658,30 @@ def test_datetime_select_discard_minute 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 = %{\n" + expected << %{\n" + expected << %{\n" + + expected << " — " + + expected << %{\n" + expected << %{\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) -- GitLab