Skip to content

Commit

Permalink
Fix time_input :include_seconds => true.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Moen Wulffeld authored and justinfrench committed Mar 13, 2010
1 parent b91bcc2 commit 3cc4ac6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def date_or_datetime_input(method, options)
labels = options.delete(:labels) || {}

time_inputs = [:hour, :minute]
time_inputs << [:second] if options[:include_seconds]
time_inputs << :second if options[:include_seconds]

list_items_capture = ""
hidden_fields_capture = ""
Expand Down
86 changes: 58 additions & 28 deletions spec/inputs/time_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,73 @@
end

describe "general" do

before do
output_buffer.replace ''
semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :time))
end
end

describe "without seconds" do
before do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :time))
end
end

it_should_have_input_wrapper_with_class("time")
it_should_have_input_wrapper_with_id("post_publish_at_input")
it_should_have_a_nested_fieldset
it_should_apply_error_logic_for_input_type(:time)
it_should_have_input_wrapper_with_class("time")
it_should_have_input_wrapper_with_id("post_publish_at_input")
it_should_have_a_nested_fieldset
it_should_apply_error_logic_for_input_type(:time)

it 'should have a legend and label with the label text inside the fieldset' do
output_buffer.should have_tag('form li.time fieldset legend.label label', /Publish at/)
end
it 'should have a legend and label with the label text inside the fieldset' do
output_buffer.should have_tag('form li.time fieldset legend.label label', /Publish at/)
end

it 'should associate the legend label with the first select' do
output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_1i"]')
end
it 'should associate the legend label with the first select' do
output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_1i"]')
end

it 'should have an ordered list of two items inside the fieldset' do
output_buffer.should have_tag('form li.time fieldset ol')
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
end
it 'should have an ordered list of two items inside the fieldset' do
output_buffer.should have_tag('form li.time fieldset ol')
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
end

it 'should have five labels for hour and minute' do
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
end

it 'should have five labels for hour and minute' do
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
it 'should have two selects for hour and minute' do
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
end
end

describe "with seconds" do
before do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
end
end

it 'should have two selects for hour and minute' do
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
it 'should have five labels for hour and minute' do
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 3)
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
output_buffer.should have_tag('form li.time fieldset ol li label', /second/i)
end

it 'should have three selects for hour, minute and seconds' do
output_buffer.should have_tag('form li.time fieldset ol li', :count => 3)
end

it 'should generate a sanitized label and matching ids for attribute' do
4.upto(6) do |i|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
end
end
end
end

describe ':selected option' do

describe "when the object has a value" do
Expand Down Expand Up @@ -102,12 +132,12 @@
end

describe ':labels option' do
fields = [:hour, :minute]
fields = [:hour, :minute, :second]
fields.each do |field|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
output_buffer.replace ''
semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :time, :labels => { field => "another #{field} label" }))
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
end
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
fields.each do |f|
Expand All @@ -118,7 +148,7 @@
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
output_buffer.replace ''
semantic_form_for(@new_post) do |builder|
concat(builder.input(:created_at, :as => :time, :labels => { field => "" }))
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
end
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
fields.each do |f|
Expand Down

0 comments on commit 3cc4ac6

Please sign in to comment.