activerecord 2.0.5 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (289) hide show
  1. data/CHANGELOG +168 -6
  2. data/README +27 -22
  3. data/RUNNING_UNIT_TESTS +7 -4
  4. data/Rakefile +22 -25
  5. data/lib/active_record.rb +8 -2
  6. data/lib/active_record/aggregations.rb +21 -12
  7. data/lib/active_record/association_preload.rb +277 -0
  8. data/lib/active_record/associations.rb +481 -295
  9. data/lib/active_record/associations/association_collection.rb +162 -37
  10. data/lib/active_record/associations/association_proxy.rb +71 -7
  11. data/lib/active_record/associations/belongs_to_association.rb +5 -3
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +5 -6
  13. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +12 -64
  14. data/lib/active_record/associations/has_many_association.rb +8 -73
  15. data/lib/active_record/associations/has_many_through_association.rb +68 -117
  16. data/lib/active_record/associations/has_one_association.rb +7 -5
  17. data/lib/active_record/associations/has_one_through_association.rb +28 -0
  18. data/lib/active_record/attribute_methods.rb +69 -19
  19. data/lib/active_record/base.rb +496 -275
  20. data/lib/active_record/calculations.rb +28 -21
  21. data/lib/active_record/callbacks.rb +9 -38
  22. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +3 -2
  23. data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -2
  24. data/lib/active_record/connection_adapters/abstract/query_cache.rb +6 -0
  25. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +232 -45
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +141 -27
  27. data/lib/active_record/connection_adapters/abstract_adapter.rb +9 -13
  28. data/lib/active_record/connection_adapters/mysql_adapter.rb +57 -24
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +143 -42
  30. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  31. data/lib/active_record/connection_adapters/sqlite_adapter.rb +18 -10
  32. data/lib/active_record/dirty.rb +158 -0
  33. data/lib/active_record/fixtures.rb +121 -156
  34. data/lib/active_record/locking/optimistic.rb +14 -11
  35. data/lib/active_record/locking/pessimistic.rb +2 -2
  36. data/lib/active_record/migration.rb +157 -77
  37. data/lib/active_record/named_scope.rb +163 -0
  38. data/lib/active_record/observer.rb +19 -5
  39. data/lib/active_record/reflection.rb +34 -14
  40. data/lib/active_record/schema.rb +7 -14
  41. data/lib/active_record/schema_dumper.rb +4 -4
  42. data/lib/active_record/serialization.rb +5 -5
  43. data/lib/active_record/serializers/json_serializer.rb +37 -28
  44. data/lib/active_record/serializers/xml_serializer.rb +52 -29
  45. data/lib/active_record/test_case.rb +36 -0
  46. data/lib/active_record/timestamp.rb +4 -4
  47. data/lib/active_record/transactions.rb +3 -3
  48. data/lib/active_record/validations.rb +182 -248
  49. data/lib/active_record/version.rb +2 -2
  50. data/test/{fixtures → assets}/example.log +0 -0
  51. data/test/{fixtures → assets}/flowers.jpg +0 -0
  52. data/test/cases/aaa_create_tables_test.rb +24 -0
  53. data/test/cases/active_schema_test_mysql.rb +95 -0
  54. data/test/cases/active_schema_test_postgresql.rb +24 -0
  55. data/test/{adapter_test.rb → cases/adapter_test.rb} +15 -14
  56. data/test/{adapter_test_sqlserver.rb → cases/adapter_test_sqlserver.rb} +95 -95
  57. data/test/{aggregations_test.rb → cases/aggregations_test.rb} +20 -20
  58. data/test/{ar_schema_test.rb → cases/ar_schema_test.rb} +6 -6
  59. data/test/cases/associations/belongs_to_associations_test.rb +412 -0
  60. data/test/{associations → cases/associations}/callbacks_test.rb +24 -10
  61. data/test/{associations → cases/associations}/cascaded_eager_loading_test.rb +18 -17
  62. data/test/cases/associations/eager_load_nested_include_test.rb +83 -0
  63. data/test/{associations → cases/associations}/eager_singularization_test.rb +5 -5
  64. data/test/{associations → cases/associations}/eager_test.rb +216 -51
  65. data/test/{associations → cases/associations}/extension_test.rb +8 -8
  66. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +684 -0
  67. data/test/cases/associations/has_many_associations_test.rb +932 -0
  68. data/test/cases/associations/has_many_through_associations_test.rb +190 -0
  69. data/test/cases/associations/has_one_associations_test.rb +323 -0
  70. data/test/cases/associations/has_one_through_associations_test.rb +74 -0
  71. data/test/{associations → cases/associations}/inner_join_association_test.rb +20 -20
  72. data/test/{associations → cases/associations}/join_model_test.rb +175 -35
  73. data/test/cases/associations_test.rb +262 -0
  74. data/test/{attribute_methods_test.rb → cases/attribute_methods_test.rb} +103 -11
  75. data/test/{base_test.rb → cases/base_test.rb} +338 -191
  76. data/test/{binary_test.rb → cases/binary_test.rb} +6 -4
  77. data/test/{calculations_test.rb → cases/calculations_test.rb} +35 -23
  78. data/test/{callbacks_test.rb → cases/callbacks_test.rb} +7 -7
  79. data/test/{class_inheritable_attributes_test.rb → cases/class_inheritable_attributes_test.rb} +3 -3
  80. data/test/{column_alias_test.rb → cases/column_alias_test.rb} +3 -3
  81. data/test/{connection_test_firebird.rb → cases/connection_test_firebird.rb} +2 -2
  82. data/test/{connection_test_mysql.rb → cases/connection_test_mysql.rb} +2 -2
  83. data/test/{copy_table_test_sqlite.rb → cases/copy_table_test_sqlite.rb} +13 -13
  84. data/test/{datatype_test_postgresql.rb → cases/datatype_test_postgresql.rb} +8 -8
  85. data/test/{date_time_test.rb → cases/date_time_test.rb} +5 -5
  86. data/test/{default_test_firebird.rb → cases/default_test_firebird.rb} +3 -3
  87. data/test/{defaults_test.rb → cases/defaults_test.rb} +8 -6
  88. data/test/{deprecated_finder_test.rb → cases/deprecated_finder_test.rb} +3 -3
  89. data/test/cases/dirty_test.rb +163 -0
  90. data/test/cases/finder_respond_to_test.rb +76 -0
  91. data/test/{finder_test.rb → cases/finder_test.rb} +266 -33
  92. data/test/{fixtures_test.rb → cases/fixtures_test.rb} +88 -72
  93. data/test/cases/helper.rb +47 -0
  94. data/test/{inheritance_test.rb → cases/inheritance_test.rb} +61 -17
  95. data/test/cases/invalid_date_test.rb +24 -0
  96. data/test/{json_serialization_test.rb → cases/json_serialization_test.rb} +36 -11
  97. data/test/{lifecycle_test.rb → cases/lifecycle_test.rb} +16 -13
  98. data/test/{locking_test.rb → cases/locking_test.rb} +17 -10
  99. data/test/{method_scoping_test.rb → cases/method_scoping_test.rb} +75 -39
  100. data/test/{migration_test.rb → cases/migration_test.rb} +420 -80
  101. data/test/{migration_test_firebird.rb → cases/migration_test_firebird.rb} +3 -3
  102. data/test/{mixin_test.rb → cases/mixin_test.rb} +7 -6
  103. data/test/{modules_test.rb → cases/modules_test.rb} +11 -6
  104. data/test/{multiple_db_test.rb → cases/multiple_db_test.rb} +5 -5
  105. data/test/cases/named_scope_test.rb +157 -0
  106. data/test/{pk_test.rb → cases/pk_test.rb} +10 -10
  107. data/test/{query_cache_test.rb → cases/query_cache_test.rb} +12 -10
  108. data/test/{readonly_test.rb → cases/readonly_test.rb} +11 -11
  109. data/test/{reflection_test.rb → cases/reflection_test.rb} +15 -14
  110. data/test/{reserved_word_test_mysql.rb → cases/reserved_word_test_mysql.rb} +4 -5
  111. data/test/{schema_authorization_test_postgresql.rb → cases/schema_authorization_test_postgresql.rb} +5 -5
  112. data/test/cases/schema_dumper_test.rb +138 -0
  113. data/test/cases/schema_test_postgresql.rb +102 -0
  114. data/test/{serialization_test.rb → cases/serialization_test.rb} +7 -7
  115. data/test/{synonym_test_oracle.rb → cases/synonym_test_oracle.rb} +5 -5
  116. data/test/{table_name_test_sqlserver.rb → cases/table_name_test_sqlserver.rb} +3 -3
  117. data/test/{threaded_connections_test.rb → cases/threaded_connections_test.rb} +7 -7
  118. data/test/{transactions_test.rb → cases/transactions_test.rb} +31 -5
  119. data/test/{unconnected_test.rb → cases/unconnected_test.rb} +2 -2
  120. data/test/{validations_test.rb → cases/validations_test.rb} +141 -39
  121. data/test/{xml_serialization_test.rb → cases/xml_serialization_test.rb} +12 -12
  122. data/test/config.rb +5 -0
  123. data/test/connections/native_db2/connection.rb +1 -1
  124. data/test/connections/native_firebird/connection.rb +1 -1
  125. data/test/connections/native_frontbase/connection.rb +1 -1
  126. data/test/connections/native_mysql/connection.rb +1 -1
  127. data/test/connections/native_openbase/connection.rb +1 -1
  128. data/test/connections/native_oracle/connection.rb +1 -1
  129. data/test/connections/native_postgresql/connection.rb +1 -3
  130. data/test/connections/native_sqlite/connection.rb +2 -2
  131. data/test/connections/native_sqlite3/connection.rb +2 -2
  132. data/test/connections/native_sqlite3/in_memory_connection.rb +3 -3
  133. data/test/connections/native_sybase/connection.rb +1 -1
  134. data/test/fixtures/author_addresses.yml +5 -0
  135. data/test/fixtures/authors.yml +2 -0
  136. data/test/fixtures/clubs.yml +6 -0
  137. data/test/fixtures/jobs.yml +7 -0
  138. data/test/fixtures/members.yml +4 -0
  139. data/test/fixtures/memberships.yml +20 -0
  140. data/test/fixtures/owners.yml +7 -0
  141. data/test/fixtures/people.yml +4 -1
  142. data/test/fixtures/pets.yml +14 -0
  143. data/test/fixtures/posts.yml +1 -0
  144. data/test/fixtures/price_estimates.yml +7 -0
  145. data/test/fixtures/readers.yml +5 -0
  146. data/test/fixtures/references.yml +17 -0
  147. data/test/fixtures/sponsors.yml +9 -0
  148. data/test/fixtures/subscribers.yml +7 -0
  149. data/test/fixtures/subscriptions.yml +12 -0
  150. data/test/fixtures/taggings.yml +4 -1
  151. data/test/fixtures/topics.yml +22 -2
  152. data/test/fixtures/warehouse-things.yml +3 -0
  153. data/test/{fixtures/migrations_with_decimal → migrations/decimal}/1_give_me_big_numbers.rb +0 -0
  154. data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/1_people_have_last_names.rb +1 -1
  155. data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/2_we_need_reminders.rb +1 -1
  156. data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/3_foo.rb +0 -0
  157. data/test/{fixtures/migrations → migrations/duplicate}/3_innocent_jointable.rb +0 -0
  158. data/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
  159. data/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
  160. data/test/{fixtures/migrations_with_duplicate → migrations/interleaved/pass_1}/3_innocent_jointable.rb +0 -0
  161. data/test/{fixtures/migrations → migrations/interleaved/pass_2}/1_people_have_last_names.rb +1 -1
  162. data/test/{fixtures/migrations_with_missing_versions/4_innocent_jointable.rb → migrations/interleaved/pass_2/3_innocent_jointable.rb} +0 -0
  163. data/test/{fixtures/migrations_with_missing_versions → migrations/interleaved/pass_3}/1_people_have_last_names.rb +1 -1
  164. data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
  165. data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
  166. data/test/{fixtures/migrations_with_missing_versions → migrations/missing}/1000_people_have_middle_names.rb +1 -1
  167. data/test/migrations/missing/1_people_have_last_names.rb +9 -0
  168. data/test/{fixtures/migrations_with_missing_versions → migrations/missing}/3_we_need_reminders.rb +1 -1
  169. data/test/migrations/missing/4_innocent_jointable.rb +12 -0
  170. data/test/migrations/valid/1_people_have_last_names.rb +9 -0
  171. data/test/{fixtures/migrations → migrations/valid}/2_we_need_reminders.rb +1 -1
  172. data/test/migrations/valid/3_innocent_jointable.rb +12 -0
  173. data/test/{fixtures → models}/author.rb +28 -4
  174. data/test/{fixtures → models}/auto_id.rb +0 -0
  175. data/test/{fixtures → models}/binary.rb +0 -0
  176. data/test/{fixtures → models}/book.rb +0 -0
  177. data/test/{fixtures → models}/categorization.rb +0 -0
  178. data/test/{fixtures → models}/category.rb +8 -5
  179. data/test/{fixtures → models}/citation.rb +0 -0
  180. data/test/models/club.rb +7 -0
  181. data/test/{fixtures → models}/column_name.rb +0 -0
  182. data/test/{fixtures → models}/comment.rb +5 -3
  183. data/test/{fixtures → models}/company.rb +15 -6
  184. data/test/{fixtures → models}/company_in_module.rb +5 -3
  185. data/test/{fixtures → models}/computer.rb +0 -1
  186. data/test/{fixtures → models}/contact.rb +1 -1
  187. data/test/{fixtures → models}/course.rb +0 -0
  188. data/test/{fixtures → models}/customer.rb +8 -8
  189. data/test/{fixtures → models}/default.rb +0 -0
  190. data/test/{fixtures → models}/developer.rb +14 -10
  191. data/test/{fixtures → models}/edge.rb +0 -0
  192. data/test/{fixtures → models}/entrant.rb +0 -0
  193. data/test/models/guid.rb +2 -0
  194. data/test/{fixtures → models}/item.rb +0 -0
  195. data/test/models/job.rb +5 -0
  196. data/test/{fixtures → models}/joke.rb +0 -0
  197. data/test/{fixtures → models}/keyboard.rb +0 -0
  198. data/test/{fixtures → models}/legacy_thing.rb +0 -0
  199. data/test/{fixtures → models}/matey.rb +0 -0
  200. data/test/models/member.rb +9 -0
  201. data/test/models/membership.rb +9 -0
  202. data/test/{fixtures → models}/minimalistic.rb +0 -0
  203. data/test/{fixtures → models}/mixed_case_monkey.rb +0 -0
  204. data/test/{fixtures → models}/movie.rb +0 -0
  205. data/test/{fixtures → models}/order.rb +2 -2
  206. data/test/models/owner.rb +4 -0
  207. data/test/{fixtures → models}/parrot.rb +0 -0
  208. data/test/models/person.rb +10 -0
  209. data/test/models/pet.rb +4 -0
  210. data/test/models/pirate.rb +9 -0
  211. data/test/{fixtures → models}/post.rb +23 -2
  212. data/test/models/price_estimate.rb +3 -0
  213. data/test/{fixtures → models}/project.rb +1 -0
  214. data/test/{fixtures → models}/reader.rb +0 -0
  215. data/test/models/reference.rb +4 -0
  216. data/test/{fixtures → models}/reply.rb +7 -5
  217. data/test/{fixtures → models}/ship.rb +0 -0
  218. data/test/models/sponsor.rb +4 -0
  219. data/test/{fixtures → models}/subject.rb +0 -0
  220. data/test/{fixtures → models}/subscriber.rb +2 -0
  221. data/test/models/subscription.rb +4 -0
  222. data/test/{fixtures → models}/tag.rb +0 -0
  223. data/test/{fixtures → models}/tagging.rb +0 -0
  224. data/test/{fixtures → models}/task.rb +0 -0
  225. data/test/{fixtures → models}/topic.rb +32 -4
  226. data/test/{fixtures → models}/treasure.rb +2 -0
  227. data/test/{fixtures → models}/vertex.rb +0 -0
  228. data/test/models/warehouse_thing.rb +5 -0
  229. data/test/schema/mysql_specific_schema.rb +12 -0
  230. data/test/schema/postgresql_specific_schema.rb +103 -0
  231. data/test/schema/schema.rb +421 -0
  232. data/test/schema/schema2.rb +6 -0
  233. data/test/schema/sqlite_specific_schema.rb +25 -0
  234. data/test/schema/sqlserver_specific_schema.rb +5 -0
  235. metadata +192 -176
  236. data/test/aaa_create_tables_test.rb +0 -72
  237. data/test/abstract_unit.rb +0 -84
  238. data/test/active_schema_test_mysql.rb +0 -46
  239. data/test/all.sh +0 -8
  240. data/test/association_inheritance_reload.rb +0 -14
  241. data/test/associations_test.rb +0 -2177
  242. data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +0 -1
  243. data/test/fixtures/bad_fixtures/attr_with_spaces +0 -1
  244. data/test/fixtures/bad_fixtures/blank_line +0 -3
  245. data/test/fixtures/bad_fixtures/duplicate_attributes +0 -3
  246. data/test/fixtures/bad_fixtures/missing_value +0 -1
  247. data/test/fixtures/db_definitions/db2.drop.sql +0 -33
  248. data/test/fixtures/db_definitions/db2.sql +0 -235
  249. data/test/fixtures/db_definitions/db22.drop.sql +0 -2
  250. data/test/fixtures/db_definitions/db22.sql +0 -5
  251. data/test/fixtures/db_definitions/firebird.drop.sql +0 -65
  252. data/test/fixtures/db_definitions/firebird.sql +0 -310
  253. data/test/fixtures/db_definitions/firebird2.drop.sql +0 -2
  254. data/test/fixtures/db_definitions/firebird2.sql +0 -6
  255. data/test/fixtures/db_definitions/frontbase.drop.sql +0 -33
  256. data/test/fixtures/db_definitions/frontbase.sql +0 -273
  257. data/test/fixtures/db_definitions/frontbase2.drop.sql +0 -1
  258. data/test/fixtures/db_definitions/frontbase2.sql +0 -4
  259. data/test/fixtures/db_definitions/openbase.drop.sql +0 -2
  260. data/test/fixtures/db_definitions/openbase.sql +0 -318
  261. data/test/fixtures/db_definitions/openbase2.drop.sql +0 -2
  262. data/test/fixtures/db_definitions/openbase2.sql +0 -7
  263. data/test/fixtures/db_definitions/oracle.drop.sql +0 -67
  264. data/test/fixtures/db_definitions/oracle.sql +0 -330
  265. data/test/fixtures/db_definitions/oracle2.drop.sql +0 -2
  266. data/test/fixtures/db_definitions/oracle2.sql +0 -6
  267. data/test/fixtures/db_definitions/postgresql.drop.sql +0 -44
  268. data/test/fixtures/db_definitions/postgresql.sql +0 -292
  269. data/test/fixtures/db_definitions/postgresql2.drop.sql +0 -2
  270. data/test/fixtures/db_definitions/postgresql2.sql +0 -4
  271. data/test/fixtures/db_definitions/schema.rb +0 -354
  272. data/test/fixtures/db_definitions/schema2.rb +0 -11
  273. data/test/fixtures/db_definitions/sqlite.drop.sql +0 -33
  274. data/test/fixtures/db_definitions/sqlite.sql +0 -219
  275. data/test/fixtures/db_definitions/sqlite2.drop.sql +0 -2
  276. data/test/fixtures/db_definitions/sqlite2.sql +0 -5
  277. data/test/fixtures/db_definitions/sybase.drop.sql +0 -35
  278. data/test/fixtures/db_definitions/sybase.sql +0 -222
  279. data/test/fixtures/db_definitions/sybase2.drop.sql +0 -4
  280. data/test/fixtures/db_definitions/sybase2.sql +0 -5
  281. data/test/fixtures/developers_projects/david_action_controller +0 -3
  282. data/test/fixtures/developers_projects/david_active_record +0 -3
  283. data/test/fixtures/developers_projects/jamis_active_record +0 -2
  284. data/test/fixtures/person.rb +0 -4
  285. data/test/fixtures/pirate.rb +0 -5
  286. data/test/fixtures/subscribers/first +0 -2
  287. data/test/fixtures/subscribers/second +0 -2
  288. data/test/schema_dumper_test.rb +0 -131
  289. data/test/schema_test_postgresql.rb +0 -64
