Skip to content
Browse files

Merge pull request #4608 from indrekj/translated_date_order

Raise exception when date.order includes invalid elements
  • Loading branch information...
2 parents 14e8ca6 + 88ec722 commit 2b74a13a4b4d6b8d21e58e49a33872baa95d3b4a @josevalim josevalim committed Jan 22, 2012
View
10 actionpack/lib/action_view/helpers/date_helper.rb
@@ -836,7 +836,15 @@ def date_order
end
def translated_date_order
- I18n.translate(:'date.order', :locale => @options[:locale]) || []
+ date_order = I18n.translate(:'date.order', :locale => @options[:locale]) || []
+
+ forbidden_elements = date_order - [:year, :month, :day]
+ if forbidden_elements.any?
+ raise StandardError,
+ "#{@options[:locale]}.date.order only accepts :year, :month and :day"
+ end
+
+ date_order
end
# Build full select tag from date type and options.
View
8 actionpack/test/template/date_helper_i18n_test.rb
@@ -118,4 +118,12 @@ def test_date_or_time_select_given_no_order_options_translates_order
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
datetime_select('post', 'updated_at', :locale => 'en')
end
+
+ def test_date_or_time_select_given_invalid_order
+ I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:invalid, :month, :day]
+
+ assert_raise StandardError do
+ datetime_select('post', 'updated_at', :locale => 'en')
+ end
+ end
end

0 comments on commit 2b74a13

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