aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-02-05 20:10:45 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-02-05 20:10:45 -0200
commit84fe7b7db64352c0186a9d2a51f4eb32d2825d2a (patch)
tree49ab417231c91102b3b878aaaf10285f1a465785 /activesupport/test
parent1df4dcf7dd9ec5cf8fed3c04d9427ad925f2b83b (diff)
parenta476020567a47f5fbec3629707d5bf31b400a284 (diff)
downloadrails-84fe7b7db64352c0186a9d2a51f4eb32d2825d2a.tar.gz
rails-84fe7b7db64352c0186a9d2a51f4eb32d2825d2a.tar.bz2
rails-84fe7b7db64352c0186a9d2a51f4eb32d2825d2a.zip
Merge pull request #13938 from marcandre/sized_enumerator
Sized enumerator
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb25
1 files changed, 4 insertions, 21 deletions
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index 6781e3c20e..6fcf6e8743 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -8,7 +8,6 @@ class SummablePayment < Payment
end
class EnumerableTests < ActiveSupport::TestCase
- Enumerator = [].each.class
class GenericEnumerable
include Enumerable
@@ -21,26 +20,6 @@ class EnumerableTests < ActiveSupport::TestCase
end
end
- def test_group_by
- names = %w(marcel sam david jeremy)
- klass = Struct.new(:name)
- objects = (1..50).map do
- klass.new names.sample
- end
-
- enum = GenericEnumerable.new(objects)
- grouped = enum.group_by { |object| object.name }
-
- grouped.each do |name, group|
- assert group.all? { |person| person.name == name }
- end
-
- assert_equal objects.uniq.map(&:name), grouped.keys
- assert({}.merge(grouped), "Could not convert ActiveSupport::OrderedHash into Hash")
- assert_equal Enumerator, enum.group_by.class
- assert_equal grouped, enum.group_by.each(&:name)
- end
-
def test_sums
enum = GenericEnumerable.new([5, 15, 10])
assert_equal 30, enum.sum
@@ -94,6 +73,10 @@ class EnumerableTests < ActiveSupport::TestCase
assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) },
payments.index_by { |p| p.price })
assert_equal Enumerator, payments.index_by.class
+ if Enumerator.method_defined? :size
+ assert_equal nil, payments.index_by.size
+ assert_equal 42, (1..42).index_by.size
+ end
assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) },
payments.index_by.each { |p| p.price })
end