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
@@ -1,15 +0,0 @@
1
- require 'yaml'
2
-
3
- module ActiveRecord
4
- module Wrappings #:nodoc:
5
- class YamlWrapper < AbstractWrapper #:nodoc:
6
- def wrap(attribute) attribute.to_yaml end
7
- def unwrap(attribute) YAML::load(attribute) end
8
- end
9
-
10
- module ClassMethods #:nodoc:
11
- # Wraps the attribute in Yaml encoding
12
- def wrap_in_yaml(*attributes) wrap_with(YamlWrapper, attributes) end
13
- end
14
- end
15
- end
@@ -1,59 +0,0 @@
1
- module ActiveRecord
2
- # A plugin framework for wrapping attribute values before they go in and unwrapping them after they go out of the database.
3
- # This was intended primarily for YAML wrapping of arrays and hashes, but this behavior is now native in the Base class.
4
- # So for now this framework is laying dorment until a need pops up.
5
- module Wrappings #:nodoc:
6
- module ClassMethods #:nodoc:
7
- def wrap_with(wrapper, *attributes)
8
- [ attributes ].flat.each { |attribute| wrapper.wrap(attribute) }
9
- end
10
- end
11
-
12
- def self.append_features(base)
13
- super
14
- base.extend(ClassMethods)
15
- end
16
-
17
- class AbstractWrapper #:nodoc:
18
- def self.wrap(attribute, record_binding) #:nodoc:
19
- %w( before_save after_save after_initialize ).each do |callback|
20
- eval "#{callback} #{name}.new('#{attribute}')", record_binding
21
- end
22
- end
23
-
24
- def initialize(attribute) #:nodoc:
25
- @attribute = attribute
26
- end
27
-
28
- def save_wrapped_attribute(record) #:nodoc:
29
- if record.attribute_present?(@attribute)
30
- record.send(
31
- "write_attribute",
32
- @attribute,
33
- wrap(record.send("read_attribute", @attribute))
34
- )
35
- end
36
- end
37
-
38
- def load_wrapped_attribute(record) #:nodoc:
39
- if record.attribute_present?(@attribute)
40
- record.send(
41
- "write_attribute",
42
- @attribute,
43
- unwrap(record.send("read_attribute", @attribute))
44
- )
45
- end
46
- end
47
-
48
- alias_method :before_save, :save_wrapped_attribute #:nodoc:
49
- alias_method :after_save, :load_wrapped_attribute #:nodoc:
50
- alias_method :after_initialize, :after_save #:nodoc:
51
-
52
- # Overwrite to implement the logic that'll take the regular attribute and wrap it.
53
- def wrap(attribute) end
54
-
55
- # Overwrite to implement the logic that'll take the wrapped attribute and unwrap it.
56
- def unwrap(attribute) end
57
- end
58
- end
59
- end
data/rakefile DELETED
@@ -1,122 +0,0 @@
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
-
9
- PKG_VERSION = "1.0.0"
10
-
11
- PKG_FILES = FileList[
12
- "lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "rakefile"
13
- ].exclude(/\bCVS\b|~$/)
14
-
15
-
16
- desc "Default Task"
17
- task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_postgresql ]
18
-
19
- # Run the unit tests
20
-
21
- Rake::TestTask.new("test_ruby_mysql") { |t|
22
- t.libs << "test" << "test/connections/native_mysql"
23
- t.test_files = "lib/active_record/vendor/mysql.rb"
24
- t.pattern = 'test/*_test.rb'
25
- t.verbose = true
26
- }
27
-
28
- Rake::TestTask.new("test_mysql_ruby") { |t|
29
- t.libs << "test" << "test/connections/native_mysql"
30
- t.pattern = 'test/*_test.rb'
31
- t.verbose = true
32
- }
33
-
34
- Rake::TestTask.new("test_postgresql") { |t|
35
- t.libs << "test" << "test/connections/native_postgresql"
36
- t.pattern = 'test/*_test.rb'
37
- t.verbose = true
38
- }
39
-
40
- Rake::TestTask.new("test_sqlite") { |t|
41
- t.libs << "test" << "test/connections/native_sqlite"
42
- t.pattern = 'test/*_test.rb'
43
- t.verbose = true
44
- }
45
-
46
- # Genereate the RDoc documentation
47
-
48
- Rake::RDocTask.new { |rdoc|
49
- rdoc.rdoc_dir = 'doc'
50
- rdoc.title = "Active Record -- Object-relation mapping put on rails"
51
- rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
52
- rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
53
- rdoc.rdoc_files.include('lib/**/*.rb')
54
- rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
55
- rdoc.rdoc_files.include('dev-utils/*.rb')
56
- }
57
-
58
-
59
- # Publish documentation
60
- desc "Publish the API documentation"
61
- task :pdoc => [:rdoc] do
62
- Rake::SshDirPublisher.new("davidhh@one.textdrive.com", "domains/rubyonrails.org/ar", "doc").upload
63
- end
64
-
65
- desc "Publish to RubyForge"
66
- task :rubyforge do
67
- Rake::RubyForgePublisher.new('activerecord', 'webster132').upload
68
- end
69
-
70
-
71
- # Create compressed packages
72
-
73
- dist_dirs = [ "lib", "test", "examples", "dev-utils" ]
74
-
75
- spec = Gem::Specification.new do |s|
76
- s.name = 'activerecord'
77
- s.version = PKG_VERSION
78
- s.summary = "Implements the ActiveRecord pattern for ORM."
79
- 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.}
80
-
81
- s.files = [ "rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG" ]
82
- dist_dirs.each do |dir|
83
- s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "CVS" ) }
84
- end
85
- s.files.delete "test/fixtures/fixture_database.sqlite"
86
- s.require_path = 'lib'
87
- s.autorequire = 'active_record'
88
-
89
- s.has_rdoc = true
90
- s.extra_rdoc_files = %w( README )
91
- s.rdoc_options.concat ['--main', 'README']
92
-
93
- s.author = "David Heinemeier Hansson"
94
- s.email = "david@loudthinking.com"
95
- s.homepage = "http://activerecord.rubyonrails.org"
96
- s.rubyforge_project = "activerecord"
97
- end
98
-
99
- Rake::GemPackageTask.new(spec) do |p|
100
- p.gem_spec = spec
101
- p.need_tar = true
102
- p.need_zip = true
103
- end
104
-
105
-
106
- task :lines do
107
- lines = 0
108
- codelines = 0
109
- Dir.foreach("lib/active_record") { |file_name|
110
- next unless file_name =~ /.*rb/
111
-
112
- f = File.open("lib/active_record/" + file_name)
113
-
114
- while line = f.gets
115
- lines += 1
116
- next if line =~ /^\s*$/
117
- next if line =~ /^\s*#/
118
- codelines += 1
119
- end
120
- }
121
- puts "Lines #{lines}, LOC #{codelines}"
122
- end
@@ -1,336 +0,0 @@
1
- require 'abstract_unit'
2
- require 'fixtures/developer'
3
- require 'fixtures/project'
4
- require 'fixtures/company'
5
- require 'fixtures/topic'
6
- # require File.dirname(__FILE__) + '/../dev-utils/eval_debugger'
7
- require 'fixtures/reply'
8
-
9
- # Can't declare new classes in test case methods, so tests before that
10
- bad_collection_keys = false
11
- begin
12
- class Car < ActiveRecord::Base; has_many :wheels, :name => "wheels"; end
13
- rescue ActiveRecord::ActiveRecordError
14
- bad_collection_keys = true
15
- end
16
- raise "ActiveRecord should have barked on bad collection keys" unless bad_collection_keys
17
-
18
-
19
- class DeprecatedAssociationsTest < Test::Unit::TestCase
20
- def setup
21
- create_fixtures "accounts", "companies", "accounts", "developers", "projects", "developers_projects", "topics"
22
- @signals37 = Firm.find(1)
23
- end
24
-
25
- def test_has_many_find
26
- assert_equal 2, Firm.find_first.clients.length
27
- end
28
-
29
- def test_has_many_orders
30
- assert_equal "Summit", Firm.find_first.clients.first.name
31
- end
32
-
33
- def test_has_many_class_name
34
- assert_equal "Microsoft", Firm.find_first.clients_sorted_desc.first.name
35
- end
36
-
37
- def test_has_many_foreign_key
38
- assert_equal "Microsoft", Firm.find_first.clients_of_firm.first.name
39
- end
40
-
41
- def test_has_many_conditions
42
- assert_equal "Microsoft", Firm.find_first.clients_like_ms.first.name
43
- end
44
-
45
- def test_has_many_sql
46
- firm = Firm.find_first
47
- assert_equal "Microsoft", firm.clients_using_sql.first.name
48
- assert_equal 1, firm.clients_using_sql_count
49
- assert_equal 1, Firm.find_first.clients_using_sql_count
50
- end
51
-
52
- def test_has_many_queries
53
- assert Firm.find_first.has_clients?
54
- firm = Firm.find_first
55
- assert_equal 2, firm.clients_count # tests using class count
56
- firm.clients
57
- assert firm.has_clients?
58
- assert_equal 2, firm.clients_count # tests using collection length
59
- end
60
-
61
- def test_has_many_dependence
62
- assert_equal 2, Client.find_all.length
63
- Firm.find_first.destroy
64
- assert_equal 0, Client.find_all.length
65
- end
66
-
67
- def test_has_many_dependence_with_transaction_support_on_failure
68
- assert_equal 2, Client.find_all.length
69
-
70
- firm = Firm.find_first
71
- clients = firm.clients
72
- clients.last.instance_eval { def before_destroy() raise "Trigger rollback" end }
73
-
74
- firm.destroy rescue "do nothing"
75
-
76
- assert_equal 2, Client.find_all.length
77
- end
78
-
79
- def test_has_one_dependence
80
- firm = Firm.find(1)
81
- assert firm.has_account?
82
- firm.destroy
83
- assert_equal 1, Account.find_all.length
84
- end
85
-
86
- def test_has_one_dependence_with_missing_association
87
- Account.destroy_all
88
- firm = Firm.find(1)
89
- assert !firm.has_account?
90
- firm.destroy
91
- end
92
-
93
- def test_belongs_to
94
- assert_equal @signals37.name, Client.find(3).firm.name
95
- assert Client.find(3).has_firm?, "Microsoft should have a firm"
96
- # assert !Company.find(1).has_firm?, "37signals shouldn't have a firm"
97
- end
98
-
99
- def test_belongs_to_with_different_class_name
100
- assert_equal Company.find(1).name, Company.find(3).firm_with_other_name.name
101
- assert Company.find(3).has_firm_with_other_name?, "Microsoft should have a firm"
102
- assert !Company.find(1).has_firm_with_other_name?, "37signals shouldn't have a firm"
103
- end
104
-
105
- def test_belongs_to_with_condition
106
- assert_equal Company.find(1).name, Company.find(3).firm_with_condition.name
107
- assert Company.find(3).has_firm_with_condition?, "Microsoft should have a firm"
108
- assert !Company.find(1).has_firm_with_condition?, "37signals shouldn't have a firm"
109
- end
110
-
111
-
112
- def test_belongs_to_equality
113
- assert Company.find(3).firm?(Company.find(1)), "Microsoft should have 37signals as firm"
114
- assert_raises(RuntimeError) { !Company.find(3).firm?(Company.find(3)) } # "Summit shouldn't have itself as firm"
115
- end
116
-
117
- def test_has_one
118
- assert @signals37.account?(Account.find(1))
119
- assert_equal Account.find(1).credit_limit, @signals37.account.credit_limit
120
- assert @signals37.has_account?, "37signals should have an account"
121
- assert Account.find(1).firm?(@signals37), "37signals account should be able to backtrack"
122
- assert Account.find(1).has_firm?, "37signals account should be able to backtrack"
123
-
124
- assert !Account.find(2).has_firm?, "Unknown isn't linked"
125
- assert !Account.find(2).firm?(@signals37), "Unknown isn't linked"
126
- end
127
-
128
- def test_has_many_dependence_on_account
129
- assert_equal 2, Account.find_all.length
130
- @signals37.destroy
131
- assert_equal 1, Account.find_all.length
132
- end
133
-
134
- def test_find_in
135
- assert_equal Client.find(2).name, @signals37.find_in_clients(2).name
136
- assert_raises(ActiveRecord::RecordNotFound) { @signals37.find_in_clients(6) }
137
- end
138
-
139
- def test_force_reload
140
- firm = Firm.new
141
- firm.save
142
- firm.clients.each {|c|} # forcing to load all clients
143
- assert firm.clients.empty?, "New firm shouldn't have client objects"
144
- assert !firm.has_clients?, "New firm shouldn't have clients"
145
- assert_equal 0, firm.clients_count, "New firm should have 0 clients"
146
-
147
- client = Client.new("firm_id" => firm.id)
148
- client.save
149
-
150
- assert firm.clients.empty?, "New firm should have cached no client objects"
151
- assert !firm.has_clients?, "New firm should have cached a no-clients response"
152
- assert_equal 0, firm.clients_count, "New firm should have cached 0 clients count"
153
-
154
- assert !firm.clients(true).empty?, "New firm should have reloaded client objects"
155
- assert firm.has_clients?(true), "New firm should have reloaded with a have-clients response"
156
- assert_equal 1, firm.clients_count(true), "New firm should have reloaded clients count"
157
- end
158
-
159
- def test_included_in_collection
160
- assert @signals37.clients.include?(Client.find(2))
161
- end
162
-
163
- def test_build_to_collection
164
- assert_equal 1, @signals37.clients_of_firm_count
165
- new_client = @signals37.build_to_clients_of_firm("name" => "Another Client")
166
- assert_equal "Another Client", new_client.name
167
- assert new_client.save
168
-
169
- assert new_client.firm?(@signals37)
170
- assert_equal 2, @signals37.clients_of_firm_count(true)
171
- end
172
-
173
- def test_create_in_collection
174
- assert_equal @signals37.create_in_clients_of_firm("name" => "Another Client"), @signals37.clients_of_firm(true).last
175
- end
176
-
177
- def test_succesful_build_association
178
- firm = Firm.new("name" => "GlobalMegaCorp")
179
- firm.save
180
-
181
- account = firm.build_account("credit_limit" => 1000)
182
- assert account.save
183
- assert_equal account, firm.account
184
- end
185
-
186
- def test_failing_build_association
187
- firm = Firm.new("name" => "GlobalMegaCorp")
188
- firm.save
189
-
190
- account = firm.build_account
191
- assert !account.save
192
- assert_equal "can't be empty", account.errors.on("credit_limit")
193
- end
194
-
195
- def test_create_association
196
- firm = Firm.new("name" => "GlobalMegaCorp")
197
- firm.save
198
- assert_equal firm.create_account("credit_limit" => 1000), firm.account
199
- end
200
-
201
- def test_has_and_belongs_to_many
202
- david = Developer.find(1)
203
- assert david.has_projects?
204
- assert_equal 2, david.projects_count
205
-
206
- active_record = Project.find(1)
207
- assert active_record.has_developers?
208
- assert_equal 2, active_record.developers_count
209
- assert_equal david.name, active_record.developers.first.name
210
- end
211
-
212
- def test_has_and_belongs_to_many_removing
213
- david = Developer.find(1)
214
- active_record = Project.find(1)
215
-
216
- david.remove_projects(active_record)
217
-
218
- assert_equal 1, david.projects_count
219
- assert_equal 1, active_record.developers_count
220
- end
221
-
222
- def test_has_and_belongs_to_many_zero
223
- david = Developer.find(1)
224
- david.remove_projects(Project.find_all)
225
-
226
- assert_equal 0, david.projects_count
227
- assert !david.has_projects?
228
- end
229
-
230
- def test_has_and_belongs_to_many_adding
231
- jamis = Developer.find(2)
232
- action_controller = Project.find(2)
233
-
234
- jamis.add_projects(action_controller)
235
-
236
- assert_equal 2, jamis.projects_count
237
- assert_equal 2, action_controller.developers_count
238
- end
239
-
240
- def test_has_and_belongs_to_many_adding_from_the_project
241
- jamis = Developer.find(2)
242
- action_controller = Project.find(2)
243
-
244
- action_controller.add_developers(jamis)
245
-
246
- assert_equal 2, jamis.projects_count
247
- assert_equal 2, action_controller.developers_count
248
- end
249
-
250
- def test_has_and_belongs_to_many_adding_a_collection
251
- aridridel = Developer.new("name" => "Aridridel")
252
- aridridel.save
253
-
254
- aridridel.add_projects([ Project.find(1), Project.find(2) ])
255
- assert_equal 2, aridridel.projects_count
256
- end
257
-
258
- def test_belongs_to_counter
259
- topic = Topic.create("title" => "Apple", "content" => "hello world")
260
- assert_equal 0, topic.send(:read_attribute, "replies_count"), "No replies yet"
261
-
262
- reply = topic.create_in_replies("title" => "I'm saying no!", "content" => "over here")
263
- assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count"), "First reply created"
264
-
265
- reply.destroy
266
- assert_equal 0, Topic.find(topic.id).send(:read_attribute, "replies_count"), "First reply deleted"
267
- end
268
-
269
- def test_natural_assignment_of_has_one
270
- apple = Firm.create("name" => "Apple")
271
- citibank = Account.create("credit_limit" => 10)
272
- apple.account = citibank
273
- assert_equal apple.id, citibank.firm_id
274
- end
275
-
276
- def test_natural_assignment_of_belongs_to
277
- apple = Firm.create("name" => "Apple")
278
- citibank = Account.create("credit_limit" => 10)
279
- citibank.firm = apple
280
- assert_equal apple.id, citibank.firm_id
281
- end
282
-
283
- def test_natural_assignment_of_has_many
284
- apple = Firm.create("name" => "Apple")
285
- natural = Client.new("name" => "Natural Company")
286
- apple.clients << natural
287
- assert_equal apple.id, natural.firm_id
288
- assert_equal Client.find(natural.id), Firm.find(apple.id).clients.find { |c| c.id == natural.id }
289
- apple.clients.delete natural
290
- assert_nil Firm.find(apple.id).clients.find { |c| c.id == natural.id }
291
- end
292
-
293
-
294
- def test_natural_adding_of_has_and_belongs_to_many
295
- rails = Project.create("name" => "Rails")
296
- ap = Project.create("name" => "Action Pack")
297
- john = Developer.create("name" => "John")
298
- mike = Developer.create("name" => "Mike")
299
- rails.developers << john
300
- rails.developers << mike
301
-
302
- assert_equal Developer.find(john.id), Project.find(rails.id).developers.find { |d| d.id == john.id }
303
- assert_equal Developer.find(mike.id), Project.find(rails.id).developers.find { |d| d.id == mike.id }
304
- assert_equal Project.find(rails.id), Developer.find(mike.id).projects.find { |p| p.id == rails.id }
305
- assert_equal Project.find(rails.id), Developer.find(john.id).projects.find { |p| p.id == rails.id }
306
- ap.developers << john
307
- assert_equal Developer.find(john.id), Project.find(ap.id).developers.find { |d| d.id == john.id }
308
- assert_equal Project.find(ap.id), Developer.find(john.id).projects.find { |p| p.id == ap.id }
309
-
310
- ap.developers.delete john
311
- assert_nil Project.find(ap.id).developers.find { |d| d.id == john.id }
312
- assert_nil Developer.find(john.id).projects.find { |p| p.id == ap.id }
313
- end
314
-
315
- def test_storing_in_pstore
316
- require "pstore"
317
- apple = Firm.create("name" => "Apple")
318
- natural = Client.new("name" => "Natural Company")
319
- apple.clients << natural
320
-
321
- db = PStore.new("/tmp/ar-pstore-association-test")
322
- db.transaction do
323
- db["apple"] = apple
324
- end
325
-
326
- db = PStore.new("/tmp/ar-pstore-association-test")
327
- db.transaction do
328
- assert_equal "Natural Company", db["apple"].clients.first.name
329
- end
330
- end
331
-
332
- def test_has_many_find_all
333
- assert_equal 2, Firm.find_first.find_all_in_clients("type = 'Client'").length
334
- assert_equal 1, Firm.find_first.find_all_in_clients("name = 'Summit'").length
335
- end
336
- end
@@ -1,3 +0,0 @@
1
- id => 1
2
- firm_id => 1
3
- credit_limit => 50
@@ -1,2 +0,0 @@
1
- id => 2
2
- credit_limit => 50
@@ -1,6 +0,0 @@
1
- id => 2
2
- type => Client
3
- firm_id => 1
4
- client_of => 2
5
- name => Summit
6
- ruby_type => Client
@@ -1,4 +0,0 @@
1
- id => 1
2
- type => Firm
3
- name => 37signals
4
- ruby_type => Firm
@@ -1,6 +0,0 @@
1
- id => 3
2
- type => Client
3
- firm_id => 1
4
- client_of => 1
5
- name => Microsoft
6
- ruby_type => Client
@@ -1,2 +0,0 @@
1
- id => 2
2
- name => Java Development
@@ -1,2 +0,0 @@
1
- id => 1
2
- name => Ruby Development
@@ -1,6 +0,0 @@
1
- id => 1
2
- name => David
3
- balance => 50
4
- address_street => Funny Street
5
- address_city => Scary Town
6
- address_country => Loony Land
@@ -1,96 +0,0 @@
1
- CREATE TABLE `accounts` (
2
- `id` int(11) NOT NULL auto_increment,
3
- `firm_id` int(11) default NULL,
4
- `credit_limit` int(5) default NULL,
5
- PRIMARY KEY (`id`)
6
- ) TYPE=InnoDB;
7
-
8
- CREATE TABLE `companies` (
9
- `id` int(11) NOT NULL auto_increment,
10
- `type` varchar(50) default NULL,
11
- `ruby_type` varchar(50) default NULL,
12
- `firm_id` int(11) default NULL,
13
- `name` varchar(50) default NULL,
14
- `client_of` int(11) default NULL,
15
- `rating` int(11) default NULL default 1,
16
- PRIMARY KEY (`id`)
17
- ) TYPE=InnoDB;
18
-
19
-
20
- CREATE TABLE `topics` (
21
- `id` int(11) NOT NULL auto_increment,
22
- `title` varchar(255) default NULL,
23
- `author_name` varchar(255) default NULL,
24
- `author_email_address` varchar(255) default NULL,
25
- `written_on` datetime default NULL,
26
- `last_read` date default NULL,
27
- `content` text,
28
- `approved` tinyint(1) default 1,
29
- `replies_count` int(11) default 0,
30
- `parent_id` int(11) default NULL,
31
- `type` varchar(50) default NULL,
32
- PRIMARY KEY (`id`)
33
- ) TYPE=InnoDB;
34
-
35
- CREATE TABLE `developers` (
36
- `id` int(11) NOT NULL auto_increment,
37
- `name` varchar(100) default NULL,
38
- PRIMARY KEY (`id`)
39
- );
40
-
41
- CREATE TABLE `projects` (
42
- `id` int(11) NOT NULL auto_increment,
43
- `name` varchar(100) default NULL,
44
- PRIMARY KEY (`id`)
45
- );
46
-
47
- CREATE TABLE `developers_projects` (
48
- `developer_id` int(11) NOT NULL,
49
- `project_id` int(11) NOT NULL
50
- );
51
-
52
- CREATE TABLE `customers` (
53
- `id` int(11) NOT NULL auto_increment,
54
- `name` varchar(100) default NULL,
55
- `balance` int(6) default 0,
56
- `address_street` varchar(100) default NULL,
57
- `address_city` varchar(100) default NULL,
58
- `address_country` varchar(100) default NULL,
59
- PRIMARY KEY (`id`)
60
- );
61
-
62
- CREATE TABLE `movies` (
63
- `movieid` int(11) NOT NULL auto_increment,
64
- `name` varchar(100) default NULL,
65
- PRIMARY KEY (`movieid`)
66
- );
67
-
68
- CREATE TABLE `subscribers` (
69
- `nick` varchar(100) NOT NULL,
70
- `name` varchar(100) default NULL,
71
- PRIMARY KEY (`nick`)
72
- );
73
-
74
- CREATE TABLE `booleantests` (
75
- `id` int(11) NOT NULL auto_increment,
76
- `value` integer default NULL,
77
- PRIMARY KEY (`id`)
78
- );
79
-
80
- CREATE TABLE `auto_id_tests` (
81
- `auto_id` int(11) NOT NULL auto_increment,
82
- `value` integer default NULL,
83
- PRIMARY KEY (`auto_id`)
84
- );
85
-
86
- CREATE TABLE `entrants` (
87
- `id` INTEGER NOT NULL PRIMARY KEY,
88
- `name` VARCHAR(255) NOT NULL,
89
- `course_id` INTEGER NOT NULL
90
- );
91
-
92
- CREATE TABLE `colnametests` (
93
- `id` int(11) NOT NULL auto_increment,
94
- `references` int(11) NOT NULL,
95
- PRIMARY KEY (`id`)
96
- );
@@ -1,4 +0,0 @@
1
- CREATE TABLE `courses` (
2
- `id` INTEGER NOT NULL PRIMARY KEY,
3
- `name` VARCHAR(255) NOT NULL
4
- );
@@ -1,2 +0,0 @@
1
- id => 1
2
- name => David
@@ -1,2 +0,0 @@
1
- id => 2
2
- name => Jamis
@@ -1,3 +0,0 @@
1
- id => 1
2
- course_id => 1
3
- name => Ruby Developer