From 22edb664cf081485e4e37bf5a797890648126a79 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Fri, 16 Nov 2012 03:20:55 -0500 Subject: [PATCH] Use Integer#div instead of Integer#/ to avoid side effects from mathn --- .../lib/active_support/core_ext/array/grouping.rb | 2 +- activesupport/test/core_ext/array_ext_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index f79b100b3b..97a25cd2e6 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -58,7 +58,7 @@ class Array # size / number gives minor group size; # size % number gives how many objects need extra accommodation; # each group hold either division or division + 1 items. - division = size / number + division = size.div number modulo = size % number # create a new array avoiding dup diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 9dfa2cbf11..efa7582ab0 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -112,6 +112,14 @@ class ArrayExtToSTests < ActiveSupport::TestCase end class ArrayExtGroupingTests < ActiveSupport::TestCase + def setup + Fixnum.send :private, :/ # test we avoid Integer#/ (redefined by mathn) + end + + def teardown + Fixnum.send :public, :/ + end + def test_in_groups_of_with_perfect_fit groups = [] ('a'..'i').to_a.in_groups_of(3) do |group|