| | 2 | |
|---|
| | 3 | |
|---|
| | 4 | class ShapeExpression < ActiveRecord::Base |
|---|
| | 5 | belongs_to :shape, :polymorphic => true |
|---|
| | 6 | belongs_to :paint, :polymorphic => true |
|---|
| | 7 | end |
|---|
| | 8 | |
|---|
| | 9 | class Circle < ActiveRecord::Base |
|---|
| | 10 | has_many :shape_expressions, :as => :shape |
|---|
| | 11 | end |
|---|
| | 12 | class Square < ActiveRecord::Base |
|---|
| | 13 | has_many :shape_expressions, :as => :shape |
|---|
| | 14 | end |
|---|
| | 15 | class Triangle < ActiveRecord::Base |
|---|
| | 16 | has_many :shape_expressions, :as => :shape |
|---|
| | 17 | end |
|---|
| | 18 | class PaintColor < ActiveRecord::Base |
|---|
| | 19 | has_many :shape_expressions, :as => :paint |
|---|
| | 20 | belongs_to :non_poly, :foreign_key => "non_poly_one_id", :class_name => "NonPolyOne" |
|---|
| | 21 | end |
|---|
| | 22 | class PaintTexture < ActiveRecord::Base |
|---|
| | 23 | has_many :shape_expressions, :as => :paint |
|---|
| | 24 | belongs_to :non_poly, :foreign_key => "non_poly_two_id", :class_name => "NonPolyTwo" |
|---|
| | 25 | end |
|---|
| | 26 | class NonPolyOne < ActiveRecord::Base |
|---|
| | 27 | has_many :paint_colors |
|---|
| | 28 | end |
|---|
| | 29 | class NonPolyTwo < ActiveRecord::Base |
|---|
| | 30 | has_many :paint_textures |
|---|
| | 31 | end |
|---|
| | 32 | |
|---|
| | 33 | |
|---|
| 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 |
|---|
| 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 |
|---|