Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Commit

Permalink
Fix for issue formtastic#152 (date/time inputs could no longer defaul…
Browse files Browse the repository at this point in the history
…t 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
justinfrench committed Dec 29, 2009
1 parent 68f789f commit 7b947cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/formtastic.rb
Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion spec/inputs/date_input_spec.rb
Expand Up @@ -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
14 changes: 14 additions & 0 deletions spec/inputs/datetime_input_spec.rb
Expand Up @@ -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.