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,22 +1,22 @@
1
- require 'abstract_unit'
2
- require 'fixtures/post'
3
- require 'fixtures/binary'
4
- require 'fixtures/topic'
5
- require 'fixtures/computer'
6
- require 'fixtures/developer'
7
- require 'fixtures/company'
8
- require 'fixtures/task'
9
- require 'fixtures/reply'
10
- require 'fixtures/joke'
11
- require 'fixtures/course'
12
- require 'fixtures/category'
13
- require 'fixtures/parrot'
14
- require 'fixtures/pirate'
15
- require 'fixtures/treasure'
16
- require 'fixtures/matey'
17
- require 'fixtures/ship'
18
-
19
- class FixturesTest < Test::Unit::TestCase
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/binary'
4
+ require 'models/topic'
5
+ require 'models/computer'
6
+ require 'models/developer'
7
+ require 'models/company'
8
+ require 'models/task'
9
+ require 'models/reply'
10
+ require 'models/joke'
11
+ require 'models/course'
12
+ require 'models/category'
13
+ require 'models/parrot'
14
+ require 'models/pirate'
15
+ require 'models/treasure'
16
+ require 'models/matey'
17
+ require 'models/ship'
18
+
19
+ class FixturesTest < ActiveRecord::TestCase
20
20
  self.use_instantiated_fixtures = true
21
21
  self.use_transactional_fixtures = false
22
22
 
@@ -27,8 +27,6 @@ class FixturesTest < Test::Unit::TestCase
27
27
  movies projects subscribers topics tasks )
28
28
  MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/
29
29
 
30
- BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg'
31
-
32
30
  def test_clean_fixtures
33
31
  FIXTURES.each do |name|
34
32
  fixtures = nil
@@ -98,6 +96,10 @@ class FixturesTest < Test::Unit::TestCase
98
96
 
99
97
  second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
100
98
  assert_nil(second_row["author_email_address"])
99
+
100
+ # This checks for a caching problem which causes a bug in the fixtures
101
+ # class-level configuration helper.
102
+ assert_not_nil topics, "Fixture data inserted, but fixture objects not returned from create"
101
103
  ensure
102
104
  # Restore prefix/suffix to its previous values
103
105
  ActiveRecord::Base.table_name_prefix = old_prefix
@@ -113,22 +115,6 @@ class FixturesTest < Test::Unit::TestCase
113
115
  assert first
114
116
  end
115
117
 
116
- def test_bad_format
117
- path = File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures')
118
- Dir.entries(path).each do |file|
119
- next unless File.file?(file) and file !~ Fixtures::DEFAULT_FILTER_RE
120
- assert_raise(Fixture::FormatError) {
121
- Fixture.new(bad_fixtures_path, file)
122
- }
123
- end
124
- end
125
-
126
- def test_deprecated_yaml_extension
127
- assert_raise(Fixture::FormatError) {
128
- Fixtures.new(nil, 'bad_extension', 'BadExtension', File.join(File.dirname(__FILE__), 'fixtures'))
129
- }
130
- end
131
-
132
118
  def test_logger_level_invariant
133
119
  level = ActiveRecord::Base.logger.level
134
120
  create_fixtures('topics')
@@ -141,7 +127,7 @@ class FixturesTest < Test::Unit::TestCase
141
127
  end
142
128
 
143
129
  def test_complete_instantiation
144
- assert_equal 2, @topics.size
130
+ assert_equal 4, @topics.size
145
131
  assert_equal "The First Topic", @first.title
146
132
  end
147
133
 
@@ -156,26 +142,26 @@ class FixturesTest < Test::Unit::TestCase
156
142
  end
157
143
 
158
144
  def test_empty_yaml_fixture
159
- assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/fixtures/naked/yml/accounts")
145
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/yml/accounts")
160
146
  end
161
147
 
162
148
  def test_empty_yaml_fixture_with_a_comment_in_it
163
- assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', File.dirname(__FILE__) + "/fixtures/naked/yml/companies")
149
+ assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', FIXTURES_ROOT + "/naked/yml/companies")
164
150
  end
