1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Raise exception when date.order includes invalid elements

This commit is contained in:
Indrek Juhkam 2012-01-22 23:47:36 +02:00
parent 4e6050b961
commit 88ec722a0f
2 changed files with 17 additions and 1 deletions

View file

@ -836,7 +836,15 @@ module ActionView
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 file

@ -118,4 +118,12 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase
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