Skip to content
Browse files

Fix for issue #152 (date/time inputs could no longer default to nil):

* added failing specs
* changed date_or_datetime_input to only fallback to Time.now when options[:selected] is not present
  • Loading branch information...
1 parent 68f789f commit 7b947cb528e1e13c1f62da23be07ba310ff2c1bd @justinfrench justinfrench committed Dec 30, 2009
Showing with 32 additions and 3 deletions.
  1. +2 −2 lib/formtastic.rb
  2. +16 −1 spec/inputs/date_input_spec.rb
  3. +14 −0 spec/inputs/datetime_input_spec.rb
View
4 lib/formtastic.rb
@@ -928,8 +928,8 @@ def date_or_datetime_input(method, options)
list_items_capture = ""
hidden_fields_capture = ""
- default_time = ::Time.now
-
+ default_time = options.has_key?(:selected) ? options[:selected] : ::Time.now
+
# Gets the datetime object. It can be a Fixnum, Date or Time, or nil.
datetime = options[:selected] || (@object ? @object.send(method) : default_time) || default_time
View
17 spec/inputs/date_input_spec.rb
@@ -41,5 +41,20 @@
it_should_select_existing_datetime_else_current(:year, :month, :day)
it_should_select_explicit_default_value_if_set(:year, :month, :day)
-
+
+ describe "when :selected is nil" do
+
+ before(:each) do
+ output_buffer.replace ''
+ semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ concat(builder.input(:publish_at, :as => :datetime, :selected => nil))
+ end
+ end
+
+ it "should not pre-select any options" do
+ output_buffer.should_not have_tag("form li.datetime li select option[@selected]")
+ end
+
+ end
+
end
View
14 spec/inputs/datetime_input_spec.rb
@@ -151,5 +151,19 @@
end
end
+ describe "when :selected is nil" do
+
+ before(:each) do
+ output_buffer.replace ''
+ semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ concat(builder.input(:publish_at, :as => :datetime, :selected => nil))
+ end
+ end
+
+ it "should not pre-select any options" do
+ output_buffer.should_not have_tag("form li.datetime li select option[@selected]")
+ end
+
+ end
end

0 comments on commit 7b947cb

Please sign in to comment.
Something went wrong with that request. Please try again.