activerecord_csi 2.3.5.p6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (333) hide show
  1. data/CHANGELOG +5858 -0
  2. data/README +351 -0
  3. data/RUNNING_UNIT_TESTS +36 -0
  4. data/Rakefile +270 -0
  5. data/examples/associations.png +0 -0
  6. data/examples/performance.rb +162 -0
  7. data/install.rb +30 -0
  8. data/lib/active_record/aggregations.rb +261 -0
  9. data/lib/active_record/association_preload.rb +389 -0
  10. data/lib/active_record/associations/association_collection.rb +475 -0
  11. data/lib/active_record/associations/association_proxy.rb +278 -0
  12. data/lib/active_record/associations/belongs_to_association.rb +76 -0
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +53 -0
  14. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +143 -0
  15. data/lib/active_record/associations/has_many_association.rb +122 -0
  16. data/lib/active_record/associations/has_many_through_association.rb +266 -0
  17. data/lib/active_record/associations/has_one_association.rb +133 -0
  18. data/lib/active_record/associations/has_one_through_association.rb +37 -0
  19. data/lib/active_record/associations.rb +2241 -0
  20. data/lib/active_record/attribute_methods.rb +388 -0
  21. data/lib/active_record/autosave_association.rb +364 -0
  22. data/lib/active_record/base.rb +3171 -0
  23. data/lib/active_record/batches.rb +81 -0
  24. data/lib/active_record/calculations.rb +311 -0
  25. data/lib/active_record/callbacks.rb +360 -0
  26. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +371 -0
  27. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +139 -0
  28. data/lib/active_record/connection_adapters/abstract/database_statements.rb +289 -0
  29. data/lib/active_record/connection_adapters/abstract/query_cache.rb +94 -0
  30. data/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
  31. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +722 -0
  32. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +434 -0
  33. data/lib/active_record/connection_adapters/abstract_adapter.rb +241 -0
  34. data/lib/active_record/connection_adapters/mysql_adapter.rb +630 -0
  35. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1113 -0
  36. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
  37. data/lib/active_record/connection_adapters/sqlite_adapter.rb +453 -0
  38. data/lib/active_record/dirty.rb +183 -0
  39. data/lib/active_record/dynamic_finder_match.rb +41 -0
  40. data/lib/active_record/dynamic_scope_match.rb +25 -0
  41. data/lib/active_record/fixtures.rb +996 -0
  42. data/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
  43. data/lib/active_record/locale/en.yml +58 -0
  44. data/lib/active_record/locking/optimistic.rb +148 -0
  45. data/lib/active_record/locking/pessimistic.rb +55 -0
  46. data/lib/active_record/migration.rb +566 -0
  47. data/lib/active_record/named_scope.rb +192 -0
  48. data/lib/active_record/nested_attributes.rb +392 -0
  49. data/lib/active_record/observer.rb +197 -0
  50. data/lib/active_record/query_cache.rb +33 -0
  51. data/lib/active_record/reflection.rb +320 -0
  52. data/lib/active_record/schema.rb +51 -0
  53. data/lib/active_record/schema_dumper.rb +182 -0
  54. data/lib/active_record/serialization.rb +101 -0
  55. data/lib/active_record/serializers/json_serializer.rb +91 -0
  56. data/lib/active_record/serializers/xml_serializer.rb +357 -0
  57. data/lib/active_record/session_store.rb +326 -0
  58. data/lib/active_record/test_case.rb +66 -0
  59. data/lib/active_record/timestamp.rb +71 -0
  60. data/lib/active_record/transactions.rb +235 -0
  61. data/lib/active_record/validations.rb +1135 -0
  62. data/lib/active_record/version.rb +9 -0
  63. data/lib/active_record.rb +84 -0
  64. data/lib/activerecord.rb +2 -0
  65. data/test/assets/example.log +1 -0
  66. data/test/assets/flowers.jpg +0 -0
  67. data/test/cases/aaa_create_tables_test.rb +24 -0
  68. data/test/cases/active_schema_test_mysql.rb +100 -0
  69. data/test/cases/active_schema_test_postgresql.rb +24 -0
  70. data/test/cases/adapter_test.rb +145 -0
  71. data/test/cases/aggregations_test.rb +167 -0
  72. data/test/cases/ar_schema_test.rb +32 -0
  73. data/test/cases/associations/belongs_to_associations_test.rb +425 -0
  74. data/test/cases/associations/callbacks_test.rb +161 -0
  75. data/test/cases/associations/cascaded_eager_loading_test.rb +131 -0
  76. data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
  77. data/test/cases/associations/eager_load_nested_include_test.rb +130 -0
  78. data/test/cases/associations/eager_singularization_test.rb +145 -0
  79. data/test/cases/associations/eager_test.rb +834 -0
  80. data/test/cases/associations/extension_test.rb +62 -0
  81. data/test/cases/associations/habtm_join_table_test.rb +56 -0
  82. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +822 -0
  83. data/test/cases/associations/has_many_associations_test.rb +1134 -0
  84. data/test/cases/associations/has_many_through_associations_test.rb +346 -0
  85. data/test/cases/associations/has_one_associations_test.rb +330 -0
  86. data/test/cases/associations/has_one_through_associations_test.rb +209 -0
  87. data/test/cases/associations/inner_join_association_test.rb +93 -0
  88. data/test/cases/associations/join_model_test.rb +712 -0
  89. data/test/cases/associations_test.rb +262 -0
  90. data/test/cases/attribute_methods_test.rb +305 -0
  91. data/test/cases/autosave_association_test.rb +1142 -0
  92. data/test/cases/base_test.rb +2154 -0
  93. data/test/cases/batches_test.rb +61 -0
  94. data/test/cases/binary_test.rb +30 -0
  95. data/test/cases/calculations_test.rb +348 -0
  96. data/test/cases/callbacks_observers_test.rb +38 -0
  97. data/test/cases/callbacks_test.rb +438 -0
  98. data/test/cases/class_inheritable_attributes_test.rb +32 -0
  99. data/test/cases/column_alias_test.rb +17 -0
  100. data/test/cases/column_definition_test.rb +70 -0
  101. data/test/cases/connection_pool_test.rb +25 -0
  102. data/test/cases/connection_test_firebird.rb +8 -0
  103. data/test/cases/connection_test_mysql.rb +64 -0
  104. data/test/cases/copy_table_test_sqlite.rb +80 -0
  105. data/test/cases/database_statements_test.rb +12 -0
  106. data/test/cases/datatype_test_postgresql.rb +204 -0
  107. data/test/cases/date_time_test.rb +37 -0
  108. data/test/cases/default_test_firebird.rb +16 -0
  109. data/test/cases/defaults_test.rb +111 -0
  110. data/test/cases/deprecated_finder_test.rb +30 -0
  111. data/test/cases/dirty_test.rb +316 -0
  112. data/test/cases/finder_respond_to_test.rb +76 -0
  113. data/test/cases/finder_test.rb +1066 -0
  114. data/test/cases/fixtures_test.rb +656 -0
  115. data/test/cases/helper.rb +68 -0
  116. data/test/cases/i18n_test.rb +46 -0
  117. data/test/cases/inheritance_test.rb +262 -0
  118. data/test/cases/invalid_date_test.rb +24 -0
  119. data/test/cases/json_serialization_test.rb +205 -0
  120. data/test/cases/lifecycle_test.rb +193 -0
  121. data/test/cases/locking_test.rb +304 -0
  122. data/test/cases/method_scoping_test.rb +704 -0
  123. data/test/cases/migration_test.rb +1523 -0
  124. data/test/cases/migration_test_firebird.rb +124 -0
  125. data/test/cases/mixin_test.rb +96 -0
  126. data/test/cases/modules_test.rb +81 -0
  127. data/test/cases/multiple_db_test.rb +85 -0
  128. data/test/cases/named_scope_test.rb +361 -0
  129. data/test/cases/nested_attributes_test.rb +581 -0
  130. data/test/cases/pk_test.rb +119 -0
  131. data/test/cases/pooled_connections_test.rb +103 -0
  132. data/test/cases/query_cache_test.rb +123 -0
  133. data/test/cases/readonly_test.rb +107 -0
  134. data/test/cases/reflection_test.rb +194 -0
  135. data/test/cases/reload_models_test.rb +22 -0
  136. data/test/cases/repair_helper.rb +50 -0
  137. data/test/cases/reserved_word_test_mysql.rb +176 -0
  138. data/test/cases/sanitize_test.rb +25 -0
  139. data/test/cases/schema_authorization_test_postgresql.rb +75 -0
  140. data/test/cases/schema_dumper_test.rb +211 -0
  141. data/test/cases/schema_test_postgresql.rb +178 -0
  142. data/test/cases/serialization_test.rb +47 -0
  143. data/test/cases/synonym_test_oracle.rb +17 -0
  144. data/test/cases/timestamp_test.rb +75 -0
  145. data/test/cases/transactions_test.rb +522 -0
  146. data/test/cases/unconnected_test.rb +32 -0
  147. data/test/cases/validations_i18n_test.rb +955 -0
  148. data/test/cases/validations_test.rb +1640 -0
  149. data/test/cases/xml_serialization_test.rb +240 -0
  150. data/test/config.rb +5 -0
  151. data/test/connections/jdbc_jdbcderby/connection.rb +18 -0
  152. data/test/connections/jdbc_jdbch2/connection.rb +18 -0
  153. data/test/connections/jdbc_jdbchsqldb/connection.rb +18 -0
  154. data/test/connections/jdbc_jdbcmysql/connection.rb +26 -0
  155. data/test/connections/jdbc_jdbcpostgresql/connection.rb +26 -0
  156. data/test/connections/jdbc_jdbcsqlite3/connection.rb +25 -0
  157. data/test/connections/native_db2/connection.rb +25 -0
  158. data/test/connections/native_firebird/connection.rb +26 -0
  159. data/test/connections/native_frontbase/connection.rb +27 -0
  160. data/test/connections/native_mysql/connection.rb +25 -0
  161. data/test/connections/native_openbase/connection.rb +21 -0
  162. data/test/connections/native_oracle/connection.rb +27 -0
  163. data/test/connections/native_postgresql/connection.rb +25 -0
  164. data/test/connections/native_sqlite/connection.rb +25 -0
  165. data/test/connections/native_sqlite3/connection.rb +25 -0
  166. data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
  167. data/test/connections/native_sybase/connection.rb +23 -0
  168. data/test/fixtures/accounts.yml +29 -0
  169. data/test/fixtures/all/developers.yml +0 -0
  170. data/test/fixtures/all/people.csv +0 -0
  171. data/test/fixtures/all/tasks.yml +0 -0
  172. data/test/fixtures/author_addresses.yml +5 -0
  173. data/test/fixtures/author_favorites.yml +4 -0
  174. data/test/fixtures/authors.yml +9 -0
  175. data/test/fixtures/binaries.yml +132 -0
  176. data/test/fixtures/books.yml +7 -0
  177. data/test/fixtures/categories/special_categories.yml +9 -0
  178. data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  179. data/test/fixtures/categories.yml +14 -0
  180. data/test/fixtures/categories_ordered.yml +7 -0
  181. data/test/fixtures/categories_posts.yml +23 -0
  182. data/test/fixtures/categorizations.yml +17 -0
  183. data/test/fixtures/clubs.yml +6 -0
  184. data/test/fixtures/comments.yml +59 -0
  185. data/test/fixtures/companies.yml +56 -0
  186. data/test/fixtures/computers.yml +4 -0
  187. data/test/fixtures/courses.yml +7 -0
  188. data/test/fixtures/customers.yml +26 -0
  189. data/test/fixtures/developers.yml +21 -0
  190. data/test/fixtures/developers_projects.yml +17 -0
  191. data/test/fixtures/edges.yml +6 -0
  192. data/test/fixtures/entrants.yml +14 -0
  193. data/test/fixtures/fixture_database.sqlite3 +0 -0
  194. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  195. data/test/fixtures/fk_test_has_fk.yml +3 -0
  196. data/test/fixtures/fk_test_has_pk.yml +2 -0
  197. data/test/fixtures/funny_jokes.yml +10 -0
  198. data/test/fixtures/items.yml +4 -0
  199. data/test/fixtures/jobs.yml +7 -0
  200. data/test/fixtures/legacy_things.yml +3 -0
  201. data/test/fixtures/mateys.yml +4 -0
  202. data/test/fixtures/member_types.yml +6 -0
  203. data/test/fixtures/members.yml +6 -0
  204. data/test/fixtures/memberships.yml +20 -0
  205. data/test/fixtures/minimalistics.yml +2 -0
  206. data/test/fixtures/mixed_case_monkeys.yml +6 -0
  207. data/test/fixtures/mixins.yml +29 -0
  208. data/test/fixtures/movies.yml +7 -0
  209. data/test/fixtures/naked/csv/accounts.csv +1 -0
  210. data/test/fixtures/naked/yml/accounts.yml +1 -0
  211. data/test/fixtures/naked/yml/companies.yml +1 -0
  212. data/test/fixtures/naked/yml/courses.yml +1 -0
  213. data/test/fixtures/organizations.yml +5 -0
  214. data/test/fixtures/owners.yml +7 -0
  215. data/test/fixtures/parrots.yml +27 -0
  216. data/test/fixtures/parrots_pirates.yml +7 -0
  217. data/test/fixtures/people.yml +15 -0
  218. data/test/fixtures/pets.yml +14 -0
  219. data/test/fixtures/pirates.yml +9 -0
  220. data/test/fixtures/posts.yml +52 -0
  221. data/test/fixtures/price_estimates.yml +7 -0
  222. data/test/fixtures/projects.yml +7 -0
  223. data/test/fixtures/readers.yml +9 -0
  224. data/test/fixtures/references.yml +17 -0
  225. data/test/fixtures/reserved_words/distinct.yml +5 -0
  226. data/test/fixtures/reserved_words/distincts_selects.yml +11 -0
  227. data/test/fixtures/reserved_words/group.yml +14 -0
  228. data/test/fixtures/reserved_words/select.yml +8 -0
  229. data/test/fixtures/reserved_words/values.yml +7 -0
  230. data/test/fixtures/ships.yml +5 -0
  231. data/test/fixtures/sponsors.yml +9 -0
  232. data/test/fixtures/subscribers.yml +7 -0
  233. data/test/fixtures/subscriptions.yml +12 -0
  234. data/test/fixtures/taggings.yml +28 -0
  235. data/test/fixtures/tags.yml +7 -0
  236. data/test/fixtures/tasks.yml +7 -0
  237. data/test/fixtures/topics.yml +42 -0
  238. data/test/fixtures/toys.yml +4 -0
  239. data/test/fixtures/treasures.yml +10 -0
  240. data/test/fixtures/vertices.yml +4 -0
  241. data/test/fixtures/warehouse-things.yml +3 -0
  242. data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
  243. data/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
  244. data/test/migrations/duplicate/1_people_have_last_names.rb +9 -0
  245. data/test/migrations/duplicate/2_we_need_reminders.rb +12 -0
  246. data/test/migrations/duplicate/3_foo.rb +7 -0
  247. data/test/migrations/duplicate/3_innocent_jointable.rb +12 -0
  248. data/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
  249. data/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
  250. data/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +12 -0
  251. data/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +9 -0
  252. data/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +12 -0
  253. data/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +9 -0
  254. data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
  255. data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
  256. data/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
  257. data/test/migrations/missing/1_people_have_last_names.rb +9 -0
  258. data/test/migrations/missing/3_we_need_reminders.rb +12 -0
  259. data/test/migrations/missing/4_innocent_jointable.rb +12 -0
  260. data/test/migrations/valid/1_people_have_last_names.rb +9 -0
  261. data/test/migrations/valid/2_we_need_reminders.rb +12 -0
  262. data/test/migrations/valid/3_innocent_jointable.rb +12 -0
  263. data/test/models/author.rb +146 -0
  264. data/test/models/auto_id.rb +4 -0
  265. data/test/models/binary.rb +2 -0
  266. data/test/models/bird.rb +3 -0
  267. data/test/models/book.rb +4 -0
  268. data/test/models/categorization.rb +5 -0
  269. data/test/models/category.rb +34 -0
  270. data/test/models/citation.rb +6 -0
  271. data/test/models/club.rb +13 -0
  272. data/test/models/column_name.rb +3 -0
  273. data/test/models/comment.rb +29 -0
  274. data/test/models/company.rb +171 -0
  275. data/test/models/company_in_module.rb +61 -0
  276. data/test/models/computer.rb +3 -0
  277. data/test/models/contact.rb +16 -0
  278. data/test/models/contract.rb +5 -0
  279. data/test/models/course.rb +3 -0
  280. data/test/models/customer.rb +73 -0
  281. data/test/models/default.rb +2 -0
  282. data/test/models/developer.rb +101 -0
  283. data/test/models/edge.rb +5 -0
  284. data/test/models/entrant.rb +3 -0
  285. data/test/models/essay.rb +3 -0
  286. data/test/models/event.rb +3 -0
  287. data/test/models/guid.rb +2 -0
  288. data/test/models/item.rb +7 -0
  289. data/test/models/job.rb +5 -0
  290. data/test/models/joke.rb +3 -0
  291. data/test/models/keyboard.rb +3 -0
  292. data/test/models/legacy_thing.rb +3 -0
  293. data/test/models/matey.rb +4 -0
  294. data/test/models/member.rb +12 -0
  295. data/test/models/member_detail.rb +5 -0
  296. data/test/models/member_type.rb +3 -0
  297. data/test/models/membership.rb +9 -0
  298. data/test/models/minimalistic.rb +2 -0
  299. data/test/models/mixed_case_monkey.rb +3 -0
  300. data/test/models/movie.rb +5 -0
  301. data/test/models/order.rb +4 -0
  302. data/test/models/organization.rb +6 -0
  303. data/test/models/owner.rb +5 -0
  304. data/test/models/parrot.rb +16 -0
  305. data/test/models/person.rb +16 -0
  306. data/test/models/pet.rb +5 -0
  307. data/test/models/pirate.rb +70 -0
  308. data/test/models/post.rb +100 -0
  309. data/test/models/price_estimate.rb +3 -0
  310. data/test/models/project.rb +30 -0
  311. data/test/models/reader.rb +4 -0
  312. data/test/models/reference.rb +4 -0
  313. data/test/models/reply.rb +46 -0
  314. data/test/models/ship.rb +10 -0
  315. data/test/models/ship_part.rb +5 -0
  316. data/test/models/sponsor.rb +4 -0
  317. data/test/models/subject.rb +4 -0
  318. data/test/models/subscriber.rb +8 -0
  319. data/test/models/subscription.rb +4 -0
  320. data/test/models/tag.rb +7 -0
  321. data/test/models/tagging.rb +10 -0
  322. data/test/models/task.rb +3 -0
  323. data/test/models/topic.rb +80 -0
  324. data/test/models/toy.rb +6 -0
  325. data/test/models/treasure.rb +8 -0
  326. data/test/models/vertex.rb +9 -0
  327. data/test/models/warehouse_thing.rb +5 -0
  328. data/test/schema/mysql_specific_schema.rb +24 -0
  329. data/test/schema/postgresql_specific_schema.rb +114 -0
  330. data/test/schema/schema.rb +493 -0
  331. data/test/schema/schema2.rb +6 -0
  332. data/test/schema/sqlite_specific_schema.rb +25 -0
  333. metadata +420 -0
