From f9243e3b786a4d113b1bb2005acfad8f05bd3280 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Thu, 1 May 2008 12:10:18 +1000 Subject: [PATCH] adds ActionView class method to set default order option for date and time form helpers --- actionpack/lib/action_view/helpers/date_helper.rb | 10 +++++++- actionpack/test/template/date_helper_test.rb | 24 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9f7790d..c7a9209 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -108,7 +108,8 @@ module ActionView # discard options. The discard options are :discard_year, :discard_month and :discard_day. Set to true, they'll # drop the respective select. Discarding the month select will also automatically discard the day select. It's also possible to explicitly # set the order of the tags using the :order option with an array of symbols :year, :month and :day in - # the desired order. Symbols may be omitted and the respective select is not included. + # the desired order. Symbols may be omitted and the respective select is not included. The default :order for your application + # maybe specified in an initializer file by changing the ActionView::Base.default_date_select_order value. # # Pass the :default option to set the default date. Use a Time object or a Hash of :year, :month, :day, :hour, :minute, and :second. # @@ -619,7 +620,7 @@ module ActionView position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 } - order = (options[:order] ||= [:year, :month, :day]) + order = (options[:order] ||= ActionView::Base.default_date_select_order) # Discard explicit and implicit by not being included in the :order discard = {} @@ -707,4 +708,9 @@ module ActionView end end end + + class Base + cattr_accessor :default_date_select_order + self.default_date_select_order = [:year, :month, :day] + end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 2373600..1949c79 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1065,7 +1065,31 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :order => [:day, :month, :year]) end + + def test_default_date_select_order + old_default_date_select_order = ActionView::Base.default_date_select_order + ActionView::Base.default_date_select_order = [:day, :month, :year] + + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = %{\n" + expected << %{\n" + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on") + ensure + ActionView::Base.default_date_select_order = old_default_date_select_order + end + def test_date_select_with_nil @post = Post.new -- 1.5.5.1