data/CHANGELOG CHANGED
@@ -1,20 +1,182 @@
1
- *2.0.5* (October 19th, 2008)
1
+ *2.1.0 (May 31st, 2008)*
2
2
 
3
- * Added SQL escaping for :limit and :offset in MySQL [Jonathan Wiess]
3
+ * Add ActiveRecord::Base.sti_name that checks ActiveRecord::Base#store_full_sti_class? and returns either the full or demodulized name. [rick]
4
4
 
5
+ * Add first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
5
6
 
6
- *2.0.4* (2nd September 2008)
7
+ * Added SQL escaping for :limit and :offset #288 [Aaron Bedra, Steven Bristol, Jonathan Wiess]
8
+
9
+ * Added first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
10
+
11
+ * Ensure hm:t preloading honours reflection options. Resolves #137. [Frederick Cheung]
12
+
13
+ * Added protection against duplicate migration names (Aslak Hellesøy) [#112]
14
+
15
+ * Base#instantiate_time_object: eliminate check for Time.zone, since we can assume this is set if time_zone_aware_attributes is set to true [Geoff Buesing]
16
+
17
+ * Time zone aware attribute methods use Time.zone.parse instead of #to_time for String arguments, so that offset information in String is respected. Resolves #105. [Scott Fleckenstein, Geoff Buesing]
18
+
19
+ * Added change_table for migrations (Jeff Dean) [#71]. Example:
20
+
21
+ change_table :videos do |t|
22
+ t.timestamps # adds created_at, updated_at
23
+ t.belongs_to :goat # adds goat_id integer
24
+ t.string :name, :email, :limit => 20 # adds name and email both with a 20 char limit
25
+ t.remove :name, :email # removes the name and email columns
26
+ end
27
+
28
+ * Fixed has_many :through .create with no parameters caused a "can't dup NilClass" error (Steven Soroka) [#85]
29
+
30
+ * Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39]
31
+
32
+ * Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67]
33
+
34
+ * Fixed that change_column should be able to use :null => true on a field that formerly had false [Nate Wiger] [#26]
35
+
36
+ * Added that the MySQL adapter should map integer to either smallint, int, or bigint depending on the :limit just like PostgreSQL [DHH]
37
+
38
+ * Change validates_uniqueness_of :case_sensitive option default back to true (from [9160]). Love your database columns, don't LOWER them. [rick]
39
+
40
+ * Add support for interleaving migrations by storing which migrations have run in the new schema_migrations table. Closes #11493 [jordi]
41
+
42
+ * ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal]
43
+
44
+ * Ensure that respond_to? considers dynamic finder methods. Closes #11538. [floehopper]
45
+
46
+ * Ensure that save on parent object fails for invalid has_one association. Closes #10518. [Pratik]
47
+
48
+ * Remove duplicate code from associations. [Pratik]
49
+
50
+ * Refactor HasManyThroughAssociation to inherit from HasManyAssociation. Association callbacks and <association>_ids= now work with hm:t. #11516 [rubyruy]
51
+
52
+ * Ensure HABTM#create and HABTM#build do not load entire association. [Pratik]
53
+
54
+ * Improve documentation. [Xavier Noria, Jack Danger Canty, leethal]
55
+
56
+ * Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {"post": {"title": ...}} [rick]
57
+
58
+ Post.find(1).to_json # => {"title": ...}
59
+ config.active_record.include_root_in_json = true
60
+ Post.find(1).to_json # => {"post": {"title": ...}}
61
+
62
+ * Add efficient #include? to AssociationCollection (for has_many/has_many :through/habtm). [stopdropandrew]
63
+
64
+ * PostgreSQL: create_ and drop_database support. #9042 [ez, pedz, nicksieger]
65
+
66
+ * Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [nik.wakelin, cavalle]
67
+
68
+ * Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable. [Jeremy Kemper]
69
+
70
+ * Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled [Geoff Buesing]
71
+
72
+ * Fixed that validates_size_of :within works in associations #11295, #10019 [cavalle]
73
+
74
+ * Track changes to unsaved attributes. [Jeremy Kemper]
75
+
76
+ * Switched to UTC-timebased version numbers for migrations and the schema. This will as good as eliminate the problem of multiple migrations getting the same version assigned in different branches. Also added rake db:migrate:up/down to apply individual migrations that may need to be run when you merge branches #11458 [jbarnette]
77
+
78
+ * Fixed that has_many :through would ignore the hash conditions #11447 [miloops]
79
+
80
+ * Fix issue where the :uniq option of a has_many :through association is ignored when find(:all) is called. Closes #9407 [cavalle]
81
+
82
+ * Fix duplicate table alias error when including an association with a has_many :through association on the same join table. Closes #7310 [cavalle]
83
+
84
+ * More efficient association preloading code that compacts a through_records array in a central location. Closes #11427 [danger]
85
+
86
+ * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert]
87
+
88
+ * Fixed that ActiveRecord#Base.find_or_create/initialize would not honor attr_protected/accessible when used with a hash #11422 [miloops]
89
+
90
+ * Added ActiveRecord#Base.all/first/last as aliases for find(:all/:first/:last) #11413 [nkallen, thechrisoshow]
91
+
92
+ * Merge the has_finder gem, renamed as 'named_scope'. #11404 [nkallen]
93
+
94
+ class Article < ActiveRecord::Base
95
+ named_scope :published, :conditions => {:published => true}
96
+ named_scope :popular, :conditions => ...
97
+ end
98
+
99
+ Article.published.paginate(:page => 1)
100
+ Article.published.popular.count
101
+ Article.popular.find(:first)
102
+ Article.popular.find(:all, :conditions => {...})
103
+
104
+ See http://pivots.pivotallabs.com/users/nick/blog/articles/284-hasfinder-it-s-now-easier-than-ever-to-create-complex-re-usable-sql-queries
105
+
106
+ * Add has_one :through support. #4756 [thechrisoshow]
7
107
 
