Make sure Array#to_sentence always returns a String

This commit is contained in:
David Cornu 2015-03-23 14:43:18 -04:00
parent 4a0f314d8a
commit a64f3e4195
2 changed files with 7 additions and 1 deletions

@ -74,7 +74,7 @@ def to_sentence(options = {})
when 0
''
when 1
self[0].to_s.dup
"#{self[0]}"
when 2
"#{self[0]}#{options[:two_words_connector]}#{self[1]}"
else

@ -60,6 +60,12 @@ def test_with_invalid_options
assert_equal exception.message, "Unknown key: :passing. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale"
end
def test_always_returns_string
assert_instance_of String, [ActiveSupport::SafeBuffer.new('one')].to_sentence
assert_instance_of String, [ActiveSupport::SafeBuffer.new('one'), 'two'].to_sentence
assert_instance_of String, [ActiveSupport::SafeBuffer.new('one'), 'two', 'three'].to_sentence
end
end
class ToSTest < ActiveSupport::TestCase