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
@@ -0,0 +1,3 @@
1
+ class PriceEstimate < ActiveRecord::Base
2
+ belongs_to :estimate_of, :polymorphic => true
3
+ end
@@ -1,5 +1,6 @@
1
1
  class Project < ActiveRecord::Base
2
2
  has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
3
+ has_and_belongs_to_many :readonly_developers, :class_name => "Developer", :readonly => true
3
4
  has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true
4
5
  has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
5
6
  has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
File without changes
@@ -0,0 +1,4 @@
1
+ class Reference < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :job
4
+ end
@@ -1,25 +1,27 @@
1
- require 'fixtures/topic'
1
+ require 'models/topic'
2
2
 
3
3
  class Reply < Topic
4
+ named_scope :base
5
+
4
6
  belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
5
7
  has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
6
8
 
7
9
  validate :errors_on_empty_content
8
10
  validate_on_create :title_is_wrong_create
9
-
11
+
10
12
  attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
11
13
 
12
14
  def validate
13
15
  errors.add("title", "Empty") unless attribute_present? "title"
14
16
  end
15
-
17
+
16
18
  def errors_on_empty_content
17
19
  errors.add("content", "Empty") unless attribute_present? "content"
18
20
  end
19
-
21
+
20
22
  def validate_on_create
21
23
  if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
22
- errors.add("title", "is Content Mismatch")
24
+ errors.add("title", "is Content Mismatch")
23
25
  end
24
26
  end
25
27
 
File without changes
@@ -0,0 +1,4 @@
1
+ class Sponsor < ActiveRecord::Base
2
+ belongs_to :sponsor_club, :class_name => "Club", :foreign_key => "club_id"
3
+ belongs_to :sponsorable, :polymorphic => true
4
+ end
File without changes
@@ -1,5 +1,7 @@
1
1
  class Subscriber < ActiveRecord::Base
2
2
  set_primary_key 'nick'
3
+ has_many :subscriptions
4
+ has_many :books, :through => :subscriptions
3
5
  end
4
6
 
5
7
  class SpecialSubscriber < Subscriber
@@ -0,0 +1,4 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :subscriber
3
+ belongs_to :book
4
+ end
File without changes
File without changes
File without changes
@@ -1,19 +1,47 @@
1
1
  class Topic < ActiveRecord::Base
2
+ named_scope :base
3
+ named_scope :written_before, lambda { |time|
4
+ { :conditions => ['written_on < ?', time] }
5
+ }
6
+ named_scope :approved, :conditions => {:approved => true}
7
+ named_scope :replied, :conditions => ['replies_count > 0']
8
+ named_scope :anonymous_extension do
9
+ def one
10
+ 1
11
+ end
12
+ end
13
+ module NamedExtension
14
+ def two
15
+ 2
16
+ end
17
+ end
18
+ module MultipleExtensionOne
19
+ def extension_one
20
+ 1
21
+ end
22
+ end
23
+ module MultipleExtensionTwo
24
+ def extension_two
25
+ 2
26
+ end
27
+ end
28
+ named_scope :named_extension, :extend => NamedExtension
29
+ named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
30
+
2
31
  has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
3
32
  serialize :content
4
-
33
+
5
34
  before_create :default_written_on
6
35
  before_destroy :destroy_children
7
36
 
8
37
  def parent
9
38
  Topic.find(parent_id)
10
39
  end
11
-
40
+
12
41
  # trivial method for testing Array#to_xml with :methods
13
42
  def topic_id
14
43
  id
15
44
  end
16
-
17
45
 
18
46
  protected
19
47
  def approved=(val)
@@ -34,4 +62,4 @@ class Topic < ActiveRecord::Base
34
62
  self.author_email_address = 'test@test.com'
35
63
  end
36
64
  end
37
- end
65
+ end
@@ -1,4 +1,6 @@
1
1
  class Treasure < ActiveRecord::Base
2
2
  has_and_belongs_to_many :parrots
3
3
  belongs_to :looter, :polymorphic => true
4
+
5
+ has_many :price_estimates, :as => :estimate_of
4
6
  end
