diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-05 01:13:37 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-05 01:15:17 +0200 |
commit | 67a43554f153a3ddb97039b5fac305c0619dd372 (patch) | |
tree | defe65bc4dec8844525c93a348dfc9a97eacf237 /activerecord | |
parent | 6401ab587021b78c3dc5e4a5ac831823a9258481 (diff) | |
download | rails-67a43554f153a3ddb97039b5fac305c0619dd372.tar.gz rails-67a43554f153a3ddb97039b5fac305c0619dd372.tar.bz2 rails-67a43554f153a3ddb97039b5fac305c0619dd372.zip |
removes Array#random_element and backports Array#sample from Ruby 1.9, thanks to Marc-Andre Lafortune
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/associations/eager_load_nested_include_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 2 |
2 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb index 2beb3f8365..c7671a8c22 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -17,7 +17,7 @@ module Remembered module ClassMethods def remembered; @@remembered ||= []; end - def random_element; @@remembered.random_element; end + def sample; @@remembered.sample; end end end @@ -79,14 +79,14 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase [Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!) end 1.upto(NUM_SIMPLE_OBJS) do - PaintColor.create!(:non_poly_one_id => NonPolyOne.random_element.id) - PaintTexture.create!(:non_poly_two_id => NonPolyTwo.random_element.id) + PaintColor.create!(:non_poly_one_id => NonPolyOne.sample.id) + PaintTexture.create!(:non_poly_two_id => NonPolyTwo.sample.id) end 1.upto(NUM_SHAPE_EXPRESSIONS) do - shape_type = [Circle, Square, Triangle].random_element - paint_type = [PaintColor, PaintTexture].random_element - ShapeExpression.create!(:shape_type => shape_type.to_s, :shape_id => shape_type.random_element.id, - :paint_type => paint_type.to_s, :paint_id => paint_type.random_element.id) + shape_type = [Circle, Square, Triangle].sample + paint_type = [PaintColor, PaintTexture].sample + ShapeExpression.create!(:shape_type => shape_type.to_s, :shape_id => shape_type.sample.id, + :paint_type => paint_type.to_s, :paint_id => paint_type.sample.id) end end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 91d8d2828b..33ffb041c1 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -301,7 +301,7 @@ class NamedScopeTest < ActiveRecord::TestCase end def test_rand_should_select_a_random_object_from_proxy - assert_kind_of Topic, Topic.approved.random_element + assert_kind_of Topic, Topic.approved.sample end def test_should_use_where_in_query_for_named_scope |