Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method String#upcase_first #24377

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* Add `String#upcase_first` method.

*Glauco Custódio*
*Glauco Custódio*, *bogdanvlviv*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is also not needed. We don't add changelog entries for bug fixes in the features.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelfranca, https://github.com/rails/rails/blob/master/guides/source/contributing_to_ruby_on_rails.md#updating-the-changelog
"You should add an entry to the top of the CHANGELOG of the framework that you modified if you're adding or removing a feature, committing a bug fix or adding deprecation notices. Refactorings and documentation changes generally should not go to the CHANGELOG."
I have done fix bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bug fixes the features that was already released. In this case this feature was never released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not give a new notice in CHANGELOG because of method was never released, but a think i helped to create this method correctly. this method will be work correctly with my help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not how our CHANGELOG works, but I'll not discuss this case anymore.


* Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
which resolves to a different name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def humanize(options = {})

# Converts just the first character to uppercase.
#
# 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
# 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
# 'w'.upcase_first # => "W"
# ''.upcase_first # => ""
def upcase_first
ActiveSupport::Inflector.upcase_first(self)
end
Expand Down
6 changes: 4 additions & 2 deletions activesupport/lib/active_support/inflector/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ def humanize(lower_case_and_underscored_word, options = {})

# Converts just the first character to uppercase.
#
# 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
# upcase_first('what a Lovely Day') # => "What a Lovely Day"
# upcase_first('w') # => "W"
# upcase_first('') # => ""
def upcase_first(string)
string[0].upcase.concat(string[1..-1])
string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ''
end

# Capitalizes all the words and replaces some characters in the string to
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/core_ext/string_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def test_upcase_first
assert_equal "What a Lovely Day", "what a Lovely Day".upcase_first
end

def test_upcase_first_with_one_char
assert_equal "W", "w".upcase_first
end

def test_upcase_first_with_empty_string
assert_equal "", "".upcase_first
end

def test_camelize
CamelToUnderscore.each do |camel, underscore|
assert_equal(camel, underscore.camelize)
Expand Down