165
151
 
166
152
  def test_dirty_dirty_yaml_file
167
153
  assert_raises(Fixture::FormatError) do
168
- Fixtures.new( Account.connection, "courses", 'Course', File.dirname(__FILE__) + "/fixtures/naked/yml/courses")
154
+ Fixtures.new( Account.connection, "courses", 'Course', FIXTURES_ROOT + "/naked/yml/courses")
169
155
  end
170
156
  end
171
157
 
172
158
  def test_empty_csv_fixtures
173
- assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/fixtures/naked/csv/accounts")
159
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
174
160
  end
175
161
 
176
162
  def test_omap_fixtures
177
163
  assert_nothing_raised do
178
- fixtures = Fixtures.new(Account.connection, 'categories', 'Category', File.dirname(__FILE__) + '/fixtures/categories_ordered')
164
+ fixtures = Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
179
165
 
180
166
  i = 0
181
167
  fixtures.each do |name, fixture|
@@ -198,13 +184,15 @@ class FixturesTest < Test::Unit::TestCase
198
184
 
199
185
  def test_binary_in_fixtures
200
186
  assert_equal 1, @binaries.size
201
- data = File.open(BINARY_FIXTURE_PATH, "rb").read.freeze
187
+ data = File.read(ASSETS_ROOT + "/flowers.jpg")
188
+ data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
189
+ data.freeze
202
190
  assert_equal data, @flowers.data
203
191
  end
204
192
  end
205
193
 
206
194
  if Account.connection.respond_to?(:reset_pk_sequence!)
207
- class FixturesResetPkSequenceTest < Test::Unit::TestCase
195
+ class FixturesResetPkSequenceTest < ActiveRecord::TestCase
208
196
  fixtures :accounts
209
197
  fixtures :companies
210
198
 
@@ -250,7 +238,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
250
238
  end
251
239
  end
252
240
 
253
- class FixturesWithoutInstantiationTest < Test::Unit::TestCase
241
+ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
254
242
  self.use_instantiated_fixtures = false
255
243
  fixtures :topics, :developers, :accounts
256
244
 
@@ -285,7 +273,7 @@ class FixturesWithoutInstantiationTest < Test::Unit::TestCase
285
273
  end
286
274
  end
287
275
 
288
- class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
276
+ class FixturesWithoutInstanceInstantiationTest < ActiveRecord::TestCase
289
277
  self.use_instantiated_fixtures = true
290
278
  self.use_instantiated_fixtures = :no_instances
291
279
 
@@ -299,7 +287,7 @@ class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
299
287
  end
300
288
  end
301
289
 
302
- class TransactionalFixturesTest < Test::Unit::TestCase
290
+ class TransactionalFixturesTest < ActiveRecord::TestCase
303
291
  self.use_instantiated_fixtures = true
304
292
  self.use_transactional_fixtures = true
305
293
 
@@ -315,7 +303,7 @@ class TransactionalFixturesTest < Test::Unit::TestCase
315
303
  end
316
304
  end
317
305
 
318
- class MultipleFixturesTest < Test::Unit::TestCase
306
+ class MultipleFixturesTest < ActiveRecord::TestCase
319
307
  fixtures :topics
320
308
  fixtures :developers, :accounts
321
309
 
@@ -324,13 +312,13 @@ class MultipleFixturesTest < Test::Unit::TestCase
324
312
  end
325
313
  end
326
314
 
327
- class SetupTest < Test::Unit::TestCase
315
+ class SetupTest < ActiveRecord::TestCase
328
316
  # fixtures :topics
329
-
317
+
330
318
  def setup
331
319
  @first = true
332
320
  end
333
-
321
+
334
322
  def test_nothing
335
323
  end
336
324
  end
@@ -340,7 +328,7 @@ class SetupSubclassTest < SetupTest
340
328
  super
341
329
  @second = true
342
330
  end
343
-
331
+
344
332
  def test_subclassing_should_preserve_setups
345
333
  assert @first
346
334
  assert @second