@@ -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
@@ -0,0 +1,70 @@
1
+ class Pirate < ActiveRecord::Base
2
+ belongs_to :parrot, :validate => true
3
+ belongs_to :non_validated_parrot, :class_name => 'Parrot'
4
+ has_and_belongs_to_many :parrots, :validate => true
5
+ has_and_belongs_to_many :non_validated_parrots, :class_name => 'Parrot'
6
+ has_and_belongs_to_many :parrots_with_method_callbacks, :class_name => "Parrot",
7
+ :before_add => :log_before_add,
8
+ :after_add => :log_after_add,
9
+ :before_remove => :log_before_remove,
10
+ :after_remove => :log_after_remove
11
+ has_and_belongs_to_many :parrots_with_proc_callbacks, :class_name => "Parrot",
12
+ :before_add => proc {|p,pa| p.ship_log << "before_adding_proc_parrot_#{pa.id || '<new>'}"},
13
+ :after_add => proc {|p,pa| p.ship_log << "after_adding_proc_parrot_#{pa.id || '<new>'}"},
14
+ :before_remove => proc {|p,pa| p.ship_log << "before_removing_proc_parrot_#{pa.id}"},
15
+ :after_remove => proc {|p,pa| p.ship_log << "after_removing_proc_parrot_#{pa.id}"}
16
+
17
+ has_many :treasures, :as => :looter
18
+ has_many :treasure_estimates, :through => :treasures, :source => :price_estimates
19
+
20
+ # These both have :autosave enabled because accepts_nested_attributes_for is used on them.
21
+ has_one :ship
22
+ has_one :non_validated_ship, :class_name => 'Ship'
23
+ has_many :birds
24
+ has_many :birds_with_method_callbacks, :class_name => "Bird",
25
+ :before_add => :log_before_add,
26
+ :after_add => :log_after_add,
27
+ :before_remove => :log_before_remove,
28
+ :after_remove => :log_after_remove
29
+ has_many :birds_with_proc_callbacks, :class_name => "Bird",
30
+ :before_add => proc {|p,b| p.ship_log << "before_adding_proc_bird_#{b.id || '<new>'}"},
31
+ :after_add => proc {|p,b| p.ship_log << "after_adding_proc_bird_#{b.id || '<new>'}"},
32
+ :before_remove => proc {|p,b| p.ship_log << "before_removing_proc_bird_#{b.id}"},
33
+ :after_remove => proc {|p,b| p.ship_log << "after_removing_proc_bird_#{b.id}"}
34
+
35
+ accepts_nested_attributes_for :parrots, :birds, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
36
+ accepts_nested_attributes_for :ship, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
37
+ accepts_nested_attributes_for :parrots_with_method_callbacks, :parrots_with_proc_callbacks,
38
+ :birds_with_method_callbacks, :birds_with_proc_callbacks, :allow_destroy => true
39
+
40
+ validates_presence_of :catchphrase
41
+
42
+ def ship_log
43
+ @ship_log ||= []
44
+ end
45
+
46
+ def reject_empty_ships_on_create(attributes)
47
+ attributes.delete('_reject_me_if_new').present? && new_record?
48
+ end
49
+
50
+ private
51
+ def log_before_add(record)
52
+ log(record, "before_adding_method")
53
+ end
54
+
55
+ def log_after_add(record)
56
+ log(record, "after_adding_method")
57
+ end
58
+
59
+ def log_before_remove(record)
60
+ log(record, "before_removing_method")
61
+ end
62
+
63
+ def log_after_remove(record)
64
+ log(record, "after_removing_method")
65
+ end
66
+
67
+ def log(record, callback)
68
+ ship_log << "#{callback}_#{record.class.name.downcase}_#{record.id || '<new>'}"
69
+ end
70
+ end
@@ -0,0 +1,100 @@
1
+ class Post < ActiveRecord::Base
2
+ named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'"
3
+ named_scope :ranked_by_comments, :order => "comments_count DESC"
4
+ named_scope :limit, lambda {|limit| {:limit => limit} }
5
+ named_scope :with_authors_at_address, lambda { |address| {
6
+ :conditions => [ 'authors.author_address_id = ?', address.id ],
7
+ :joins => 'JOIN authors ON authors.id = posts.author_id'
8
+ }
9
+ }
10
+
11
+ belongs_to :author do
12
+ def greeting
13
+ "hello"
14
+ end
15
+ end
16
+
17
+ belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
18
+ belongs_to :author_with_address, :class_name => "Author", :foreign_key => :author_id, :include => :author_address
19
+
20
+ has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
21
+
22
+ named_scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} }
23
+ named_scope :with_very_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'VerySpecialComment'} }
24
+ named_scope :with_post, lambda {|post_id|
25
+ { :joins => :comments, :conditions => {:comments => {:post_id => post_id} } }
26
+ }
27
+
28
+ has_many :comments, :order => "body" do
29
+ def find_most_recent
30
+ find(:first, :order => "id DESC")
31
+ end
32
+ end
33
+
34
+ has_many :author_favorites, :through => :author
35
+
36
+ has_many :comments_with_interpolated_conditions, :class_name => 'Comment',
37
+ :conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
38
+
39
+ has_one :very_special_comment
40
+ has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
41
+ has_many :special_comments
42
+ has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
43
+
44
+ has_and_belongs_to_many :categories
45
+ has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
46
+
47
+ has_many :taggings, :as => :taggable
48
+ has_many :tags, :through => :taggings do
49
+ def add_joins_and_select
50
+ find :all, :select => 'tags.*, authors.id as author_id', :include => false,
51
+ :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
52
+ end
53
+ end
54
+
55
+ has_many :funky_tags, :through => :taggings, :source => :tag
56
+ has_many :super_tags, :through => :taggings
57
+ has_one :tagging, :as => :taggable
58
+
59
+ has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
60
+ has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
61
+
62
+ has_many :categorizations, :foreign_key => :category_id
63
+ has_many :authors, :through => :categorizations
64
+
65
+ has_many :readers
66
+ has_many :people, :through => :readers
67
+ has_many :people_with_callbacks, :source=>:person, :through => :readers,
68
+ :before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
69
+ :after_add => lambda {|owner, reader| log(:added, :after, reader.first_name) },
70
+ :before_remove => lambda {|owner, reader| log(:removed, :before, reader.first_name) },
71
+ :after_remove => lambda {|owner, reader| log(:removed, :after, reader.first_name) }
72
+
73
+ def self.top(limit)
74
+ ranked_by_comments.limit(limit)
75
+ end
76
+
77
+ def self.reset_log
78
+ @log = []
79
+ end
80
+
81
+ def self.log(message=nil, side=nil, new_record=nil)
82
+ return @log if message.nil?
83
+ @log << [message, side, new_record]
84
+ end
85
+
86
+ def self.what_are_you
87
+ 'a post...'
88
+ end
89
+ end
90
+
91
+ class SpecialPost < Post; end
92
+
93
+ class StiPost < Post
94
+ self.abstract_class = true
95
+ has_one :special_comment, :class_name => "SpecialComment"
96
+ end
97
+
98
+ class SubStiPost < StiPost
99
+ self.table_name = Post.table_name
100
+ end
@@ -0,0 +1,3 @@
1
+ class PriceEstimate < ActiveRecord::Base
2
+ belongs_to :estimate_of, :polymorphic => true
3
+ end
@@ -0,0 +1,30 @@
1
+ class Project < ActiveRecord::Base
2
+ has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
3
+ has_and_belongs_to_many :readonly_developers, :class_name => "Developer", :readonly => true
4
+ has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true
5
+ has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
6
+ has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
7
+ has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
8
+ has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true
9
+ has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
10
+ has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id} ORDER BY t.id'
11
+ has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
12
+ has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || '<new>'}"},
13
+ :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
14
+ :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
15
+ :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
16
+ has_and_belongs_to_many :well_payed_salary_groups, :class_name => "Developer", :group => "developers.salary", :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary"
17
+
18
+ attr_accessor :developers_log
19
+
20
+ def after_initialize
21
+ @developers_log = []
22
+ end
23
+
24
+ end
25
+
26
+ class SpecialProject < Project
27
+ def hello_world
28
+ "hello there!"
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ class Reader < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :person
4
+ end
@@ -0,0 +1,4 @@
1
+ class Reference < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :job
4
+ end
@@ -0,0 +1,46 @@
1
+ require 'models/topic'
2
+
3
+ class Reply < Topic
4
+ named_scope :base
5
+
6
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
7
+ belongs_to :topic_with_primary_key, :class_name => "Topic", :primary_key => "title", :foreign_key => "parent_title", :counter_cache => "replies_count"
8
+ has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
9
+
10
+ validate :errors_on_empty_content
11
+ validate_on_create :title_is_wrong_create
12
+
13
+ attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read, :parent_title
14
+
15
+ def validate
16
+ errors.add("title", "Empty") unless attribute_present? "title"
17
+ end
18
+
19
+ def errors_on_empty_content
20
+ errors.add("content", "Empty") unless attribute_present? "content"
21
+ end
22
+
23
+ def validate_on_create
24
+ if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
25
+ errors.add("title", "is Content Mismatch")
26
+ end
27
+ end
28
+
29
+ def title_is_wrong_create
30
+ errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
31
+ end
32
+
33
+ def validate_on_update
34
+ errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
35
+ end
36
+ end
37
+
38
+ class SillyReply < Reply
39
+ belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
40
+ end
41
+
42
+ module Web
43
+ class Reply < Web::Topic
44
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true, :class_name => 'Web::Topic'
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ class Ship < ActiveRecord::Base
2
+ self.record_timestamps = false
3
+
4
+ belongs_to :pirate
5
+ has_many :parts, :class_name => 'ShipPart', :autosave => true
6
+
7
+ accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
8
+
9
+ validates_presence_of :name
10
+ end
@@ -0,0 +1,5 @@
1
+ class ShipPart < ActiveRecord::Base
2
+ belongs_to :ship
3
+
4
+ validates_presence_of :name
5
+ end
@@ -0,0 +1,4 @@
1
+ class Sponsor < ActiveRecord::Base
2
+ belongs_to :sponsor_club, :class_name => "Club", :foreign_key => "club_id"
3
+ belongs_to :sponsorable, :polymorphic => true
4
+ end
@@ -0,0 +1,4 @@
1
+ # used for OracleSynonymTest, see test/synonym_test_oci.rb
2
+ #
3
+ class Subject < ActiveRecord::Base
4
+ end
@@ -0,0 +1,8 @@
1
+ class Subscriber < ActiveRecord::Base
2
+ set_primary_key 'nick'
3
+ has_many :subscriptions
4
+ has_many :books, :through => :subscriptions
5
+ end
6
+
7
+ class SpecialSubscriber < Subscriber
8
+ end
@@ -0,0 +1,4 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :subscriber
3
+ belongs_to :book
4
+ end
@@ -0,0 +1,7 @@
1
+ class Tag < ActiveRecord::Base
2
+ has_many :taggings
3
+ has_many :taggables, :through => :taggings
4
+ has_one :tagging
5
+
6
+ has_many :tagged_posts, :through => :taggings, :source => :taggable, :source_type => 'Post'
7
+ end
@@ -0,0 +1,10 @@
1
+ # test that attr_readonly isn't called on the :taggable polymorphic association
2
+ module Taggable
3
+ end
4
+
5
+ class Tagging < ActiveRecord::Base
6
+ belongs_to :tag, :include => :tagging
7
+ belongs_to :super_tag, :class_name => 'Tag', :foreign_key => 'super_tag_id'
8
+ belongs_to :invalid_tag, :class_name => 'Tag', :foreign_key => 'tag_id'
9
+ belongs_to :taggable, :polymorphic => true, :counter_cache => true
10
+ end
@@ -0,0 +1,3 @@
1
+ class Task < ActiveRecord::Base
2
+
3
+ end