activerecord 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (311) hide show
  1. data/CHANGELOG +4928 -3
  2. data/README +45 -46
  3. data/RUNNING_UNIT_TESTS +8 -11
  4. data/Rakefile +247 -0
  5. data/install.rb +8 -38
  6. data/lib/active_record/aggregations.rb +64 -49
  7. data/lib/active_record/associations/association_collection.rb +217 -47
  8. data/lib/active_record/associations/association_proxy.rb +159 -0
  9. data/lib/active_record/associations/belongs_to_association.rb +56 -0
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
  11. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +155 -37
  12. data/lib/active_record/associations/has_many_association.rb +145 -75
  13. data/lib/active_record/associations/has_many_through_association.rb +283 -0
  14. data/lib/active_record/associations/has_one_association.rb +96 -0
  15. data/lib/active_record/associations.rb +1537 -304
  16. data/lib/active_record/attribute_methods.rb +328 -0
  17. data/lib/active_record/base.rb +2001 -588
  18. data/lib/active_record/calculations.rb +269 -0
  19. data/lib/active_record/callbacks.rb +169 -165
  20. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +308 -0
  21. data/lib/active_record/connection_adapters/abstract/database_statements.rb +171 -0
  22. data/lib/active_record/connection_adapters/abstract/query_cache.rb +87 -0
  23. data/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
  24. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +472 -0
  25. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +306 -0
  26. data/lib/active_record/connection_adapters/abstract_adapter.rb +125 -279
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +442 -77
  28. data/lib/active_record/connection_adapters/postgresql_adapter.rb +805 -135
  29. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
  30. data/lib/active_record/connection_adapters/sqlite_adapter.rb +353 -69
  31. data/lib/active_record/fixtures.rb +946 -100
  32. data/lib/active_record/locking/optimistic.rb +144 -0
  33. data/lib/active_record/locking/pessimistic.rb +77 -0
  34. data/lib/active_record/migration.rb +417 -0
  35. data/lib/active_record/observer.rb +142 -32
  36. data/lib/active_record/query_cache.rb +23 -0
  37. data/lib/active_record/reflection.rb +163 -70
  38. data/lib/active_record/schema.rb +58 -0
  39. data/lib/active_record/schema_dumper.rb +171 -0
  40. data/lib/active_record/serialization.rb +98 -0
  41. data/lib/active_record/serializers/json_serializer.rb +71 -0
  42. data/lib/active_record/serializers/xml_serializer.rb +315 -0
  43. data/lib/active_record/timestamp.rb +41 -0
  44. data/lib/active_record/transactions.rb +87 -57
  45. data/lib/active_record/validations.rb +909 -122
  46. data/lib/active_record/vendor/db2.rb +362 -0
  47. data/lib/active_record/vendor/mysql.rb +126 -29
  48. data/lib/active_record/version.rb +9 -0
  49. data/lib/active_record.rb +35 -7
  50. data/lib/activerecord.rb +1 -0
  51. data/test/aaa_create_tables_test.rb +72 -0
  52. data/test/abstract_unit.rb +73 -5
  53. data/test/active_schema_test_mysql.rb +43 -0
  54. data/test/adapter_test.rb +105 -0
  55. data/test/adapter_test_sqlserver.rb +95 -0
  56. data/test/aggregations_test.rb +110 -16
  57. data/test/all.sh +2 -2
  58. data/test/ar_schema_test.rb +33 -0
  59. data/test/association_inheritance_reload.rb +14 -0
  60. data/test/associations/ar_joins_test.rb +0 -0
  61. data/test/associations/callbacks_test.rb +147 -0
  62. data/test/associations/cascaded_eager_loading_test.rb +110 -0
  63. data/test/associations/eager_singularization_test.rb +145 -0
  64. data/test/associations/eager_test.rb +442 -0
  65. data/test/associations/extension_test.rb +47 -0
  66. data/test/associations/inner_join_association_test.rb +88 -0
  67. data/test/associations/join_model_test.rb +553 -0
  68. data/test/associations_test.rb +1930 -267
  69. data/test/attribute_methods_test.rb +146 -0
  70. data/test/base_test.rb +1316 -84
  71. data/test/binary_test.rb +32 -0
  72. data/test/calculations_test.rb +251 -0
  73. data/test/callbacks_test.rb +400 -0
  74. data/test/class_inheritable_attributes_test.rb +3 -4
  75. data/test/column_alias_test.rb +17 -0
  76. data/test/connection_test_firebird.rb +8 -0
  77. data/test/connection_test_mysql.rb +30 -0
  78. data/test/connections/native_db2/connection.rb +25 -0
  79. data/test/connections/native_firebird/connection.rb +26 -0
  80. data/test/connections/native_frontbase/connection.rb +27 -0
  81. data/test/connections/native_mysql/connection.rb +21 -18
  82. data/test/connections/native_openbase/connection.rb +21 -0
  83. data/test/connections/native_oracle/connection.rb +27 -0
  84. data/test/connections/native_postgresql/connection.rb +17 -18
  85. data/test/connections/native_sqlite/connection.rb +17 -16
  86. data/test/connections/native_sqlite3/connection.rb +25 -0
  87. data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
  88. data/test/connections/native_sybase/connection.rb +23 -0
  89. data/test/copy_table_test_sqlite.rb +69 -0
  90. data/test/datatype_test_postgresql.rb +203 -0
  91. data/test/date_time_test.rb +37 -0
  92. data/test/default_test_firebird.rb +16 -0
  93. data/test/defaults_test.rb +67 -0
  94. data/test/deprecated_finder_test.rb +30 -0
  95. data/test/finder_test.rb +607 -32
  96. data/test/fixtures/accounts.yml +28 -0
  97. data/test/fixtures/all/developers.yml +0 -0
  98. data/test/fixtures/all/people.csv +0 -0
  99. data/test/fixtures/all/tasks.yml +0 -0
  100. data/test/fixtures/author.rb +107 -0
  101. data/test/fixtures/author_favorites.yml +4 -0
  102. data/test/fixtures/authors.yml +7 -0
  103. data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
  104. data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
  105. data/test/fixtures/bad_fixtures/blank_line +3 -0
  106. data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
  107. data/test/fixtures/bad_fixtures/missing_value +1 -0
  108. data/test/fixtures/binaries.yml +132 -0
  109. data/test/fixtures/binary.rb +2 -0
  110. data/test/fixtures/book.rb +4 -0
  111. data/test/fixtures/books.yml +7 -0
  112. data/test/fixtures/categories/special_categories.yml +9 -0
  113. data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  114. data/test/fixtures/categories.yml +14 -0
  115. data/test/fixtures/categories_ordered.yml +7 -0
  116. data/test/fixtures/categories_posts.yml +23 -0
  117. data/test/fixtures/categorization.rb +5 -0
  118. data/test/fixtures/categorizations.yml +17 -0
  119. data/test/fixtures/category.rb +26 -0
  120. data/test/fixtures/citation.rb +6 -0
  121. data/test/fixtures/comment.rb +23 -0
  122. data/test/fixtures/comments.yml +59 -0
  123. data/test/fixtures/companies.yml +55 -0
  124. data/test/fixtures/company.rb +81 -4
  125. data/test/fixtures/company_in_module.rb +32 -6
  126. data/test/fixtures/computer.rb +4 -0
  127. data/test/fixtures/computers.yml +4 -0
  128. data/test/fixtures/contact.rb +16 -0
  129. data/test/fixtures/courses.yml +7 -0
  130. data/test/fixtures/customer.rb +28 -3
  131. data/test/fixtures/customers.yml +17 -0
  132. data/test/fixtures/db_definitions/db2.drop.sql +33 -0
  133. data/test/fixtures/db_definitions/db2.sql +235 -0
  134. data/test/fixtures/db_definitions/db22.drop.sql +2 -0
  135. data/test/fixtures/db_definitions/db22.sql +5 -0
  136. data/test/fixtures/db_definitions/firebird.drop.sql +65 -0
  137. data/test/fixtures/db_definitions/firebird.sql +310 -0
  138. data/test/fixtures/db_definitions/firebird2.drop.sql +2 -0
  139. data/test/fixtures/db_definitions/firebird2.sql +6 -0
  140. data/test/fixtures/db_definitions/frontbase.drop.sql +33 -0
  141. data/test/fixtures/db_definitions/frontbase.sql +273 -0
  142. data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
  143. data/test/fixtures/db_definitions/frontbase2.sql +4 -0
  144. data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
  145. data/test/fixtures/db_definitions/openbase.sql +318 -0
  146. data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
  147. data/test/fixtures/db_definitions/openbase2.sql +7 -0
  148. data/test/fixtures/db_definitions/oracle.drop.sql +67 -0
  149. data/test/fixtures/db_definitions/oracle.sql +330 -0
  150. data/test/fixtures/db_definitions/oracle2.drop.sql +2 -0
  151. data/test/fixtures/db_definitions/oracle2.sql +6 -0
  152. data/test/fixtures/db_definitions/postgresql.drop.sql +44 -0
  153. data/test/fixtures/db_definitions/postgresql.sql +217 -38
  154. data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
  155. data/test/fixtures/db_definitions/postgresql2.sql +2 -2
  156. data/test/fixtures/db_definitions/schema.rb +354 -0
  157. data/test/fixtures/db_definitions/schema2.rb +11 -0
  158. data/test/fixtures/db_definitions/sqlite.drop.sql +33 -0
  159. data/test/fixtures/db_definitions/sqlite.sql +139 -5
  160. data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
  161. data/test/fixtures/db_definitions/sqlite2.sql +1 -0
  162. data/test/fixtures/db_definitions/sybase.drop.sql +35 -0
  163. data/test/fixtures/db_definitions/sybase.sql +222 -0
  164. data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
  165. data/test/fixtures/db_definitions/sybase2.sql +5 -0
  166. data/test/fixtures/developer.rb +70 -6
  167. data/test/fixtures/developers.yml +21 -0
  168. data/test/fixtures/developers_projects/david_action_controller +2 -1
  169. data/test/fixtures/developers_projects/david_active_record +2 -1
  170. data/test/fixtures/developers_projects.yml +17 -0
  171. data/test/fixtures/edge.rb +5 -0
  172. data/test/fixtures/edges.yml +6 -0
  173. data/test/fixtures/entrants.yml +14 -0
  174. data/test/fixtures/example.log +1 -0
  175. data/test/fixtures/fk_test_has_fk.yml +3 -0
  176. data/test/fixtures/fk_test_has_pk.yml +2 -0
  177. data/test/fixtures/flowers.jpg +0 -0
  178. data/test/fixtures/funny_jokes.yml +10 -0
  179. data/test/fixtures/item.rb +7 -0
  180. data/test/fixtures/items.yml +4 -0
  181. data/test/fixtures/joke.rb +3 -0
  182. data/test/fixtures/keyboard.rb +3 -0
  183. data/test/fixtures/legacy_thing.rb +3 -0
  184. data/test/fixtures/legacy_things.yml +3 -0
  185. data/test/fixtures/matey.rb +4 -0
  186. data/test/fixtures/mateys.yml +4 -0
  187. data/test/fixtures/migrations/1_people_have_last_names.rb +9 -0
  188. data/test/fixtures/migrations/2_we_need_reminders.rb +12 -0
  189. data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
  190. data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
  191. data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
  192. data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
  193. data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
  194. data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
  195. data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
  196. data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
  197. data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
  198. data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
  199. data/test/fixtures/minimalistic.rb +2 -0
  200. data/test/fixtures/minimalistics.yml +2 -0
  201. data/test/fixtures/mixed_case_monkey.rb +3 -0
  202. data/test/fixtures/mixed_case_monkeys.yml +6 -0
  203. data/test/fixtures/mixins.yml +29 -0
  204. data/test/fixtures/movies.yml +7 -0
  205. data/test/fixtures/naked/csv/accounts.csv +1 -0
  206. data/test/fixtures/naked/yml/accounts.yml +1 -0
  207. data/test/fixtures/naked/yml/companies.yml +1 -0
  208. data/test/fixtures/naked/yml/courses.yml +1 -0
  209. data/test/fixtures/order.rb +4 -0
  210. data/test/fixtures/parrot.rb +13 -0
  211. data/test/fixtures/parrots.yml +27 -0
  212. data/test/fixtures/parrots_pirates.yml +7 -0
  213. data/test/fixtures/people.yml +3 -0
  214. data/test/fixtures/person.rb +4 -0
  215. data/test/fixtures/pirate.rb +5 -0
  216. data/test/fixtures/pirates.yml +9 -0
  217. data/test/fixtures/post.rb +59 -0
  218. data/test/fixtures/posts.yml +48 -0
  219. data/test/fixtures/project.rb +27 -2
  220. data/test/fixtures/projects.yml +7 -0
  221. data/test/fixtures/reader.rb +4 -0
  222. data/test/fixtures/readers.yml +4 -0
  223. data/test/fixtures/reply.rb +18 -2
  224. data/test/fixtures/reserved_words/distinct.yml +5 -0
  225. data/test/fixtures/reserved_words/distincts_selects.yml +11 -0
  226. data/test/fixtures/reserved_words/group.yml +14 -0
  227. data/test/fixtures/reserved_words/select.yml +8 -0
  228. data/test/fixtures/reserved_words/values.yml +7 -0
  229. data/test/fixtures/ship.rb +3 -0
  230. data/test/fixtures/ships.yml +5 -0
  231. data/test/fixtures/subject.rb +4 -0
  232. data/test/fixtures/subscriber.rb +4 -3
  233. data/test/fixtures/tag.rb +7 -0
  234. data/test/fixtures/tagging.rb +10 -0
  235. data/test/fixtures/taggings.yml +25 -0
  236. data/test/fixtures/tags.yml +7 -0
  237. data/test/fixtures/task.rb +3 -0
  238. data/test/fixtures/tasks.yml +7 -0
  239. data/test/fixtures/topic.rb +20 -3
  240. data/test/fixtures/topics.yml +22 -0
  241. data/test/fixtures/treasure.rb +4 -0
  242. data/test/fixtures/treasures.yml +10 -0
  243. data/test/fixtures/vertex.rb +9 -0
  244. data/test/fixtures/vertices.yml +4 -0
  245. data/test/fixtures_test.rb +574 -8
  246. data/test/inheritance_test.rb +113 -27
  247. data/test/json_serialization_test.rb +180 -0
  248. data/test/lifecycle_test.rb +56 -29
  249. data/test/locking_test.rb +273 -0
  250. data/test/method_scoping_test.rb +416 -0
  251. data/test/migration_test.rb +933 -0
  252. data/test/migration_test_firebird.rb +124 -0
  253. data/test/mixin_test.rb +95 -0
  254. data/test/modules_test.rb +23 -10
  255. data/test/multiple_db_test.rb +17 -3
  256. data/test/pk_test.rb +59 -15
  257. data/test/query_cache_test.rb +104 -0
  258. data/test/readonly_test.rb +107 -0
  259. data/test/reflection_test.rb +124 -27
  260. data/test/reserved_word_test_mysql.rb +177 -0
  261. data/test/schema_authorization_test_postgresql.rb +75 -0
  262. data/test/schema_dumper_test.rb +131 -0
  263. data/test/schema_test_postgresql.rb +64 -0
  264. data/test/serialization_test.rb +47 -0
  265. data/test/synonym_test_oracle.rb +17 -0
  266. data/test/table_name_test_sqlserver.rb +23 -0
  267. data/test/threaded_connections_test.rb +48 -0
  268. data/test/transactions_test.rb +227 -29
  269. data/test/unconnected_test.rb +14 -6
  270. data/test/validations_test.rb +1293 -32
  271. data/test/xml_serialization_test.rb +202 -0
  272. metadata +347 -143
  273. data/dev-utils/eval_debugger.rb +0 -9
  274. data/examples/associations.rb +0 -87
  275. data/examples/shared_setup.rb +0 -15
  276. data/examples/validation.rb +0 -88
  277. data/lib/active_record/deprecated_associations.rb +0 -70
  278. data/lib/active_record/support/class_attribute_accessors.rb +0 -43
  279. data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
  280. data/lib/active_record/support/clean_logger.rb +0 -10
  281. data/lib/active_record/support/inflector.rb +0 -70
  282. data/lib/active_record/vendor/simple.rb +0 -702
  283. data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
  284. data/lib/active_record/wrappings.rb +0 -59
  285. data/rakefile +0 -122
  286. data/test/deprecated_associations_test.rb +0 -336
  287. data/test/fixtures/accounts/signals37 +0 -3
  288. data/test/fixtures/accounts/unknown +0 -2
  289. data/test/fixtures/companies/first_client +0 -6
  290. data/test/fixtures/companies/first_firm +0 -4
  291. data/test/fixtures/companies/second_client +0 -6
  292. data/test/fixtures/courses/java +0 -2
  293. data/test/fixtures/courses/ruby +0 -2
  294. data/test/fixtures/customers/david +0 -6
  295. data/test/fixtures/db_definitions/mysql.sql +0 -96
  296. data/test/fixtures/db_definitions/mysql2.sql +0 -4
  297. data/test/fixtures/developers/david +0 -2
  298. data/test/fixtures/developers/jamis +0 -2
  299. data/test/fixtures/entrants/first +0 -3
  300. data/test/fixtures/entrants/second +0 -3
  301. data/test/fixtures/entrants/third +0 -3
  302. data/test/fixtures/fixture_database.sqlite +0 -0
  303. data/test/fixtures/fixture_database_2.sqlite +0 -0
  304. data/test/fixtures/movies/first +0 -2
  305. data/test/fixtures/movies/second +0 -2
  306. data/test/fixtures/projects/action_controller +0 -2
  307. data/test/fixtures/projects/active_record +0 -2
  308. data/test/fixtures/topics/first +0 -9
  309. data/test/fixtures/topics/second +0 -8
  310. data/test/inflector_test.rb +0 -104
  311. data/test/thread_safety_test.rb +0 -33
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ # i wonder what will happen here
@@ -0,0 +1 @@
1
+ qwerty
@@ -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,13 @@
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
+ end
7
+
8
+ class LiveParrot < Parrot
9
+ end
10
+
11
+ class DeadParrot < Parrot
12
+ belongs_to :killer, :class_name => 'Pirate'
13
+ end
@@ -0,0 +1,27 @@
1
+ george:
2
+ name: "Curious George"
3
+ treasures: diamond, sapphire
4
+ parrot_sti_class: LiveParrot
5
+
6
+ louis:
7
+ name: "King Louis"
8
+ treasures: [diamond, sapphire]
9
+ parrot_sti_class: LiveParrot
10
+
11
+ frederick:
12
+ name: $LABEL
13
+ parrot_sti_class: LiveParrot
14
+
15
+ polly:
16
+ id: 4
17
+ name: $LABEL
18
+ killer: blackbeard
19
+ treasures: sapphire, ruby
20
+ parrot_sti_class: DeadParrot
21
+
22
+ DEFAULTS: &DEFAULTS
23
+ treasures: sapphire, ruby
24
+ parrot_sti_class: LiveParrot
25
+
26
+ davey:
27
+ <<: *DEFAULTS
@@ -0,0 +1,7 @@
1
+ george_blackbeard:
2
+ parrot_id: <%= Fixtures.identify(:george) %>
3
+ pirate_id: <%= Fixtures.identify(:blackbeard) %>
4
+
5
+ louis_blackbeard:
6
+ parrot_id: <%= Fixtures.identify(:louis) %>
7
+ pirate_id: <%= Fixtures.identify(:blackbeard) %>
@@ -0,0 +1,3 @@
1
+ michael:
2
+ id: 1
3
+ first_name: Michael
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ has_many :readers
3
+ has_many :posts, :through => :readers
4
+ end
@@ -0,0 +1,5 @@
1
+ class Pirate < ActiveRecord::Base
2
+ belongs_to :parrot
3
+ has_and_belongs_to_many :parrots
4
+ has_many :loots, :as => :looter
5
+ end
@@ -0,0 +1,9 @@
1
+ blackbeard:
2
+ catchphrase: "Yar."
3
+ parrot: george
4
+
5
+ redbeard:
6
+ catchphrase: "Avast!"
7
+ parrot: louis
8
+ created_on: <%= 2.weeks.ago.to_s(:db) %>
9
+ updated_on: <%= 2.weeks.ago.to_s(:db) %>
@@ -0,0 +1,59 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :author do
3
+ def greeting
4
+ "hello"
5
+ end
6
+ end
7
+
8
+ belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
9
+
10
+ has_many :comments, :order => "body" do
11
+ def find_most_recent
12
+ find(:first, :order => "id DESC")
13
+ end
14
+ end
15
+
16
+ has_one :very_special_comment
17
+ has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
18
+ has_many :special_comments
19
+ has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
20
+
21
+ has_and_belongs_to_many :categories
22
+ has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
23
+
24
+ has_many :taggings, :as => :taggable
25
+ has_many :tags, :through => :taggings, :include => :tagging do
26
+ def add_joins_and_select
27
+ find :all, :select => 'tags.*, authors.id as author_id', :include => false,
28
+ :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
29
+ end
30
+ end
31
+
32
+ has_many :funky_tags, :through => :taggings, :source => :tag
33
+ has_many :super_tags, :through => :taggings
34
+ has_one :tagging, :as => :taggable
35
+
36
+ has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
37
+ has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
38
+
39
+ has_many :categorizations, :foreign_key => :category_id
40
+ has_many :authors, :through => :categorizations
41
+
42
+ has_many :readers
43
+ has_many :people, :through => :readers
44
+
45
+ def self.what_are_you
46
+ 'a post...'
47
+ end
48
+ end
49
+
50
+ class SpecialPost < Post; end
51
+
52
+ class StiPost < Post
53
+ self.abstract_class = true
54
+ has_one :special_comment, :class_name => "SpecialComment"
55
+ end
56
+
57
+ class SubStiPost < StiPost
58
+ self.table_name = Post.table_name
59
+ end
@@ -0,0 +1,48 @@
1
+ welcome:
2
+ id: 1
3
+ author_id: 1
4
+ title: Welcome to the weblog
5
+ body: Such a lovely day
6
+ type: Post
7
+
8
+ thinking:
9
+ id: 2
10
+ author_id: 1
11
+ title: So I was thinking
12
+ body: Like I hopefully always am
13
+ type: SpecialPost
14
+
15
+ authorless:
16
+ id: 3
17
+ author_id: 0
18
+ title: I don't have any comments
19
+ body: I just don't want to
20
+ type: Post
21
+
22
+ sti_comments:
23
+ id: 4
24
+ author_id: 1
25
+ title: sti comments
26
+ body: hello
27
+ type: Post
28
+
29
+ sti_post_and_comments:
30
+ id: 5
31
+ author_id: 1
32
+ title: sti me
33
+ body: hello
34
+ type: StiPost
35
+
36
+ sti_habtm:
37
+ id: 6
38
+ author_id: 1
39
+ title: habtm sti test
40
+ body: hello
41
+ type: Post
42
+
43
+ eager_other:
44
+ id: 7
45
+ author_id: 2
46
+ title: eager loading with OR'd conditions
47
+ body: hello
48
+ type: Post
@@ -1,3 +1,28 @@
1
1
  class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers
