提交 a64f3e41 编写于 作者: D David Cornu

Make sure Array#to_sentence always returns a String

上级 4a0f314d
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册