aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 23:28:52 +0100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 23:28:52 +0100
commit0361414ae328c10de8ed778e826d8244ba0aa63a (patch)
tree69dcc4b2c63c8e86d24e9ce84c14254e7c90e3ba /activesupport/test/core_ext
parenta74a655648618a6ed568b9b4ef3a17a8970e7774 (diff)
downloadrails-0361414ae328c10de8ed778e826d8244ba0aa63a.tar.gz
rails-0361414ae328c10de8ed778e826d8244ba0aa63a.tar.bz2
rails-0361414ae328c10de8ed778e826d8244ba0aa63a.zip
Add uniq_by and uniq_by! to Array.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb26
1 files changed, 23 insertions, 3 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index f5f91ddd80..6f3b28682a 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -51,9 +51,7 @@ class ArrayExtToParamTests < Test::Unit::TestCase
end
end
-class ArrayExtToSentenceTests < Test::Unit::TestCase
- include ActiveSupport::Testing::Deprecation
-
+class ArrayExtToSentenceTests < ActiveSupport::TestCase
def test_plain_array_to_sentence
assert_equal "", [].to_sentence
assert_equal "one", ['one'].to_sentence
@@ -320,6 +318,28 @@ class ArrayExtractOptionsTests < Test::Unit::TestCase
end
end
+class ArrayUniqByTests < Test::Unit::TestCase
+ def test_uniq_by
+ assert_equal [1,2], [1,2,3,4].uniq_by { |i| i.odd? }
+ assert_equal [1,2], [1,2,3,4].uniq_by(&:even?)
+ assert_equal (-5..0).to_a, (-5..5).to_a.uniq_by{ |i| i**2 }
+ end
+
+ def test_uniq_by!
+ a = [1,2,3,4]
+ a.uniq_by! { |i| i.odd? }
+ assert_equal [1,2], a
+
+ a = [1,2,3,4]
+ a.uniq_by! { |i| i.even? }
+ assert_equal [1,2], a
+
+ a = (-5..5).to_a
+ a.uniq_by! { |i| i**2 }
+ assert_equal (-5..0).to_a, a
+ end
+end
+
class ArrayExtRandomTests < Test::Unit::TestCase
def test_random_element_from_array
assert_nil [].rand