From 67a43554f153a3ddb97039b5fac305c0619dd372 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Jun 2010 01:13:37 +0200 Subject: removes Array#random_element and backports Array#sample from Ruby 1.9, thanks to Marc-Andre Lafortune --- .../cases/associations/eager_load_nested_include_test.rb | 14 +++++++------- activerecord/test/cases/named_scope_test.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'activerecord/test/cases') 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 -- cgit v1.2.3