@@ -348,7 +336,7 @@ class SetupSubclassTest < SetupTest
348
336
  end
349
337
 
350
338
 
351
- class OverlappingFixturesTest < Test::Unit::TestCase
339
+ class OverlappingFixturesTest < ActiveRecord::TestCase
352
340
  fixtures :topics, :developers
353
341
  fixtures :developers, :accounts
354
342
 
@@ -357,7 +345,7 @@ class OverlappingFixturesTest < Test::Unit::TestCase
357
345
  end
358
346
  end
359
347
 
360
- class ForeignKeyFixturesTest < Test::Unit::TestCase
348
+ class ForeignKeyFixturesTest < ActiveRecord::TestCase
361
349
  fixtures :fk_test_has_pk, :fk_test_has_fk
362
350
 
363
351
  # if foreign keys are implemented and fixtures
@@ -373,18 +361,24 @@ class ForeignKeyFixturesTest < Test::Unit::TestCase
373
361
  end
374
362
  end
375
363
 
376
- class SetTableNameFixturesTest < Test::Unit::TestCase
364
+ class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
377
365
  set_fixture_class :funny_jokes => 'Joke'
378
366
  fixtures :funny_jokes
367
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
368
+ # and thus takes into account our set_fixture_class
369
+ self.use_transactional_fixtures = false
379
370
 
380
371
  def test_table_method
381
372
  assert_kind_of Joke, funny_jokes(:a_joke)
382
373
  end
383
374
  end
384
375
 
385
- class CustomConnectionFixturesTest < Test::Unit::TestCase
376
+ class CustomConnectionFixturesTest < ActiveRecord::TestCase
386
377
  set_fixture_class :courses => Course
387
378
  fixtures :courses
379
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
380
+ # and thus takes into account our set_fixture_class
381
+ self.use_transactional_fixtures = false
388
382
 
389
383
  def test_connection
390
384
  assert_kind_of Course, courses(:ruby)
@@ -392,8 +386,11 @@ class CustomConnectionFixturesTest < Test::Unit::TestCase
392
386
  end
393
387
  end
394
388
 
395
- class InvalidTableNameFixturesTest < Test::Unit::TestCase
389
+ class InvalidTableNameFixturesTest < ActiveRecord::TestCase
396
390
  fixtures :funny_jokes
391
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
392
+ # and thus takes into account our lack of set_fixture_class
393
+ self.use_transactional_fixtures = false
397
394
 
398
395
  def test_raises_error
399
396
  assert_raises FixtureClassNotFound do
@@ -402,9 +399,12 @@ class InvalidTableNameFixturesTest < Test::Unit::TestCase
402
399
  end
403
400
  end
404
401
 
405
- class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
402
+ class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
406
403
  set_fixture_class :funny_jokes => 'Joke'
407
404
  fixtures :funny_jokes
405
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
406
+ # and thus takes into account our set_fixture_class
407
+ self.use_transactional_fixtures = false
408
408
 
409
409
  def test_proper_escaped_fixture
410
410
  assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
@@ -412,7 +412,7 @@ class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
412
412
  end
413
413
 
414
414
  class DevelopersProject; end
415
- class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
415
+ class ManyToManyFixturesWithClassDefined < ActiveRecord::TestCase
416
416
  fixtures :developers_projects
417
417
 
418
418
  def test_this_should_run_cleanly
@@ -420,22 +420,22 @@ class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
420
420
  end
421
421
  end
422
422
 
423
- class FixturesBrokenRollbackTest < Test::Unit::TestCase
423
+ class FixturesBrokenRollbackTest < ActiveRecord::TestCase
424
424
  def blank_setup; end
425
- alias_method :ar_setup_with_fixtures, :setup_with_fixtures
426
- alias_method :setup_with_fixtures, :blank_setup
425
+ alias_method :ar_setup_fixtures, :setup_fixtures
426
+ alias_method :setup_fixtures, :blank_setup
427
427
  alias_method :setup, :blank_setup
428
428
 
429
429
  def blank_teardown; end