8
108
  * Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow]
9
109
 
110
+ * Added logging for dependency load errors with fixtures #11056 [stuthulhu]
111
+
112
+ * Time zone aware attributes use Time#in_time_zone [Geoff Buesing]
113
+
114
+ * Fixed that scoped joins would not always be respected #6821 [Theory/Danger]
115
+
10
116
  * Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]
11
117
 
118
+ * Added add/remove_timestamps to the schema statements for adding the created_at/updated_at columns on existing tables #11129 [jramirez]
119
+
120
+ * Added ActiveRecord::Base.find(:last) #11338 [miloops]
121
+
122
+ * test_native_types expects DateTime.local_offset instead of DateTime.now.offset; fixes test breakage due to dst transition [Geoff Buesing]
123
+
124
+ * Add :readonly option to HasManyThrough associations. #11156 [miloops]
125
+
126
+ * Improve performance on :include/:conditions/:limit queries by selectively joining in the pre-query. #9560 [dasil003]
127
+
128
+ * Perf fix: Avoid the use of named block arguments. Closes #11109 [adymo]
129
+
130
+ * PostgreSQL: support server versions 7.4 through 8.0 and the ruby-pg driver. #11127 [jdavis]
131
+
132
+ * Ensure association preloading doesn't break when an association returns nil. ##11145 [GMFlash]
133
+
134
+ * Make dynamic finders respect the :include on HasManyThrough associations. #10998. [cpytel]
135
+
136
+ * Base#instantiate_time_object only uses Time.zone when Base.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability [Geoff Buesing]
137
+
138
+ * Refactor ConnectionAdapters::Column.new_time: leverage DateTime failover behavior of Time#time_with_datetime_fallback [Geoff Buesing]
139
+
140
+ * Improve associations performance by using symbol callbacks instead of string callbacks. #11108 [adymo]
141
+
142
+ * Optimise the BigDecimal conversion code. #11110 [adymo]
143
+
144
+ * Introduce the :readonly option to all associations. Records from the association cannot be saved. #11084 [miloops]
145
+
146
+ * Multiparameter attributes for time columns fail over to DateTime when out of range of Time [Geoff Buesing]
147
+
148
+ * Base#instantiate_time_object uses Time.zone.local() [Geoff Buesing]
149
+
150
+ * Add timezone-aware attribute readers and writers. #10982 [Geoff Buesing]
151
+
152
+ * Instantiating time objects in multiparameter attributes uses Time.zone if available. #10982 [rick]
153
+
154
+ * Add note about how ActiveRecord::Observer classes are initialized in a Rails app. #10980 [fxn]
155
+
156
+ * MySQL: omit text/blob defaults from the schema instead of using an empty string. #10963 [mdeiters]
157
+
158
+ * belongs_to supports :dependent => :destroy and :delete. #10592 [Jonathan Viney]
159
+
160
+ * Introduce preload query strategy for eager :includes. #9640 [Frederick Cheung, Aleksey Kondratenko, codafoo]
161
+
162
+ * Support aggregations in finder conditions. #10572 [Ryan Kinderman]
163
+
164
+ * Organize and clean up the Active Record test suite. #10742 [John Barnette]
165
+
12
166
  * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
