ensured_schema 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile.lock +23 -0
  3. data/Rakefile +19 -0
  4. data/ensured_schema.gemspec +4 -0
  5. data/lib/ensured_schema/column.rb +9 -0
  6. data/lib/ensured_schema/ensured_table.rb +53 -0
  7. data/lib/ensured_schema/mysql_column.rb +17 -0
  8. data/lib/ensured_schema/schema.rb +7 -0
  9. data/lib/ensured_schema/schema_statements.rb +69 -0
  10. data/lib/ensured_schema/version.rb +1 -1
  11. data/lib/ensured_schema.rb +5 -155
  12. data/test/cases/ensured_schema_test.rb +206 -0
  13. data/test/cases/helper.rb +70 -0
  14. data/test/cases/migration_test.rb +1523 -0
  15. data/test/cases/repair_helper.rb +50 -0
  16. data/test/config.rb +5 -0
  17. data/test/connections/native_mysql/connection.rb +25 -0
  18. data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
  19. data/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
  20. data/test/migrations/duplicate/1_people_have_last_names.rb +9 -0
  21. data/test/migrations/duplicate/2_we_need_reminders.rb +12 -0
  22. data/test/migrations/duplicate/3_foo.rb +7 -0
  23. data/test/migrations/duplicate/3_innocent_jointable.rb +12 -0
  24. data/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
  25. data/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
  26. data/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +12 -0
  27. data/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +9 -0
  28. data/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +12 -0
  29. data/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +9 -0
  30. data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
  31. data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
  32. data/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
  33. data/test/migrations/missing/1_people_have_last_names.rb +9 -0
  34. data/test/migrations/missing/3_we_need_reminders.rb +12 -0
  35. data/test/migrations/missing/4_innocent_jointable.rb +12 -0
  36. data/test/migrations/valid/1_people_have_last_names.rb +9 -0
  37. data/test/migrations/valid/2_we_need_reminders.rb +12 -0
  38. data/test/migrations/valid/3_innocent_jointable.rb +12 -0
  39. data/test/models/author.rb +146 -0
  40. data/test/models/auto_id.rb +4 -0
  41. data/test/models/binary.rb +2 -0
  42. data/test/models/bird.rb +3 -0
  43. data/test/models/book.rb +4 -0
  44. data/test/models/categorization.rb +5 -0
  45. data/test/models/category.rb +34 -0
  46. data/test/models/citation.rb +6 -0
  47. data/test/models/club.rb +13 -0
  48. data/test/models/column_name.rb +3 -0
  49. data/test/models/comment.rb +29 -0
  50. data/test/models/company.rb +171 -0
  51. data/test/models/company_in_module.rb +61 -0
  52. data/test/models/computer.rb +3 -0
  53. data/test/models/contact.rb +16 -0
  54. data/test/models/contract.rb +5 -0
  55. data/test/models/course.rb +3 -0
  56. data/test/models/customer.rb +73 -0
  57. data/test/models/default.rb +2 -0
  58. data/test/models/developer.rb +101 -0
  59. data/test/models/edge.rb +5 -0
  60. data/test/models/entrant.rb +3 -0
  61. data/test/models/essay.rb +3 -0
  62. data/test/models/event.rb +3 -0
  63. data/test/models/guid.rb +2 -0
  64. data/test/models/item.rb +7 -0
  65. data/test/models/job.rb +5 -0
  66. data/test/models/joke.rb +3 -0
  67. data/test/models/keyboard.rb +3 -0
  68. data/test/models/legacy_thing.rb +3 -0
  69. data/test/models/matey.rb +4 -0
  70. data/test/models/member.rb +12 -0
  71. data/test/models/member_detail.rb +5 -0
  72. data/test/models/member_type.rb +3 -0
  73. data/test/models/membership.rb +9 -0
  74. data/test/models/minimalistic.rb +2 -0
  75. data/test/models/mixed_case_monkey.rb +3 -0
  76. data/test/models/movie.rb +5 -0
  77. data/test/models/order.rb +4 -0
  78. data/test/models/organization.rb +6 -0
  79. data/test/models/owner.rb +5 -0
  80. data/test/models/parrot.rb +16 -0
  81. data/test/models/person.rb +16 -0
  82. data/test/models/pet.rb +5 -0
  83. data/test/models/pirate.rb +70 -0
  84. data/test/models/post.rb +100 -0
  85. data/test/models/price_estimate.rb +3 -0
  86. data/test/models/project.rb +30 -0
  87. data/test/models/reader.rb +4 -0
  88. data/test/models/reference.rb +4 -0
  89. data/test/models/reply.rb +46 -0
  90. data/test/models/ship.rb +10 -0
  91. data/test/models/ship_part.rb +5 -0
  92. data/test/models/sponsor.rb +4 -0
  93. data/test/models/subject.rb +4 -0
  94. data/test/models/subscriber.rb +8 -0
  95. data/test/models/subscription.rb +4 -0
  96. data/test/models/tag.rb +7 -0
  97. data/test/models/tagging.rb +10 -0
  98. data/test/models/task.rb +3 -0
  99. data/test/models/topic.rb +80 -0
  100. data/test/models/toy.rb +6 -0
  101. data/test/models/treasure.rb +8 -0
  102. data/test/models/vertex.rb +9 -0
  103. data/test/models/warehouse_thing.rb +5 -0
  104. data/test/schema/mysql_specific_schema.rb +24 -0
  105. data/test/schema/postgresql_specific_schema.rb +114 -0
  106. data/test/schema/schema.rb +493 -0
  107. data/test/schema/schema2.rb +6 -0
  108. data/test/schema/sqlite_specific_schema.rb +25 -0
  109. metadata +237 -7
