Skip to content

Commit

Permalink
Undeprecate plural positional argument
Browse files Browse the repository at this point in the history
```ruby
pluralize people.count, 'person', 'people'
```
reads more naturally than
```ruby
pluralize people.count, 'person', plural: 'people'
```
so let's not deprecate it.

We could label both, but that's a mouthful:
```ruby
pluralize people.count, singular: 'person', plural: 'people'
```

(The `plural:` kwarg shipped in 5.0.0, so we're keeping it.)
  • Loading branch information
jeremy committed Sep 22, 2016
1 parent 1996624 commit 12d06dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
9 changes: 1 addition & 8 deletions actionview/lib/action_view/helpers/text_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,7 @@ def excerpt(text, phrase, options = {})
#
# pluralize(2, 'Person', locale: :de)
# # => 2 Personen
def pluralize(count, singular, deprecated_plural = nil, plural: nil, locale: I18n.locale)
if deprecated_plural
ActiveSupport::Deprecation.warn("Passing plural as a positional argument " \
"is deprecated and will be removed in Rails 5.1. Use e.g. " \
"pluralize(1, 'person', plural: 'people') instead.")
plural ||= deprecated_plural
end

def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
word = if (count == 1 || count =~ /^1(\.0+)?$/)
singular
else
Expand Down
8 changes: 2 additions & 6 deletions actionview/test/template/text_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ def test_pluralization
assert_equal("1.25 counts", pluralize("1.25", "count"))
assert_equal("1.0 count", pluralize("1.0", "count"))
assert_equal("1.00 count", pluralize("1.00", "count"))
assert_equal("2 counters", pluralize(2, "count", "counters"))
assert_equal("0 counters", pluralize(nil, "count", "counters"))
assert_equal("2 counters", pluralize(2, "count", plural: "counters"))
assert_equal("0 counters", pluralize(nil, "count", plural: "counters"))
assert_equal("2 people", pluralize(2, "person"))
Expand All @@ -405,12 +407,6 @@ def test_localized_pluralization
end
end

def test_deprecated_plural_as_positional_argument
assert_deprecated do
pluralize(2, "count", "counters")
end
end

def test_cycle_class
value = Cycle.new("one", 2, "3")
assert_equal("one", value.to_s)
Expand Down

0 comments on commit 12d06dd

Please sign in to comment.