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
@@ -1,7 +1,7 @@
1
- require 'abstract_unit'
2
- require 'fixtures/course'
1
+ require "cases/helper"
2
+ require 'models/course'
3
3
 
4
- class FirebirdMigrationTest < Test::Unit::TestCase
4
+ class FirebirdMigrationTest < ActiveRecord::TestCase
5
5
  self.use_transactional_fixtures = false
6
6
 
7
7
  def setup
@@ -1,4 +1,4 @@
1
- require 'abstract_unit'
1
+ require "cases/helper"
2
2
 
3
3
  class Mixin < ActiveRecord::Base
4
4
  end
@@ -7,7 +7,7 @@ end
7
7
  class Time
8
8
  @@forced_now_time = nil
9
9
  cattr_accessor :forced_now_time
10
-
10
+
11
11
  class << self
12
12
  def now_with_forcing
13
13
  if @@forced_now_time
@@ -21,13 +21,13 @@ class Time
21
21
  end
22
22
 
23
23
 
24
- class TouchTest < Test::Unit::TestCase
24
+ class TouchTest < ActiveRecord::TestCase
25
25
  fixtures :mixins
26
-
26
+
27
27
  def setup
28
28
  Time.forced_now_time = Time.now
29
29
  end
30
-
30
+
31
31
  def teardown
32
32
  Time.forced_now_time = nil
33
33
  end
@@ -36,7 +36,7 @@ class TouchTest < Test::Unit::TestCase
36
36
  five_minutes_ago = 5.minutes.ago
37
37
  Time.forced_now_time = five_minutes_ago
38
38
  assert_equal five_minutes_ago, Time.now
39
-
39
+
40
40
  Time.forced_now_time = nil
41
41
  assert_not_equal five_minutes_ago, Time.now
42
42
  end
@@ -69,6 +69,7 @@ class TouchTest < Test::Unit::TestCase
69
69
  old_updated_at = stamped.updated_at
70
70
 
71
71
  Time.forced_now_time = 5.minutes.from_now
72
+ stamped.lft_will_change!
72
73
  stamped.save
73
74
 
74
75
  assert_equal Time.now, stamped.updated_at
@@ -1,7 +1,7 @@
1
- require 'abstract_unit'
2
- require 'fixtures/company_in_module'
1
+ require "cases/helper"
2
+ require 'models/company_in_module'
3
3
 
4
- class ModulesTest < Test::Unit::TestCase
4
+ class ModulesTest < ActiveRecord::TestCase
5
5
  fixtures :accounts, :companies, :projects, :developers
6
6
 
7
7
  def test_module_spanning_associations
@@ -15,7 +15,7 @@ class ModulesTest < Test::Unit::TestCase
15
15
  project.developers << MyApplication::Business::Developer.create("name" => "John")
16
16
  assert "John", project.developers.last.name
17
17
  end
18
-
18
+
19
19
  def test_associations_spanning_cross_modules
20
20
  account = MyApplication::Billing::Account.find(:first, :order => 'id')
21
21
  assert_kind_of MyApplication::Business::Firm, account.firm
@@ -24,11 +24,16 @@ class ModulesTest < Test::Unit::TestCase
24
24
  assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_qualified_billing_firm
25
25
  assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_unqualified_billing_firm
26
26
  end
27
-
27
+
28
28
  def test_find_account_and_include_company
29
29
  account = MyApplication::Billing::Account.find(1, :include => :firm)
30
30
  assert_kind_of MyApplication::Business::Firm, account.instance_variable_get('@firm')
31
31
  assert_kind_of MyApplication::Business::Firm, account.firm
32
32
  end
33
-
33
+
34
+ def test_table_name
35
+ assert_equal 'accounts', MyApplication::Billing::Account.table_name, 'table_name for ActiveRecord model in module'
36
+ assert_equal 'companies', MyApplication::Business::Client.table_name, 'table_name for ActiveRecord model subclass'
37
+ assert_equal 'company_contacts', MyApplication::Business::Client::Contact.table_name, 'table_name for ActiveRecord model enclosed by another ActiveRecord model'
38
+ end
34
39
  end
