Permalink
Browse files

pushed new branch

git-svn-id: https://calendardateselect.googlecode.com/svn/tags/RELEASE_1_8_1@215 4972a71b-da31-0410-b7dd-373b726a5e75
  • Loading branch information...
2 parents 78a7013 + beaa5d2 commit 23d25bd2a45a86ea4db7a95c6812ced113f7880f timcharper committed Sep 28, 2007
Showing with 67 additions and 8 deletions.
  1. +16 −7 lib/calendar_date_select.rb
  2. +43 −0 test/functional/calendar_date_select_test.rb
  3. +8 −1 test/test_helper.rb
@@ -80,10 +80,8 @@ def calendar_date_select_process_options(options)
for key in callbacks
calendar_options[key] = "function(param) { #{calendar_options[key]} }" unless calendar_options[key].include?("function") if calendar_options[key]
end
-
- calendar_options[:year_range] ||= 10
- calendar_options[:format] ||= CalendarDateSelect.date_format_string(calendar_options[:time])
+ calendar_options[:year_range] ||= 10
calendar_options
end
@@ -92,14 +90,25 @@ def calendar_date_select(object, method, options={})
if !options.include?(:time) && obj.class.respond_to?("columns_hash")
column_type = (obj.class.columns_hash[method.to_s].type rescue nil)
- options[:time] = true if column_type==:datetime
+ options[:time] = true if column_type == :datetime
+ end
+
+ use_time = options[:time]
+
+ if options[:time].to_s=="mixed"
+ use_time = false if Date===obj.send(method)
end
calendar_options = calendar_date_select_process_options(options)
- value = obj.send(method).strftime(calendar_options[:format]) rescue obj.send("#{method}_before_type_cast")
-
- calendar_options.delete(:format)
+ value = if obj.send(method).respond_to?(:strftime)
+ obj.send(method).strftime(CalendarDateSelect.date_format_string(use_time))
+ elsif obj.respond_to?("#{method}_before_type_cast")
+ obj.send("#{method}_before_type_cast")
+ else
+ obj.send(method).to_s
+ end
+
options = options.merge(:value => value)
tag = ActionView::Helpers::InstanceTag.new(object, method, self, nil, options.delete(:object))
@@ -0,0 +1,43 @@
+require File.join(File.dirname(__FILE__), '../test_helper.rb')
+
+class HelperMethodsTest < Test::Unit::TestCase
+ include ActionView::Helpers::FormHelper
+ include ActionView::Helpers::JavaScriptHelper
+ include ActionView::Helpers::AssetTagHelper
+ include ActionView::Helpers::TagHelper
+
+ include CalendarDateSelect::FormHelper
+
+ def setup
+ @controller = ActionController::Base.new
+ @request = OpenStruct.new
+ @controller.request = @request
+
+ @model = OpenStruct.new
+ end
+
+ def test_mixed_time__model_returns_date__should_render_without_time
+ @model.start_datetime = Date.parse("January 2, 2007")
+ output = calendar_date_select(:model, :start_datetime, :time => "mixed")
+ assert_no_match(/12:00 AM/, output, "Shouldn't have outputted a time")
+ end
+
+ def test_mixed_time__model_returns_time__should_render_with_time
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
+ output = calendar_date_select(:model, :start_datetime, :time => "mixed")
+ assert_match(/12:00 AM/, output, "Should have outputted a time")
+ end
+
+ def test_time_true__model_returns_date__should_render_with_time
+ @model.start_datetime = Date.parse("January 2, 2007")
+ output = calendar_date_select(:model, :start_datetime, :time => "true")
+ assert_match(/12:00 AM/, output, "Should have outputted a time")
+ end
+
+ def test_time_false__model_returns_time__should_render_without_time
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
+ output = calendar_date_select(:model, :start_datetime, :time => false)
+ assert_no_match(/12:00 AM/, output, "Shouldn't have outputted a time")
+ end
+
+end
View
@@ -1,6 +1,13 @@
-require 'test/unit'
require "rubygems"
+
+require 'test/unit'
+
require 'active_support'
+require 'action_pack'
+require 'action_controller'
+require 'action_view'
+
+require 'ostruct'
for file in ["../lib/calendar_date_select.rb", "../lib/includes_helper.rb"]
require File.expand_path(File.join(File.dirname(__FILE__), file))

0 comments on commit 23d25bd

Please sign in to comment.