diff options
author | Chris McGrath <chris@octopod.info> | 2013-01-17 15:21:26 +0000 |
---|---|---|
committer | Chris McGrath <chris@octopod.info> | 2013-01-17 15:21:26 +0000 |
commit | 6bb784eab0d286d1966c12e1bacc793113d6fbae (patch) | |
tree | 436d9680844b511a16c1ccef6f54671df8f050b3 /actionpack | |
parent | 038574a5385e07f1091e355b78558821e123a48c (diff) | |
download | rails-6bb784eab0d286d1966c12e1bacc793113d6fbae.tar.gz rails-6bb784eab0d286d1966c12e1bacc793113d6fbae.tar.bz2 rails-6bb784eab0d286d1966c12e1bacc793113d6fbae.zip |
Remove i18n symbol dependency
date.order is the only key in rails i18n that is required to be a
symbol. This patch allows for symbols or strings which means:
* No requirement for symbol type in .yml files. A future
YAML.safe_load wouldn't need to load symbols
* Rails could actually use json rather than yml as the backend
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 1 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_i18n_test.rb | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index cf978d8e83..3af9116135 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -880,6 +880,7 @@ module ActionView def translated_date_order date_order = I18n.translate(:'date.order', :locale => @options[:locale], :default => []) + date_order.map! { |element| element.to_sym } forbidden_elements = date_order - [:year, :month, :day] if forbidden_elements.any? diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index 495a9d3f9d..21fca35185 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -117,7 +117,7 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt end - I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day] + I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(year month day) datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true) end @@ -129,15 +129,20 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase end def test_date_or_time_select_given_no_order_options_translates_order - I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day] + I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(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', :default => []).returns [:invalid, :month, :day] + I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(invalid month day) assert_raise StandardError do datetime_select('post', 'updated_at', :locale => 'en') end end + + def test_date_or_time_select_given_symbol_keys + I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en') + end end |