430
- alias_method :ar_teardown_with_fixtures, :teardown_with_fixtures
431
- alias_method :teardown_with_fixtures, :blank_teardown
430
+ alias_method :ar_teardown_fixtures, :teardown_fixtures
431
+ alias_method :teardown_fixtures, :blank_teardown
432
432
  alias_method :teardown, :blank_teardown
433
433
 
434
434
  def test_no_rollback_in_teardown_unless_transaction_active
435
435
  assert_equal 0, Thread.current['open_transactions']
436
- assert_raise(RuntimeError) { ar_setup_with_fixtures }
436
+ assert_raise(RuntimeError) { ar_setup_fixtures }
437
437
  assert_equal 0, Thread.current['open_transactions']
438
- assert_nothing_raised { ar_teardown_with_fixtures }
438
+ assert_nothing_raised { ar_teardown_fixtures }
439
439
  assert_equal 0, Thread.current['open_transactions']
440
440
  end
441
441
 
@@ -445,8 +445,8 @@ class FixturesBrokenRollbackTest < Test::Unit::TestCase
445
445
  end
446
446
  end
447
447
 
448
- class LoadAllFixturesTest < Test::Unit::TestCase
449
- self.fixture_path= File.join(File.dirname(__FILE__), '/fixtures/all')
448
+ class LoadAllFixturesTest < ActiveRecord::TestCase
449
+ self.fixture_path = FIXTURES_ROOT + "/all"
450
450
  fixtures :all
451
451
 
452
452
  def test_all_there
@@ -454,7 +454,7 @@ class LoadAllFixturesTest < Test::Unit::TestCase
454
454
  end
455
455
  end
456
456
 
457
- class FasterFixturesTest < Test::Unit::TestCase
457
+ class FasterFixturesTest < ActiveRecord::TestCase
458
458
  fixtures :categories, :authors
459
459
 
460
460
  def load_extra_fixture(name)
@@ -479,7 +479,7 @@ class FasterFixturesTest < Test::Unit::TestCase
479
479
  end
480
480
  end
481
481
 
482
- class FoxyFixturesTest < Test::Unit::TestCase
482
+ class FoxyFixturesTest < ActiveRecord::TestCase
483
483
  fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers
484
484
 
485
485
  def test_identifies_strings
@@ -599,7 +599,7 @@ class FoxyFixturesTest < Test::Unit::TestCase
599
599
  end
600
600
  end
601
601
 
602
- class ActiveSupportSubclassWithFixturesTest < ActiveSupport::TestCase
602
+ class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
603
603
  fixtures :parrots
604
604
 
605
605
  # This seemingly useless assertion catches a bug that caused the fixtures
@@ -608,3 +608,19 @@ class ActiveSupportSubclassWithFixturesTest < ActiveSupport::TestCase
608
608
  assert_equal parrots(:louis), Parrot.find_by_name("King Louis")
609
609
  end
610
610
  end
