activerecord 1.6.0 → 1.7.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 (96) hide show
  1. data/CHANGELOG +78 -0
  2. data/README +20 -29
  3. data/RUNNING_UNIT_TESTS +1 -2
  4. data/examples/validation.rb +0 -3
  5. data/install.rb +3 -16
  6. data/lib/active_record.rb +11 -4
  7. data/lib/active_record/aggregations.rb +2 -2
  8. data/lib/active_record/associations.rb +8 -8
  9. data/lib/active_record/associations/association_collection.rb +1 -1
  10. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +1 -1
  11. data/lib/active_record/base.rb +117 -43
  12. data/lib/active_record/callbacks.rb +2 -2
  13. data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -14
  14. data/lib/active_record/connection_adapters/db2_adapter.rb +33 -22
  15. data/lib/active_record/connection_adapters/mysql_adapter.rb +74 -33
  16. data/lib/active_record/connection_adapters/oci_adapter.rb +265 -0
  17. data/lib/active_record/connection_adapters/postgresql_adapter.rb +23 -3
  18. data/lib/active_record/connection_adapters/sqlite_adapter.rb +13 -4
  19. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +158 -67
  20. data/lib/active_record/deprecated_associations.rb +4 -4
  21. data/lib/active_record/fixtures.rb +12 -5
  22. data/lib/active_record/locking.rb +22 -22
  23. data/lib/active_record/observer.rb +6 -3
  24. data/lib/active_record/timestamp.rb +15 -5
  25. data/lib/active_record/transactions.rb +4 -4
  26. data/lib/active_record/validations.rb +272 -189
  27. data/lib/active_record/wrappings.rb +2 -2
  28. data/rakefile +17 -2
  29. data/test/aaa_create_tables_test.rb +58 -0
  30. data/test/abstract_unit.rb +3 -2
  31. data/test/aggregations_test.rb +0 -1
  32. data/test/associations_test.rb +27 -28
  33. data/test/base_test.rb +74 -2
  34. data/test/binary_test.rb +6 -2
  35. data/test/class_inheritable_attributes_test.rb +1 -1
  36. data/test/column_alias_test.rb +9 -2
  37. data/test/connections/native_oci/connection.rb +25 -0
  38. data/test/connections/native_sqlite/connection.rb +4 -1
  39. data/test/connections/native_sqlite3/connection.rb +4 -2
  40. data/test/deprecated_associations_test.rb +4 -5
  41. data/test/finder_test.rb +20 -4
  42. data/test/fixtures/db_definitions/create_oracle_db.bat +5 -0
  43. data/test/fixtures/db_definitions/create_oracle_db.sh +5 -0
  44. data/test/fixtures/db_definitions/db2.drop.sql +18 -0
  45. data/test/fixtures/db_definitions/db2.sql +1 -0
  46. data/test/fixtures/db_definitions/db22.drop.sql +2 -0
  47. data/test/fixtures/db_definitions/db22.sql +1 -0
  48. data/test/fixtures/db_definitions/drop_oracle_tables.sql +35 -0
  49. data/test/fixtures/db_definitions/drop_oracle_tables2.sql +3 -0
  50. data/test/fixtures/db_definitions/mysql.drop.sql +18 -0
  51. data/test/fixtures/db_definitions/mysql.sql +2 -1
  52. data/test/fixtures/db_definitions/mysql2.drop.sql +2 -0
  53. data/test/fixtures/db_definitions/mysql2.sql +1 -0
  54. data/test/fixtures/db_definitions/oci.drop.sql +18 -0
  55. data/test/fixtures/db_definitions/oci.sql +167 -0
  56. data/test/fixtures/db_definitions/oci2.drop.sql +2 -0
  57. data/test/fixtures/db_definitions/oci2.sql +6 -0
  58. data/test/fixtures/db_definitions/postgresql.drop.sql +18 -0
  59. data/test/fixtures/db_definitions/postgresql.sql +2 -1
  60. data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
  61. data/test/fixtures/db_definitions/postgresql2.sql +2 -1
  62. data/test/fixtures/db_definitions/sqlite.drop.sql +18 -0
  63. data/test/fixtures/db_definitions/sqlite.sql +2 -1
  64. data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
  65. data/test/fixtures/db_definitions/sqlite2.sql +1 -0
  66. data/test/fixtures/db_definitions/sqlserver.drop.sql +18 -0
  67. data/test/fixtures/db_definitions/sqlserver.sql +1 -0
  68. data/test/fixtures/db_definitions/sqlserver2.drop.sql +2 -0
  69. data/test/fixtures/db_definitions/sqlserver2.sql +1 -0
  70. data/test/fixtures/fixture_database.sqlite +0 -0
  71. data/test/fixtures/fixture_database_2.sqlite +0 -0
  72. data/test/fixtures/topics.yml +3 -3
  73. data/test/lifecycle_test.rb +0 -1
  74. data/test/modules_test.rb +0 -1
  75. data/test/reflection_test.rb +0 -1
  76. data/test/validations_test.rb +229 -41
  77. metadata +36 -28
  78. data/dev-utils/eval_debugger.rb +0 -14
  79. data/lib/active_record/support/binding_of_caller.rb +0 -83
  80. data/lib/active_record/support/breakpoint.rb +0 -518
  81. data/lib/active_record/support/class_attribute_accessors.rb +0 -57
  82. data/lib/active_record/support/class_inheritable_attributes.rb +0 -117
  83. data/lib/active_record/support/clean_logger.rb +0 -10
  84. data/lib/active_record/support/core_ext.rb +0 -1
  85. data/lib/active_record/support/core_ext/hash.rb +0 -5
  86. data/lib/active_record/support/core_ext/hash/keys.rb +0 -35
  87. data/lib/active_record/support/core_ext/numeric.rb +0 -7
  88. data/lib/active_record/support/core_ext/numeric/bytes.rb +0 -33
  89. data/lib/active_record/support/core_ext/numeric/time.rb +0 -59
  90. data/lib/active_record/support/core_ext/object_and_class.rb +0 -24
  91. data/lib/active_record/support/core_ext/string.rb +0 -5
  92. data/lib/active_record/support/core_ext/string/inflections.rb +0 -45
  93. data/lib/active_record/support/dependencies.rb +0 -63
  94. data/lib/active_record/support/inflector.rb +0 -84
  95. data/lib/active_record/support/misc.rb +0 -8
  96. data/lib/active_record/support/module_attribute_accessors.rb +0 -57