@@ -0,0 +1,50 @@
1
+ module ActiveRecord
2
+ module Testing
3
+ module RepairHelper
4
+ def self.included(base)
5
+ base.class_eval do
6
+ extend ClassMethods
7
+ end
8
+ end
9
+
10
+ module Toolbox
11
+ def self.record_validations(*model_classes)
12
+ model_classes.inject({}) do |repair, klass|
13
+ repair[klass] ||= {}
14
+ [:validate, :validate_on_create, :validate_on_update].each do |callback|
15
+ the_callback = klass.instance_variable_get("@#{callback.to_s}_callbacks")
16
+ repair[klass][callback] = (the_callback.nil? ? nil : the_callback.dup)
17
+ end
18
+ repair
19
+ end
20
+ end
21
+
22
+ def self.reset_validations(recorded)
23
+ recorded.each do |klass, repairs|
24
+ [:validate, :validate_on_create, :validate_on_update].each do |callback|
25
+ klass.instance_variable_set("@#{callback.to_s}_callbacks", repairs[callback])
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module ClassMethods
32
+ def repair_validations(*model_classes)
33
+ setup do
34
+ @validation_repairs = ActiveRecord::Testing::RepairHelper::Toolbox.record_validations(*model_classes)
35
+ end
36
+ teardown do
37
+ ActiveRecord::Testing::RepairHelper::Toolbox.reset_validations(@validation_repairs)
38
+ end
39
+ end
40
+ end
41
+
42
+ def repair_validations(*model_classes, &block)
43
+ validation_repairs = ActiveRecord::Testing::RepairHelper::Toolbox.record_validations(*model_classes)
44
+ return block.call
45
+ ensure
46
+ ActiveRecord::Testing::RepairHelper::Toolbox.reset_validations(validation_repairs)
47
+ end
48
+ end
49
+ end
50
+ end
data/test/config.rb ADDED
@@ -0,0 +1,5 @@
1
+ TEST_ROOT = File.expand_path(File.dirname(__FILE__))
2
+ ASSETS_ROOT = TEST_ROOT + "/assets"
3
+ FIXTURES_ROOT = TEST_ROOT + "/fixtures"
4
+ MIGRATIONS_ROOT = TEST_ROOT + "/migrations"
5
+ SCHEMA_ROOT = TEST_ROOT + "/schema"
@@ -0,0 +1,25 @@
1
+ print "Using native MySQL\n"
2
+ require_dependency 'models/course'
3
+ require 'logger'
4
+
5
+ ActiveRecord::Base.logger = Logger.new("debug.log")
6
+
7
+ # GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
8
+ # GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
9
+
10
+ ActiveRecord::Base.configurations = {
11
+ 'arunit' => {
12
+ :adapter => 'mysql',
13
+ :username => 'rails',
14
+ :encoding => 'utf8',
15
+ :database => 'activerecord_unittest',
16
+ },
17
+ 'arunit2' => {
18
+ :adapter => 'mysql',
19
+ :username => 'rails',
20
+ :database => 'activerecord_unittest2'
21
+ }
22
+ }
23
+
24
+ ActiveRecord::Base.establish_connection 'arunit'
25
+ Course.establish_connection 'arunit2'
@@ -0,0 +1,10 @@
1
+ class MigrationThatRaisesException < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ raise 'Something broke'
5
+ end
6
+
7
+ def self.down
8
+ remove_column "people", "last_name"
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ class GiveMeBigNumbers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :big_numbers do |table|
4
+ table.column :bank_balance, :decimal, :precision => 10, :scale => 2
5
+ table.column :big_bank_balance, :decimal, :precision => 15, :scale => 2
6
+ table.column :world_population, :decimal, :precision => 10
7
+ table.column :my_house_population, :decimal, :precision => 2
8
+ table.column :value_of_e, :decimal
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :big_numbers
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveLastNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "last_name"
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class WeNeedReminders < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("reminders") do |t|
4
+ t.column :content, :text
5
+ t.column :remind_at, :datetime
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "reminders"
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class Foo < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class Chunky < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Chunky < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveLastNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "last_name"
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveLastNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "last_name"
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class IRaiseOnDown < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ raise
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveMiddleNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "middle_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "middle_name"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveLastNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "last_name"
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class WeNeedReminders < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("reminders") do |t|
4
+ t.column :content, :text
5
+ t.column :remind_at, :datetime
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "reminders"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class PeopleHaveLastNames < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column "people", "last_name"
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class WeNeedReminders < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("reminders") do |t|
4
+ t.column :content, :text
5
+ t.column :remind_at, :datetime
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "reminders"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class InnocentJointable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table("people_reminders", :id => false) do |t|
4
+ t.column :reminder_id, :integer
5
+ t.column :person_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "people_reminders"
11
+ end
12
+ end
@@ -0,0 +1,146 @@
1
+ class Author < ActiveRecord::Base
2
+ has_many :posts
3
+ has_many :very_special_comments, :through => :posts
4
+ has_many :posts_with_comments, :include => :comments, :class_name => "Post"
5
+ has_many :popular_grouped_posts, :include => :comments, :class_name => "Post", :group => "type", :having => "SUM(comments_count) > 1", :select => "type"
6
+ has_many :posts_with_comments_sorted_by_comment_id, :include => :comments, :class_name => "Post", :order => 'comments.id'
7
+ has_many :posts_sorted_by_id_limited, :class_name => "Post", :order => 'posts.id', :limit => 1
8
+ has_many :posts_with_categories, :include => :categories, :class_name => "Post"
9
+ has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
10
+ has_many :posts_containing_the_letter_a, :class_name => "Post"
11
+ has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
12
+ def testing_proxy_owner
13
+ proxy_owner
14
+ end
15
+ def testing_proxy_reflection
16
+ proxy_reflection
17
+ end
18
+ def testing_proxy_target
19
+ proxy_target
20
+ end
21
+ end
22
+ has_one :post_about_thinking, :class_name => 'Post', :conditions => "posts.title like '%thinking%'"
23
+ has_one :post_about_thinking_with_last_comment, :class_name => 'Post', :conditions => "posts.title like '%thinking%'", :include => :last_comment
24
+ has_many :comments, :through => :posts
25
+ has_many :comments_containing_the_letter_e, :through => :posts, :source => :comments
26
+ has_many :comments_with_order_and_conditions, :through => :posts, :source => :comments, :order => 'comments.body', :conditions => "comments.body like 'Thank%'"
27
+ has_many :comments_with_include, :through => :posts, :source => :comments, :include => :post
28
+
29
+ has_many :thinking_posts, :class_name => 'Post', :conditions => { :title => 'So I was thinking' }, :dependent => :delete_all
30
+ has_many :welcome_posts, :class_name => 'Post', :conditions => { :title => 'Welcome to the weblog' }
31
+
32
+ has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
33
+ has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
34
+ has_many :funky_comments, :through => :posts, :source => :comments
35
+ has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id'
36
+ has_many :ordered_uniq_comments_desc, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id DESC'
37
+ has_many :readonly_comments, :through => :posts, :source => :comments, :readonly => true
38
+
39
+ has_many :special_posts
40
+ has_many :special_post_comments, :through => :special_posts, :source => :comments
41
+
42
+ has_many :sti_posts, :class_name => 'StiPost'
43
+ has_many :sti_post_comments, :through => :sti_posts, :source => :comments
44
+
45
+ has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
46
+ has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
47
+ has_many :nonexistant_comments, :through => :posts
48
+
49
+ has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
50
+ has_many :hello_post_comments, :through => :hello_posts, :source => :comments
51
+ has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments
52
+
53
+ has_many :hello_posts_with_hash_conditions, :class_name => "Post",
54
+ :conditions => {:body => 'hello'}
55
+ has_many :hello_post_comments_with_hash_conditions, :through =>
56
+ :hello_posts_with_hash_conditions, :source => :comments
57
+
58
+ has_many :other_posts, :class_name => "Post"
59
+ has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
60
+ :after_add => :log_after_adding,
61
+ :before_remove => :log_before_removing,
62
+ :after_remove => :log_after_removing
63
+ has_many :posts_with_proc_callbacks, :class_name => "Post",
64
+ :before_add => Proc.new {|o, r| o.post_log << "before_adding#{r.id || '<new>'}"},
65
+ :after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id || '<new>'}"},
66
+ :before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
67
+ :after_remove => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
68
+ has_many :posts_with_multiple_callbacks, :class_name => "Post",
69
+ :before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id || '<new>'}"}],
70
+ :after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || '<new>'}"}]
71
+ has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
72
+
73
+ has_many :categorizations
74
+ has_many :categories, :through => :categorizations
75
+
76
+ has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
77
+
78
+ has_many :categorized_posts, :through => :categorizations, :source => :post
79
+ has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
80
+
81
+ has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
82
+
83
+ has_many :author_favorites
84
+ has_many :favorite_authors, :through => :author_favorites, :order => 'name'
85
+
86
+ has_many :tagging, :through => :posts # through polymorphic has_one
87
+ has_many :taggings, :through => :posts, :source => :taggings # through polymorphic has_many
88
+ has_many :tags, :through => :posts # through has_many :through
89
+ has_many :post_categories, :through => :posts, :source => :categories
90
+
91
+ has_one :essay, :primary_key => :name, :as => :writer
92
+
93
+ belongs_to :author_address, :dependent => :destroy
94
+ belongs_to :author_address_extra, :dependent => :delete, :class_name => "AuthorAddress"
95
+
96
+ attr_accessor :post_log
97
+
98
+ def after_initialize
99
+ @post_log = []
100
+ end
101
+
102
+ def label
103
+ "#{id}-#{name}"
104
+ end
105
+
106
+ private
107
+ def log_before_adding(object)
108
+ @post_log << "before_adding#{object.id || '<new>'}"
109
+ end
110
+
111
+ def log_after_adding(object)
112
+ @post_log << "after_adding#{object.id}"
113
+ end
114
+
115
+ def log_before_removing(object)
116
+ @post_log << "before_removing#{object.id}"
117
+ end
118
+
119
+ def log_after_removing(object)
120
+ @post_log << "after_removing#{object.id}"
121
+ end
122
+
123
+ def raise_exception(object)
124
+ raise Exception.new("You can't add a post")
125
+ end
126
+ end
127
+
128
+ class AuthorAddress < ActiveRecord::Base
129
+ has_one :author
130
+
131
+ def self.destroyed_author_address_ids
132
+ @destroyed_author_address_ids ||= Hash.new { |h,k| h[k] = [] }
133
+ end
134
+
135
+ before_destroy do |author_address|
136
+ if author_address.author
137
+ AuthorAddress.destroyed_author_address_ids[author_address.author.id] << author_address.id
138
+ end
139
+ true
140
+ end
141
+ end
142
+
143
+ class AuthorFavorite < ActiveRecord::Base
144
+ belongs_to :author
145
+ belongs_to :favorite_author, :class_name => "Author"
146
+ end
@@ -0,0 +1,4 @@
1
+ class AutoId < ActiveRecord::Base
2
+ def self.table_name () "auto_id_tests" end
3
+ def self.primary_key () "auto_id" end
4
+ end
@@ -0,0 +1,2 @@
1
+ class Binary < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class Bird < ActiveRecord::Base
2
+ validates_presence_of :name
3
+ end
@@ -0,0 +1,4 @@
1
+ class Book < ActiveRecord::Base
2
+ has_many :citations, :foreign_key => 'book1_id'
3
+ has_many :references, :through => :citations, :source => :reference_of, :uniq => true
4
+ end
@@ -0,0 +1,5 @@
1
+ class Categorization < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :category
4
+ belongs_to :author
5
+ end
@@ -0,0 +1,34 @@
1
+ class Category < ActiveRecord::Base
2
+ has_and_belongs_to_many :posts
3
+ has_and_belongs_to_many :special_posts, :class_name => "Post"
4
+ has_and_belongs_to_many :other_posts, :class_name => "Post"
5
+ has_and_belongs_to_many :posts_with_authors_sorted_by_author_id, :class_name => "Post", :include => :authors, :order => "authors.id"
6
+
7
+ has_and_belongs_to_many(:select_testing_posts,
8
+ :class_name => 'Post',
9
+ :foreign_key => 'category_id',
10
+ :association_foreign_key => 'post_id',
11
+ :select => 'posts.*, 1 as correctness_marker')
12
+
13
+ has_and_belongs_to_many :post_with_conditions,
14
+ :class_name => 'Post',
15
+ :conditions => { :title => 'Yet Another Testing Title' }
16
+
17
+ has_and_belongs_to_many :popular_grouped_posts, :class_name => "Post", :group => "posts.type", :having => "sum(comments.post_id) > 2", :include => :comments
18
+ has_and_belongs_to_many :posts_gruoped_by_title, :class_name => "Post", :group => "title", :select => "title"
19
+
20
+ def self.what_are_you
21
+ 'a category...'
22
+ end
23
+
24
+ has_many :categorizations
25
+ has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
26
+ end
27
+
28
+ class SpecialCategory < Category
29
+
30
+ def self.what_are_you
31
+ 'a special category...'
32
+ end
33
+
34
+ end
@@ -0,0 +1,6 @@
1
+ class Citation < ActiveRecord::Base
2
+ belongs_to :reference_of, :class_name => "Book", :foreign_key => :book2_id
3
+
4
+ belongs_to :book1, :class_name => "Book", :foreign_key => :book1_id
5
+ belongs_to :book2, :class_name => "Book", :foreign_key => :book2_id
6
+ end
@@ -0,0 +1,13 @@
1
+ class Club < ActiveRecord::Base
2
+ has_many :memberships
3
+ has_many :members, :through => :memberships
4
+ has_many :current_memberships
5
+ has_one :sponsor
6
+ has_one :sponsored_member, :through => :sponsor, :source => :sponsorable, :source_type => "Member"
7
+
8
+ private
9
+
10
+ def private_method
11
+ "I'm sorry sir, this is a *private* club, not a *pirate* club"
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class ColumnName < ActiveRecord::Base
2
+ def self.table_name () "colnametests" end
3
+ end
@@ -0,0 +1,29 @@
1
+ class Comment < ActiveRecord::Base
2
+ named_scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
3
+ named_scope :for_first_post, :conditions => { :post_id => 1 }
4
+ named_scope :for_first_author,
5
+ :joins => :post,
6
+ :conditions => { "posts.author_id" => 1 }
7
+
8
+ belongs_to :post, :counter_cache => true
9
+
10
+ def self.what_are_you
11
+ 'a comment...'
12
+ end
13
+
14
+ def self.search_by_type(q)
15
+ self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
16
+ end
17
+ end
18
+
19
+ class SpecialComment < Comment
20
+ def self.what_are_you
21
+ 'a special comment...'
22
+ end
23
+ end
24
+
25
+ class VerySpecialComment < Comment
26
+ def self.what_are_you
27
+ 'a very special comment...'
28
+ end
29
+ end