3
- end
2
+ has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
3
+ has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true
4
+ has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
5
+ has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
6
+ has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
7
+ has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true
8
+ has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
9
+ 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}'
10
+ 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}"
11
+ 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>'}"},
12
+ :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
13
+ :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
14
+ :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
15
+
16
+ attr_accessor :developers_log
17
+
18
+ def after_initialize
19
+ @developers_log = []
20
+ end
21
+
22
+ end
23
+
24
+ class SpecialProject < Project
25
+ def hello_world
26
+ "hello there!"
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ action_controller:
2
+ id: 2
3
+ name: Active Controller
4
+
5
+ active_record:
6
+ id: 1
7
+ name: Active Record
@@ -0,0 +1,4 @@
1
+ class Reader < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :person
4
+ end
@@ -0,0 +1,4 @@
1
+ michael_welcome:
2
+ id: 1
3
+ post_id: 1
4
+ person_id: 1
@@ -1,21 +1,37 @@
1
+ require 'fixtures/topic'
2
+
1
3
  class Reply < Topic
2
4
  belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
5
+ has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
6
+
7
+ validate :errors_on_empty_content
8
+ validate_on_create :title_is_wrong_create
3
9
 
4
10
  attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
5
11
 
6
12
  def validate
7
13
  errors.add("title", "Empty") unless attribute_present? "title"