@@ -3,6 +3,9 @@ require 'fixtures/course'
3
3
  require 'logger'
4
4
  ActiveRecord::Base.logger = Logger.new("debug.log")
5
5
 
6
+ class SqliteError < StandardError
7
+ end
8
+
6
9
  BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
7
10
  sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
8
11
  sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
@@ -12,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file)
12
15
  puts "SQLite database not found at #{db_file}. Rebuilding it."
13
16
  sqlite_command = "sqlite #{db_file} 'create table a (a integer); drop table a;'"
14
17
  puts "Executing '#{sqlite_command}'"
15
- `#{sqlite_command}`
18
+ raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
16
19
  clazz.establish_connection(
17
20
  :adapter => "sqlite",
18
21
  :dbfile => db_file)
@@ -2,7 +2,9 @@ print "Using native SQLite3\n"
2
2
  require 'fixtures/course'
3
3
  require 'logger'
4
4
  ActiveRecord::Base.logger = Logger.new("debug.log")
5
- ActiveRecord::Base.logger.level = Logger::DEBUG
5
+
6
+ class SqliteError < StandardError
7
+ end
6
8
 
7
9
  BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
8
10
  sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
@@ -13,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file)
13
15
  puts "SQLite3 database not found at #{db_file}. Rebuilding it."
14
16
  sqlite_command = "sqlite3 #{db_file} 'create table a (a integer); drop table a;'"
15
17
  puts "Executing '#{sqlite_command}'"
16
- `#{sqlite_command}`
18
+ raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
17
19
  clazz.establish_connection(
18
20
  :adapter => "sqlite3",
19
21
  :dbfile => db_file)
@@ -3,7 +3,6 @@ require 'fixtures/developer'
3
3
  require 'fixtures/project'
4
4
  require 'fixtures/company'
5
5
  require 'fixtures/topic'
6
- # require File.dirname(__FILE__) + '/../dev-utils/eval_debugger'
7
6
  require 'fixtures/reply'
8
7
 
9
8
  # Can't declare new classes in test case methods, so tests before that
@@ -249,11 +248,11 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase
249
248
  end
250
249
 
251
250
  def test_has_and_belongs_to_many_adding_a_collection
252
- aridridel = Developer.new("name" => "Aridridel")
253
- aridridel.save
251
+ aredridel = Developer.new("name" => "Aredridel")
252
+ aredridel.save
254
253
 
