activerecord 1.0.0 → 2.0.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 (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
data/README CHANGED
@@ -1,14 +1,14 @@
1
1
  = Active Record -- Object-relation mapping put on rails
2
2
 
3
3
  Active Record connects business objects and database tables to create a persistable
4
- domain model where logic and data is presented in one wrapping. It's an implementation
4
+ domain model where logic and data are presented in one wrapping. It's an implementation
5
5
  of the object-relational mapping (ORM) pattern[http://www.martinfowler.com/eaaCatalog/activeRecord.html]
6
6
  by the same name as described by Martin Fowler:
7
7
 
8
8
  "An object that wraps a row in a database table or view, encapsulates
9
9
  the database access, and adds domain logic on that data."
10
10
 
11
- Active Records main contribution to the pattern is to relieve the original of two stunting problems:
11
+ Active Record's main contribution to the pattern is to relieve the original of two stunting problems:
12
12
  lack of associations and inheritance. By adding a simple domain language-like set of macros to describe
13
13
  the former and integrating the Single Table Inheritance pattern for the latter, Active Record narrows the
14
14
  gap of functionality between the data mapper and active record approach.
@@ -29,7 +29,7 @@ A short rundown of the major features:
29
29
 
30
30
  ...which again gives Product#name and Product#name=(new_name)
31
31
 
32
- Learn more in link:classes/ActiveRecord/Base.html
32
+ {Learn more}[link:classes/ActiveRecord/Base.html]
33
33
 
34
34
 
35
35
  * Associations between objects controlled by simple meta-programming macros.
@@ -40,7 +40,7 @@ A short rundown of the major features:
40
40
  belongs_to :conglomorate
41
41
  end
42
42
 
43
- Learn more in link:classes/ActiveRecord/Associations/ClassMethods.html
43
+ {Learn more}[link:classes/ActiveRecord/Associations/ClassMethods.html]
44
44
 
45
45
 
46
46
  * Aggregations of value objects controlled by simple meta-programming macros.
@@ -52,23 +52,33 @@ A short rundown of the major features:
52
52
  :mapping => [%w(address_street street), %w(address_city city)]
53
53
  end
54
54
 
55
- Learn more in link:classes/ActiveRecord/Aggregations/ClassMethods.html
55
+ {Learn more}[link:classes/ActiveRecord/Aggregations/ClassMethods.html]
56
56
 
57
57
 
58
58
  * Validation rules that can differ for new or existing objects.
59
59
 
60
- class Post < ActiveRecord::Base
61
- def validate # validates on both creates and updates
62
- errors.add_on_empty "title"
63
- end
60
+ class Account < ActiveRecord::Base
61
+ validates_presence_of :subdomain, :name, :email_address, :password
62
+ validates_uniqueness_of :subdomain
63
+ validates_acceptance_of :terms_of_service, :on => :create
64
+ validates_confirmation_of :password, :email_address, :on => :create
65
+ end
66
+
67
+ {Learn more}[link:classes/ActiveRecord/Validations.html]
64
68
 
65
- def validate_on_update
66
- errors.add_on_empty "password"
67
- end
68
- end
69
69
 
70
- Learn more in link:classes/ActiveRecord/Validations.html
70
+ * Acts that can make records work as lists or trees:
71
71
 
72
+ class Item < ActiveRecord::Base
73
+ belongs_to :list
74
+ acts_as_list :scope => :list
75
+ end
76
+
77
+ item.move_higher
78
+ item.move_to_bottom
79
+
80
+ Learn about {acts_as_list}[link:classes/ActiveRecord/Acts/List/ClassMethods.html], {the instance methods acts_as_list provides}[link:classes/ActiveRecord/Acts/List/InstanceMethods.html], and
81
+ {acts_as_tree}[link:classes/ActiveRecord/Acts/Tree/ClassMethods.html]
72
82
 
73
83
  * Callbacks as methods or queues on the entire lifecycle (instantiation, saving, destroying, validating, etc).
74
84
 
@@ -82,18 +92,18 @@ A short rundown of the major features:
82
92
  after_find :eager_load, 'self.class.announce(#{id})'
83
93
  end
84
94
 
85
- Learn more in link:classes/ActiveRecord/Callbacks.html
95
+ {Learn more}[link:classes/ActiveRecord/Callbacks.html]
86
96
 
87
97
 
88
98
  * Observers for the entire lifecycle
89
99
 
90
100
  class CommentObserver < ActiveRecord::Observer
91
101
  def after_create(comment) # is called just after Comment#save
92
- NotificationService.send_email("david@loudthinking.com", comment)
102
+ Notifications.deliver_new_comment("david@loudthinking.com", comment)
93
103
  end
94
104
  end
95
105
 
96
- Learn more in link:classes/ActiveRecord/Observer.html
106
+ {Learn more}[link:classes/ActiveRecord/Observer.html]
97
107
 
98
108
 
99
109
  * Inheritance hierarchies
@@ -103,11 +113,11 @@ A short rundown of the major features:
103
113
  class Client < Company; end
104
114
  class PriorityClient < Client; end
105
115
 
106
- Learn more in link:classes/ActiveRecord/Base.html
116
+ {Learn more}[link:classes/ActiveRecord/Base.html]
107
117
 
108
118
 
109
119
  * Transaction support on both a database and object level. The latter is implemented
110
- by using Transaction::Simple[http://www.halostatue.ca/ruby/Transaction__Simple.html]
120
+ by using Transaction::Simple[http://railsmanual.com/module/Transaction::Simple]
111
121
 
112
122
  # Just database transaction
113
123
  Account.transaction do
@@ -121,7 +131,7 @@ A short rundown of the major features:
121
131
  mary.deposit(100)
122
132
  end
123
133
 
124
- Learn more in link:classes/ActiveRecord/Transactions/ClassMethods.html
134
+ {Learn more}[link:classes/ActiveRecord/Transactions/ClassMethods.html]
125
135
 
126
136
 
127
137
  * Reflections on columns, associations, and aggregations
@@ -130,7 +140,7 @@ A short rundown of the major features:
130
140
  reflection.klass # => Client (class)
131
141
  Firm.columns # Returns an array of column descriptors for the firms table
132
142
 
133
- Learn more in link:classes/ActiveRecord/Reflection/ClassMethods.html
143
+ {Learn more}[link:classes/ActiveRecord/Reflection/ClassMethods.html]
134
144
 
135
145
 
136
146
  * Direct manipulation (instead of service invocation)
@@ -147,15 +157,15 @@ A short rundown of the major features:
147
157
 
148
158
  pkId = 1234
149
159
  cat = Cat.find(pkId)
150
- # something even more interesting involving a the same cat...
160
+ # something even more interesting involving the same cat...
151
161
  cat.save
152
162
 
153
- Learn more in link:classes/ActiveRecord/Base.html
163
+ {Learn more}[link:classes/ActiveRecord/Base.html]
154
164
 
155
165
 
156
166
  * Database abstraction through simple adapters (~100 lines) with a shared connector
157
167
 
158
- ActiveRecord::Base.establish_connection(:adapter => "sqlite", :dbfile => "dbfile")
168
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite", :database => "dbfile")
159
169
 
160
170
  ActiveRecord::Base.establish_connection(
161
171
  :adapter => "mysql",
@@ -165,7 +175,8 @@ A short rundown of the major features:
165
175
  :database => "activerecord"
166
176
  )
167
177
 
168
- Learn more in link:classes/ActiveRecord/Base.html#M000081
178
+ {Learn more}[link:classes/ActiveRecord/Base.html#M000081] and read about the built-in support for
179
+ MySQL[link:classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html], PostgreSQL[link:classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html], SQLite[link:classes/ActiveRecord/ConnectionAdapters/SQLiteAdapter.html], Oracle[link:classes/ActiveRecord/ConnectionAdapters/OracleAdapter.html], SQLServer[link:classes/ActiveRecord/ConnectionAdapters/SQLServerAdapter.html], and DB2[link:classes/ActiveRecord/ConnectionAdapters/DB2Adapter.html].
169
180
 
170
181
 
171
182
  * Logging support for Log4r[http://log4r.sourceforge.net] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc]
@@ -178,7 +189,7 @@ A short rundown of the major features:
178
189
 
179
190
  Data definitions are specified only in the database. Active Record queries the database for
180
191
  the column names (that then serves to determine which attributes are valid) on regular
181
- objects instantiation through the new constructor and relies on the column names in the rows
192
+ object instantiation through the new constructor and relies on the column names in the rows
182
193
  with the finders.
183
194
 
184
195
  # CREATE TABLE companies (
@@ -224,7 +235,7 @@ Active Record will also automatically link the "Person" object to the "people" t
224
235
 
225
236
  == Simple example (2/2): Using the domain
226
237
 
227
- Picking a database connection for all the active records
238
+ Picking a database connection for all the Active Records
228
239
 
229
240
  ActiveRecord::Base.establish_connection(
230
241
  :adapter => "mysql",
@@ -253,7 +264,7 @@ Lots of different finders
253
264
  next_angle = Firm.find(1)
254
265
 
255
266
  # SQL: SELECT * FROM companies WHERE id = 1 AND name = 'Next Angle'
256
- next_angle = Company.find_first "name = 'Next Angle'"
267
+ next_angle = Company.find(:first, :conditions => "name = 'Next Angle'")
257
268
 
258
269
  next_angle = Firm.find_by_sql("SELECT * FROM companies WHERE id = 1").first
259
270
 
@@ -287,22 +298,11 @@ the examples themselves.
287
298
  It's also highly recommended to have a look at the unit tests. Read more in link:files/RUNNING_UNIT_TESTS.html
288
299
 
289
300
 
290
- == Database support
291
-
292
- Active Record ships with adapters for MySQL/Ruby[http://www.tmtm.org/en/mysql/ruby/]
293
- (compatible with Ruby/MySQL[http://www.tmtm.org/ruby/mysql/README_en.html]),
294
- PostgreSQL[http://www.postgresql.jp/interfaces/ruby/], and
295
- SQLite[http://rubyforge.org/projects/sqlite-ruby/] (needs SQLite 2.8.13+ and SQLite-Ruby 1.1.2+).
296
- The adapters are around 100 lines of code fulfilling the interface specified by
297
- ActiveRecord::ConnectionAdapters::AbstractAdapter. Writing a new adapter should be a small task --
298
- especially considering the extensive test suite that'll make sure you're fulfilling the contract.
299
-
300
-
301
301
  == Philosophy
302
302
 
303
- Active Record attempts to provide a coherent wrapping for the inconvenience that is
303
+ Active Record attempts to provide a coherent wrapper as a solution for the inconvenience that is
304
304
  object-relational mapping. The prime directive for this mapping has been to minimize
305
- the amount of code needed to built a real-world domain model. This is made possible
305
+ the amount of code needed to build a real-world domain model. This is made possible
306
306
  by relying on a number of conventions that make it easy for Active Record to infer
307
307
  complex relations and structures from a minimal amount of explicit direction.
308
308
 
@@ -324,7 +324,7 @@ The latest version of Active Record can be found at
324
324
 
325
325
  Documentation can be found at
326
326
 
327
- * http://ar.rubyonrails.org
327
+ * http://ar.rubyonrails.com
328
328
 
329
329
 
330
330
  == Installation
@@ -333,7 +333,7 @@ The prefered method of installing Active Record is through its GEM file. You'll
333
333
  RubyGems[http://rubygems.rubyforge.org/wiki/wiki.pl] installed for that, though. If you have,
334
334
  then use:
335
335
 
336
- % [sudo] gem install activerecord-0.9.0.gem
336
+ % [sudo] gem install activerecord-1.10.0.gem
337
337
 
338
338
  You can also install Active Record the old-fashion way with the following command:
339
339
 
@@ -344,12 +344,12 @@ from its distribution directory.
344
344
 
345
345
  == License
346
346
 
347
- Active Record is released under the same license as Ruby.
347
+ Active Record is released under the MIT license.
348
348
 
349
349
 
350
350
  == Support
351
351
 
352
- The Active Record homepage is http://activerecord.rubyonrails.org. You can find the Active Record
352
+ The Active Record homepage is http://www.rubyonrails.com. You can find the Active Record
353
353
  RubyForge page at http://rubyforge.org/projects/activerecord. And as Jim from Rake says:
354
354
 
355
355
  Feel free to submit commits or feature requests. If you send a patch,
@@ -358,4 +358,3 @@ RubyForge page at http://rubyforge.org/projects/activerecord. And as Jim from Ra
358
358
 
359
359
  For other information, feel free to ask on the ruby-talk mailing list
360
360
  (which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com.
361
-
data/RUNNING_UNIT_TESTS CHANGED
@@ -7,30 +7,27 @@ test/connections/<your database>/connection.rb.
7
7
  When you have the database online, you can import the fixture tables with
8
8
  the test/fixtures/db_definitions/*.sql files.
9
9
 
10
- Make sure that you create database objects with the same user that you specified in i
11
- connection.rb otherwise (on Postgres, at least) tests for default values will fail
12
- (see http://dev.rubyonrails.org/trac.cgi/ticket/118)
10
+ Make sure that you create database objects with the same user that you specified in
11
+ connection.rb otherwise (on Postgres, at least) tests for default values will fail.
13
12
 
14
13
  == Running with Rake
15
14
 
16
15
  The easiest way to run the unit tests is through Rake. The default task runs
17
16
  the entire test suite for all the adapters. You can also run the suite on just
18
- one adapter by using the tasks test_mysql_ruby, test_ruby_mysql, test_sqlite,
19
- or test_postresql. For more information, checkout the full array of rake tasks with "rake -T"
17
+ one adapter by using the tasks test_mysql, test_sqlite, test_postgresql or any
18
+ of the other test_ tasks. For more information, checkout the full array of rake
19
+ tasks with "rake -T"
20
20
 
21
21
  Rake can be found at http://rake.rubyforge.org
22
22
 
23
23
  == Running by hand
24
24
 
25
25
  Unit tests are located in test directory. If you only want to run a single test suite,
26
- or don't want to bother with Rake, you can do so with something like:
26
+ you can do so with:
27
27
 
28
- cd test; ruby -I "connections/native_mysql" base_test.rb
28
+ rake test_mysql TEST=base_test.rb
29
29
 
30
- That'll run the base suite using the MySQL-Ruby adapter. Change the adapter
31
- and test suite name as needed.
30
+ That'll run the base suite using the MySQL-Ruby adapter.
32
31
 
33
- You can also run all the suites on a specific adapter with:
34
32
 
35
- cd test; all.sh "connections/native_mysql"
36
33
 
data/Rakefile ADDED
@@ -0,0 +1,247 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/contrib/rubyforgepublisher'
8
+ require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
9
+
10
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
11
+ PKG_NAME = 'activerecord'
12
+ PKG_VERSION = ActiveRecord::VERSION::STRING + PKG_BUILD
13
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14
+
15
+ RELEASE_NAME = "REL #{PKG_VERSION}"
16
+
17
+ RUBY_FORGE_PROJECT = "activerecord"
18
+ RUBY_FORGE_USER = "webster132"
19
+
20
+ PKG_FILES = FileList[
21
+ "lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "Rakefile"
22
+ ].exclude(/\bCVS\b|~$/)
23
+
24
+
25
+ desc 'Run mysql, sqlite, and postgresql tests by default'
26
+ task :default => :test
27
+
28
+ desc 'Run mysql, sqlite, and postgresql tests'
29
+ task :test => %w(test_mysql test_sqlite test_sqlite3 test_postgresql)
30
+
31
+ for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase )
32
+ Rake::TestTask.new("test_#{adapter}") { |t|
33
+ t.libs << "test" << "test/connections/native_#{adapter}"
34
+ adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
35
+ t.pattern = "test/**/*_test{,_#{adapter_short}}.rb"
36
+ t.verbose = true
37
+ }
38
+
39
+ namespace adapter do
40
+ task :test => "test_#{adapter}"
41
+ end
42
+ end
43
+
44
+ SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))
45
+
46
+ namespace :mysql do
47
+ desc 'Build the MySQL test databases'
48
+ task :build_databases do
49
+ %x( mysqladmin create activerecord_unittest )
50
+ %x( mysqladmin create activerecord_unittest2 )
51
+ %x( mysql -e "grant all on activerecord_unittest.* to rails@localhost" )
52
+ %x( mysql -e "grant all on activerecord_unittest2.* to rails@localhost" )
53
+ end
54
+
55
+ desc 'Drop the MySQL test databases'
56
+ task :drop_databases do
57
+ %x( mysqladmin -f drop activerecord_unittest )
58
+ %x( mysqladmin -f drop activerecord_unittest2 )
59
+ end
60
+
61
+ desc 'Rebuild the MySQL test databases'
62
+ task :rebuild_databases => [:drop_databases, :build_databases]
63
+ end
64
+
65
+ task :build_mysql_databases => 'mysql:build_databases'
66
+ task :drop_mysql_databases => 'mysql:drop_databases'
67
+ task :rebuild_mysql_databases => 'mysql:rebuild_databases'
68
+
69
+
70
+ namespace :postgresql do
71
+ desc 'Build the PostgreSQL test databases'
72
+ task :build_databases do
73
+ %x( createdb -U postgres activerecord_unittest )
74
+ %x( createdb -U postgres activerecord_unittest2 )
75
+ %x( psql activerecord_unittest -f #{File.join(SCHEMA_PATH, 'postgresql.sql')} postgres )
76
+ %x( psql activerecord_unittest2 -f #{File.join(SCHEMA_PATH, 'postgresql2.sql')} postgres )
77
+ end
78
+
79
+ desc 'Drop the PostgreSQL test databases'
80
+ task :drop_databases do
81
+ %x( dropdb -U postgres activerecord_unittest )
82
+ %x( dropdb -U postgres activerecord_unittest2 )
83
+ end
84
+
85
+ desc 'Rebuild the PostgreSQL test databases'
86
+ task :rebuild_databases => [:drop_databases, :build_databases]
87
+ end
88
+
89
+ task :build_postgresql_databases => 'postgresql:build_databases'
90
+ task :drop_postgresql_databases => 'postgresql:drop_databases'
91
+ task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
92
+
93
+
94
+ namespace :frontbase do
95
+ desc 'Build the FrontBase test databases'
96
+ task :build_databases => :rebuild_frontbase_databases
97
+
98
+ desc 'Rebuild the FrontBase test databases'
99
+ task :rebuild_databases do
100
+ build_frontbase_database = Proc.new do |db_name, sql_definition_file|
101
+ %(
102
+ STOP DATABASE #{db_name};
103
+ DELETE DATABASE #{db_name};
104
+ CREATE DATABASE #{db_name};
105
+
106
+ CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
107
+ SET COMMIT FALSE;
108
+
109
+ CREATE USER RAILS;
110
+ CREATE SCHEMA RAILS AUTHORIZATION RAILS;
111
+ COMMIT;
112
+
113
+ SET SESSION AUTHORIZATION RAILS;
114
+ SCRIPT '#{sql_definition_file}';
115
+
116
+ COMMIT;
117
+
118
+ DISCONNECT ALL;
119
+ )
120
+ end
121
+ create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_PATH, 'frontbase.sql')]
122
+ create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_PATH, 'frontbase2.sql')]
123
+ execute_frontbase_sql = Proc.new do |sql|
124
+ system(<<-SHELL)
125
+ /Library/FrontBase/bin/sql92 <<-SQL
126
+ #{sql}
127
+ SQL
128
+ SHELL
129
+ end
130
+ execute_frontbase_sql[create_activerecord_unittest]
131
+ execute_frontbase_sql[create_activerecord_unittest2]
132
+ end
133
+ end
134
+
135
+ task :build_frontbase_databases => 'frontbase:build_databases'
136
+ task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
137
+
138
+
139
+ # Generate the RDoc documentation
140
+
141
+ Rake::RDocTask.new { |rdoc|
142
+ rdoc.rdoc_dir = 'doc'
143
+ rdoc.title = "Active Record -- Object-relation mapping put on rails"
144
+ rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
145
+ rdoc.options << '--charset' << 'utf-8'
146
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
147
+ rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
148
+ rdoc.rdoc_files.include('lib/**/*.rb')
149
+ rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
150
+ rdoc.rdoc_files.include('dev-utils/*.rb')
151
+ }
152
+
153
+ # Enhance rdoc task to copy referenced images also
154
+ task :rdoc do
155
+ FileUtils.mkdir_p "doc/files/examples/"
156
+ FileUtils.copy "examples/associations.png", "doc/files/examples/associations.png"
157
+ end
158
+
159
+
160
+ # Create compressed packages
161
+
162
+ dist_dirs = [ "lib", "test", "examples" ]
163
+
164
+ spec = Gem::Specification.new do |s|
165
+ s.name = PKG_NAME
166
+ s.version = PKG_VERSION
167
+ s.summary = "Implements the ActiveRecord pattern for ORM."
168
+ s.description = %q{Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.}
169
+
170
+ s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG" ]
171
+ dist_dirs.each do |dir|
172
+ s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
173
+ end
174
+
175
+ s.add_dependency('activesupport', '= 2.0.0' + PKG_BUILD)
176
+
177
+ s.files.delete "test/fixtures/fixture_database.sqlite"
178
+ s.files.delete "test/fixtures/fixture_database_2.sqlite"
179
+ s.files.delete "test/fixtures/fixture_database.sqlite3"
180
+ s.files.delete "test/fixtures/fixture_database_2.sqlite3"
181
+ s.require_path = 'lib'
182
+ s.autorequire = 'active_record'
183
+
184
+ s.has_rdoc = true
185
+ s.extra_rdoc_files = %w( README )
186
+ s.rdoc_options.concat ['--main', 'README']
187
+
188
+ s.author = "David Heinemeier Hansson"
189
+ s.email = "david@loudthinking.com"
190
+ s.homepage = "http://www.rubyonrails.org"
191
+ s.rubyforge_project = "activerecord"
192
+ end
193
+
194
+ Rake::GemPackageTask.new(spec) do |p|
195
+ p.gem_spec = spec
196
+ p.need_tar = true
197
+ p.need_zip = true
198
+ end
199
+
200
+ task :lines do
201
+ lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
202
+
203
+ for file_name in FileList["lib/active_record/**/*.rb"]
204
+ next if file_name =~ /vendor/
205
+ f = File.open(file_name)
206
+
207
+ while line = f.gets
208
+ lines += 1
209
+ next if line =~ /^\s*$/
210
+ next if line =~ /^\s*#/
211
+ codelines += 1
212
+ end
213
+ puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
214
+
215
+ total_lines += lines
216
+ total_codelines += codelines
217
+
218
+ lines, codelines = 0, 0
219
+ end
220
+
221
+ puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
222
+ end
223
+
224
+
225
+ # Publishing ------------------------------------------------------
226
+
227
+ desc "Publish the beta gem"
228
+ task :pgem => [:package] do
229
+ Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
230
+ `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
231
+ end
232
+
233
+ desc "Publish the API documentation"
234
+ task :pdoc => [:rdoc] do
235
+ Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.org", "public_html/ar", "doc").upload
236
+ end
237
+
238
+ desc "Publish the release files to RubyForge."
239
+ task :release => [ :package ] do
240
+ require 'rubyforge'
241
+
242
+ packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
243
+
244
+ rubyforge = RubyForge.new
245
+ rubyforge.login
246
+ rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
247
+ end
data/install.rb CHANGED
@@ -18,43 +18,13 @@ unless $sitedir
18
18
  end
19
19
  end
20
20
 
21
- makedirs = %w{ active_record/associations active_record/connection_adapters active_record/support active_record/vendor }
22
- makedirs.each {|f| File::makedirs(File.join($sitedir, *f.split(/\//)))}
23
-
24
- # deprecated files that should be removed
25
- # deprecated = %w{ }
26
-
27
- # files to install in library path
28
- files = %w-
29
- active_record.rb
30
- active_record/aggregations.rb
31
- active_record/associations.rb
32
- active_record/associations/association_collection.rb
33
- active_record/associations/has_and_belongs_to_many_association.rb
34
- active_record/associations/has_many_association.rb
35
- active_record/base.rb
36
- active_record/callbacks.rb
37
- active_record/connection_adapters/abstract_adapter.rb
38
- active_record/connection_adapters/mysql_adapter.rb
39
- active_record/connection_adapters/postgresql_adapter.rb
40
- active_record/connection_adapters/sqlite_adapter.rb
41
- active_record/deprecated_associations.rb
42
- active_record/fixtures.rb
43
- active_record/observer.rb
44
- active_record/reflection.rb
45
- active_record/support/class_attribute_accessors.rb
46
- active_record/support/class_inheritable_attributes.rb
47
- active_record/support/clean_logger.rb
48
- active_record/support/inflector.rb
49
- active_record/transactions.rb
50
- active_record/validations.rb
51
- active_record/vendor/mysql.rb
52
- active_record/vendor/simple.rb
53
- -
54
-
55
- # the acual gruntwork
21
+ # the actual gruntwork
56
22
  Dir.chdir("lib")
57
- # File::safe_unlink *deprecated.collect{|f| File.join($sitedir, f.split(/\//))}
58
- files.each {|f|
59
- File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
23
+
24
+ Find.find("active_record", "active_record.rb") { |f|
25
+ if f[-3..-1] == ".rb"
26
+ File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
27
+ else
28
+ File::makedirs(File.join($sitedir, *f.split(/\//)))
29
+ end
60
30
  }