Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8914

Show
Ignore:
Timestamp:
02/20/08 05:31:03 (9 months ago)
Author:
nzkoz
Message:

Move the eager load nested include tables into schema.rb and use delete_all instead of drop table to reset the state.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/test/cases/associations/eager_load_nested_include_test.rb

    r8908 r8914  
    11require 'cases/helper' 
     2 
     3 
     4class ShapeExpression < ActiveRecord::Base 
     5  belongs_to :shape, :polymorphic => true 
     6  belongs_to :paint, :polymorphic => true 
     7end 
     8 
     9class Circle < ActiveRecord::Base 
     10  has_many :shape_expressions, :as => :shape 
     11end 
     12class Square < ActiveRecord::Base 
     13  has_many :shape_expressions, :as => :shape 
     14end 
     15class Triangle < ActiveRecord::Base 
     16  has_many :shape_expressions, :as => :shape 
     17end 
     18class PaintColor  < ActiveRecord::Base 
     19  has_many   :shape_expressions, :as => :paint 
     20  belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne" 
     21end 
     22class PaintTexture < ActiveRecord::Base 
     23  has_many   :shape_expressions, :as => :paint 
     24  belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo" 
     25end 
     26class NonPolyOne < ActiveRecord::Base 
     27  has_many :paint_colors 
     28end 
     29class NonPolyTwo < ActiveRecord::Base 
     30  has_many :paint_textures 
     31end 
     32 
     33 
    234 
    335class EagerLoadPolyAssocsTest < ActiveRecord::TestCase 
     
    638 
    739  def setup 
    8     silence_stream(STDOUT) { create_test_tables } 
    940    generate_test_object_graphs 
    1041  end 
    11  
    12   def create_test_tables 
    13     conn = ActiveRecord::Base.connection 
    14  
    15     [:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t| 
    16       conn.create_table(t, :force => true) { } 
     42   
     43  def teardown 
     44    [Circle, Square, Triangle, PaintColor, PaintTexture,  
     45     ShapeExpression, NonPolyOne, NonPolyTwo].each do |c| 
     46      c.delete_all 
    1747    end 
    18  
    19     conn.create_table :shape_expressions, :force => true do |t| 
    20       t.string  :paint_type 
    21       t.integer :paint_id 
    22       t.string  :shape_type 
    23       t.integer :shape_id 
    24     end 
    25     conn.create_table :paint_colors, :force => true do |t| 
    26       t.integer :non_poly_one_id 
    27     end 
    28     conn.create_table :paint_textures, :force => true do |t| 
    29       t.integer :non_poly_two_id 
    30     end 
     48     
    3149  end 
    3250 
    33   def teardown 
    34     drop_tables 
    35   end 
    36  
    37   def drop_tables 
    38     conn = ActiveRecord::Base.connection 
    39     conn.reconnect! 
    40  
    41     silence_stream(STDOUT) do 
    42       [:circles, :squares, :triangles, :paint_colors, :paint_textures, 
    43        :shape_expressions, :non_poly_ones, :non_poly_twos].each do |t| 
    44         conn.drop_table t 
    45       end 
    46     end 
    47   end 
    4851 
    4952  # meant to be supplied as an ID, never returns 0 
     
    7982  end 
    8083end 
    81  
    82 class ShapeExpression < ActiveRecord::Base 
    83   belongs_to :shape, :polymorphic => true 
    84   belongs_to :paint, :polymorphic => true 
    85 end 
    86  
    87 class Circle < ActiveRecord::Base 
    88   has_many :shape_expressions, :as => :shape 
    89 end 
    90 class Square < ActiveRecord::Base 
    91   has_many :shape_expressions, :as => :shape 
    92 end 
    93 class Triangle < ActiveRecord::Base 
    94   has_many :shape_expressions, :as => :shape 
    95 end 
    96 class PaintColor  < ActiveRecord::Base 
    97   has_many   :shape_expressions, :as => :paint 
    98   belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne" 
    99 end 
    100 class PaintTexture < ActiveRecord::Base 
    101   has_many   :shape_expressions, :as => :paint 
    102   belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo" 
    103 end 
    104 class NonPolyOne < ActiveRecord::Base 
    105   has_many :paint_colors 
    106 end 
    107 class NonPolyTwo < ActiveRecord::Base 
    108   has_many :paint_textures 
    109 end 
  • trunk/activerecord/test/schema/schema.rb

    r8776 r8914  
    374374    t.integer :price 
    375375  end 
     376   
     377  [:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t| 
     378    create_table(t, :force => true) { } 
     379  end 
     380 
     381  create_table :shape_expressions, :force => true do |t| 
     382    t.string  :paint_type 
     383    t.integer :paint_id 
     384    t.string  :shape_type 
     385    t.integer :shape_id 
     386  end 
     387   
     388  create_table :paint_colors, :force => true do |t| 
     389    t.integer :non_poly_one_id 
     390  end 
     391  create_table :paint_textures, :force => true do |t| 
     392    t.integer :non_poly_two_id 
     393  end 
     394   
    376395end