13
167
 
14
168
  * Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
15
169
 
170
+ * Fixtures: removed support for the ancient pre-YAML file format. #10736 [John Barnette]
171
+
172
+ * More thoroughly quote table names. #10698 [dimdenis, lotswholetime, Jeremy Kemper]
173
+
16
174
  * update_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. #10686 [Brendan Ribera]
17
175
 
176
+ * Added ActiveRecord::Base.cache_key to make it easier to cache Active Records in combination with the new ActiveSupport::Cache::* libraries [DHH]
177
+
178
+ * Make sure CSV fixtures are compatible with ruby 1.9's new csv implementation. [JEG2]
179
+
18
180
  * Added by parameter to increment, decrement, and their bang varieties so you can do player1.increment!(:points, 5) #10542 [Sam]
19
181
 
20
182
  * Optimize ActiveRecord::Base#exists? to use #select_all instead of #find. Closes #10605 [jamesh, fcheung, protocool]
@@ -25,7 +187,7 @@
25
187
 
26
188
  * SQLite: fix rename_ and remove_column for columns with unique indexes. #10576 [Brandon Keepers]
27
189
 
28
- * Ruby 1.9 compatibility. [Jeremy Kemper]
190
+ * Ruby 1.9 compatibility. #10655 [Jeremy Kemper, Dirkjan Bussink]
29
191
 
