1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Revert "Merge pull request #25811 from oss92/to_sentence_fallback_string"

This reverts commit bad3a120f1, reversing
changes made to 2384317465.

Reason: Adding a new option in the API for something that can be done
with a `#presence` check could do.
This commit is contained in:
Rafael Mendonça França 2016-11-14 13:16:00 -05:00
parent 5f32221559
commit 7c1566b278
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 3 additions and 20 deletions

View file

@ -145,12 +145,6 @@
*Genadi Samokovarov*
* Add `:fallback_string` option to `Array#to_sentence`. If an empty array
calls the function and a fallback string option is set then it returns the
fallback string other than an empty string.
*Mohamed Osama*
* Fix `ActiveSupport::TimeZone#strptime`. Now raises `ArgumentError` when the
given time doesn't match the format. The error is the same as the one given
by Ruby's `Date.strptime`. Previously it raised

View file

@ -40,12 +40,6 @@ class Array
# ['one', 'two', 'three'].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ')
# # => "one or two or at least three"
#
# [].to_sentence(fallback_string: 'none')
# # => "none"
#
# ['one', 'two'].to_sentence(fallback_string: 'none')
# # => "one and two"
#
# Using <tt>:locale</tt> option:
#
# # Given this locale dictionary:
@ -63,7 +57,7 @@ class Array
# ['uno', 'dos', 'tres'].to_sentence(locale: :es)
# # => "uno o dos o al menos tres"
def to_sentence(options = {})
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale, :fallback_string)
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
default_connectors = {
words_connector: ", ",
@ -78,7 +72,7 @@ class Array
case length
when 0
"#{options[:fallback_string] || ''}"
""
when 1
"#{self[0]}"
when 2

View file

@ -25,11 +25,6 @@ class ToSentenceTest < ActiveSupport::TestCase
assert_equal "one, two and three", ["one", "two", "three"].to_sentence(last_word_connector: " and ")
end
def test_to_sentence_with_fallback_string
assert_equal "none", [].to_sentence(fallback_string: "none")
assert_equal "one, two, and three", ["one", "two", "three"].to_sentence(fallback_string: "none")
end
def test_two_elements
assert_equal "one and two", ["one", "two"].to_sentence
assert_equal "one two", ["one", "two"].to_sentence(two_words_connector: " ")
@ -63,7 +58,7 @@ class ToSentenceTest < ActiveSupport::TestCase
["one", "two"].to_sentence(passing: "invalid option")
end
assert_equal exception.message, "Unknown key: :passing. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale, :fallback_string"
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