255
- aridridel.add_projects([ Project.find(1), Project.find(2) ])
256
- assert_equal 2, aridridel.projects_count
254
+ aredridel.add_projects([ Project.find(1), Project.find(2) ])
255
+ assert_equal 2, aredridel.projects_count
257
256
  end
258
257
 
259
258
  def test_belongs_to_counter
@@ -34,10 +34,16 @@ class FinderTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_find_all_with_prepared_limit_and_offset
37
- entrants = Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1]
38
-
39
- assert_equal(2, entrants.size)
40
- assert_equal(@entrants["second"]["name"], entrants.first.name)
37
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
38
+ if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
39
+ assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1] }
40
+ end
41
+ else
42
+ entrants = Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1]
43
+
44
+ assert_equal(2, entrants.size)
45
+ assert_equal(@entrants["second"]["name"], entrants.first.name)
46
+ end
41
47
  end
42
48
 
43
49
  def test_find_with_entire_select_statement
@@ -193,6 +199,16 @@ class FinderTest < Test::Unit::TestCase
193
199
 
194
200
  assert_equal [], Topic.find_all_by_title("The First Topic!!")
195
201
  end
202
+
203
+ def test_find_all_by_boolean_attribute
204
+ topics = Topic.find_all_by_approved(false)
205
+ assert_equal 1, topics.size
206
+ assert topics.include?(@topics["first"].find)
207
+
208
+ topics = Topic.find_all_by_approved(true)
209
+ assert_equal 1, topics.size
210
+ assert topics.include?(@topics["second"].find)
211
+ end
196
212
 
197
213
  def test_find_by_nil_attribute
198
214
  topic = Topic.find_by_last_read nil
@@ -0,0 +1,5 @@
1
+ sqlplus arunit/arunit @ drop_oracle_tables
2
+ sqlplus arunit/arunit @ oracle
3
+ sqlplus arunit2/arunit2 @ drop_oracle_tables2
4
+ sqlplus arunit2/arunit2 @ oracle2
5
+
@@ -0,0 +1,5 @@
1
+ sqlplus arunit/arunit @ drop_oracle_tables
2
+ sqlplus arunit/arunit @ oracle
3
+ sqlplus arunit2/arunit2 @ drop_oracle_tables2
4
+ sqlplus arunit2/arunit2 @ oracle2
5
+
@@ -0,0 +1,18 @@
1
+ DROP TABLE accounts;
2
+ DROP TABLE companies;
3
+ DROP TABLE topics;
4
+ DROP TABLE developers;
5
+ DROP TABLE projects;
6
+ DROP TABLE developers_projects;
7
+ DROP TABLE customers;
8
+ DROP TABLE movies;
9
+ DROP TABLE subscribers;
10
+ DROP TABLE booleantests;
11
+ DROP TABLE auto_id_tests;
12
+ DROP TABLE entrants;
13
+ DROP TABLE colnametests;
14
+ DROP TABLE mixins;
15
+ DROP TABLE people;
16
+ DROP TABLE binaries;
17
+ DROP TABLE computers;
18
+
@@ -127,3 +127,4 @@ CREATE TABLE computers (
127
127
  id int generated by default as identity (start with +10000),
128
128
  developer int NOT NULL
129
129
  );
130
+
@@ -0,0 +1,2 @@
1
+ DROP TABLE courses;
2
+
@@ -2,3 +2,4 @@ CREATE TABLE courses (
2
2
  id int NOT NULL PRIMARY KEY,
3
3
  name varchar(255) NOT NULL
4
4
  );