30
192
 
31
193
  *2.0.2* (December 16th, 2007)
@@ -87,7 +249,7 @@ so newlines etc are escaped #10385 [Norbert Crombach]
87
249
 
88
250
  * Dynamic finders on association collections respect association :order and :limit. #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty]
89
251
 
90
- * Add 'foxy' support for fixtures of polymorphic associations. #10183 [jbarnette, David Lowenfels]
252
+ * Add 'foxy' support for fixtures of polymorphic associations. #10183 [John Barnette, David Lowenfels]
91
253
 
92
254
  * validates_inclusion_of and validates_exclusion_of allow formatted :message strings. #8132 [devrieda, Mike Naberezny]
93
255
 
@@ -135,7 +297,7 @@ so newlines etc are escaped #10385 [Norbert Crombach]
135
297
  - autofill timestamp columns
136
298
  - support YAML defaults
137
299
  - fixture label interpolation
138
- Enabled for fixtures that correspond to a model class and don't specify a primary key value. #9981 [jbarnette]
300
+ Enabled for fixtures that correspond to a model class and don't specify a primary key value. #9981 [John Barnette]
139
301
 
140
302
  * Add docs explaining how to protect all attributes using attr_accessible with no arguments. Closes #9631 [boone, rmm5t]
141
303
 
