aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-23 14:59:55 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-23 14:59:55 -0300
commitfbdcba86cf0a174ddcc8b913db703c5e69d77f9f (patch)
treebdbe7310f423a5a11683fb078ca55a6e22b236dc /activesupport
parent02f3081332862e031bf99fa133bb5f79f9e59be0 (diff)
parent3920d64479c8763e1f0a64db872e5f072268cda9 (diff)
downloadrails-fbdcba86cf0a174ddcc8b913db703c5e69d77f9f.tar.gz
rails-fbdcba86cf0a174ddcc8b913db703c5e69d77f9f.tar.bz2
rails-fbdcba86cf0a174ddcc8b913db703c5e69d77f9f.zip
Merge pull request #15275 from kuldeepaggarwal/add-test
add test cases for negative position in Array#from
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb2
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb2
2 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb
index 67f58bc0fe..d0791a161f 100644
--- a/activesupport/lib/active_support/core_ext/array/access.rb
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -5,6 +5,8 @@ class Array
# %w( a b c d ).from(2) # => ["c", "d"]
# %w( a b c d ).from(10) # => []
# %w().from(0) # => []
+ # %w( a b c d ).from(-2) # => ["c", "d"]
+ # %w( a b c ).from(-10) # => []
def from(position)
self[position, length] || []
end
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index e0e54f47e4..4601a80d42 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -10,6 +10,8 @@ class ArrayExtAccessTests < ActiveSupport::TestCase
assert_equal %w( a b c d ), %w( a b c d ).from(0)
assert_equal %w( c d ), %w( a b c d ).from(2)
assert_equal %w(), %w( a b c d ).from(10)
+ assert_equal %w( d e ), %w( a b c d e ).from(-2)
+ assert_equal %w(), %w( a b c d e ).from(-10)
end
def test_to