611
+
612
+ class FixtureLoadingTest < ActiveRecord::TestCase
613
+ uses_mocha 'reloading_fixtures_through_accessor_methods' do
614
+ def test_logs_message_for_failed_dependency_load
615
+ Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError)
616
+ ActiveRecord::Base.logger.expects(:warn)
617
+ Test::Unit::TestCase.try_to_load_dependency(:does_not_exist)
618
+ end
619
+
620
+ def test_does_not_logs_message_for_successful_dependency_load
621
+ Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine)
622
+ ActiveRecord::Base.logger.expects(:warn).never
623
+ Test::Unit::TestCase.try_to_load_dependency(:works_out_fine)
624
+ end
625
+ end
626
+ end
@@ -0,0 +1,47 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'config'
4
+ require 'test/unit'
5
+
6
+ require 'active_record'
7
+ require 'active_record/fixtures'
8
+ require 'active_record/test_case'
9
+ require 'connection'
10
+
11
+ # Show backtraces for deprecated behavior for quicker cleanup.
12
+ ActiveSupport::Deprecation.debug = true
13
+
14
+ # Quote "type" if it's a reserved word for the current connection.
15
+ QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
16
+
17
+ def current_adapter?(*types)
18
+ types.any? do |type|
19
+ ActiveRecord::ConnectionAdapters.const_defined?(type) &&
20
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
21
+ end
22
+ end
23
+
24
+ def uses_mocha(description)
25
+ require 'rubygems'
26
+ require 'mocha'
27
+ yield
28
+ rescue LoadError
29
+ $stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
30
+ end
31
+
32
+ ActiveRecord::Base.connection.class.class_eval do
33
+ IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]
34
+
35
+ def execute_with_counting(sql, name = nil, &block)
36
+ $query_count ||= 0
37
+ $query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
38
+ execute_without_counting(sql, name, &block)
39
+ end
40
+
41
+ alias_method_chain :execute, :counting
42
+ end
43
+
44
+ # Make with_scope public for tests
45
+ class << ActiveRecord::Base
46
+ public :with_scope, :with_exclusive_scope
47
+ end
@@ -1,11 +1,55 @@
1
- require 'abstract_unit'
2
- require 'fixtures/company'
3
- require 'fixtures/project'
4
- require 'fixtures/subscriber'
1
+ require "cases/helper"
2
+ require 'models/company'
3
+ require 'models/project'
4
+ require 'models/subscriber'
5
5
 
6
- class InheritanceTest < Test::Unit::TestCase
6
+ class InheritanceTest < ActiveRecord::TestCase
7
7
  fixtures :companies, :projects, :subscribers, :accounts
8
8
 
9
+ def test_class_with_store_full_sti_class_returns_full_name
10
+ old = ActiveRecord::Base.store_full_sti_class
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
13
+ ensure
14
+ ActiveRecord::Base.store_full_sti_class = old
15
+ end
16
+
17
+ def test_class_without_store_full_sti_class_returns_demodulized_name
18
+ old = ActiveRecord::Base.store_full_sti_class
19
+ ActiveRecord::Base.store_full_sti_class = false
20
+ assert_equal 'Company', Namespaced::Company.sti_name
21
+ ensure
22
+ ActiveRecord::Base.store_full_sti_class = old
23
+ end
24
+
25
+ def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled
26
+ old = ActiveRecord::Base.store_full_sti_class
27
+ ActiveRecord::Base.store_full_sti_class = false
28
+ item = Namespaced::Company.new
29
+ assert_equal 'Company', item[:type]
30
+ ensure
31
+ ActiveRecord::Base.store_full_sti_class = old
32
+ end
33
+
34
+ def test_should_store_full_class_name_with_store_full_sti_class_option_enabled
35
+ old = ActiveRecord::Base.store_full_sti_class
36
+ ActiveRecord::Base.store_full_sti_class = true
37
+ item = Namespaced::Company.new
38
+ assert_equal 'Namespaced::Company', item[:type]
39
+ ensure
40
+ ActiveRecord::Base.store_full_sti_class = old
41
+ end
42
+
43
+ def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option
44
+ old = ActiveRecord::Base.store_full_sti_class
45
+ ActiveRecord::Base.store_full_sti_class = true
46
+ item = Namespaced::Company.create :name => "Wolverine 2"
47
+ assert_not_nil Company.find(item.id)
48
+ assert_not_nil Namespaced::Company.find(item.id)
49
+ ensure
50
+ ActiveRecord::Base.store_full_sti_class = old
51
+ end
52
+
9
53
  def test_company_descends_from_active_record
10
54
  assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? }
11
55
  assert AbstractCompany.descends_from_active_record?, 'AbstractCompany should descend from ActiveRecord::Base'
@@ -33,7 +77,7 @@ class InheritanceTest < Test::Unit::TestCase
33
77
  assert Company.find(2).kind_of?(Client), "Summit should be a client"
34
78
  assert Client.find(2).kind_of?(Client), "Summit should be a client"
35
79
  end
36
-
80
+
37
81
  def test_alt_inheritance_find
38
82
  switch_to_alt_inheritance_column
39
83
  test_inheritance_find