@@ -1,10 +1,10 @@
1
- require 'abstract_unit'
2
- require 'fixtures/entrant'
1
+ require "cases/helper"
2
+ require 'models/entrant'
3
3
 
4
4
  # So we can test whether Course.connection survives a reload.
5
- require_dependency 'fixtures/course'
5
+ require_dependency 'models/course'
6
6
 
7
- class MultipleDbTest < Test::Unit::TestCase
7
+ class MultipleDbTest < ActiveRecord::TestCase
8
8
  self.use_transactional_fixtures = false
9
9
 
10
10
  def setup
@@ -53,7 +53,7 @@ class MultipleDbTest < Test::Unit::TestCase
53
53
 
54
54
  Dependencies.clear
55
55
  Object.send(:remove_const, :Course)
56
- require_dependency 'fixtures/course'
56
+ require_dependency 'models/course'
57
57
 
58
58
  assert Course.connection
59
59
  end
@@ -0,0 +1,157 @@
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/topic'
4
+ require 'models/comment'
5
+ require 'models/reply'
6
+ require 'models/author'
7
+
8
+ class NamedScopeTest < ActiveRecord::TestCase
9
+ fixtures :posts, :authors, :topics, :comments
10
+
11
+ def test_implements_enumerable
12
+ assert !Topic.find(:all).empty?
13
+
14
+ assert_equal Topic.find(:all), Topic.base
15
+ assert_equal Topic.find(:all), Topic.base.to_a
16
+ assert_equal Topic.find(:first), Topic.base.first
17
+ assert_equal Topic.find(:all), Topic.base.each { |i| i }
18
+ end
19
+
20
+ def test_found_items_are_cached
21
+ Topic.columns
22
+ all_posts = Topic.base
23
+
24
+ assert_queries(1) do
25
+ all_posts.collect
26
+ all_posts.collect
27
+ end
28
+ end
29
+
30
+ def test_reload_expires_cache_of_found_items
31
+ all_posts = Topic.base
32
+ all_posts.inspect
33
+
34
+ new_post = Topic.create!
35
+ assert !all_posts.include?(new_post)
36
+ assert all_posts.reload.include?(new_post)
37
+ end
38
+
39
+ def test_delegates_finds_and_calculations_to_the_base_class
40
+ assert !Topic.find(:all).empty?
41
+
42
+ assert_equal Topic.find(:all), Topic.base.find(:all)
43
+ assert_equal Topic.find(:first), Topic.base.find(:first)
44
+ assert_equal Topic.count, Topic.base.count
45
+ assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
46
+ end
47
+
48
+ def test_subclasses_inherit_scopes
49
+ assert Topic.scopes.include?(:base)
50
+
51
+ assert Reply.scopes.include?(:base)
52
+ assert_equal Reply.find(:all), Reply.base
53
+ end
54
+
55
+ def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
56
+ assert !Topic.find(:all, :conditions => {:approved => true}).empty?
57
+
58
+ assert_equal Topic.find(:all, :conditions => {:approved => true}), Topic.approved
59
+ assert_equal Topic.count(:conditions => {:approved => true}), Topic.approved.count
60
+ end
61
+
62
+ def test_scopes_are_composable
63
+ assert_equal (approved = Topic.find(:all, :conditions => {:approved => true})), Topic.approved
64
+ assert_equal (replied = Topic.find(:all, :conditions => 'replies_count > 0')), Topic.replied
65
+ assert !(approved == replied)
66
+ assert !(approved & replied).empty?
67
+
68
+ assert_equal approved & replied, Topic.approved.replied
69
+ end
70
+
71
+ def test_procedural_scopes
72
+ topics_written_before_the_third = Topic.find(:all, :conditions => ['written_on < ?', topics(:third).written_on])
73
+ topics_written_before_the_second = Topic.find(:all, :conditions => ['written_on < ?', topics(:second).written_on])
74
+ assert_not_equal topics_written_before_the_second, topics_written_before_the_third
75
+
76
+ assert_equal topics_written_before_the_third, Topic.written_before(topics(:third).written_on)
77
+ assert_equal topics_written_before_the_second, Topic.written_before(topics(:second).written_on)
78
+ end
79
+
80
+ def test_extensions
81
+ assert_equal 1, Topic.anonymous_extension.one
82
+ assert_equal 2, Topic.named_extension.two
83
+ end
84
+
85
+ def test_multiple_extensions
86
+ assert_equal 2, Topic.multiple_extensions.extension_two
87
+ assert_equal 1, Topic.multiple_extensions.extension_one
88
+ end
89
+
90
+ def test_has_many_associations_have_access_to_named_scopes
91
+ assert_not_equal Post.containing_the_letter_a, authors(:david).posts
92
+ assert !Post.containing_the_letter_a.empty?
93
+
94
+ assert_equal authors(:david).posts & Post.containing_the_letter_a, authors(:david).posts.containing_the_letter_a
95
+ end
96
+
97
+ def test_has_many_through_associations_have_access_to_named_scopes
98
+ assert_not_equal Comment.containing_the_letter_e, authors(:david).comments
99
+ assert !Comment.containing_the_letter_e.empty?
100
+
101
+ assert_equal authors(:david).comments & Comment.containing_the_letter_e, authors(:david).comments.containing_the_letter_e
102
+ end
103
+
104
+ def test_active_records_have_scope_named__all__
105
+ assert !Topic.find(:all).empty?
106
+
107
+ assert_equal Topic.find(:all), Topic.base
108
+ end
109
+
110
+ def test_active_records_have_scope_named__scoped__
111
+ assert !Topic.find(:all, scope = {:conditions => "content LIKE '%Have%'"}).empty?
112
+
113
+ assert_equal Topic.find(:all, scope), Topic.scoped(scope)
114
+ end
115
+
116
+ def test_proxy_options
117
+ expected_proxy_options = { :conditions => { :approved => true } }
118
+ assert_equal expected_proxy_options, Topic.approved.proxy_options
119
+ end
120
+
121
+ def test_first_and_last_should_support_find_options
122
+ assert_equal Topic.base.first(:order => 'title'), Topic.base.find(:first, :order => 'title')
123
+ assert_equal Topic.base.last(:order => 'title'), Topic.base.find(:last, :order => 'title')
124
+ end
125
+
126
+ def test_first_and_last_should_allow_integers_for_limit
127
+ assert_equal Topic.base.first(2), Topic.base.to_a.first(2)
128
+ assert_equal Topic.base.last(2), Topic.base.to_a.last(2)
129
+ end
130
+
131
+ def test_first_and_last_should_not_use_query_when_results_are_loaded
132
+ topics = Topic.base
133
+ topics.reload # force load
134
+ assert_no_queries do
135
+ topics.first
136
+ topics.last
137
+ end
138
+ end
139
+
140
+ def test_first_and_last_find_options_should_use_query_when_results_are_loaded
141
+ topics = Topic.base
142
+ topics.reload # force load
143
+ assert_queries(2) do
144
+ topics.first(:order => 'title')
145
+ topics.last(:order => 'title')
146
+ end
147
+ end
148
+
149
+ def test_empty_should_not_load_results
150
+ topics = Topic.base
151
+ assert_queries(2) do
152
+ topics.empty? # use count query
153
+ topics.collect # force load
154
+ topics.empty? # use loaded (no query)
155
+ end
156
+ end
157
+ end
@@ -1,12 +1,12 @@
1
- require "#{File.dirname(__FILE__)}/abstract_unit"
2
- require 'fixtures/topic'
3
- require 'fixtures/reply'
4
- require 'fixtures/subscriber'
5
- require 'fixtures/movie'
6
- require 'fixtures/keyboard'
7
- require 'fixtures/mixed_case_monkey'
1
+ require "cases/helper"
2
+ require 'models/topic'
3
+ require 'models/reply'
4
+ require 'models/subscriber'
5
+ require 'models/movie'
6
+ require 'models/keyboard'
7
+ require 'models/mixed_case_monkey'
8
8
 