File without changes
@@ -0,0 +1,5 @@
1
+ class WarehouseThing < ActiveRecord::Base
2
+ set_table_name "warehouse-things"
3
+
4
+ validates_uniqueness_of :value
5
+ end
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :binary_fields, :force => true do |t|
3
+ t.binary :tiny_blob, :limit => 255
4
+ t.binary :normal_blob, :limit => 65535
5
+ t.binary :medium_blob, :limit => 16777215
6
+ t.binary :long_blob, :limit => 2147483647
7
+ t.text :tiny_text, :limit => 255
8
+ t.text :normal_text, :limit => 65535
9
+ t.text :medium_text, :limit => 16777215
10
+ t.text :long_text, :limit => 2147483647
11
+ end
12
+ end
@@ -0,0 +1,103 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ %w(postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times postgresql_network_addresses postgresql_bit_strings
4
+ postgresql_oids defaults geometrics).each do |table_name|
5
+ execute "DROP TABLE IF EXISTS #{quote_table_name table_name}"
6
+ end
7
+
8
+ execute 'DROP SEQUENCE IF EXISTS companies_nonstd_seq CASCADE'
9
+ execute 'CREATE SEQUENCE companies_nonstd_seq START 101 OWNED BY companies.id'
10
+ execute "ALTER TABLE companies ALTER COLUMN id SET DEFAULT nextval('companies_nonstd_seq')"
11
+ execute 'DROP SEQUENCE IF EXISTS companies_id_seq'
12
+
13
+ %w(accounts_id_seq developers_id_seq projects_id_seq topics_id_seq customers_id_seq orders_id_seq).each do |seq_name|
14
+ execute "SELECT setval('#{seq_name}', 100)"
15
+ end
16
+
17
+ execute <<_SQL
18
+ CREATE TABLE defaults (
19
+ id serial primary key,
20
+ modified_date date default CURRENT_DATE,
21
+ modified_date_function date default now(),
22
+ fixed_date date default '2004-01-01',
23
+ modified_time timestamp default CURRENT_TIMESTAMP,
24
+ modified_time_function timestamp default now(),
25
+ fixed_time timestamp default '2004-01-01 00:00:00.000000-00',
26
+ char1 char(1) default 'Y',
27
+ char2 character varying(50) default 'a varchar field',
28
+ char3 text default 'a text field',
29
+ positive_integer integer default 1,
30
+ negative_integer integer default -1,
31
+ decimal_number decimal(3,2) default 2.78,
32
+ multiline_default text DEFAULT '--- []
33
+
34
+ '::text
35
+ );
36
+ _SQL
37
+
38
+ execute <<_SQL
39
+ CREATE TABLE geometrics (
40
+ id serial primary key,
41
+ a_point point,
42
+ -- a_line line, (the line type is currently not implemented in postgresql)
43
+ a_line_segment lseg,
44
+ a_box box,
45
+ a_path path,
46
+ a_polygon polygon,
47
+ a_circle circle
48
+ );
49
+ _SQL
50
+
51
+ execute <<_SQL
52
+ CREATE TABLE postgresql_arrays (
53
+ id SERIAL PRIMARY KEY,
54
+ commission_by_quarter INTEGER[],
55
+ nicknames TEXT[]
56
+ );
57
+ _SQL
58
+ execute <<_SQL
59
+ CREATE TABLE postgresql_moneys (
60
+ id SERIAL PRIMARY KEY,
61
+ wealth MONEY
62
+ );
63
+ _SQL
64
+
65
+ execute <<_SQL
66
+ CREATE TABLE postgresql_numbers (
67
+ id SERIAL PRIMARY KEY,
68
+ single REAL,
69
+ double DOUBLE PRECISION
70
+ );
71
+ _SQL
72
+
73
+ execute <<_SQL
74
+ CREATE TABLE postgresql_times (
75
+ id SERIAL PRIMARY KEY,
76
+ time_interval INTERVAL
77
+ );
78
+ _SQL
79
+
80
+ execute <<_SQL
81
+ CREATE TABLE postgresql_network_addresses (
82
+ id SERIAL PRIMARY KEY,
83
+ cidr_address CIDR,
84
+ inet_address INET,
85
+ mac_address MACADDR
86
+ );
87
+ _SQL
88
+
89
+ execute <<_SQL
90
+ CREATE TABLE postgresql_bit_strings (
91
+ id SERIAL PRIMARY KEY,
92
+ bit_string BIT(8),
93
+ bit_string_varying BIT VARYING(8)
94
+ );
95
+ _SQL
96
+
97
+ execute <<_SQL
98
+ CREATE TABLE postgresql_oids (
99
+ id SERIAL PRIMARY KEY,
100
+ obj_id OID
101
+ );
102
+ _SQL
103
+ end
@@ -0,0 +1,421 @@
1
+
2
+ ActiveRecord::Schema.define do
3
+ def except(adapter_names_to_exclude)
4
+ unless [adapter_names_to_exclude].flatten.include?(adapter_name)
5
+ yield
6
+ end
7
+ end
8
+
9
+ #put adapter specific setup here
10
+ case adapter_name
11
+ # For Firebird, set the sequence values 10000 when create_table is called;
12
+ # this prevents primary key collisions between "normally" created records
13
+ # and fixture-based (YAML) records.
14
+ when "Firebird"
15
+ def create_table(*args, &block)
16
+ ActiveRecord::Base.connection.create_table(*args, &block)
17
+ ActiveRecord::Base.connection.execute "SET GENERATOR #{args.first}_seq TO 10000"
18
+ end
19
+ end
20
+
21
+
22
+ # Please keep these create table statements in alphabetical order
23
+ # unless the ordering matters. In which case, define them below
24
+ create_table :accounts, :force => true do |t|
25
+ t.integer :firm_id
26
+ t.integer :credit_limit
27
+ end
28
+
29
+ create_table :audit_logs, :force => true do |t|
30
+ t.column :message, :string, :null=>false
31
+ t.column :developer_id, :integer, :null=>false
32
+ end
33
+
34
+ create_table :authors, :force => true do |t|
35
+ t.string :name, :null => false
36
+ t.integer :author_address_id
37
+ t.integer :author_address_extra_id
38
+ end
39
+
40
+ create_table :author_addresses, :force => true do |t|
41
+ end
42
+
43
+ create_table :author_favorites, :force => true do |t|
44
+ t.column :author_id, :integer
45
+ t.column :favorite_author_id, :integer
46
+ end
47
+
48
+
49
+ create_table :auto_id_tests, :force => true, :id => false do |t|
50
+ t.primary_key :auto_id
51
+ t.integer :value
52
+ end
53
+
54
+ create_table :binaries, :force => true do |t|
55
+ t.binary :data
56
+ end
57
+
58
+ create_table :books, :force => true do |t|
59
+ t.column :name, :string
60
+ end
61
+
62
+ create_table :booleantests, :force => true do |t|
63
+ t.integer :value
64
+ end
65
+
66
+ create_table :categories, :force => true do |t|
67
+ t.string :name, :null => false
68
+ t.string :type
69
+ end
70
+
71
+ create_table :categories_posts, :force => true, :id => false do |t|
72
+ t.integer :category_id, :null => false
73
+ t.integer :post_id, :null => false
74
+ end
75
+
76
+ create_table :categorizations, :force => true do |t|
77
+ t.column :category_id, :integer
78
+ t.column :post_id, :integer
79
+ t.column :author_id, :integer
80
+ end
81
+
82
+ create_table :citations, :force => true do |t|
83
+ t.column :book1_id, :integer
84
+ t.column :book2_id, :integer
85
+ end
86
+
87
+ create_table :clubs, :force => true do |t|
88
+ t.string :name
89
+ end
90
+
91
+ create_table :colnametests, :force => true do |t|
92
+ t.integer :references, :null => false
93
+ end
94
+
95
+ create_table :comments, :force => true do |t|
96
+ t.integer :post_id, :null => false
97
+ t.text :body, :null => false
98
+ t.string :type
99
+ end
100
+
101
+ create_table :companies, :force => true do |t|
102
+ t.string :type
103
+ t.string :ruby_type
104
+ t.integer :firm_id
105
+ t.string :name
106
+ t.integer :client_of
107
+ t.integer :rating, :default => 1
108
+ end
109
+
110
+ create_table :computers, :force => true do |t|
111
+ t.integer :developer, :null => false
112
+ t.integer :extendedWarranty, :null => false
113
+ end
114
+
115
+
116
+ create_table :customers, :force => true do |t|
117
+ t.string :name
118
+ t.integer :balance, :default => 0
119
+ t.string :address_street
120
+ t.string :address_city
121
+ t.string :address_country
122
+ t.string :gps_location
123
+ end
124
+
125
+ create_table :developers, :force => true do |t|
126
+ t.string :name
127
+ t.integer :salary, :default => 70000
128
+ t.datetime :created_at
129
+ t.datetime :updated_at
130
+ end
131
+
132
+ create_table :developers_projects, :force => true, :id => false do |t|
133
+ t.integer :developer_id, :null => false
134
+ t.integer :project_id, :null => false
135
+ t.date :joined_on
136
+ t.integer :access_level, :default => 1
137
+ end
138
+
139
+ create_table :edges, :force => true do |t|
140
+ t.column :source_id, :integer, :null => false
141
+ t.column :sink_id, :integer, :null => false
142
+ end
143
+ add_index :edges, [:source_id, :sink_id], :unique => true, :name => 'unique_edge_index'
144
+
145
+
146
+ create_table :entrants, :force => true do |t|
147
+ t.string :name, :null => false
148
+ t.integer :course_id, :null => false
149
+ end
150
+
151
+ create_table :funny_jokes, :force => true do |t|
152
+ t.string :name
153
+ end
154
+
155
+ create_table :items, :force => true do |t|
156
+ t.column :name, :integer
157
+ end
158
+
159
+ create_table :inept_wizards, :force => true do |t|
160
+ t.column :name, :string, :null => false
161
+ t.column :city, :string, :null => false
162
+ t.column :type, :string
163
+ end
164
+
165
+
166
+ create_table :jobs, :force => true do |t|
167
+ t.integer :ideal_reference_id
168
+ end
169
+
170
+ create_table :keyboards, :force => true, :id => false do |t|
171
+ t.primary_key :key_number
172
+ t.string :name
173
+ end
174
+
175
+ create_table :legacy_things, :force => true do |t|
176
+ t.integer :tps_report_number
177
+ t.integer :version, :null => false, :default => 0
178
+ end
179
+
180
+ create_table :lock_without_defaults, :force => true do |t|
181
+ t.column :lock_version, :integer
182
+ end
183
+
184
+ create_table :lock_without_defaults_cust, :force => true do |t|
185
+ t.column :custom_lock_version, :integer
186
+ end
187
+
188
+ create_table :mateys, :id => false, :force => true do |t|
189
+ t.column :pirate_id, :integer
190
+ t.column :target_id, :integer
191
+ t.column :weight, :integer
192
+ end
193
+
194
+ create_table :members, :force => true do |t|
195
+ t.string :name
196
+ end
197
+
198
+ create_table :memberships, :force => true do |t|
199
+ t.datetime :joined_on
200
+ t.integer :club_id, :member_id
201
+ t.boolean :favourite, :default => false
202
+ t.string :type
203
+ end
204
+
205
+ create_table :references, :force => true do |t|
206
+ t.integer :person_id
207
+ t.integer :job_id
208
+ t.boolean :favourite
209
+ t.integer :lock_version, :default => 0
210
+ end
211
+
212
+ create_table :minimalistics, :force => true do |t|
213
+ end
214
+
215
+ create_table :mixed_case_monkeys, :force => true, :id => false do |t|
216
+ t.primary_key :monkeyID
217
+ t.integer :fleaCount
218
+ end
219
+
220
+ create_table :mixins, :force => true do |t|
221
+ t.integer :parent_id
222
+ t.integer :pos
223
+ t.datetime :created_at
224
+ t.datetime :updated_at
225
+ t.integer :lft
226
+ t.integer :rgt
227
+ t.integer :root_id
228
+ t.string :type
229
+ end
230
+
231
+ create_table :movies, :force => true, :id => false do |t|
232
+ t.primary_key :movieid
233
+ t.string :name
234
+ end
235
+
236
+ create_table :numeric_data, :force => true do |t|
237
+ t.decimal :bank_balance, :precision => 10, :scale => 2
238
+ t.decimal :big_bank_balance, :precision => 15, :scale => 2
239
+ t.decimal :world_population, :precision => 10, :scale => 0
240
+ t.decimal :my_house_population, :precision => 2, :scale => 0
241
+ t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78
242
+ end
243
+
244
+ create_table :orders, :force => true do |t|
245
+ t.string :name
246
+ t.integer :billing_customer_id
247
+ t.integer :shipping_customer_id
248
+ end
249
+
250
+ create_table :owners, :primary_key => :owner_id ,:force => true do |t|
251
+ t.string :name
252
+ end
253
+
254
+
255
+ create_table :paint_colors, :force => true do |t|
256
+ t.integer :non_poly_one_id
257
+ end
258
+
259
+ create_table :paint_textures, :force => true do |t|
260
+ t.integer :non_poly_two_id
261
+ end
262
+
263
+ create_table :parrots, :force => true do |t|
264
+ t.column :name, :string
265
+ t.column :parrot_sti_class, :string
266
+ t.column :killer_id, :integer
267
+ t.column :created_at, :datetime
268
+ t.column :created_on, :datetime
269
+ t.column :updated_at, :datetime
270
+ t.column :updated_on, :datetime
271
+ end
272
+
273
+ create_table :parrots_pirates, :id => false, :force => true do |t|
274
+ t.column :parrot_id, :integer
275
+ t.column :pirate_id, :integer
276
+ end
277
+
278
+ create_table :parrots_treasures, :id => false, :force => true do |t|
279
+ t.column :parrot_id, :integer
280
+ t.column :treasure_id, :integer
281
+ end
282
+
283
+ create_table :people, :force => true do |t|
284
+ t.string :first_name, :null => false
285
+ t.integer :lock_version, :null => false, :default => 0
286
+ end
287
+
288
+ create_table :pets, :primary_key => :pet_id ,:force => true do |t|
289
+ t.string :name
290
+ t.integer :owner_id, :integer
291
+ end
292
+
293
+ create_table :pirates, :force => true do |t|
294
+ t.column :catchphrase, :string
295
+ t.column :parrot_id, :integer
296
+ t.column :created_on, :datetime
297
+ t.column :updated_on, :datetime
298
+ end
299
+
300
+ create_table :posts, :force => true do |t|
301
+ t.integer :author_id
302
+ t.string :title, :null => false
303
+ t.text :body, :null => false
304
+ t.string :type
305
+ t.integer :comments_count, :default => 0
306
+ t.integer :taggings_count, :default => 0
307
+ end
308
+
309
+ create_table :price_estimates, :force => true do |t|
310
+ t.string :estimate_of_type
311
+ t.integer :estimate_of_id
312
+ t.integer :price
313
+ end
314
+
315
+ create_table :projects, :force => true do |t|
316
+ t.string :name
317
+ t.string :type
318
+ end
319
+
320
+ create_table :readers, :force => true do |t|
321
+ t.integer :post_id, :null => false
322
+ t.integer :person_id, :null => false
323
+ end
324
+
325
+ create_table :shape_expressions, :force => true do |t|
326
+ t.string :paint_type
327
+ t.integer :paint_id
328
+ t.string :shape_type
329
+ t.integer :shape_id
330
+ end
331
+
332
+ create_table :ships, :force => true do |t|
333
+ t.string :name
334
+ t.datetime :created_at
335
+ t.datetime :created_on
336
+ t.datetime :updated_at
337
+ t.datetime :updated_on
338
+ end
339
+
340
+ create_table :sponsors, :force => true do |t|
341
+ t.integer :club_id
342
+ t.integer :sponsorable_id
343
+ t.string :sponsorable_type
344
+ end
345
+
346
+ create_table :subscribers, :force => true, :id => false do |t|
347
+ t.string :nick, :null => false
348
+ t.string :name
349
+ end
350
+ add_index :subscribers, :nick, :unique => true
351
+
352
+ create_table :subscriptions, :force => true do |t|
353
+ t.string :subscriber_id
354
+ t.integer :book_id
355
+ end
356
+
357
+ create_table :tasks, :force => true do |t|
358
+ t.datetime :starting
359
+ t.datetime :ending
360
+ end
361
+
362
+ create_table :topics, :force => true do |t|
363
+ t.string :title
364
+ t.string :author_name
365
+ t.string :author_email_address
366
+ t.datetime :written_on
367
+ t.time :bonus_time
368
+ t.date :last_read
369
+ t.text :content
370
+ t.boolean :approved, :default => true
371
+ t.integer :replies_count, :default => 0
372
+ t.integer :parent_id
373
+ t.string :type
374
+ end
375
+
376
+ create_table :taggings, :force => true do |t|
377
+ t.column :tag_id, :integer
378
+ t.column :super_tag_id, :integer
379
+ t.column :taggable_type, :string
380
+ t.column :taggable_id, :integer
381
+ end
382
+
383
+ create_table :tags, :force => true do |t|
384
+ t.column :name, :string
385
+ t.column :taggings_count, :integer, :default => 0
386
+ end
387
+
388
+ create_table :treasures, :force => true do |t|
389
+ t.column :name, :string
390
+ t.column :looter_id, :integer
391
+ t.column :looter_type, :string
392
+ end
393
+
394
+ create_table :vertices, :force => true do |t|
395
+ t.column :label, :string
396
+ end
397
+
398
+ create_table 'warehouse-things', :force => true do |t|
399
+ t.integer :value
400
+ end
401
+
402
+ [:circles, :squares, :triangles, :non_poly_ones, :non_poly_twos].each do |t|
403
+ create_table(t, :force => true) { }
404
+ end
405
+
406
+ create_table :guids, :force => true do |t|
407
+ t.column :key, :string
408
+ end
409
+
410
+ except 'SQLite' do
411
+ # fk_test_has_fk should be before fk_test_has_pk
412
+ create_table :fk_test_has_fk, :force => true do |t|
413
+ t.integer :fk_id, :null => false
414
+ end
415
+
416
+ create_table :fk_test_has_pk, :force => true do |t|
417
+ end
418
+
419
+ execute "ALTER TABLE fk_test_has_fk ADD CONSTRAINT fk_name FOREIGN KEY (#{quote_column_name 'fk_id'}) REFERENCES #{quote_table_name 'fk_test_has_pk'} (#{quote_column_name 'id'})"
420
+ end
421
+ end