Skip to content
Browse files

Merge pull request #826 from justinfrench/rename_timeish_inputs

Rename DateInput, TimeInput, DatetimeInput:
  • Loading branch information...
2 parents 7bfdb01 + a315547 commit e971195f8f841e4018a76a4911978250eae109fc @justinfrench committed Mar 24, 2012
View
3 CHANGELOG
@@ -6,6 +6,9 @@ HEAD
* deprecated :error_class option (use global configuration)
* deprecated :group_by and :group_label (use :collection option with a HTML string generated by Rails' grouped_options_for_select())
* deprecated :find_options
+* renamed TimeInput (:as => :time) to TimeSelectInput (:as => :time_select), aliased and deprecated TimeInput
+* renamed DatetimeInput (:as => :datetime) to DatetimeSelectInput (:as => :datetime_select), aliased and deprecated DatetimeInput
+* renamed DateInput (:as => :date) to TimeSelectInput (:as => :date_select), aliased and deprecated DateInput
2.1.1
View
6 README.textile
@@ -333,9 +333,9 @@ The Formtastic input types:
* @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
* @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
* @:text@ - a textarea. Default for column types: @:text@.
-* @:date@ - a date select. Default for column types: @:date@.
-* @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
-* @:time@ - a time select. Default for column types: @:time@.
+* @:date_select@ - a date select. Default for column types: @:date@.
+* @:datetime_select@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
+* @:time_select@ - a time select. Default for column types: @:time@.
* @:boolean@ - a checkbox. Default for column types: @:boolean@.
* @:string@ - a text field. Default for column types: @:string@.
* @:number@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
View
14 lib/formtastic/helpers/input_helper.rb
@@ -89,8 +89,8 @@ module InputHelper
# * `:boolean` (see {Inputs::BooleanInput})
# * `:check_boxes` (see {Inputs::CheckBoxesInput})
# * `:country` (see {Inputs::CountryInput})
- # * `:datetime` (see {Inputs::DatetimeInput})
- # * `:date` (see {Inputs::DateInput})
+ # * `:datetime_select` (see {Inputs::DatetimeSelectInput})
+ # * `:date_select` (see {Inputs::DateSelectInput})
# * `:email` (see {Inputs::EmailInput})
# * `:file` (see {Inputs::FileInput})
# * `:hidden` (see {Inputs::HiddenInput})
@@ -103,7 +103,7 @@ module InputHelper
# * `:string` (see {Inputs::StringInput})
# * `:text` (see {Inputs::TextInput})
# * `:time_zone` (see {Inputs::TimeZoneInput})
- # * `:time` (see {Inputs::TimeInput})
+ # * `:time_select` (see {Inputs::TimeSelectInput})
# * `:url` (see {Inputs::UrlInput})
#
# Calling `:as => :string` (for example) will call `#to_html` on a new instance of
@@ -275,8 +275,12 @@ def default_input_type(method, options = {}) #:nodoc:
return :number
when :float, :decimal
return :number
- when :timestamp
- return :datetime
+ when :datetime, :timestamp
+ return :datetime_select
+ when :time
+ return :time_select
+ when :date
+ return :date_select
end
# Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
View
3 lib/formtastic/inputs.rb
@@ -10,7 +10,9 @@ module Inputs
autoload :DateInput
autoload :DatePickerInput
autoload :DatetimePickerInput
+ autoload :DateSelectInput
autoload :DatetimeInput
+ autoload :DatetimeSelectInput
autoload :EmailInput
autoload :FileInput
autoload :HiddenInput
@@ -26,6 +28,7 @@ module Inputs
autoload :TextInput
autoload :TimeInput
autoload :TimePickerInput
+ autoload :TimeSelectInput
autoload :TimeZoneInput
autoload :Timeish
autoload :UrlInput
View
34 lib/formtastic/inputs/base/timeish.rb
@@ -1,7 +1,7 @@
module Formtastic
module Inputs
module Base
- # Timeish inputs (`:date`, `:datetime`, `:time`) are similar to the Rails date and time
+ # Timeish inputs (`:date_select`, `:datetime_select`, `:time_select`) are similar to the Rails date and time
# helpers (`date_select`, `datetime_select`, `time_select`), rendering a series of `<select>`
# tags for each fragment (year, month, day, hour, minute, seconds). The fragments are then
# re-combined to a date by ActiveRecord through multi-parameter assignment.
@@ -21,12 +21,12 @@ module Base
# * floating the `<li>` fragments against each other as a single line
# * hiding the `<label>` of each fragment with `display:none`
#
- # @example `:date` input with full form context and sample HTMl output
+ # @example `:date_select` input with full form context and sample HTMl output
#
# <%= semantic_form_for(@post) do |f| %>
# <%= f.inputs do %>
# ...
- # <%= f.input :publish_at, :as => :date %>
+ # <%= f.input :publish_at, :as => :date_select %>
# <% end %>
# <% end %>
#
@@ -56,31 +56,31 @@ module Base
# </form>
#
#
- # @example `:time` input
- # <%= f.input :publish_at, :as => :time %>
+ # @example `:time_select` input
+ # <%= f.input :publish_at, :as => :time_select %>
#
- # @example `:datetime` input
- # <%= f.input :publish_at, :as => :datetime %>
+ # @example `:datetime_select` input
+ # <%= f.input :publish_at, :as => :datetime_select %>
#
# @example Change the labels for each fragment
- # <%= f.input :publish_at, :as => :date, :labels => { :year => "Y", :month => "M", :day => "D" } %>
+ # <%= f.input :publish_at, :as => :date_select, :labels => { :year => "Y", :month => "M", :day => "D" } %>
#
# @example Skip a fragment (defaults to 1, skips all following fragments)
- # <%= f.input :publish_at, :as => :datetime, :discard_minute => true %>
- # <%= f.input :publish_at, :as => :datetime, :discard_hour => true %>
- # <%= f.input :publish_at, :as => :datetime, :discard_day => true %>
- # <%= f.input :publish_at, :as => :datetime, :discard_month => true %>
- # <%= f.input :publish_at, :as => :datetime, :discard_year => true %>
+ # <%= f.input :publish_at, :as => :datetime_select, :discard_minute => true %>
+ # <%= f.input :publish_at, :as => :datetime_select, :discard_hour => true %>
+ # <%= f.input :publish_at, :as => :datetime_select, :discard_day => true %>
+ # <%= f.input :publish_at, :as => :datetime_select, :discard_month => true %>
+ # <%= f.input :publish_at, :as => :datetime_select, :discard_year => true %>
#
# @example Change the order
- # <%= f.input :publish_at, :as => :date, :order => [:month, :day, :year] %>
+ # <%= f.input :publish_at, :as => :date_select, :order => [:month, :day, :year] %>
#
# @example Include seconds with times (excluded by default)
- # <%= f.input :publish_at, :as => :time, :include_seconds => true %>
+ # <%= f.input :publish_at, :as => :time_select, :include_seconds => true %>
#
# @example Specify if there should be a blank option at the start of each select or not. Note that, unlike select inputs, :include_blank does not accept a string value.
- # <%= f.input :publish_at, :as => :time, :include_blank => true %>
- # <%= f.input :publish_at, :as => :time, :include_blank => false %>
+ # <%= f.input :publish_at, :as => :time_select, :include_blank => true %>
+ # <%= f.input :publish_at, :as => :time_select, :include_blank => false %>
#
# @todo Document i18n
# @todo Check what other Rails options are supported (`start_year`, `end_year`, `use_month_numbers`, `use_short_month`, `add_month_numbers`, `prompt`), write tests for them, and otherwise support them
View
34 lib/formtastic/inputs/date_input.rb
@@ -1,34 +1,10 @@
module Formtastic
module Inputs
- # Outputs a series of select boxes for the fragments that make up a date (year, month, day).
- #
- # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
- class DateInput
- include Base
- include Base::Timeish
-
- # We don't want hour and minute fragments on a date input
- def time_fragments
- []
+ class DateInput < DateSelectInput
+ def to_html
+ ::ActiveSupport::Deprecation.warn("DateInput (:as => :date) has been renamed to DateSelectInput (:as => :date_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
+ super
end
-
- def hidden_date_fragments
- default_date_fragments - date_fragments
- end
-
- def hidden_fragments
- hidden_date_fragments.map do |fragment|
- template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
- end.join.html_safe
- end
-
- def fragment_value(fragment)
- if fragment == :year
- Time.now.year
- else
- '1'
- end
- end
end
end
-end
+end
View
34 lib/formtastic/inputs/date_select_input.rb
@@ -0,0 +1,34 @@
+module Formtastic
+ module Inputs
+ # Outputs a series of select boxes for the fragments that make up a date (year, month, day).
+ #
+ # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
+ class DateSelectInput
+ include Base
+ include Base::Timeish
+
+ # We don't want hour and minute fragments on a date input
+ def time_fragments
+ []
+ end
+
+ def hidden_date_fragments
+ default_date_fragments - date_fragments
+ end
+
+ def hidden_fragments
+ hidden_date_fragments.map do |fragment|
+ template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
+ end.join.html_safe
+ end
+
+ def fragment_value(fragment)
+ if fragment == :year
+ Time.now.year
+ else
+ '1'
+ end
+ end
+ end
+ end
+end
View
14 lib/formtastic/inputs/datetime_input.rb
@@ -1,12 +1,10 @@
module Formtastic
module Inputs
-
- # Outputs a series of select boxes for the fragments that make up a date and time (year, month, day, hour, minute, second).
- #
- # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
- class DatetimeInput
- include Base
- include Base::Timeish
+ class DatetimeInput < DatetimeSelectInput
+ def to_html
+ ::ActiveSupport::Deprecation.warn("DatetimeInput (:as => :datetime) has been renamed to DatetimeSelectInput (:as => :datetime_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
+ super
+ end
end
end
-end
+end
View
12 lib/formtastic/inputs/datetime_select_input.rb
@@ -0,0 +1,12 @@
+module Formtastic
+ module Inputs
+
+ # Outputs a series of select boxes for the fragments that make up a date and time (year, month, day, hour, minute, second).
+ #
+ # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
+ class DatetimeSelectInput
+ include Base
+ include Base::Timeish
+ end
+ end
+end
View
2 lib/formtastic/inputs/radio_input.rb
@@ -20,7 +20,7 @@ module Inputs
#
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
- # * a `:date`, `:time` or `:datetime` input (where the user could choose from a small set of pre-determined dates)
+ # * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from a small set of pre-determined dates)
# * a `:number` input (where the user could choose from a small set of pre-defined numbers)
# * a `:time_zone` input (where you want to provide your own small set of choices instead of relying on Rails)
# * a `:country` input (where you want to provide a small set of choices, no need for a plugin really)
View
2 lib/formtastic/inputs/select_input.rb
@@ -17,7 +17,7 @@ module Inputs
#
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
- # * a `:date`, `:time` or `:datetime` input (where the user could choose from pre-selected dates)
+ # * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from pre-selected dates)
# * a `:number` input (where the user could choose from a set of pre-defined numbers)
# * a `:time_zone` input (where you want to provide your own set of choices instead of relying on Rails)
# * a `:country` input (no need for a plugin really)
View
32 lib/formtastic/inputs/time_input.rb
@@ -1,34 +1,10 @@
module Formtastic
module Inputs
- # Outputs a series of select boxes for the fragments that make up a time (hour, minute, second).
- # Unless `:ignore_date` is true, it will render hidden inputs for the year, month and day as
- # well, defaulting to `Time.current` if the form object doesn't have a value, much like Rails'
- # own `time_select`.
- #
- # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
- class TimeInput
- include Base
- include Base::Timeish
-
- # we don't want year / month / day fragments if :ignore_date => true
- def fragments
- time_fragments
+ class TimeInput < TimeSelectInput
+ def to_html
+ ::ActiveSupport::Deprecation.warn("TimeInput (:as => :time) has been renamed to TimeSelectInput (:as => :time_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
+ super
end
-
- def fragment_value(fragment)
- value ? value.send(fragment) : ""
- end
-
- def hidden_fragments
- if !options[:ignore_date]
- date_fragments.map do |fragment|
- template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
- end.join.html_safe
- else
- super
- end
- end
-
end
end
end
View
34 lib/formtastic/inputs/time_select_input.rb
@@ -0,0 +1,34 @@
+module Formtastic
+ module Inputs
+ # Outputs a series of select boxes for the fragments that make up a time (hour, minute, second).
+ # Unless `:ignore_date` is true, it will render hidden inputs for the year, month and day as
+ # well, defaulting to `Time.current` if the form object doesn't have a value, much like Rails'
+ # own `time_select`.
+ #
+ # @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
+ class TimeSelectInput
+ include Base
+ include Base::Timeish
+
+ # we don't want year / month / day fragments if :ignore_date => true
+ def fragments
+ time_fragments
+ end
+
+ def fragment_value(fragment)
+ value ? value.send(fragment) : ""
+ end
+
+ def hidden_fragments
+ if !options[:ignore_date]
+ date_fragments.map do |fragment|
+ template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
+ end.join.html_safe
+ else
+ super
+ end
+ end
+
+ end
+ end
+end
View
16 spec/helpers/input_helper_spec.rb
@@ -417,17 +417,17 @@ def length_should_be_required(options)
default_input_type(:text).should == :text
end
- it 'should default to :date for :date column types' do
- default_input_type(:date).should == :date
+ it 'should default to :date_select for :date column types' do
+ default_input_type(:date).should == :date_select
end
- it 'should default to :datetime for :datetime and :timestamp column types' do
- default_input_type(:datetime).should == :datetime
- default_input_type(:timestamp).should == :datetime
+ it 'should default to :datetime_select for :datetime and :timestamp column types' do
+ default_input_type(:datetime).should == :datetime_select
+ default_input_type(:timestamp).should == :datetime_select
end
- it 'should default to :time for :time column types' do
- default_input_type(:time).should == :time
+ it 'should default to :time_select for :time column types' do
+ default_input_type(:time).should == :time_select
end
it 'should default to :boolean for :boolean column types' do
@@ -492,7 +492,7 @@ def length_should_be_required(options)
end
it 'should call the corresponding input class with .to_html' do
- [:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
+ [:select, :time_zone, :radio, :date_select, :datetime_select, :time_select, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
@new_post.stub!(:generic_column_name)
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
semantic_form_for(@new_post) do |builder|
View
68 spec/inputs/date_input_spec.rb → spec/inputs/date_select_input_spec.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'spec_helper'
-describe 'date input' do
+describe 'date select input' do
include FormtasticSpecHelper
@@ -15,43 +15,43 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
end)
end
- it_should_have_input_wrapper_with_class("date")
+ it_should_have_input_wrapper_with_class("date_select")
it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_publish_at_input")
it_should_have_a_nested_fieldset
it_should_have_a_nested_fieldset_with_class('fragments')
it_should_have_a_nested_ordered_list_with_class('fragments-group')
- it_should_apply_error_logic_for_input_type(:date)
+ it_should_apply_error_logic_for_input_type(:date_select)
it 'should have a legend and label with the label text inside the fieldset' do
- output_buffer.should have_tag('form li.date fieldset legend.label label', /Publish at/)
+ output_buffer.should have_tag('form li.date_select 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.date fieldset legend.label')
- output_buffer.should have_tag('form li.date fieldset legend.label label')
- output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
- output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_1i"]')
+ output_buffer.should have_tag('form li.date_select fieldset legend.label')
+ output_buffer.should have_tag('form li.date_select fieldset legend.label label')
+ output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for]')
+ output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for="post_publish_at_1i"]')
end
it 'should have an ordered list of three items inside the fieldset' do
- output_buffer.should have_tag('form li.date fieldset ol.fragments-group')
- output_buffer.should have_tag('form li.date fieldset ol li.fragment', :count => 3)
+ output_buffer.should have_tag('form li.date_select fieldset ol.fragments-group')
+ output_buffer.should have_tag('form li.date_select fieldset ol li.fragment', :count => 3)
end
it 'should have three labels for year, month and day' do
- output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
- output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
- output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
- output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => 3)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', /year/i)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', /month/i)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', /day/i)
end
it 'should have three selects for year, month and day' do
- output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
+ output_buffer.should have_tag('form li.date_select fieldset ol li select', :count => 3)
end
end
@@ -60,7 +60,7 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month, :day]))
end)
end
@@ -79,7 +79,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.fields_for(:author, :index => 3) do |author|
- concat(author.input(:created_at, :as => :date))
+ concat(author.input(:created_at, :as => :date_select))
end)
end)
end
@@ -108,40 +108,40 @@
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
+ concat(builder.input(:created_at, :as => :date_select, :labels => { field => "another #{field} label" }))
end)
- output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length)
fields.each do |f|
- output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
end
end
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
+ concat(builder.input(:created_at, :as => :date_select, :labels => { field => "" }))
end)
- output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :date, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :date_select, :labels => { field => false }))
end)
- output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not render unsafe HTML when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :date_select, :include_seconds => true, :labels => { field => false }))
end)
output_buffer.should_not include("&gt;")
end
@@ -153,7 +153,7 @@
it "should add the required attribute to the input's html options" do
with_config :use_required_attribute, true do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => :date, :required => true))
+ concat(builder.input(:title, :as => :date_select, :required => true))
end)
output_buffer.should have_tag("select[@required]", :count => 3)
end
@@ -164,7 +164,7 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:year, :month]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :month]))
end)
end
@@ -181,7 +181,7 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:year, :day]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:year, :day]))
end)
end
@@ -198,7 +198,7 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:month, :day]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:month, :day]))
end)
end
@@ -215,12 +215,12 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :date, :order => [:day, :month, :year]))
+ concat(builder.input(:publish_at, :as => :date_select, :order => [:day, :month, :year]))
end)
end
it 'should associate the legend label with the new first select' do
- output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_3i"]')
+ output_buffer.should have_tag('form li.date_select fieldset legend.label label[@for="post_publish_at_3i"]')
end
end
View
66 spec/inputs/datetime_input_spec.rb → spec/inputs/datetime_select_input_spec.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'spec_helper'
-describe 'datetime input' do
+describe 'datetime select input' do
include FormtasticSpecHelper
@@ -16,45 +16,45 @@
::I18n.backend.store_translations :en, {}
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :datetime))
+ concat(builder.input(:publish_at, :as => :datetime_select))
end)
end
- it_should_have_input_wrapper_with_class("datetime")
+ it_should_have_input_wrapper_with_class("datetime_select")
it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_publish_at_input")
it_should_have_a_nested_fieldset
it_should_have_a_nested_fieldset_with_class('fragments')
it_should_have_a_nested_ordered_list_with_class('fragments-group')
- it_should_apply_error_logic_for_input_type(:datetime)
+ it_should_apply_error_logic_for_input_type(:datetime_select)
it 'should have a legend and label with the label text inside the fieldset' do
- output_buffer.should have_tag('form li.datetime fieldset legend.label label', /Publish at/)
+ output_buffer.should have_tag('form li.datetime_select 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.datetime fieldset legend.label')
- output_buffer.should have_tag('form li.datetime fieldset legend.label label')
- output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for]')
- output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
+ output_buffer.should have_tag('form li.datetime_select fieldset legend.label')
+ output_buffer.should have_tag('form li.datetime_select fieldset legend.label label')
+ output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for]')
+ output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_1i"]')
end
it 'should have an ordered list of five items inside the fieldset' do
- output_buffer.should have_tag('form li.datetime fieldset ol.fragments-group')
- output_buffer.should have_tag('form li.datetime fieldset ol li.fragment', :count => 5)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol.fragments-group')
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li.fragment', :count => 5)
end
it 'should have five labels for year, month and day' do
- output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /min/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => 5)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /year/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /month/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /day/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /hour/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /min/i)
end
it 'should have five selects' do
- output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li select', :count => 5)
end
end
@@ -63,7 +63,7 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
- concat(builder.input(:publish_at, :as => :datetime))
+ concat(builder.input(:publish_at, :as => :datetime_select))
end)
end
@@ -84,7 +84,7 @@
concat(semantic_form_for(@new_post) do |builder|
concat(builder.fields_for(:author, :index => 3) do |author|
- concat(author.input(:created_at, :as => :datetime))
+ concat(author.input(:created_at, :as => :datetime_select))
end)
end)
end
@@ -118,40 +118,40 @@
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :datetime, :labels => { field => "another #{field} label" }))
+ concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "another #{field} label" }))
end)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length)
fields.each do |f|
- output_buffer.should have_tag('form li.datetime fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
end
end
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :datetime, :labels => { field => "" }))
+ concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => "" }))
end)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :datetime, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :datetime_select, :labels => { field => false }))
end)
- output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.datetime fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not render unsafe HTML when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :datetime_select, :include_seconds => true, :labels => { field => false }))
end)
output_buffer.should_not include("&gt;")
end
@@ -162,7 +162,7 @@
it "should add the required attribute to the input's html options" do
with_config :use_required_attribute, true do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => :datetime, :required => true))
+ concat(builder.input(:title, :as => :datetime_select, :required => true))
end)
output_buffer.should have_tag("select[@required]", :count => 5)
end
@@ -173,12 +173,12 @@
before do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :datetime, :order => [:day, :month, :year]))
+ concat(builder.input(:publish_at, :as => :datetime_select, :order => [:day, :month, :year]))
end)
end
it 'should associate the legend label with the new first select' do
- output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_3i"]')
+ output_buffer.should have_tag('form li.datetime_select fieldset legend.label label[@for="post_publish_at_3i"]')
end
end
View
48 spec/inputs/deprecated_time_date_datetime_inputs_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+
+describe 'deprecated time, datetime and date inputs' do
+ include FormtasticSpecHelper
+
+ before do
+ @output_buffer = ''
+ mock_everything
+ end
+
+ it 'should warn :time is deprecated' do
+ ::ActiveSupport::Deprecation.should_receive(:warn)
+ semantic_form_for(@new_post) do |f|
+ concat(f.input :created_at, :as => :time)
+ end
+ end
+
+ it 'should warn :datetime is deprecated' do
+ ::ActiveSupport::Deprecation.should_receive(:warn)
+ semantic_form_for(@new_post) do |f|
+ concat(f.input :created_at, :as => :datetime)
+ end
+ end
+
+ it 'should warn :date is deprecated' do
+ ::ActiveSupport::Deprecation.should_receive(:warn)
+ semantic_form_for(@new_post) do |f|
+ concat(f.input :created_at, :as => :date)
+ end
+ end
+
+ it 'should use wrapper css class based off :as, not off their parent class' do
+ with_deprecation_silenced do
+ concat(semantic_form_for(@new_post) do |f|
+ concat(f.input :created_at, :as => :time)
+ concat(f.input :created_at, :as => :datetime)
+ concat(f.input :created_at, :as => :date)
+ end)
+ end
+ output_buffer.should have_tag('li.time')
+ output_buffer.should have_tag('li.datetime')
+ output_buffer.should have_tag('li.date')
+ output_buffer.should_not have_tag('li.time_select')
+ output_buffer.should_not have_tag('li.datetime_select')
+ output_buffer.should_not have_tag('li.date_select')
+ end
+
+end
View
6 spec/inputs/include_blank_spec.rb
@@ -15,9 +15,9 @@
SELECT_INPUT_TYPES = {
:select => :author,
- :datetime => :publish_at,
- :date => :publish_at,
- :time => :publish_at
+ :datetime_select => :publish_at,
+ :date_select => :publish_at,
+ :time_select => :publish_at
}
SELECT_INPUT_TYPES.each do |as, attribute|
View
2 spec/inputs/label_spec.rb
@@ -98,7 +98,7 @@
it 'should return nil if label is false for timeish fragments' do
concat(semantic_form_for(@new_post) do |builder|
- builder.input(:title, :as => :time, :label => false)
+ builder.input(:title, :as => :time_select, :label => false)
end)
output_buffer.should_not have_tag('li.time > label')
output_buffer.should_not include("&gt;")
View
70 spec/inputs/time_input_spec.rb → spec/inputs/time_select_input_spec.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'spec_helper'
-describe 'time input' do
+describe 'time select input' do
include FormtasticSpecHelper
@@ -19,7 +19,7 @@
describe "with :ignore_date => true" do
before do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :time, :ignore_date => true))
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => true))
end)
end
@@ -40,7 +40,7 @@
before do
@new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :time, :ignore_date => false))
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
end)
end
@@ -59,7 +59,7 @@
end
it 'should associate the legend label with the hour select' do
- output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_4i"]')
+ output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
end
end
@@ -68,7 +68,7 @@
before do
@new_post.stub(:publish_at)
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :time, :ignore_date => false))
+ concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
end)
end
@@ -94,58 +94,58 @@
describe "without seconds" do
before do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :time))
+ concat(builder.input(:publish_at, :as => :time_select))
end)
end
- it_should_have_input_wrapper_with_class("time")
+ it_should_have_input_wrapper_with_class("time_select")
it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_publish_at_input")
it_should_have_a_nested_fieldset
it_should_have_a_nested_fieldset_with_class('fragments')
it_should_have_a_nested_ordered_list_with_class('fragments-group')
- it_should_apply_error_logic_for_input_type(:time)
+ it_should_apply_error_logic_for_input_type(:time_select)
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/)
+ output_buffer.should have_tag('form li.time_select 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_4i"]')
+ output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
end
it 'should have an ordered list of two items inside the fieldset' do
- output_buffer.should have_tag('form li.time fieldset ol.fragments-group')
- output_buffer.should have_tag('form li.time fieldset ol li.fragment', :count => 2)
+ output_buffer.should have_tag('form li.time_select fieldset ol.fragments-group')
+ output_buffer.should have_tag('form li.time_select fieldset ol li.fragment', :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)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 2)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
end
it 'should have two selects for hour and minute' do
- output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
+ output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 2)
end
end
describe "with seconds" do
before do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
+ concat(builder.input(:publish_at, :as => :time_select, :include_seconds => true))
end)
end
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)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 3)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
+ output_buffer.should have_tag('form li.time_select 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)
+ output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 3)
end
it 'should generate a sanitized label and matching ids for attribute' do
@@ -163,40 +163,40 @@
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
end)
- output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length)
fields.each do |f|
- output_buffer.should have_tag('form li.time fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
end
end
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
end)
- output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not render the label when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
end)
- output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
fields.each do |f|
- output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
end
end
it "should not render unsafe HTML when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
end)
output_buffer.should_not include("&gt;")
end
@@ -207,7 +207,7 @@
describe ':namespace option' do
before do
concat(semantic_form_for(@new_post, :namespace => 'form2') do |builder|
- concat(builder.input(:publish_at, :as => :time))
+ concat(builder.input(:publish_at, :as => :time_select))
end)
end
@@ -222,7 +222,7 @@
it "should add the required attribute to the input's html options" do
with_config :use_required_attribute, true do
concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => :time, :required => true))
+ concat(builder.input(:title, :as => :time_select, :required => true))
end)
output_buffer.should have_tag("select[@required]", :count => 2)
end
@@ -234,7 +234,7 @@
before do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.fields_for(:author, :index => 3) do |author|
- concat(author.input(:created_at, :as => :time))
+ concat(author.input(:created_at, :as => :time_select))
end)
end)
end

0 comments on commit e971195

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