data/README CHANGED
@@ -102,21 +102,14 @@ A short rundown of the major features:
102
102
  {Learn more}[link:classes/ActiveRecord/Base.html]
103
103
 
104
104
 
105
- * Transaction support on both a database and object level. The latter is implemented
106
- by using Transaction::Simple[http://railsmanual.com/module/Transaction::Simple]
105
+ * Transactions
107
106
 
108
- # Just database transaction
107
+ # Database transaction
109
108
  Account.transaction do
110
109
  david.withdrawal(100)
111
110
  mary.deposit(100)
112
111
  end
113
112
 
114
- # Database and object transaction
115
- Account.transaction(david, mary) do
116
- david.withdrawal(100)
117
- mary.deposit(100)
118
- end
119
-
120
113
  {Learn more}[link:classes/ActiveRecord/Transactions/ClassMethods.html]
121
114
 
122
115
 
@@ -171,6 +164,28 @@ A short rundown of the major features:
171
164
  ActiveRecord::Base.logger = Log4r::Logger.new("Application Log")
172
165
 
173
166
 
167
+ * Database agnostic schema management with Migrations
168
+
169
+ class AddSystemSettings < ActiveRecord::Migration
170
+ def self.up
171
+ create_table :system_settings do |t|
172
+ t.string :name
173
+ t.string :label
174
+ t.text :value
175
+ t.string :type
176
+ t.integer :position
177
+ end
178
+
179
+ SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
180
+ end
181
+
182
+ def self.down
183
+ drop_table :system_settings
184
+ end
185
+ end
186
+
187
+ {Learn more}[link:classes/ActiveRecord/Migration.html]
188
+
174
189
  == Simple example (1/2): Defining tables and classes (using MySQL)
175
190
 
176
191
  Data definitions are specified only in the database. Active Record queries the database for
@@ -274,16 +289,6 @@ Bi-directional associations thanks to the "belongs_to" macro
274
289
  thirty_seven_signals.firm.nil? # true
275
290
 
276
291
 
277
- == Examples
278
-
279
- Active Record ships with a couple of examples that should give you a good feel for
280
- operating usage. Be sure to edit the <tt>examples/shared_setup.rb</tt> file for your
281
- own database before running the examples. Possibly also the table definition SQL in
282
- the examples themselves.
283
-
284
- It's also highly recommended to have a look at the unit tests. Read more in link:files/RUNNING_UNIT_TESTS.html
285
-
286
-
287
292
  == Philosophy
288
293
 
289
294
  Active Record attempts to provide a coherent wrapper as a solution for the inconvenience that is
@@ -321,7 +326,7 @@ then use:
321
326
 
322
327
  % [sudo] gem install activerecord-1.10.0.gem
323
328
 
324
- You can also install Active Record the old-fashion way with the following command:
329
+ You can also install Active Record the old-fashioned way with the following command:
325
330
 
326
331
  % [sudo] ruby install.rb
327
332
 
@@ -342,5 +347,5 @@ RubyForge page at http://rubyforge.org/projects/activerecord. And as Jim from Ra
342
347
  remember to update the corresponding unit tests. If fact, I prefer
343
348
  new feature to be submitted in the form of new unit tests.
344
349
 
345
- For other information, feel free to ask on the ruby-talk mailing list
346
- (which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com.
350
+ For other information, feel free to ask on the rubyonrails-talk
351
+ (http://groups.google.com/group/rubyonrails-talk) mailing list.
@@ -5,7 +5,7 @@ The default names for the test databases are "activerecord_unittest" and
5
5
  to update the connection adapter setups you want to test with in
6
6
  test/connections/<your database>/connection.rb.
7
7
  When you have the database online, you can import the fixture tables with
8
- the test/fixtures/db_definitions/*.sql files.
8
+ the test/schema/*.sql files.
9
9
 
10
10
  Make sure that you create database objects with the same user that you specified in
11
11
  connection.rb otherwise (on Postgres, at least) tests for default values will fail.
@@ -22,12 +22,15 @@ Rake can be found at http://rake.rubyforge.org
22
22
 
23
23
  == Running by hand
24
24
 
25
- Unit tests are located in test directory. If you only want to run a single test suite,
25
+ Unit tests are located in test/cases directory. If you only want to run a single test suite,
26
26
  you can do so with:
27
27
 
28
- rake test_mysql TEST=base_test.rb
28
+ rake test_mysql TEST=test/cases/base_test.rb
29
29
 
30
- That'll run the base suite using the MySQL-Ruby adapter.
30
+ That'll run the base suite using the MySQL-Ruby adapter. Some tests rely on the schema
31
+ being initialized - you can initialize the schema with:
32
+
33
+ rake test_mysql TEST=test/cases/aaa_create_tables_test.rb
31
34
 
32
35
 
33
36
 
data/Rakefile CHANGED
@@ -5,8 +5,9 @@ require 'rake/rdoctask'
5
5
  require 'rake/packagetask'
6
6
  require 'rake/gempackagetask'
7
7
  require 'rake/contrib/sshpublisher'
8
- require 'rake/contrib/rubyforgepublisher'
8
+
9
9
  require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
10
+ require File.expand_path(File.dirname(__FILE__)) + "/test/config"
10
11
 
11
12
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
12
13
  PKG_NAME = 'activerecord'
@@ -18,6 +19,8 @@ RELEASE_NAME = "REL #{PKG_VERSION}"
18
19
  RUBY_FORGE_PROJECT = "activerecord"
19
20
  RUBY_FORGE_USER = "webster132"
20
21
 
22
+ MYSQL_DB_USER = 'rails'
23
+
21
24
  PKG_FILES = FileList[
22
25
  "lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "Rakefile"
23
26
  ].exclude(/\bCVS\b|~$/)
@@ -33,7 +36,7 @@ for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase op
33
36
  Rake::TestTask.new("test_#{adapter}") { |t|
34
37
  t.libs << "test" << "test/connections/native_#{adapter}"
35
38
  adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
36
- t.pattern = "test/**/*_test{,_#{adapter_short}}.rb"
39
+ t.test_files=Dir.glob( "test/cases/**/*_test{,_#{adapter_short}}.rb" ).sort
37
40
  t.verbose = true
38
41
  }
39
42
 
@@ -42,21 +45,17 @@ for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase op
42
45
  end
43
46
  end
44
47
 
45
- SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))
46
-
47
48
  namespace :mysql do
48
49
  desc 'Build the MySQL test databases'
49
50
  task :build_databases do
50
- %x( mysqladmin create activerecord_unittest )
51
- %x( mysqladmin create activerecord_unittest2 )
52
- %x( mysql -e "grant all on activerecord_unittest.* to rails@localhost" )
53
- %x( mysql -e "grant all on activerecord_unittest2.* to rails@localhost" )
51
+ %x( mysqladmin --user=#{MYSQL_DB_USER} create activerecord_unittest )
52
+ %x( mysqladmin --user=#{MYSQL_DB_USER} create activerecord_unittest2 )
54
53
  end
55
54
 
56
55
  desc 'Drop the MySQL test databases'
57
56
  task :drop_databases do
58
- %x( mysqladmin -f drop activerecord_unittest )
59
- %x( mysqladmin -f drop activerecord_unittest2 )
57
+ %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest )
58
+ %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest2 )
60
59
  end
61
60
 
62
61
  desc 'Rebuild the MySQL test databases'
@@ -71,16 +70,14 @@ task :rebuild_mysql_databases => 'mysql:rebuild_databases'
71
70
  namespace :postgresql do
72
71
  desc 'Build the PostgreSQL test databases'
73
72
  task :build_databases do
74
- %x( createdb -U postgres activerecord_unittest )
75
- %x( createdb -U postgres activerecord_unittest2 )
76
- %x( psql activerecord_unittest -f #{File.join(SCHEMA_PATH, 'postgresql.sql')} postgres )
77
- %x( psql activerecord_unittest2 -f #{File.join(SCHEMA_PATH, 'postgresql2.sql')} postgres )
73
+ %x( createdb activerecord_unittest )
74
+ %x( createdb activerecord_unittest2 )
78
75
  end
79
76
 
80
77
  desc 'Drop the PostgreSQL test databases'
81
78
  task :drop_databases do
82
- %x( dropdb -U postgres activerecord_unittest )
83
- %x( dropdb -U postgres activerecord_unittest2 )
79
+ %x( dropdb activerecord_unittest )
80
+ %x( dropdb activerecord_unittest2 )
84
81
  end
85
82
 
86
83
  desc 'Rebuild the PostgreSQL test databases'
@@ -119,8 +116,8 @@ namespace :frontbase do
119
116
  DISCONNECT ALL;
120
117
  )
121
118
  end
122
- create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_PATH, 'frontbase.sql')]
123
- create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_PATH, 'frontbase2.sql')]
119
+ create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_ROOT, 'frontbase.sql')]
120
+ create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_ROOT, 'frontbase2.sql')]
124
121
  execute_frontbase_sql = Proc.new do |sql|
