0
+ def self.included(base)
0
+ base.extend ClassMethods
0
+ after_create :remember
0
+ def remember; self.class.remembered << self; end
0
+ def remembered; @@remembered ||= []; end
0
+ def rand; @@remembered.rand; end
0
class ShapeExpression < ActiveRecord::Base
0
belongs_to :shape, :polymorphic => true
0
class Circle < ActiveRecord::Base
0
has_many :shape_expressions, :as => :shape
0
class Square < ActiveRecord::Base
0
has_many :shape_expressions, :as => :shape
0
class Triangle < ActiveRecord::Base
0
has_many :shape_expressions, :as => :shape
0
class PaintColor < ActiveRecord::Base
0
has_many :shape_expressions, :as => :paint
0
belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne"
0
class PaintTexture < ActiveRecord::Base
0
has_many :shape_expressions, :as => :paint
0
belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo"
0
class NonPolyOne < ActiveRecord::Base
0
class NonPolyTwo < ActiveRecord::Base
0
has_many :paint_textures
0
@@ -49,23 +71,19 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
0
- # meant to be supplied as an ID, never returns 0
0
- val = (NUM_SIMPLE_OBJS * rand).round
0
def generate_test_object_graphs
0
1.upto(NUM_SIMPLE_OBJS) do
0
[Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!)
0
- 1.upto(NUM_SIMPLE_OBJS) do |i|
0
- PaintColor.create!(:non_poly_one_id => rand_simple)
0
- PaintTexture.create!(:non_poly_two_id => rand_simple)
0
+ 1.upto(NUM_SIMPLE_OBJS) do
0
+ PaintColor.create!(:non_poly_one_id => NonPolyOne.rand.id)
0
+ PaintTexture.create!(:non_poly_two_id => NonPolyTwo.rand.id)
0
- 1.upto(NUM_SHAPE_EXPRESSIONS) do |i|
0
- ShapeExpression.create!(:shape_type => [Circle, Square, Triangle].rand.to_s, :shape_id => rand_simple,
0
- :paint_type => [PaintColor, PaintTexture].rand.to_s, :paint_id => rand_simple)
0
+ 1.upto(NUM_SHAPE_EXPRESSIONS) do
0
+ shape_type = [Circle, Square, Triangle].rand
0
+ paint_type = [PaintColor, PaintTexture].rand
0
+ ShapeExpression.create!(:shape_type => shape_type.to_s, :shape_id => shape_type.rand.id,
0
+ :paint_type => paint_type.to_s, :paint_id => paint_type.rand.id)