aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-10-02 11:05:40 -0400
committerGitHub <noreply@github.com>2018-10-02 11:05:40 -0400
commitcf608ee34dd833b0357ef4eefa692db33242d2aa (patch)
tree7515c745a15dd29e2e50aca534f764044bece91c /activesupport/test
parent96e69b5a33f44e5339345ef3c4871aba51a1e938 (diff)
parentec9a89cb8be037cde2466a5347ea5c4ec648a4c3 (diff)
downloadrails-cf608ee34dd833b0357ef4eefa692db33242d2aa.tar.gz
rails-cf608ee34dd833b0357ef4eefa692db33242d2aa.tar.bz2
rails-cf608ee34dd833b0357ef4eefa692db33242d2aa.zip
Merge pull request #33058 from gmcgibbon/string_first_last_negative_deprecation
Add deprecation warning when String#first and String#last receive neg…
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index aa120a6f9a..2468fe3603 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -469,6 +469,15 @@ class StringAccessTest < ActiveSupport::TestCase
assert_not_same different_string, string
end
+ test "#first with negative Integer is deprecated" do
+ string = "hello"
+ message = "Calling String#first with a negative integer limit " \
+ "will raise an ArgumentError in Rails 6.1."
+ assert_deprecated(message) do
+ string.first(-1)
+ end
+ end
+
test "#last returns the last character" do
assert_equal "o", "hello".last
assert_equal "x", "x".last
@@ -487,6 +496,15 @@ class StringAccessTest < ActiveSupport::TestCase
assert_not_same different_string, string
end
+ test "#last with negative Integer is deprecated" do
+ string = "hello"
+ message = "Calling String#last with a negative integer limit " \
+ "will raise an ArgumentError in Rails 6.1."
+ assert_deprecated(message) do
+ string.last(-1)
+ end
+ end
+
test "access returns a real string" do
hash = {}
hash["h"] = true