9
- class PrimaryKeysTest < Test::Unit::TestCase
9
+ class PrimaryKeysTest < ActiveRecord::TestCase
10
10
  fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
11
11
 
12
12
  def test_integer_key
@@ -65,7 +65,7 @@ class PrimaryKeysTest < Test::Unit::TestCase
65
65
  def test_find_with_more_than_one_string_key
66
66
  assert_equal 2, Subscriber.find(subscribers(:first).nick, subscribers(:second).nick).length
67
67
  end
68
-
68
+
69
69
  def test_primary_key_prefix
70
70
  ActiveRecord::Base.primary_key_prefix_type = :table_name
71
71
  Topic.reset_primary_key
@@ -79,7 +79,7 @@ class PrimaryKeysTest < Test::Unit::TestCase
79
79
  Topic.reset_primary_key
80
80
  assert_equal "id", Topic.primary_key
81
81
  end
82
-
82
+
83
83
  def test_delete_should_quote_pkey
84
84
  assert_nothing_raised { MixedCaseMonkey.delete(1) }
85
85
  end
@@ -1,13 +1,13 @@
1
- require 'abstract_unit'
2
- require 'fixtures/topic'
3
- require 'fixtures/reply'
4
- require 'fixtures/task'
5
- require 'fixtures/course'
6
- require 'fixtures/category'
7
- require 'fixtures/post'
1
+ require "cases/helper"
2
+ require 'models/topic'
3
+ require 'models/reply'
4
+ require 'models/task'
5
+ require 'models/course'
6
+ require 'models/category'
7
+ require 'models/post'
8
8
 
