From 1159b7a5e233bc0d9544924c56cf8ba7f628e485 Mon Sep 17 00:00:00 2001 From: Bob Klosinski Date: Thu, 26 Jun 2008 13:17:56 -0500 Subject: [PATCH] fixed select_date seperator and documentation also added tests --- actionpack/lib/action_view/helpers/date_helper.rb | 14 ++++++++--- actionpack/test/template/date_helper_test.rb | 26 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 7ed6272..b0e942c 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -239,8 +239,8 @@ module ActionView # select_datetime(my_date_time, :order => [:year, :month, :day]) # # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) - # # with a '/' between each date field. - # select_datetime(my_date_time, :date_separator => '/') + # # with a '/' between the date fields and the time fields. + # select_datetime(my_date_time, :datetime_separator => '/') # # # Generates a datetime select that discards the type of the field and defaults to the datetime in # # my_date_time (four days after today) @@ -275,21 +275,27 @@ module ActionView # # with the fields ordered year, month, day rather than month, day, year. # select_date(my_date, :order => [:year, :month, :day]) # + # # Generates a date select that defaults to the date in my_date_time (six days after today) + # # with a '/' between each date field. + # select_date(my_date, :date_separator => '/') + # # # Generates a date select that discards the type of the field and defaults to the date in # # my_date (six days after today) - # select_datetime(my_date_time, :discard_type => true) + # select_date(my_date, :discard_type => true) # # # Generates a date select that defaults to the datetime in my_date (six days after today) # # prefixed with 'payday' rather than 'date' - # select_datetime(my_date_time, :prefix => 'payday') + # select_date(my_date, :prefix => 'payday') # def select_date(date = Date.current, options = {}, html_options = {}) options[:order] ||= [] [:year, :month, :day].each { |o| options[:order].push(o) unless options[:order].include?(o) } select_date = '' + separator = options[:date_separator] || '' options[:order].each do |o| select_date << self.send("select_#{o}", date, options, html_options) + select_date << separator unless o == options[:order].last end select_date end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 11b3bdb..b742374 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -539,6 +539,26 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]") end + + def test_select_date_with_separator + expected = %(\n" + + expected << ":" + + expected << %(\n" + + expected << ":" + + expected << %(\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :date_separator => ":") + end def test_select_date_with_order expected = %(\n) expected << %(\n\n\n) expected << "\n" + + expected << "-" expected << %(\n" + + expected << "-" expected << %(\n" - assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :datetime_separator => ' — ', :time_separator => ' : ') + assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :date_separator => '-', :datetime_separator => ' — ', :time_separator => ' : ') end def test_select_datetime_with_nil_value_and_no_start_and_end_year -- 1.5.5.4