@@ -45,7 +89,7 @@ class InheritanceTest < Test::Unit::TestCase
45
89
  assert companies[0].kind_of?(Firm), "37signals should be a firm"
46
90
  assert companies[1].kind_of?(Client), "Summit should be a client"
47
91
  end
48
-
92
+
49
93
  def test_alt_inheritance_find_all
50
94
  switch_to_alt_inheritance_column
51
95
  test_inheritance_find_all
@@ -56,11 +100,11 @@ class InheritanceTest < Test::Unit::TestCase
56
100
  firm = Firm.new
57
101
  firm.name = "Next Angle"
58
102
  firm.save
59
-
103
+
60
104
  next_angle = Company.find(firm.id)
61
105
  assert next_angle.kind_of?(Firm), "Next Angle should be a firm"
62
106
  end
63
-
107
+
64
108
  def test_alt_inheritance_save
65
109
  switch_to_alt_inheritance_column
66
110
  test_inheritance_save
@@ -72,7 +116,7 @@ class InheritanceTest < Test::Unit::TestCase
72
116
  assert_equal 2, Firm.count
73
117
  assert_equal 3, Client.count
74
118
  end
75
-
119
+
76
120
  def test_alt_inheritance_condition
77
121
  switch_to_alt_inheritance_column
78
122
  test_inheritance_condition
@@ -83,7 +127,7 @@ class InheritanceTest < Test::Unit::TestCase
83
127
  assert_raises(ActiveRecord::RecordNotFound) { Firm.find(2) }
84
128
  assert_nothing_raised { Firm.find(1) }
85
129
  end
86
-
130
+
87
131
  def test_alt_finding_incorrect_type_data
88
132
  switch_to_alt_inheritance_column
89
133
  test_finding_incorrect_type_data
@@ -95,7 +139,7 @@ class InheritanceTest < Test::Unit::TestCase
95
139
  assert_equal "I am a client", Client.find(:all).first.name
96
140
  assert_equal "37signals", Firm.find(:all).first.name
97
141
  end
98
-
142
+
99
143
  def test_alt_update_all_within_inheritance
100
144
  switch_to_alt_inheritance_column
101
145
  test_update_all_within_inheritance
@@ -107,7 +151,7 @@ class InheritanceTest < Test::Unit::TestCase
107
151
  assert_equal 0, Client.count
108
152
  assert_equal 2, Firm.count
109
153
  end
110
-
154
+
111
155
  def test_alt_destroy_all_within_inheritance
112
156
  switch_to_alt_inheritance_column
113
157
  test_destroy_all_within_inheritance
@@ -119,7 +163,7 @@ class InheritanceTest < Test::Unit::TestCase
119
163
  assert_kind_of Firm, Firm.find(:first, :conditions => "name = '37signals'")
120
164
  assert_nil Client.find(:first, :conditions => "name = '37signals'")
121
165
  end
122
-
166
+
123
167
  def test_alt_find_first_within_inheritance
124
168
  switch_to_alt_inheritance_column
125
169
  test_find_first_within_inheritance
@@ -141,12 +185,12 @@ class InheritanceTest < Test::Unit::TestCase
141
185
  test_complex_inheritance
142
186
  switch_to_default_inheritance_column
143
187
  end
144
-
188
+
145
189
  def test_eager_load_belongs_to_something_inherited
146
190
  account = Account.find(1, :include => :firm)
147
191
  assert_not_nil account.instance_variable_get("@firm"), "nil proves eager load failed"
148
192
  end
149
-
193
+
150
194
  def test_alt_eager_loading
151
195
  switch_to_alt_inheritance_column
152
196
  test_eager_load_belongs_to_something_inherited
@@ -175,7 +219,7 @@ class InheritanceTest < Test::Unit::TestCase
175
219
  end
176
220
 
177
221
 
178
- class InheritanceComputeTypeTest < Test::Unit::TestCase
222
+ class InheritanceComputeTypeTest < ActiveRecord::TestCase
179
223
  fixtures :companies
180
224
 
181
225
  def setup