14
+ end
15
+
16
+ def errors_on_empty_content
8
17
  errors.add("content", "Empty") unless attribute_present? "content"
9
18
  end
10
19
 
11
20
  def validate_on_create
12
- errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
13
21
  if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
14
22
  errors.add("title", "is Content Mismatch")
15
23
  end
16
24
  end
17
25
 
26
+ def title_is_wrong_create
27
+ errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
28
+ end
29
+
18
30
  def validate_on_update
19
31
  errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
20
32
  end
21
- end
33
+ end
34
+
35
+ class SillyReply < Reply
36
+ belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
37
+ end
@@ -0,0 +1,5 @@
1
+ distinct1:
2
+ id: 1
3
+
4
+ distinct2:
5
+ id: 2
@@ -0,0 +1,11 @@
1
+ distincts_selects1:
2
+ distinct_id: 1
3
+ select_id: 1
4
+
5
+ distincts_selects2:
6
+ distinct_id: 1
7
+ select_id: 2
8
+
9
+ distincts_selects3:
10
+ distinct_id: 2
11
+ select_id: 3
@@ -0,0 +1,14 @@
1
+ group1:
2
+ id: 1
3
+ select_id: 1
4
+ order: x
5
+
6
+ group2:
7
+ id: 2
8
+ select_id: 2
9
+ order: y
10
+
11
+ group3:
12
+ id: 3
13
+ select_id: 2
14
+ order: z
@@ -0,0 +1,8 @@
1
+ select1:
2
+ id: 1
3
+
4
+ select2:
5
+ id: 2
6
+
7
+ select3:
8
+ id: 3
@@ -0,0 +1,7 @@
1
+ values1:
2
+ id: 1
3
+ group_id: 2
4
+
5
+ values2:
6
+ id: 2
7
+ group_id: 1
@@ -0,0 +1,3 @@
1
+ class Ship < ActiveRecord::Base
2
+ self.record_timestamps = false
3
+ end
@@ -0,0 +1,5 @@
1
+ black_pearl:
2
+ name: "Black Pearl"
3
+ interceptor:
4
+ id: 2
5
+ name: "Interceptor"
@@ -0,0 +1,4 @@
1
+ # used for OracleSynonymTest, see test/synonym_test_oci.rb
2
+ #
3
+ class Subject < ActiveRecord::Base
4
+ end
@@ -1,5 +1,6 @@
1
1
  class Subscriber < ActiveRecord::Base
