Permalink
Browse files

date_or_datetime_input should allow :order as an option or try to ret…

…rieve it from I18n.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
1 parent a4e046b commit eea9d98939cbb19dde36efabb2cef3061a7e5cb7 @josevalim josevalim committed with justinfrench Mar 6, 2009
Showing with 33 additions and 3 deletions.
  1. +3 −3 lib/formtastic.rb
  2. +30 −0 spec/formtastic_spec.rb
View
@@ -567,11 +567,11 @@ def time_input(method, options)
# </ol>
# </fieldset>
#
- # This is an absolute abomination, but so is the official Rails select_date(). Mainly
- # missing the ability to re-order the inputs, but maybe that's fine!
+ # This is an absolute abomination, but so is the official Rails select_date().
+ #
def date_or_datetime_input(method, options)
position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
- inputs = [:year, :month, :day]
+ inputs = options.delete(:order) || I18n.translate(:'date.order') || [:year, :month, :day]
time_inputs = [:hour, :minute]
time_inputs << [:second] if options[:include_seconds]
View
@@ -1686,6 +1686,36 @@ def custom(arg1, arg2, options = {})
end
end
+ describe 'inputs order' do
+ it 'should have a default' do
+ semantic_form_for(@new_post) do |builder|
+ self.should_receive(:select_year).once.ordered.and_return('')
+ self.should_receive(:select_month).once.ordered.and_return('')
+ self.should_receive(:select_day).once.ordered.and_return('')
+ builder.input(:publish_at, :as => :datetime)
+ end
+ end
+
+ it 'should be specified with :order option' do
+ I18n.backend.store_translations 'en', :date => { :order => [:month, :year, :day] }
+ semantic_form_for(@new_post) do |builder|
+ self.should_receive(:select_month).once.ordered.and_return('')
+ self.should_receive(:select_year).once.ordered.and_return('')
+ self.should_receive(:select_day).once.ordered.and_return('')
+ builder.input(:publish_at, :as => :datetime)
+ end
+ end
+
+ it 'should be changed through I18n' do
+ semantic_form_for(@new_post) do |builder|
+ self.should_receive(:select_day).once.ordered.and_return('')
+ self.should_receive(:select_month).once.ordered.and_return('')
+ self.should_receive(:select_year).once.ordered.and_return('')
+ builder.input(:publish_at, :as => :datetime, :order => [:day, :month, :year])
+ end
+ end
+ end
+
describe 'when the locale changes the label text' do
before do
I18n.backend.store_translations 'en', :formtastic => {

0 comments on commit eea9d98

Please sign in to comment.