9
9
 
10
- class QueryCacheTest < ActiveSupport::TestCase
10
+ class QueryCacheTest < ActiveRecord::TestCase
11
11
  fixtures :tasks, :topics, :categories, :posts, :categories_posts
12
12
 
13
13
  def test_find_queries
@@ -57,7 +57,7 @@ end
57
57
 
58
58
  uses_mocha 'QueryCacheExpiryTest' do
59
59
 
60
- class QueryCacheExpiryTest < Test::Unit::TestCase
60
+ class QueryCacheExpiryTest < ActiveRecord::TestCase
61
61
  fixtures :tasks
62
62
 
63
63
  def test_find
@@ -82,7 +82,9 @@ class QueryCacheExpiryTest < Test::Unit::TestCase
82
82
  Task.connection.expects(:clear_query_cache).times(2)
83
83
 
84
84
  Task.cache do
85
- Task.find(1).save!
85
+ task = Task.find(1)
86
+ task.starting = Time.now.utc
87
+ task.save!
86
88
  end
87
89
  end
88
90
 
@@ -1,17 +1,17 @@
1
- require 'abstract_unit'
2
- require 'fixtures/post'
3
- require 'fixtures/comment'
4
- require 'fixtures/developer'
5
- require 'fixtures/project'
6
- require 'fixtures/reader'
7
- require 'fixtures/person'
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/comment'
4
+ require 'models/developer'
5
+ require 'models/project'
6
+ require 'models/reader'
7
+ require 'models/person'
8
8
 
9
9
  # Dummy class methods to test implicit association scoping.
10
10
  def Comment.foo() find :first end
11
11
  def Project.foo() find :first end
12
12
 
13
13
 
14
- class ReadOnlyTest < Test::Unit::TestCase
14
+ class ReadOnlyTest < ActiveRecord::TestCase
15
15
  fixtures :posts, :comments, :developers, :projects, :developers_projects