2
- def self.primary_key
3
- "nick"
4
- end
2
+ set_primary_key 'nick'
3
+ end
4
+
5
+ class SpecialSubscriber < Subscriber
5
6
  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,25 @@
1
+ welcome_general:
2
+ id: 1
3
+ tag_id: 1
4
+ super_tag_id: 2
5
+ taggable_id: 1
6
+ taggable_type: Post
7
+
8
+ thinking_general:
9
+ id: 2
10
+ tag_id: 1
11
+ taggable_id: 2
12
+ taggable_type: Post
13
+
14
+ fake:
15
+ id: 3
16
+ tag_id: 1
17
+ taggable_id: 1
18
+ taggable_type: FakeModel
19
+
20
+ godfather:
21
+ id: 4
22
+ tag_id: 1
23
+ taggable_id: 1
24
+ taggable_type: Item
25
+
@@ -0,0 +1,7 @@
1
+ general:
2
+ id: 1
3
+ name: General
4
+
5
+ misc:
6
+ id: 2
7
+ name: Misc
@@ -0,0 +1,3 @@
1
+ class Task < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ first_task:
3
+ id: 1
4
+ starting: 2005-03-30t06:30:00.00+01:00
5
+ ending: 2005-03-30t08:30:00.00+01:00
6
+ another_task:
7
+ id: 2
@@ -1,15 +1,26 @@
1
1
  class Topic < ActiveRecord::Base
