class EagerLoadPolyAssocsTest

Constants

NUM_SHAPE_EXPRESSIONS
NUM_SIMPLE_OBJS

Public Instance Methods

generate_test_object_graphs() click to toggle source
# File activerecord/test/cases/associations/eager_load_nested_include_test.rb, line 76
def generate_test_object_graphs
  1.upto(NUM_SIMPLE_OBJS) do
    [Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!)
  end
  1.upto(NUM_SIMPLE_OBJS) do
    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].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
setup() click to toggle source
# File activerecord/test/cases/associations/eager_load_nested_include_test.rb, line 67
def setup
  generate_test_object_graphs
end
test_include_query() click to toggle source
# File activerecord/test/cases/associations/eager_load_nested_include_test.rb, line 92
def test_include_query
  res = ShapeExpression.all.merge!(includes: [ :shape, { paint: :non_poly } ]).to_a
  assert_equal NUM_SHAPE_EXPRESSIONS, res.size
  assert_queries(0) do
    res.each do |se|
      assert_not_nil se.paint.non_poly, "this is the association that was loading incorrectly before the change"
      assert_not_nil se.shape, "just making sure other associations still work"
    end
  end
end