diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-26 12:54:22 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-26 22:05:56 -0300 |
commit | 60571b853920707c1103c5f9659e7b690d8eae73 (patch) | |
tree | d2054a5a54c058a0217ad569076832382c9fe8a7 /activesupport/test | |
parent | 5847f59b2506d40e45edc2db671b897b9bffe640 (diff) | |
download | rails-60571b853920707c1103c5f9659e7b690d8eae73.tar.gz rails-60571b853920707c1103c5f9659e7b690d8eae73.tar.bz2 rails-60571b853920707c1103c5f9659e7b690d8eae73.zip |
Ensure Array#to_sentence does not modify given hash
Also simplify I18n logic for Array#to_sentence, doing only one lookup
for all keys and using merge!, instead of one lookup for each option key.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/i18n_test.rb | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 58835c0ac5..9dfa2cbf11 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -90,6 +90,12 @@ class ArrayExtToSentenceTests < ActiveSupport::TestCase def test_one_non_string_element assert_equal '1', [1].to_sentence end + + def test_does_not_modify_given_hash + options = { words_connector: ' ' } + assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(options) + assert_equal({ words_connector: ' ' }, options) + end end class ArrayExtToSTests < ActiveSupport::TestCase diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 4f2027f4eb..ddbba444cf 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -97,4 +97,9 @@ class I18nTest < ActiveSupport::TestCase I18n.backend.store_translations 'en', :support => { :array => { :two_words_connector => default_two_words_connector } } I18n.backend.store_translations 'en', :support => { :array => { :last_word_connector => default_last_word_connector } } end + + def test_to_sentence_with_empty_i18n_store + I18n.backend.store_translations 'empty', {} + assert_equal 'a, b, and c', %w[a b c].to_sentence(locale: 'empty') + end end |