125
122
  system(<<-SHELL)
126
123
  /Library/FrontBase/bin/sql92 <<-SQL
@@ -174,12 +171,12 @@ spec = Gem::Specification.new do |s|
174
171
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
175
172
  end
176
173
 
177
- s.add_dependency('activesupport', '= 2.0.5' + PKG_BUILD)
174
+ s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
178
175
 
179
- s.files.delete "test/fixtures/fixture_database.sqlite"
180
- s.files.delete "test/fixtures/fixture_database_2.sqlite"
181
- s.files.delete "test/fixtures/fixture_database.sqlite3"
182
- s.files.delete "test/fixtures/fixture_database_2.sqlite3"
176
+ s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
177
+ s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
178
+ s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite3"
179
+ s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite3"
183
180
  s.require_path = 'lib'
184
181
  s.autorequire = 'active_record'
185
182
 
@@ -228,8 +225,8 @@ end
228
225
 
229
226
  desc "Publish the beta gem"
230
227
  task :pgem => [:package] do
231
- Rake::SshFilePublisher.new("david@greed.loudthinking.com", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
232
- `ssh david@greed.loudthinking.com '/u/sites/gems/gemupdate.sh'`
228
+ Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
229
+ `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
233
230
  end
234
231
 
235
232
  desc "Publish the API documentation"
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2007 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2008 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -37,12 +37,14 @@ unless defined? ActiveSupport
37
37
  end
38
38
 
39
39
  require 'active_record/base'
40
+ require 'active_record/named_scope'
40
41
  require 'active_record/observer'
41
42
  require 'active_record/query_cache'
42
43
  require 'active_record/validations'
43
44
  require 'active_record/callbacks'
44
45
  require 'active_record/reflection'
45
46
  require 'active_record/associations'
47
+ require 'active_record/association_preload'
46
48
  require 'active_record/aggregations'
47
49
  require 'active_record/transactions'
48
50
  require 'active_record/timestamp'
@@ -53,22 +55,26 @@ require 'active_record/schema'
53
55
  require 'active_record/calculations'
54
56
  require 'active_record/serialization'
55
57
  require 'active_record/attribute_methods'
58
+ require 'active_record/dirty'
56
59
 
57
60
  ActiveRecord::Base.class_eval do
58
61
  extend ActiveRecord::QueryCache
59
62
  include ActiveRecord::Validations
60
63
  include ActiveRecord::Locking::Optimistic
61
64
  include ActiveRecord::Locking::Pessimistic
65
+ include ActiveRecord::AttributeMethods
66
+ include ActiveRecord::Dirty
62
67
  include ActiveRecord::Callbacks
63
68
  include ActiveRecord::Observing
64
69
  include ActiveRecord::Timestamp
65
70
  include ActiveRecord::Associations
71
+ include ActiveRecord::NamedScope
72
+ include ActiveRecord::AssociationPreload
66
73
  include ActiveRecord::Aggregations
67
74
  include ActiveRecord::Transactions
68
75
  include ActiveRecord::Reflection
69
76
  include ActiveRecord::Calculations
70
77
  include ActiveRecord::Serialization
71
- include ActiveRecord::AttributeMethods
72
78
  end
73
79
 
74
80
  require 'active_record/connection_adapters/abstract_adapter'