2
- has_many :replies, :foreign_key => "parent_id"
2
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
3
3
  serialize :content
4
4
 
5
5
  before_create :default_written_on
6
- before_destroy :destroy_children #'self.class.delete_all "parent_id = #{id}"'
6
+ before_destroy :destroy_children
7
7
 
8
8
  def parent
9
- self.class.find(parent_id)
9
+ Topic.find(parent_id)
10
10
  end
11
11
 
12
+ # trivial method for testing Array#to_xml with :methods
13
+ def topic_id
14
+ id
15
+ end
16
+
17
+
12
18
  protected
19
+ def approved=(val)
20
+ @custom_approved = val
21
+ write_attribute(:approved, val)
22
+ end
23
+
13
24
  def default_written_on
14
25
  self.written_on = Time.now unless attribute_present?("written_on")
15
26
  end
@@ -17,4 +28,10 @@ class Topic < ActiveRecord::Base
17
28
  def destroy_children
18
29
  self.class.delete_all "parent_id = #{id}"
19
30
  end
31
+
32
+ def after_initialize
33
+ if self.new_record?
34
+ self.author_email_address = 'test@test.com'
35
+ end
36
+ end
20
37
  end
@@ -0,0 +1,22 @@
1
+ first:
2
+ id: 1
3
+ title: The First Topic
4
+ author_name: David
5
+ author_email_address: david@loudthinking.com
6
+ written_on: 2003-07-16t15:28:11.2233+01:00
7
+ last_read: 2004-04-15
8
+ bonus_time: 2005-01-30t15:28:00.00+01:00
9
+ content: Have a nice day
10
+ approved: false
11
+ replies_count: 1
12
+
13
+ second:
14
+ id: 2
15
+ title: The Second Topic's of the day
16
+ author_name: Mary
17
+ written_on: 2003-07-15t15:28:00.0099+01:00
18
+ content: Have a nice day
19
+ approved: true
20
+ replies_count: 0
21
+ parent_id: 1
22
+ type: Reply
@@ -0,0 +1,4 @@
1
+ class Treasure < ActiveRecord::Base
2
+ has_and_belongs_to_many :parrots
3
+ belongs_to :looter, :polymorphic => true
4
+ end
@@ -0,0 +1,10 @@
1
+ diamond:
2
+ name: $LABEL
3
+
4
+ sapphire:
5
+ name: $LABEL
6
+ looter: redbeard (Pirate)
7
+
8
+ ruby:
9
+ name: $LABEL
10
+ looter: louis (Parrot)
@@ -0,0 +1,9 @@
1
+ # This class models a vertex in a directed graph.
2
+ class Vertex < ActiveRecord::Base
3
+ has_many :sink_edges, :class_name => 'Edge', :foreign_key => 'source_id'
4
+ has_many :sinks, :through => :sink_edges
5
+
6
+ has_and_belongs_to_many :sources,
7
+ :class_name => 'Vertex', :join_table => 'edges',
8
+ :foreign_key => 'sink_id', :association_foreign_key => 'source_id'
9
+ end
@@ -0,0 +1,4 @@
1
+ <% (1..5).each do |id| %>
2
+ vertex_<%= id %>:
3
+ id: <%= id %>
4
+ <% end %>