aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-02-20 05:31:03 +0000
committerMichael Koziarski <michael@koziarski.com>2008-02-20 05:31:03 +0000
commit44c169397a4241b924413de85eeee53b2a0216aa (patch)
tree28f27a86a3f042304c9c7ae3494e5530324d8115 /activerecord
parent63173630db5ccf25695d8b1eae7fbc0b669b19e5 (diff)
downloadrails-44c169397a4241b924413de85eeee53b2a0216aa.tar.gz
rails-44c169397a4241b924413de85eeee53b2a0216aa.tar.bz2
rails-44c169397a4241b924413de85eeee53b2a0216aa.zip
Move the eager load nested include tables into schema.rb and use delete_all instead of drop table to reset the state.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8914 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/eager_load_nested_include_test.rb102
-rw-r--r--activerecord/test/schema/schema.rb19
2 files changed, 57 insertions, 64 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 ac3f997fa5..80cfc84b32 100644
--- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb
+++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -1,51 +1,54 @@
require 'cases/helper'
+
+class ShapeExpression < ActiveRecord::Base
+ belongs_to :shape, :polymorphic => true
+ belongs_to :paint, :polymorphic => true
+end
+
+class Circle < ActiveRecord::Base
+ has_many :shape_expressions, :as => :shape
+end
+class Square < ActiveRecord::Base
+ has_many :shape_expressions, :as => :shape
+end
+class Triangle < ActiveRecord::Base
+ has_many :shape_expressions, :as => :shape
+end
+class PaintColor < ActiveRecord::Base
+ has_many :shape_expressions, :as => :paint
+ belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne"
+end
+class PaintTexture < ActiveRecord::Base
+ has_many :shape_expressions, :as => :paint
+ belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo"
+end
+class NonPolyOne < ActiveRecord::Base
+ has_many :paint_colors
+end
+class NonPolyTwo < ActiveRecord::Base
+ has_many :paint_textures
+end
+
+
+
class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
NUM_SIMPLE_OBJS = 50
NUM_SHAPE_EXPRESSIONS = 100
def setup
- silence_stream(STDOUT) { create_test_tables }
generate_test_object_graphs
end
-
- def create_test_tables
- conn = ActiveRecord::Base.connection
-
- [:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t|
- conn.create_table(t, :force => true) { }
- end
-
- conn.create_table :shape_expressions, :force => true do |t|
- t.string :paint_type
- t.integer :paint_id
- t.string :shape_type
- t.integer :shape_id
- end
- conn.create_table :paint_colors, :force => true do |t|
- t.integer :non_poly_one_id
- end
- conn.create_table :paint_textures, :force => true do |t|
- t.integer :non_poly_two_id
- end
- end
-
+
def teardown
- drop_tables
- end
-
- def drop_tables
- conn = ActiveRecord::Base.connection
- conn.reconnect!
-
- silence_stream(STDOUT) do
- [:circles, :squares, :triangles, :paint_colors, :paint_textures,
- :shape_expressions, :non_poly_ones, :non_poly_twos].each do |t|
- conn.drop_table t
- end
+ [Circle, Square, Triangle, PaintColor, PaintTexture,
+ ShapeExpression, NonPolyOne, NonPolyTwo].each do |c|
+ c.delete_all
end
+
end
+
# meant to be supplied as an ID, never returns 0
def rand_simple
val = (NUM_SIMPLE_OBJS * rand).round
@@ -78,32 +81,3 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
end
end
end
-
-class ShapeExpression < ActiveRecord::Base
- belongs_to :shape, :polymorphic => true
- belongs_to :paint, :polymorphic => true
-end
-
-class Circle < ActiveRecord::Base
- has_many :shape_expressions, :as => :shape
-end
-class Square < ActiveRecord::Base
- has_many :shape_expressions, :as => :shape
-end
-class Triangle < ActiveRecord::Base
- has_many :shape_expressions, :as => :shape
-end
-class PaintColor < ActiveRecord::Base
- has_many :shape_expressions, :as => :paint
- belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne"
-end
-class PaintTexture < ActiveRecord::Base
- has_many :shape_expressions, :as => :paint
- belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo"
-end
-class NonPolyOne < ActiveRecord::Base
- has_many :paint_colors
-end
-class NonPolyTwo < ActiveRecord::Base
- has_many :paint_textures
-end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 951217b198..45da902088 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -373,4 +373,23 @@ ActiveRecord::Schema.define do
t.integer :estimate_of_id
t.integer :price
end
+
+ [:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t|
+ create_table(t, :force => true) { }
+ end
+
+ create_table :shape_expressions, :force => true do |t|
+ t.string :paint_type
+ t.integer :paint_id
+ t.string :shape_type
+ t.integer :shape_id
+ end
+
+ create_table :paint_colors, :force => true do |t|
+ t.integer :non_poly_one_id
+ end
+ create_table :paint_textures, :force => true do |t|
+ t.integer :non_poly_two_id
+ end
+
end