Make sure Array#to_sentence always returns a String
This commit is contained in:
parent
4a0f314d8a
commit
a64f3e4195
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user