activerecord 1.14.4 → 1.15.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 (159) hide show
  1. data/CHANGELOG +400 -1
  2. data/README +2 -2
  3. data/RUNNING_UNIT_TESTS +21 -3
  4. data/Rakefile +55 -10
  5. data/lib/active_record.rb +10 -4
  6. data/lib/active_record/acts/list.rb +15 -4
  7. data/lib/active_record/acts/nested_set.rb +11 -12
  8. data/lib/active_record/acts/tree.rb +13 -14
  9. data/lib/active_record/aggregations.rb +46 -22
  10. data/lib/active_record/associations.rb +213 -162
  11. data/lib/active_record/associations/association_collection.rb +45 -15
  12. data/lib/active_record/associations/association_proxy.rb +32 -13
  13. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +18 -18
  14. data/lib/active_record/associations/has_many_association.rb +37 -17
  15. data/lib/active_record/associations/has_many_through_association.rb +120 -30
  16. data/lib/active_record/associations/has_one_association.rb +1 -1
  17. data/lib/active_record/attribute_methods.rb +75 -0
  18. data/lib/active_record/base.rb +282 -203
  19. data/lib/active_record/calculations.rb +95 -54
  20. data/lib/active_record/callbacks.rb +13 -24
  21. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +12 -1
  22. data/lib/active_record/connection_adapters/abstract/connection_specification.rb.rej +21 -0
  23. data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -4
  24. data/lib/active_record/connection_adapters/abstract/quoting.rb +16 -9
  25. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +121 -37
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +55 -23
  27. data/lib/active_record/connection_adapters/abstract_adapter.rb +8 -0
  28. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -11
  29. data/lib/active_record/connection_adapters/firebird_adapter.rb +364 -50
  30. data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
  31. data/lib/active_record/connection_adapters/mysql_adapter.rb +86 -33
  32. data/lib/active_record/connection_adapters/openbase_adapter.rb +4 -3
  33. data/lib/active_record/connection_adapters/oracle_adapter.rb +151 -127
  34. data/lib/active_record/connection_adapters/postgresql_adapter.rb +125 -48
  35. data/lib/active_record/connection_adapters/sqlite_adapter.rb +38 -10
  36. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +183 -155
  37. data/lib/active_record/connection_adapters/sybase_adapter.rb +190 -212
  38. data/lib/active_record/deprecated_associations.rb +24 -10
  39. data/lib/active_record/deprecated_finders.rb +4 -1
  40. data/lib/active_record/fixtures.rb +37 -23
  41. data/lib/active_record/locking/optimistic.rb +106 -0
  42. data/lib/active_record/locking/pessimistic.rb +77 -0
  43. data/lib/active_record/migration.rb +8 -5
  44. data/lib/active_record/observer.rb +73 -34
  45. data/lib/active_record/reflection.rb +21 -7
  46. data/lib/active_record/schema_dumper.rb +33 -5
  47. data/lib/active_record/timestamp.rb +23 -34
  48. data/lib/active_record/transactions.rb +37 -30
  49. data/lib/active_record/validations.rb +46 -30
  50. data/lib/active_record/vendor/mysql.rb +20 -5
  51. data/lib/active_record/version.rb +2 -2
  52. data/lib/active_record/wrappings.rb +1 -2
  53. data/lib/active_record/xml_serialization.rb +308 -0
  54. data/test/aaa_create_tables_test.rb +5 -1
  55. data/test/abstract_unit.rb +18 -8
  56. data/test/{active_schema_mysql.rb → active_schema_test_mysql.rb} +2 -2
  57. data/test/adapter_test.rb +9 -7
  58. data/test/adapter_test_sqlserver.rb +81 -0
  59. data/test/aggregations_test.rb +29 -0
  60. data/test/{association_callbacks_test.rb → associations/callbacks_test.rb} +10 -8
  61. data/test/{associations_cascaded_eager_loading_test.rb → associations/cascaded_eager_loading_test.rb} +35 -3
  62. data/test/{associations_go_eager_test.rb → associations/eager_test.rb} +36 -2
  63. data/test/{associations_extensions_test.rb → associations/extension_test.rb} +5 -0
  64. data/test/{associations_join_model_test.rb → associations/join_model_test.rb} +118 -8
  65. data/test/associations_test.rb +339 -45
  66. data/test/attribute_methods_test.rb +49 -0
  67. data/test/base_test.rb +321 -67
  68. data/test/calculations_test.rb +48 -10
  69. data/test/callbacks_test.rb +13 -0
  70. data/test/connection_test_firebird.rb +8 -0
  71. data/test/connections/native_db2/connection.rb +18 -17
  72. data/test/connections/native_firebird/connection.rb +19 -17
  73. data/test/connections/native_frontbase/connection.rb +27 -0
  74. data/test/connections/native_mysql/connection.rb +18 -15
  75. data/test/connections/native_openbase/connection.rb +14 -15
  76. data/test/connections/native_oracle/connection.rb +16 -12
  77. data/test/connections/native_postgresql/connection.rb +16 -17
  78. data/test/connections/native_sqlite/connection.rb +3 -6
  79. data/test/connections/native_sqlite3/connection.rb +3 -6
  80. data/test/connections/native_sqlserver/connection.rb +16 -17
  81. data/test/connections/native_sqlserver_odbc/connection.rb +18 -19
  82. data/test/connections/native_sybase/connection.rb +16 -17
  83. data/test/datatype_test_postgresql.rb +52 -0
  84. data/test/defaults_test.rb +52 -10
  85. data/test/deprecated_associations_test.rb +151 -107
  86. data/test/deprecated_finder_test.rb +83 -66
  87. data/test/empty_date_time_test.rb +25 -0
  88. data/test/finder_test.rb +118 -11
  89. data/test/fixtures/accounts.yml +6 -1
  90. data/test/fixtures/author.rb +27 -4
  91. data/test/fixtures/categorizations.yml +8 -2
  92. data/test/fixtures/category.rb +1 -2
  93. data/test/fixtures/comments.yml +0 -6
  94. data/test/fixtures/companies.yml +6 -1
  95. data/test/fixtures/company.rb +23 -1
  96. data/test/fixtures/company_in_module.rb +8 -10
  97. data/test/fixtures/customer.rb +2 -2
  98. data/test/fixtures/customers.yml +9 -0
  99. data/test/fixtures/db_definitions/db2.drop.sql +1 -0
  100. data/test/fixtures/db_definitions/db2.sql +9 -0
  101. data/test/fixtures/db_definitions/firebird.drop.sql +3 -0
  102. data/test/fixtures/db_definitions/firebird.sql +13 -1
  103. data/test/fixtures/db_definitions/frontbase.drop.sql +31 -0
  104. data/test/fixtures/db_definitions/frontbase.sql +262 -0
  105. data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
  106. data/test/fixtures/db_definitions/frontbase2.sql +4 -0
  107. data/test/fixtures/db_definitions/mysql.drop.sql +1 -0
  108. data/test/fixtures/db_definitions/mysql.sql +23 -14
  109. data/test/fixtures/db_definitions/openbase.sql +13 -1
  110. data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
  111. data/test/fixtures/db_definitions/oracle.sql +29 -2
  112. data/test/fixtures/db_definitions/postgresql.drop.sql +3 -1
  113. data/test/fixtures/db_definitions/postgresql.sql +13 -3
  114. data/test/fixtures/db_definitions/schema.rb +29 -1
  115. data/test/fixtures/db_definitions/sqlite.drop.sql +1 -0
  116. data/test/fixtures/db_definitions/sqlite.sql +12 -3
  117. data/test/fixtures/db_definitions/sqlserver.drop.sql +3 -0
  118. data/test/fixtures/db_definitions/sqlserver.sql +35 -0
  119. data/test/fixtures/db_definitions/sybase.drop.sql +2 -0
  120. data/test/fixtures/db_definitions/sybase.sql +13 -4
  121. data/test/fixtures/developer.rb +12 -0
  122. data/test/fixtures/edge.rb +5 -0
  123. data/test/fixtures/edges.yml +6 -0
  124. data/test/fixtures/funny_jokes.yml +3 -7
  125. data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
  126. data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
  127. data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
  128. data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
  129. data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
  130. data/test/fixtures/mixin.rb +15 -0
  131. data/test/fixtures/mixins.yml +38 -0
  132. data/test/fixtures/post.rb +3 -2
  133. data/test/fixtures/project.rb +3 -1
  134. data/test/fixtures/topic.rb +6 -1
  135. data/test/fixtures/topics.yml +4 -4
  136. data/test/fixtures/vertex.rb +9 -0
  137. data/test/fixtures/vertices.yml +4 -0
  138. data/test/fixtures_test.rb +45 -0
  139. data/test/inheritance_test.rb +67 -6
  140. data/test/lifecycle_test.rb +40 -19
  141. data/test/locking_test.rb +170 -26
  142. data/test/method_scoping_test.rb +2 -2
  143. data/test/migration_test.rb +387 -110
  144. data/test/migration_test_firebird.rb +124 -0
  145. data/test/mixin_nested_set_test.rb +14 -2
  146. data/test/mixin_test.rb +56 -18
  147. data/test/modules_test.rb +8 -2
  148. data/test/multiple_db_test.rb +2 -2
  149. data/test/pk_test.rb +1 -0
  150. data/test/reflection_test.rb +8 -2
  151. data/test/schema_authorization_test_postgresql.rb +75 -0
  152. data/test/schema_dumper_test.rb +40 -4
  153. data/test/table_name_test_sqlserver.rb +23 -0
  154. data/test/threaded_connections_test.rb +19 -16
  155. data/test/transactions_test.rb +86 -72
  156. data/test/validations_test.rb +126 -56
  157. data/test/xml_serialization_test.rb +125 -0
  158. metadata +45 -11
  159. data/lib/active_record/locking.rb +0 -79