5
+
@@ -0,0 +1,35 @@
1
+ DROP TABLE accounts;
2
+ DROP SEQUENCE accounts_id;
3
+ DROP TABLE companies;
4
+ DROP SEQUENCE companies_id;
5
+ DROP TABLE topics;
6
+ DROP SEQUENCE topics_id;
7
+ DROP TABLE developers;
8
+ DROP SEQUENCE developers_id;
9
+ DROP TABLE projects;
10
+ DROP SEQUENCE projects_id;
11
+ DROP TABLE developers_projects;
12
+ DROP SEQUENCE developers_projects_id;
13
+ DROP TABLE customers;
14
+ DROP SEQUENCE customers_id;
15
+ DROP TABLE movies;
16
+ DROP SEQUENCE movies_id;
17
+ DROP TABLE subscribers;
18
+ DROP SEQUENCE subscribers_id;
19
+ DROP TABLE booleantests;
20
+ DROP SEQUENCE booleantests_id;
21
+ DROP TABLE auto_id_tests;
22
+ DROP SEQUENCE auto_id_tests_id;
23
+ DROP TABLE entrants;
24
+ DROP SEQUENCE entrants_id;
25
+ DROP TABLE colnametests;
26
+ DROP SEQUENCE colnametests_id;
27
+ DROP TABLE mixins;
28
+ DROP SEQUENCE mixins_id;
29
+ DROP TABLE people;
30
+ DROP SEQUENCE people_id;
31
+ DROP TABLE binaries;
32
+ DROP SEQUENCE binaries_id;
33
+ DROP TABLE computers;
34
+ DROP SEQUENCE computers_id;
35
+ EXIT;
@@ -0,0 +1,3 @@
1
+ DROP TABLE courses;
2
+ DROP SEQUENCE courses_id;
3
+ EXIT;
@@ -0,0 +1,18 @@
1
+ DROP TABLE accounts;
2
+ DROP TABLE companies;
3
+ DROP TABLE topics;
4
+ DROP TABLE developers;
5
+ DROP TABLE projects;
6
+ DROP TABLE developers_projects;
7
+ DROP TABLE customers;
8
+ DROP TABLE movies;
9
+ DROP TABLE subscribers;
10
+ DROP TABLE booleantests;
11
+ DROP TABLE auto_id_tests;
12
+ DROP TABLE entrants;
13
+ DROP TABLE colnametests;
14
+ DROP TABLE mixins;
15
+ DROP TABLE people;
16
+ DROP TABLE binaries;
17
+ DROP TABLE computers;
18
+
@@ -126,4 +126,5 @@ CREATE TABLE `binaries` (
126
126
  CREATE TABLE `computers` (
127
127
  `id` INTEGER NOT NULL PRIMARY KEY,
128
128
  `developer` INTEGER NOT NULL
129
- );
129
+ );
130
+
@@ -0,0 +1,2 @@
1
+ DROP TABLE courses;
2
+
@@ -2,3 +2,4 @@ CREATE TABLE `courses` (
2
2
  `id` INTEGER NOT NULL PRIMARY KEY,
3
3
  `name` VARCHAR(255) NOT NULL
4
4
  );
