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,171 @@
1
+ class AbstractCompany < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
4
+
5
+ class Company < AbstractCompany
6
+ attr_protected :rating
7
+ set_sequence_name :companies_nonstd_seq
8
+
9
+ validates_presence_of :name
10
+
11
+ has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
12
+ has_many :contracts
13
+ has_many :developers, :through => :contracts
14
+
15
+ def arbitrary_method
16
+ "I am Jack's profound disappointment"
17
+ end
18
+
19
+ private
20
+
21
+ def private_method
22
+ "I am Jack's innermost fears and aspirations"
23
+ end
24
+ end
25
+
26
+ module Namespaced
27
+ class Company < ::Company
28
+ end
29
+
30
+ class Firm < ::Company
31
+ has_many :clients, :class_name => 'Namespaced::Client'
32
+ end
33
+
34
+ class Client < ::Company
35
+ end
36
+ end
37
+
38
+ class Firm < Company
39
+ has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
40
+ "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
41
+ "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
42
+ has_many :unsorted_clients, :class_name => "Client"
43
+ has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
44
+ has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
45
+ has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
46
+ has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
47
+ has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
48
+ has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
49
+ has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
50
+ has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
51
+ has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
52
+ has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
53
+ has_many :clients_using_counter_sql, :class_name => "Client",
54
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
55
+ :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
56
+ has_many :clients_using_zero_counter_sql, :class_name => "Client",
57
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
58
+ :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
59
+ has_many :no_clients_using_counter_sql, :class_name => "Client",
60
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
61
+ :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
62
+ has_many :clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1'
63
+ has_many :plain_clients, :class_name => 'Client'
64
+ has_many :readonly_clients, :class_name => 'Client', :readonly => true
65
+ has_many :clients_using_primary_key, :class_name => 'Client',
66
+ :primary_key => 'name', :foreign_key => 'firm_name'
67
+ has_many :clients_using_primary_key_with_delete_all, :class_name => 'Client',
68
+ :primary_key => 'name', :foreign_key => 'firm_name', :dependent => :delete_all
69
+ has_many :clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id", :select => "firm_id"
70
+ has_many :clients_grouped_by_name, :class_name => "Client", :group => "name", :select => "name"
71
+
72
+ has_one :account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
73
+ has_one :unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
74
+ has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
75
+ has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
76
+ has_one :account_using_primary_key, :primary_key => "firm_id", :class_name => "Account"
77
+ has_one :account_using_foreign_and_primary_keys, :foreign_key => "firm_name", :primary_key => "name", :class_name => "Account"
78
+ has_one :deletable_account, :foreign_key => "firm_id", :class_name => "Account", :dependent => :delete
79
+
80
+ has_one :account_limit_500_with_hash_conditions, :foreign_key => "firm_id", :class_name => "Account", :conditions => { :credit_limit => 500 }
81
+
82
+ has_one :unautosaved_account, :foreign_key => "firm_id", :class_name => 'Account', :autosave => false
83
+ has_many :accounts
84
+ has_many :unautosaved_accounts, :foreign_key => "firm_id", :class_name => 'Account', :autosave => false
85
+ end
86
+
87
+ class DependentFirm < Company
88
+ has_one :account, :foreign_key => "firm_id", :dependent => :nullify
89
+ has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
90
+ end
91
+
92
+ class Client < Company
93
+ belongs_to :firm, :foreign_key => "client_of"
94
+ belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
95
+ belongs_to :firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id"
96
+ belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
97
+ belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
98
+ belongs_to :firm_with_primary_key, :class_name => "Firm", :primary_key => "name", :foreign_key => "firm_name"
99
+ belongs_to :readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true
100
+
101
+ # Record destruction so we can test whether firm.clients.clear has
102
+ # is calling client.destroy, deleting from the database, or setting
103
+ # foreign keys to NULL.
104
+ def self.destroyed_client_ids
105
+ @destroyed_client_ids ||= Hash.new { |h,k| h[k] = [] }
106
+ end
107
+
108
+ before_destroy do |client|
109
+ if client.firm
110
+ Client.destroyed_client_ids[client.firm.id] << client.id
111
+ end
112
+ true
113
+ end
114
+
115
+ # Used to test that read and question methods are not generated for these attributes
116
+ def ruby_type
117
+ read_attribute :ruby_type
118
+ end
119
+
120
+ def rating?
121
+ query_attribute :rating
122
+ end
123
+
124
+ class << self
125
+ private
126
+
127
+ def private_method
128
+ "darkness"
129
+ end
130
+ end
131
+ end
132
+
133
+ class ExclusivelyDependentFirm < Company
134
+ has_one :account, :foreign_key => "firm_id", :dependent => :delete
135
+ has_many :dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
136
+ has_many :dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
137
+ has_many :dependent_hash_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => {:name => 'BigShot Inc.'}
138
+ end
139
+
140
+ class SpecialClient < Client
141
+ end
142
+
143
+ class VerySpecialClient < SpecialClient
144
+ end
145
+
146
+ class Account < ActiveRecord::Base
147
+ belongs_to :firm
148
+ belongs_to :unautosaved_firm, :foreign_key => "firm_id", :class_name => "Firm", :autosave => false
149
+
150
+ def self.destroyed_account_ids
151
+ @destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
152
+ end
153
+
154
+ before_destroy do |account|
155
+ if account.firm
156
+ Account.destroyed_account_ids[account.firm.id] << account.id
157
+ end
158
+ true
159
+ end
160
+
161
+ protected
162
+ def validate
163
+ errors.add_on_empty "credit_limit"
164
+ end
165
+
166
+ private
167
+
168
+ def private_method
169
+ "Sir, yes sir!"
170
+ end
171
+ end
@@ -0,0 +1,61 @@
1
+ module MyApplication
2
+ module Business
3
+ class Company < ActiveRecord::Base
4
+ attr_protected :rating
5
+ end
6
+
7
+ class Firm < Company
8
+ has_many :clients, :order => "id", :dependent => :destroy
9
+ has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
10
+ has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
11
+ has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
12
+ has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
13
+
14
+ has_one :account, :class_name => 'MyApplication::Billing::Account', :dependent => :destroy
15
+ end
16
+
17
+ class Client < Company
18
+ belongs_to :firm, :foreign_key => "client_of"
19
+ belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
20
+
21
+ class Contact < ActiveRecord::Base; end
22
+ end
23
+
24
+ class Developer < ActiveRecord::Base
25
+ has_and_belongs_to_many :projects
26
+ validates_length_of :name, :within => (3..20)
27
+ end
28
+
29
+ class Project < ActiveRecord::Base
30
+ has_and_belongs_to_many :developers
31
+ end
32
+
33
+ end
34
+
35
+ module Billing
36
+ class Firm < ActiveRecord::Base
37
+ self.table_name = 'companies'
38
+ end
39
+
40
+ module Nested
41
+ class Firm < ActiveRecord::Base
42
+ self.table_name = 'companies'
43
+ end
44
+ end
45
+
46
+ class Account < ActiveRecord::Base
47
+ with_options(:foreign_key => :firm_id) do |i|
48
+ i.belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
49
+ i.belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
50
+ i.belongs_to :unqualified_billing_firm, :class_name => 'Firm'
51
+ i.belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
52
+ i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
53
+ end
54
+
55
+ protected
56
+ def validate
57
+ errors.add_on_empty "credit_limit"
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ class Computer < ActiveRecord::Base
2
+ belongs_to :developer, :foreign_key=>'developer'
3
+ end
@@ -0,0 +1,16 @@
1
+ class Contact < ActiveRecord::Base
2
+ # mock out self.columns so no pesky db is needed for these tests
3
+ def self.column(name, sql_type = nil, options = {})
4
+ @columns ||= []
5
+ @columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], sql_type.to_s, options[:null])
6
+ end
7
+
8
+ column :name, :string
9
+ column :age, :integer
10
+ column :avatar, :binary
11
+ column :created_at, :datetime
12
+ column :awesome, :boolean
13
+ column :preferences, :string
14
+
15
+ serialize :preferences
16
+ end
@@ -0,0 +1,5 @@
1
+ class Contract < ActiveRecord::Base
2
+ belongs_to :company
3
+ belongs_to :developer
4
+ end
5
+
@@ -0,0 +1,3 @@
1
+ class Course < ActiveRecord::Base
2
+ has_many :entrants
3
+ end
@@ -0,0 +1,73 @@
1
+ class Customer < ActiveRecord::Base
2
+ composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil => true
3
+ composed_of :balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| balance.to_money }
4
+ composed_of :gps_location, :allow_nil => true
5
+ composed_of :fullname, :mapping => %w(name to_s), :constructor => Proc.new { |name| Fullname.parse(name) }, :converter => :parse
6
+ end
7
+
8
+ class Address
9
+ attr_reader :street, :city, :country
10
+
11
+ def initialize(street, city, country)
12
+ @street, @city, @country = street, city, country
13
+ end
14
+
15
+ def close_to?(other_address)
16
+ city == other_address.city && country == other_address.country
17
+ end
18
+
19
+ def ==(other)
20
+ other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
21
+ end
22
+ end
23
+
24
+ class Money
25
+ attr_reader :amount, :currency
26
+
27
+ EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
28
+
29
+ def initialize(amount, currency = "USD")
30
+ @amount, @currency = amount, currency
31
+ end
32
+
33
+ def exchange_to(other_currency)
34
+ Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
35
+ end
36
+ end
37
+
38
+ class GpsLocation
39
+ attr_reader :gps_location
40
+
41
+ def initialize(gps_location)
42
+ @gps_location = gps_location
43
+ end
44
+
45
+ def latitude
46
+ gps_location.split("x").first
47
+ end
48
+
49
+ def longitude
50
+ gps_location.split("x").last
51
+ end
52
+
53
+ def ==(other)
54
+ self.latitude == other.latitude && self.longitude == other.longitude
55
+ end
56
+ end
57
+
58
+ class Fullname
59
+ attr_reader :first, :last
60
+
61
+ def self.parse(str)
62
+ return nil unless str
63
+ new(*str.to_s.split)
64
+ end
65
+
66
+ def initialize(first, last = nil)
67
+ @first, @last = first, last
68
+ end
69
+
70
+ def to_s
71
+ "#{first} #{last.upcase}"
72
+ end
73
+ end
@@ -0,0 +1,2 @@
1
+ class Default < ActiveRecord::Base
2
+ end
@@ -0,0 +1,101 @@
1
+ module DeveloperProjectsAssociationExtension
2
+ def find_most_recent
3
+ find(:first, :order => "id DESC")
4
+ end
5
+ end
6
+
7
+ module DeveloperProjectsAssociationExtension2
8
+ def find_least_recent
9
+ find(:first, :order => "id ASC")
10
+ end
11
+ end
12
+
13
+ class Developer < ActiveRecord::Base
14
+ has_and_belongs_to_many :projects do
15
+ def find_most_recent
16
+ find(:first, :order => "id DESC")
17
+ end
18
+ end
19
+
20
+ has_and_belongs_to_many :projects_extended_by_name,
21
+ :class_name => "Project",
22
+ :join_table => "developers_projects",
23
+ :association_foreign_key => "project_id",
24
+ :extend => DeveloperProjectsAssociationExtension
25
+
26
+ has_and_belongs_to_many :projects_extended_by_name_twice,
27
+ :class_name => "Project",
28
+ :join_table => "developers_projects",
29
+ :association_foreign_key => "project_id",
30
+ :extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
31
+
32
+ has_and_belongs_to_many :projects_extended_by_name_and_block,
33
+ :class_name => "Project",
34
+ :join_table => "developers_projects",
35
+ :association_foreign_key => "project_id",
36
+ :extend => DeveloperProjectsAssociationExtension do
37
+ def find_least_recent
38
+ find(:first, :order => "id ASC")
39
+ end
40
+ end
41
+
42
+ has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
43
+
44
+ has_many :audit_logs
45
+
46
+ named_scope :jamises, :conditions => {:name => 'Jamis'}
47
+
48
+ validates_inclusion_of :salary, :in => 50000..200000
49
+ validates_length_of :name, :within => 3..20
50
+
51
+ before_create do |developer|
52
+ developer.audit_logs.build :message => "Computer created"
53
+ end
54
+
55
+ def log=(message)
56
+ audit_logs.build :message => message
57
+ end
58
+ end
59
+
60
+ class AuditLog < ActiveRecord::Base
61
+ belongs_to :developer, :validate => true
62
+ belongs_to :unvalidated_developer, :class_name => 'Developer'
63
+ end
64
+
65
+ DeveloperSalary = Struct.new(:amount)
66
+ class DeveloperWithAggregate < ActiveRecord::Base
67
+ self.table_name = 'developers'
68
+ composed_of :salary, :class_name => 'DeveloperSalary', :mapping => [%w(salary amount)]
69
+ end
70
+
71
+ class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
72
+ self.table_name = 'developers'
73
+ has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id'
74
+ before_destroy :raise_if_projects_empty!
75
+
76
+ def raise_if_projects_empty!
77
+ raise if projects.empty?
78
+ end
79
+ end
80
+
81
+ class DeveloperOrderedBySalary < ActiveRecord::Base
82
+ self.table_name = 'developers'
83
+ default_scope :order => 'salary DESC'
84
+ named_scope :by_name, :order => 'name DESC'
85
+
86
+ def self.all_ordered_by_name
87
+ with_scope(:find => { :order => 'name DESC' }) do
88
+ find(:all)
89
+ end
90
+ end
91
+ end
92
+
93
+ class DeveloperCalledDavid < ActiveRecord::Base
94
+ self.table_name = 'developers'
95
+ default_scope :conditions => "name = 'David'"
96
+ end
97
+
98
+ class DeveloperCalledJamis < ActiveRecord::Base
99
+ self.table_name = 'developers'
100
+ default_scope :conditions => { :name => 'Jamis' }
101
+ end
@@ -0,0 +1,5 @@
1
+ # This class models an edge in a directed graph.
2
+ class Edge < ActiveRecord::Base
3
+ belongs_to :source, :class_name => 'Vertex', :foreign_key => 'source_id'
4
+ belongs_to :sink, :class_name => 'Vertex', :foreign_key => 'sink_id'
5
+ end
@@ -0,0 +1,3 @@
1
+ class Entrant < ActiveRecord::Base
2
+ belongs_to :course
3
+ end
@@ -0,0 +1,3 @@
1
+ class Essay < ActiveRecord::Base
2
+ belongs_to :writer, :primary_key => :name, :polymorphic => true
3
+ end
@@ -0,0 +1,3 @@
1
+ class Event < ActiveRecord::Base
2
+ validates_uniqueness_of :title
3
+ end
@@ -0,0 +1,2 @@
1
+ class Guid < ActiveRecord::Base
2
+ end
@@ -0,0 +1,7 @@
1
+ class AbstractItem < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ has_one :tagging, :as => :taggable
4
+ end
5
+
6
+ class Item < AbstractItem
7
+ end
@@ -0,0 +1,5 @@
1
+ class Job < ActiveRecord::Base
2
+ has_many :references
3
+ has_many :people, :through => :references
4
+ belongs_to :ideal_reference, :class_name => 'Reference'
5
+ end
@@ -0,0 +1,3 @@
1
+ class Joke < ActiveRecord::Base
2
+ set_table_name 'funny_jokes'
3
+ end
@@ -0,0 +1,3 @@
1
+ class Keyboard < ActiveRecord::Base
2
+ set_primary_key 'key_number'
3
+ end
@@ -0,0 +1,3 @@
1
+ class LegacyThing < ActiveRecord::Base
2
+ set_locking_column :version
3
+ end
@@ -0,0 +1,4 @@
1
+ class Matey < ActiveRecord::Base
2
+ belongs_to :pirate
3
+ belongs_to :target, :class_name => 'Pirate'
4
+ end
@@ -0,0 +1,12 @@
1
+ class Member < ActiveRecord::Base
2
+ has_one :current_membership
3
+ has_many :memberships
4
+ has_many :fellow_members, :through => :club, :source => :members
5
+ has_one :club, :through => :current_membership
6
+ has_one :favourite_club, :through => :memberships, :conditions => ["memberships.favourite = ?", true], :source => :club
7
+ has_one :sponsor, :as => :sponsorable
8
+ has_one :sponsor_club, :through => :sponsor
9
+ has_one :member_detail
10
+ has_one :organization, :through => :member_detail
11
+ belongs_to :member_type
12
+ end
@@ -0,0 +1,5 @@
1
+ class MemberDetail < ActiveRecord::Base
2
+ belongs_to :member
3
+ belongs_to :organization
4
+ has_one :member_type, :through => :member
5
+ end
@@ -0,0 +1,3 @@
1
+ class MemberType < ActiveRecord::Base
2
+ has_many :members
3
+ end
@@ -0,0 +1,9 @@
1
+ class Membership < ActiveRecord::Base
2
+ belongs_to :member
3
+ belongs_to :club
4
+ end
5
+
6
+ class CurrentMembership < Membership
7
+ belongs_to :member
8
+ belongs_to :club
9
+ end
@@ -0,0 +1,2 @@
1
+ class Minimalistic < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class MixedCaseMonkey < ActiveRecord::Base
2
+ set_primary_key 'monkeyID'
3
+ end
@@ -0,0 +1,5 @@
1
+ class Movie < ActiveRecord::Base
2
+ def self.primary_key
3
+ "movieid"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ class Order < ActiveRecord::Base
2
+ belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
3
+ belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
4
+ end
@@ -0,0 +1,6 @@
1
+ class Organization < ActiveRecord::Base
2
+ has_many :member_details
3
+ has_many :members, :through => :member_details
4
+
5
+ named_scope :clubs, { :from => 'clubs' }
6
+ end
@@ -0,0 +1,5 @@
1
+ class Owner < ActiveRecord::Base
2
+ set_primary_key :owner_id
3
+ has_many :pets
4
+ has_many :toys, :through => :pets
5
+ end
@@ -0,0 +1,16 @@
1
+ class Parrot < ActiveRecord::Base
2
+ set_inheritance_column :parrot_sti_class
3
+ has_and_belongs_to_many :pirates
4
+ has_and_belongs_to_many :treasures
5
+ has_many :loots, :as => :looter
6
+ alias_attribute :title, :name
7
+
8
+ validates_presence_of :name
9
+ end
10
+
11
+ class LiveParrot < Parrot
12
+ end
13
+
14
+ class DeadParrot < Parrot
15
+ belongs_to :killer, :class_name => 'Pirate'
16
+ end
@@ -0,0 +1,16 @@
1
+ class Person < ActiveRecord::Base
2
+ has_many :readers
3
+ has_many :posts, :through => :readers
4
+ has_many :posts_with_no_comments, :through => :readers, :source => :post, :include => :comments, :conditions => 'comments.id is null'
5
+
6
+ has_many :references
7
+ has_many :jobs, :through => :references
8
+ has_one :favourite_reference, :class_name => 'Reference', :conditions => ['favourite=?', true]
9
+ has_many :posts_with_comments_sorted_by_comment_id, :through => :readers, :source => :post, :include => :comments, :order => 'comments.id'
10
+
11
+ belongs_to :primary_contact, :class_name => 'Person'
12
+ has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id'
13
+
14
+ named_scope :males, :conditions => { :gender => 'M' }
15
+ named_scope :females, :conditions => { :gender => 'F' }
16
+ end
@@ -0,0 +1,5 @@
1
+ class Pet < ActiveRecord::Base
2
+ set_primary_key :pet_id
3
+ belongs_to :owner, :touch => true
4
+ has_many :toys
5
+ end