16
16
 
17
17
  def test_cant_save_readonly_record
@@ -71,13 +71,13 @@ class ReadOnlyTest < Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def test_readonly_scoping
74
- Post.with_scope(:find => { :conditions => '1=1' }) do
74
+ Post.with_scope(:find => { :conditions => '1=1' }) do
75
75
  assert !Post.find(1).readonly?
76
76
  assert Post.find(1, :readonly => true).readonly?
77
77
  assert !Post.find(1, :readonly => false).readonly?
78
78
  end
79
79
 
80
- Post.with_scope(:find => { :joins => ' ' }) do
80
+ Post.with_scope(:find => { :joins => ' ' }) do
81
81
  assert !Post.find(1).readonly?
82
82
  assert Post.find(1, :readonly => true).readonly?
83
83
  assert !Post.find(1, :readonly => false).readonly?
@@ -86,7 +86,7 @@ class ReadOnlyTest < Test::Unit::TestCase
86
86
  # Oracle barfs on this because the join includes unqualified and
87
87
  # conflicting column names
88
88
  unless current_adapter?(:OracleAdapter)
89
- Post.with_scope(:find => { :joins => ', developers' }) do
89
+ Post.with_scope(:find => { :joins => ', developers' }) do
90
90
  assert Post.find(1).readonly?
91
91
  assert Post.find(1, :readonly => true).readonly?
92
92
  assert !Post.find(1, :readonly => false).readonly?
@@ -1,11 +1,11 @@
1
- require 'abstract_unit'
2
- require 'fixtures/topic'
3
- require 'fixtures/customer'
4
- require 'fixtures/company'
5
- require 'fixtures/company_in_module'
6
- require 'fixtures/subscriber'
7
-
8
- class ReflectionTest < Test::Unit::TestCase
1
+ require "cases/helper"
2
+ require 'models/topic'
3
+ require 'models/customer'
4
+ require 'models/company'
5
+ require 'models/company_in_module'
6
+ require 'models/subscriber'
7
+
8
+ class ReflectionTest < ActiveRecord::TestCase
9
9
  fixtures :topics, :customers, :companies, :subscribers
10
10
 
11
11
  def setup
@@ -45,7 +45,7 @@ class ReflectionTest < Test::Unit::TestCase
45
45
  assert_equal :string, @first.column_for_attribute("title").type
46
46
  assert_equal 255, @first.column_for_attribute("title").limit
47
47
  end
48
-
48
+
49
49
  def test_column_null_not_null
50
50
  subscriber = Subscriber.find(:first)
51
51
  assert subscriber.column_for_attribute("name").null
@@ -87,7 +87,7 @@ class ReflectionTest < Test::Unit::TestCase
87
87
  assert_equal reflection_for_address, Customer.reflect_on_aggregation(:address)
88
88
 
89
89
  assert_equal Address, Customer.reflect_on_aggregation(:address).klass
90
-
90
+
91
91
  assert_equal Money, Customer.reflect_on_aggregation(:balance).klass
92
92
  end
93
93
 
@@ -157,11 +157,12 @@ class ReflectionTest < Test::Unit::TestCase
157
157
  :class_name => 'Nested::Firm',
158
158
  :table_name => 'companies'
159
159
  end
160
-
160
+
161
161
  def test_reflection_of_all_associations
162
- assert_equal 17, Firm.reflect_on_all_associations.size
163
- assert_equal 15, Firm.reflect_on_all_associations(:has_many).size
164
- assert_equal 2, Firm.reflect_on_all_associations(:has_one).size
162
+ # FIXME these assertions bust a lot
163
+ assert_equal 20, Firm.reflect_on_all_associations.size
164
+ assert_equal 16, Firm.reflect_on_all_associations(:has_many).size
165
+ assert_equal 4, Firm.reflect_on_all_associations(:has_one).size
165
166
  assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
166
167
  end
167
168