5
+
@@ -0,0 +1,18 @@
1
+ drop table accounts;
2
+ drop table companies;
3
+ drop table topics;
4
+ drop table developers;
5
+ drop table projects;
6
+ drop table developers_projects;
7
+ drop table customers;
8
+ drop table movies;
9
+ drop table subscribers;
10
+ drop table booleantests;
11
+ drop table auto_id_tests;
12
+ drop table entrants;
13
+ drop table colnametests;
14
+ drop table mixins;
15
+ drop table people;
16
+ drop table binaries;
17
+ drop table computers;
18
+ drop sequence rails_sequence;
@@ -0,0 +1,167 @@
1
+ create sequence rails_sequence minvalue 10000;
2
+
3
+ create table companies (
4
+ id integer not null,
5
+ type varchar(50) default null,
6
+ ruby_type varchar(50) default null,
7
+ firm_id integer default null references companies initially deferred disable,
8
+ name varchar(50) default null,
9
+ client_of integer default null references companies initially deferred disable,
10
+ companies_count integer default 0,
11
+ rating integer default 1,
12
+ primary key (id)
13
+ );
14
+
15
+ create table accounts (
16
+ id integer not null,
17
+ firm_id integer default null references companies initially deferred disable,
18
+ credit_limit integer default null,
19
+ primary key (id)
20
+ );
21
+
22
+ create table topics (
23
+ id integer not null,
24
+ title varchar(255) default null,
25
+ author_name varchar(255) default null,
26
+ author_email_address varchar(255) default null,
27
+ written_on timestamp default null,
28
+ bonus_time timestamp default null,
29
+ last_read timestamp default null,
30
+ content varchar(4000),
31
+ approved integer default 1,
32
+ replies_count integer default 0,
33
+ parent_id integer references topics initially deferred disable,
34
+ type varchar(50) default null,
35
+ primary key (id)
36
+ );
37
+ -- try again for 8i
38
+ create table topics (
39
+ id integer not null,
40
+ title varchar(255) default null,
41
+ author_name varchar(255) default null,
42
+ author_email_address varchar(255) default null,
43
+ written_on date default null,
44
+ bonus_time date default null,
45
+ last_read date default null,
46
+ content varchar(4000),
47
+ approved integer default 1,
48
+ replies_count integer default 0,
49
+ parent_id integer references topics initially deferred disable,
50
+ type varchar(50) default null,
51
+ primary key (id)
52
+ );
53
+
54
+ create table developers (
55
+ id integer not null,
56
+ name varchar(100) default null,
57
+ salary integer default 70000,
58
+ primary key (id)
59
+ );
60
+
61
+ create table projects (
62
+ id integer not null,
63
+ name varchar(100) default null,
64
+ primary key (id)
65
+ );
66
+
67
+ create table developers_projects (
68
+ developer_id integer not null references developers initially deferred disable,
69
+ project_id integer not null references projects initially deferred disable,
70
+ joined_on timestamp default null
71
+ );
72
+ -- Try again for 8i
73
+ create table developers_projects (
74
+ developer_id integer not null references developers initially deferred disable,
75
+ project_id integer not null references projects initially deferred disable,
76
+ joined_on date default null
77
+ );
78
+
79
+ create table customers (
80
+ id integer not null,
81
+ name varchar(100) default null,
82
+ balance integer default 0,
83
+ address_street varchar(100) default null,
84
+ address_city varchar(100) default null,
85
+ address_country varchar(100) default null,
86
+ primary key (id)
87
+ );
88
+
89
+ create table movies (
90
+ movieid integer not null,
91
+ name varchar(100) default null,
92
+ primary key (movieid)
93
+ );
94
+
95
+ create table subscribers (
96
+ nick varchar(100) not null,
97
+ name varchar(100) default null,
98
+ primary key (nick)
99
+ );
100
+
101
+ create table booleantests (
102
+ id integer not null,
103
+ value integer default null,
104
+ primary key (id)
105
+ );
106
+
107
+ create table auto_id_tests (
108
+ auto_id integer not null,
109
+ value integer default null,
110
+ primary key (auto_id)
111
+ );
112
+
113
+ create table entrants (
114
+ id integer not null primary key,
115
+ name varchar(255) not null,
116
+ course_id integer not null
117
+ );
118
+
119
+ create table colnametests (
120
+ id integer not null,
121
+ references integer not null,
122
+ primary key (id)
123
+ );
124
+
125
+ create table mixins (
126
+ id integer not null,
127
+ parent_id integer default null references mixins initially deferred disable,
128
+ type varchar(40) default null,
129
+ pos integer default null,
130
+ lft integer default null,
131
+ rgt integer default null,
132
+ root_id integer default null,
133
+ created_at timestamp default null,
134
+ updated_at timestamp default null,
135
+ primary key (id)
136
+ );
137
+ -- try again for 8i
138
+ create table mixins (
139
+ id integer not null,
140
+ parent_id integer default null references mixins initially deferred disable,
141
+ type varchar(40) default null,
142
+ pos integer default null,
143
+ lft integer default null,
144
+ rgt integer default null,
145
+ root_id integer default null,
146
+ created_at date default null,
147
+ updated_at date default null,
148
+ primary key (id)
149
+ );
150
+
151
+ create table people (
152
+ id integer not null,
153
+ first_name varchar(40) null,
154
+ lock_version integer default 0,
155
+ primary key (id)
156
+ );
157
+
158
+ create table binaries (
159
+ id integer not null,
160
+ data blob null,
161
+ primary key (id)
162
+ );
163
+
164
+ create table computers (
165
+ id integer not null primary key,
166
+ developer integer not null references developers initially deferred disable
167
+ );
@@ -0,0 +1,2 @@
1
+ drop table courses;
2
+ drop sequence rails_sequence;
@@ -0,0 +1,6 @@
1
+ create sequence rails_sequence minvalue 10000;
2
+
3
+ create table courses (
4
+ id int not null primary key,
5
+ name varchar(255) not null
6
+ );
@@ -0,0 +1,18 @@
1
+ DROP TABLE accounts;
2
+ DROP TABLE companies;
3
+ DROP TABLE topics;
4
+ DROP TABLE developers;
5
+ DROP TABLE projects;
6
+ DROP TABLE developers_projects;
7
+ DROP TABLE customers;
8
+ DROP TABLE movies;
9
+ DROP TABLE subscribers;
10
+ DROP TABLE booleantests;
11
+ DROP TABLE auto_id_tests;
12
+ DROP TABLE entrants;
13
+ DROP TABLE colnametests;
14
+ DROP TABLE mixins;
15
+ DROP TABLE people;
16
+ DROP TABLE binaries;
17
+ DROP TABLE computers;
18
+