@@ -0,0 +1 @@
1
+ DROP TABLE courses CASCADE;
@@ -0,0 +1,4 @@
1
+ CREATE TABLE courses (
2
+ id integer DEFAULT unique,
3
+ name varchar(100)
4
+ );
@@ -28,3 +28,4 @@ DROP TABLE fk_test_has_fk;
28
28
  DROP TABLE fk_test_has_pk;
29
29
  DROP TABLE keyboards;
30
30
  DROP TABLE legacy_things;
31
+ DROP TABLE numeric_data;
@@ -37,7 +37,7 @@ CREATE TABLE `topics` (
37
37
  `parent_id` int(11) default NULL,
38
38
  `type` varchar(50) default NULL,
39
39
  PRIMARY KEY (`id`)
40
- ) TYPE=InnoDB;
40
+ ) TYPE=InnoDB DEFAULT CHARSET=utf8;
41
41
 
42
42
  CREATE TABLE `developers` (
43
43
  `id` int(11) NOT NULL auto_increment,
@@ -51,7 +51,7 @@ CREATE TABLE `developers` (
51
51
  CREATE TABLE `projects` (
52
52
  `id` int(11) NOT NULL auto_increment,
53
53
  `name` varchar(100) default NULL,
54
- `type` VARCHAR(255) NOT NULL,
54
+ `type` VARCHAR(255) default NULL,
55
55
  PRIMARY KEY (`id`)
56
56
  ) TYPE=InnoDB;
57
57
 
@@ -106,7 +106,7 @@ CREATE TABLE `auto_id_tests` (
106
106
  ) TYPE=InnoDB;
107
107
 
108
108
  CREATE TABLE `entrants` (
109
- `id` INTEGER NOT NULL PRIMARY KEY,
109
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
110
110
  `name` VARCHAR(255) NOT NULL,
111
111
  `course_id` INTEGER NOT NULL
112
112
  );
@@ -131,13 +131,13 @@ CREATE TABLE `mixins` (
131
131
  ) TYPE=InnoDB;
132
132
 
133
133
  CREATE TABLE `people` (
134
- `id` INTEGER NOT NULL PRIMARY KEY,
134
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
135
135
  `first_name` VARCHAR(40) NOT NULL,
136
136
  `lock_version` INTEGER NOT NULL DEFAULT 0
137
137
  ) TYPE=InnoDB;
138
138
 
139
139
  CREATE TABLE `readers` (
140
- `id` int(11) NOT NULL PRIMARY KEY,
140
+ `id` int(11) NOT NULL auto_increment PRIMARY KEY,
141
141
  `post_id` INTEGER NOT NULL,
142
142
  `person_id` INTEGER NOT NULL
143
143
  ) TYPE=InnoDB;
@@ -149,28 +149,28 @@ CREATE TABLE `binaries` (
149
149
  ) TYPE=InnoDB;
150
150
 
151
151
  CREATE TABLE `computers` (
152
- `id` INTEGER NOT NULL PRIMARY KEY,
152
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
153
153
  `developer` INTEGER NOT NULL,
154
154
  `extendedWarranty` INTEGER NOT NULL
155
155
  ) TYPE=InnoDB;
156
156
 
157
157
  CREATE TABLE `posts` (
158
- `id` INTEGER NOT NULL PRIMARY KEY,
158
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
159
159
  `author_id` INTEGER,
160
160
  `title` VARCHAR(255) NOT NULL,
161
161
  `body` TEXT NOT NULL,
162
- `type` VARCHAR(255) NOT NULL
162
+ `type` VARCHAR(255) default NULL
163
163
  ) TYPE=InnoDB;
164
164
 
165
165
  CREATE TABLE `comments` (
166
- `id` INTEGER NOT NULL PRIMARY KEY,
166
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
167
167
  `post_id` INTEGER NOT NULL,
168
168
  `body` TEXT NOT NULL,
169
- `type` VARCHAR(255) NOT NULL
169
+ `type` VARCHAR(255) default NULL
170
170
  ) TYPE=InnoDB;
171
171
 
172
172
  CREATE TABLE `authors` (
173
- `id` INTEGER NOT NULL PRIMARY KEY,
173
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
174
174
  `name` VARCHAR(255) NOT NULL
175
175
  ) TYPE=InnoDB;
176
176
 
@@ -184,7 +184,7 @@ CREATE TABLE `tasks` (
184
184
  CREATE TABLE `categories` (
185
185
  `id` int(11) NOT NULL auto_increment,
186
186
  `name` VARCHAR(255) NOT NULL,
187
- `type` VARCHAR(255) NOT NULL,
187
+ `type` VARCHAR(255) default NULL,
188
188
  PRIMARY KEY (`id`)
189
189
  ) TYPE=InnoDB;
190
190
 
@@ -194,11 +194,11 @@ CREATE TABLE `categories_posts` (
194
194
  ) TYPE=InnoDB;
195
195
 
196
196
  CREATE TABLE `fk_test_has_pk` (
197
- `id` INTEGER NOT NULL PRIMARY KEY
197
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY
198
198
  ) TYPE=InnoDB;
199
199
 
200
200
  CREATE TABLE `fk_test_has_fk` (
201
- `id` INTEGER NOT NULL PRIMARY KEY,
201
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
202
202
  `fk_id` INTEGER NOT NULL,
203
203
 
204
204
  FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)
@@ -217,3 +217,12 @@ CREATE TABLE `legacy_things` (
217
217
  `version` int(11) NOT NULL default 0,
218
218
  PRIMARY KEY (`id`)
219
219
  ) TYPE=InnoDB;
220
+
221
+ CREATE TABLE `numeric_data` (
222
+ `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
223
+ `bank_balance` decimal(10,2),
224
+ `big_bank_balance` decimal(15,2),
225
+ `world_population` decimal(10),
226
+ `my_house_population` decimal(2),
227
+ `decimal_number_with_default` decimal(3,2) DEFAULT 2.78
228
+ ) TYPE=InnoDB;
@@ -279,4 +279,16 @@ CREATE TABLE legacy_things (
279
279
  )
280
280
  go
281
281
  CREATE PRIMARY KEY legacy_things (id)
282
- go
282
+ go
283
+
284
+ CREATE TABLE numeric_data (
285
+ id INTEGER NOT NULL DEFAULT _rowid,
286
+ bank_balance DECIMAL(10,2),
287
+ big_bank_balance DECIMAL(15,2),
288
+ world_population DECIMAL(10),
289
+ my_house_population DECIMAL(2),
290
+ decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78
291
+ );
292
+ go
293
+ CREATE PRIMARY KEY numeric_data (id)
294
+ go
@@ -29,6 +29,7 @@ drop table fk_test_has_pk;
29
29
  drop table fk_test_has_fk;
30
30
  drop table keyboards;
31
31
  drop table legacy_things;
32
+ drop table numeric_data;
32
33
 
33
34
  drop sequence accounts_seq;
34
35
  drop sequence funny_jokes_seq;
@@ -59,3 +60,4 @@ drop sequence fk_test_has_pk_seq;
59
60
  drop sequence fk_test_has_fk_seq;
60
61
  drop sequence keyboards_seq;
61
62
  drop sequence legacy_things_seq;
63
+ drop sequence numeric_data_seq;
@@ -37,7 +37,7 @@ create table topics (
37
37
  bonus_time timestamp default null,
38
38
  last_read timestamp default null,
39
39
  content varchar(4000),
40
- approved integer default 1,
40
+ approved number(1) default 1,
41
41
  replies_count integer default 0,
42
42
  parent_id integer references topics initially deferred disable,
43
43
  type varchar(50) default null,
@@ -53,7 +53,7 @@ create table topics (
53
53
  bonus_time date default null,
54
54
  last_read date default null,
55
55
  content varchar(4000),
56
- approved integer default 1,
56
+ approved number(1) default 1,
57
57
  replies_count integer default 0,
58
58
  parent_id integer references topics initially deferred disable,
59
59
  type varchar(50) default null,
@@ -137,6 +137,23 @@ create table booleantests (
137
137
  );
138
138
  create sequence booleantests_seq minvalue 10000;
139
139
 
140
+ CREATE TABLE defaults (
141
+ id integer not null,
142
+ modified_date date default sysdate,
143
+ modified_date_function date default sysdate,
144
+ fixed_date date default to_date('2004-01-01', 'YYYY-MM-DD'),
145
+ modified_time date default sysdate,
146
+ modified_time_function date default sysdate,
147
+ fixed_time date default TO_DATE('2004-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),
148
+ char1 varchar2(1) default 'Y',
149
+ char2 varchar2(50) default 'a varchar field',
150
+ char3 clob default 'a text field',
151
+ positive_integer integer default 1,
152
+ negative_integer integer default -1,
153
+ decimal_number number(3,2) default 2.78
154
+ );
155
+ create sequence defaults_seq minvalue 10000;
156
+
140
157
  create table auto_id_tests (
141
158
  auto_id integer not null,
142
159
  value integer default null,
@@ -290,3 +307,13 @@ create table legacy_things (
290
307
  version integer default 0
291
308
  );
292
309
  create sequence legacy_things_seq minvalue 10000;
310
+
311
+ CREATE TABLE numeric_data (
312
+ id integer NOT NULL PRIMARY KEY,
313
+ bank_balance decimal(10,2),
314
+ big_bank_balance decimal(15,2),
315
+ world_population decimal(10),
316
+ my_house_population decimal(2),
317
+ decimal_number_with_default decimal(3,2) DEFAULT 2.78
318
+ );
319
+ create sequence numeric_data_seq minvalue 10000;
@@ -1,5 +1,5 @@
1
- DROP SEQUENCE accounts_id_seq;
2
1
  DROP TABLE accounts;
2
+ DROP SEQUENCE accounts_id_seq;
3
3
  DROP TABLE funny_jokes;
4
4
  DROP TABLE companies;
5
5
  DROP SEQUENCE companies_nonstd_seq;
@@ -32,3 +32,5 @@ DROP TABLE fk_test_has_pk;
32
32
  DROP TABLE geometrics;
33
33
  DROP TABLE keyboards;
34
34
  DROP TABLE legacy_things;
35
+ DROP TABLE numeric_data;
36
+ DROP TABLE column_data;
@@ -118,7 +118,8 @@ CREATE TABLE defaults (
118
118
  char2 character varying(50) default 'a varchar field',
119
119
  char3 text default 'a text field',
120
120
  positive_integer integer default 1,
121
- negative_integer integer default -1
121
+ negative_integer integer default -1,
122
+ decimal_number decimal(3,2) default 2.78
122
123
  );
123
124
 
124
125
  CREATE TABLE auto_id_tests (
@@ -129,8 +130,8 @@ CREATE TABLE auto_id_tests (
129
130
 
130
131
  CREATE TABLE entrants (
131
132
  id serial,
132
- name text,
133
- course_id integer
133
+ name text not null,
134
+ course_id integer not null
134
135
  );
135
136
 
136
137
  CREATE TABLE colnametests (
@@ -246,3 +247,12 @@ CREATE TABLE legacy_things (
246
247
  tps_report_number integer,
247
248
  version integer default 0
248
249
  );
250
+
251
+ CREATE TABLE numeric_data (
252
+ id serial primary key,
253
+ bank_balance decimal(10,2),
254
+ big_bank_balance decimal(15,2),
255
+ world_population decimal(10),
256
+ my_house_population decimal(2),
257
+ decimal_number_with_default decimal(3,2) default 2.78
258
+ );
@@ -1,5 +1,15 @@
1
1
  ActiveRecord::Schema.define do
2
2
 
3
+ # For Firebird, set the sequence values 10000 when create_table is called;
4
+ # this prevents primary key collisions between "normally" created records
5
+ # and fixture-based (YAML) records.
6
+ if adapter_name == "Firebird"
7
+ def create_table(*args, &block)
8
+ ActiveRecord::Base.connection.create_table(*args, &block)
9
+ ActiveRecord::Base.connection.execute "SET GENERATOR #{args.first}_seq TO 10000"
10
+ end
11
+ end
12
+
3
13
  create_table :taggings, :force => true do |t|
4
14
  t.column :tag_id, :integer
5
15
  t.column :super_tag_id, :integer
@@ -29,4 +39,22 @@ ActiveRecord::Schema.define do
29
39
  t.column :author_id, :integer
30
40
  t.column :favorite_author_id, :integer
31
41
  end
32
- end
42
+
43
+ create_table :vertices, :force => true do |t|
44
+ t.column :label, :string
45
+ end
46
+
47
+ create_table :edges, :force => true do |t|
48
+ t.column :source_id, :integer, :null => false
49
+ t.column :sink_id, :integer, :null => false
50
+ end
51
+ add_index :edges, [:source_id, :sink_id], :unique => true, :name => 'unique_edge_index'
52
+
53
+ create_table :lock_without_defaults, :force => true do |t|
54
+ t.column :lock_version, :integer
55
+ end
56
+
57
+ create_table :lock_without_defaults_cust, :force => true do |t|
58
+ t.column :custom_lock_version, :integer
59
+ end
60
+ end
@@ -28,3 +28,4 @@ DROP TABLE fk_test_has_fk;
28
28
  DROP TABLE fk_test_has_pk;
29
29
  DROP TABLE keyboards;
30
30
  DROP TABLE legacy_things;
31
+ DROP TABLE numeric_data;
@@ -144,14 +144,14 @@ CREATE TABLE 'posts' (
144
144
  'id' INTEGER NOT NULL PRIMARY KEY,
145
145
  'author_id' INTEGER,
146
146
  'title' VARCHAR(255) NOT NULL,
147
- 'type' VARCHAR(255) NOT NULL,
147
+ 'type' VARCHAR(255) DEFAULT NULL,
148
148
  'body' TEXT NOT NULL
149
149
  );
150
150
 
151
151
  CREATE TABLE 'comments' (
152
152
  'id' INTEGER NOT NULL PRIMARY KEY,
153
153
  'post_id' INTEGER NOT NULL,
154
- 'type' VARCHAR(255) NOT NULL,
154
+ 'type' VARCHAR(255) DEFAULT NULL,
155
155
  'body' TEXT NOT NULL
156
156
  );
157
157
 
@@ -198,4 +198,13 @@ CREATE TABLE 'legacy_things' (
198
198
  'id' INTEGER NOT NULL PRIMARY KEY,
199
199
  'tps_report_number' INTEGER DEFAULT NULL,
200
200
  'version' INTEGER NOT NULL DEFAULT 0
201
- )
201
+ );
202
+
203
+ CREATE TABLE 'numeric_data' (
204
+ 'id' INTEGER NOT NULL PRIMARY KEY,
205
+ 'bank_balance' DECIMAL(10,2),
206
+ 'big_bank_balance' DECIMAL(15,2),
207
+ 'world_population' DECIMAL(10),
208
+ 'my_house_population' DECIMAL(2),
209
+ 'decimal_number_with_default' DECIMAL(3,2) DEFAULT 2.78
210
+ );
@@ -10,6 +10,7 @@ DROP TABLE orders;
10
10
  DROP TABLE movies;
11
11
  DROP TABLE subscribers;
12
12
  DROP TABLE booleantests;
13
+ DROP TABLE defaults;
13
14
  DROP TABLE auto_id_tests;
14
15
  DROP TABLE entrants;
15
16
  DROP TABLE colnametests;
@@ -28,3 +29,5 @@ DROP TABLE fk_test_has_fk;
28
29
  DROP TABLE fk_test_has_pk;
29
30
  DROP TABLE keyboards;
30
31
  DROP TABLE legacy_things;
32
+ DROP TABLE numeric_data;
33
+ DROP TABLE [order];
@@ -88,6 +88,24 @@ CREATE TABLE booleantests (
88
88
  value bit default NULL
89
89
  );
90
90
 
91
+ CREATE TABLE defaults (
92
+ id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
93
+ -- these brought from the PostgreSQL defaults_test.rb but
94
+ -- tests only exist for integers and decimals, currently
95
+ -- modified_date date default CURRENT_DATE,
96
+ -- modified_date_function date default now(),
97
+ -- fixed_date date default '2004-01-01',
98
+ -- modified_time timestamp default CURRENT_TIMESTAMP,
99
+ -- modified_time_function timestamp default now(),
100
+ -- fixed_time timestamp default '2004-01-01 00:00:00.000000-00',
101
+ -- char1 char(1) default 'Y',
102
+ -- char2 character varying(50) default 'a varchar field',
103
+ -- char3 text default 'a text field',
104
+ positive_integer integer default 1,
105
+ negative_integer integer default -1,
106
+ decimal_number decimal(3,2) default 2.78
107
+ );
108
+
91
109
  CREATE TABLE auto_id_tests (
92
110
  auto_id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
93
111
  value int default NULL
@@ -201,3 +219,20 @@ CREATE TABLE legacy_things (
201
219
  version int default 0,
202
220
  PRIMARY KEY (id)
203
221
  );
222
+
223
+ CREATE TABLE numeric_data (
224
+ id int NOT NULL IDENTITY(1, 1),
225
+ bank_balance decimal(10,2),
226
+ big_bank_balance decimal(15,2),
227
+ world_population decimal(10),
228
+ my_house_population decimal(2),
229
+ decimal_number_with_default decimal(3,2) DEFAULT 2.78
230
+ );
231
+
232
+ CREATE TABLE [order] (
233
+ id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
234
+ color varchar(255),
235
+ fruit_size varchar(255),
236
+ texture varchar(255),
237
+ flavor varchar(255)
238
+ );
@@ -28,4 +28,6 @@ DROP TABLE fk_test_has_fk
28
28
  DROP TABLE fk_test_has_pk
29
29
  DROP TABLE keyboards
30
30
  DROP TABLE legacy_things
31
+ DROP TABLE numeric_data
32
+ DROP TABLE schema_info
31
33
  go
@@ -26,7 +26,7 @@ CREATE TABLE topics (
26
26
  author_name varchar(255) NULL,
27
27
  author_email_address varchar(255) NULL,
28
28
  written_on datetime NULL,
29
- bonus_time time NULL,
29
+ bonus_time datetime NULL,
30
30
  last_read datetime NULL,
31
31
  content varchar(255) NULL,
32
32
  approved bit default 1,
@@ -118,7 +118,7 @@ CREATE TABLE mixins (
118
118
 
119
119
  CREATE TABLE people (
120
120
  id numeric(9,0) IDENTITY PRIMARY KEY,
121
- first_name varchar(40) NOT NULL,
121
+ first_name varchar(40) NULL,
122
122
  lock_version int DEFAULT 0
123
123
  )
124
124
 
@@ -197,8 +197,17 @@ CREATE TABLE keyboards (
197
197
  CREATE TABLE legacy_things (
198
198
  id numeric(9,0) IDENTITY PRIMARY KEY,
199
199
  tps_report_number int default NULL,
200
- version int default 0,
200
+ version int default 0
201
201
  )
202
202
 
203
- go
204
203
 
204
+ CREATE TABLE numeric_data (
205
+ id numeric(9,0) IDENTITY PRIMARY KEY,
206
+ bank_balance numeric(10,2),
207
+ big_bank_balance numeric(15,2),
208
+ world_population numeric(10),
209
+ my_house_population numeric(2),
210
+ decimal_number_with_default numeric(3,2) DEFAULT 2.78
211
+ )
212
+
213
+ go
@@ -4,6 +4,12 @@ module DeveloperProjectsAssociationExtension
4
4
  end
5
5
  end
6
6
 
7
+ module DeveloperProjectsAssociationExtension2
8
+ def find_least_recent
9
+ find(:first, :order => "id ASC")
10
+ end
11
+ end
12
+
7
13
  class Developer < ActiveRecord::Base
8
14
  has_and_belongs_to_many :projects do
9
15
  def find_most_recent
@@ -17,6 +23,12 @@ class Developer < ActiveRecord::Base
17
23
  :association_foreign_key => "project_id",
18
24
  :extend => DeveloperProjectsAssociationExtension
19
25
 
26
+ has_and_belongs_to_many :projects_extended_by_name_twice,
27
+ :class_name => "Project",
28
+ :join_table => "developers_projects",
29
+ :association_foreign_key => "project_id",
30
+ :extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
31
+
20
32
  has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
21
33
 
22
34
  validates_inclusion_of :salary, :in => 50000..200000