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.
- data/CHANGELOG +400 -1
- data/README +2 -2
- data/RUNNING_UNIT_TESTS +21 -3
- data/Rakefile +55 -10
- data/lib/active_record.rb +10 -4
- data/lib/active_record/acts/list.rb +15 -4
- data/lib/active_record/acts/nested_set.rb +11 -12
- data/lib/active_record/acts/tree.rb +13 -14
- data/lib/active_record/aggregations.rb +46 -22
- data/lib/active_record/associations.rb +213 -162
- data/lib/active_record/associations/association_collection.rb +45 -15
- data/lib/active_record/associations/association_proxy.rb +32 -13
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +18 -18
- data/lib/active_record/associations/has_many_association.rb +37 -17
- data/lib/active_record/associations/has_many_through_association.rb +120 -30
- data/lib/active_record/associations/has_one_association.rb +1 -1
- data/lib/active_record/attribute_methods.rb +75 -0
- data/lib/active_record/base.rb +282 -203
- data/lib/active_record/calculations.rb +95 -54
- data/lib/active_record/callbacks.rb +13 -24
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +12 -1
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb.rej +21 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -4
- data/lib/active_record/connection_adapters/abstract/quoting.rb +16 -9
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +121 -37
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +55 -23
- data/lib/active_record/connection_adapters/abstract_adapter.rb +8 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -11
- data/lib/active_record/connection_adapters/firebird_adapter.rb +364 -50
- data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +86 -33
- data/lib/active_record/connection_adapters/openbase_adapter.rb +4 -3
- data/lib/active_record/connection_adapters/oracle_adapter.rb +151 -127
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +125 -48
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +38 -10
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +183 -155
- data/lib/active_record/connection_adapters/sybase_adapter.rb +190 -212
- data/lib/active_record/deprecated_associations.rb +24 -10
- data/lib/active_record/deprecated_finders.rb +4 -1
- data/lib/active_record/fixtures.rb +37 -23
- data/lib/active_record/locking/optimistic.rb +106 -0
- data/lib/active_record/locking/pessimistic.rb +77 -0
- data/lib/active_record/migration.rb +8 -5
- data/lib/active_record/observer.rb +73 -34
- data/lib/active_record/reflection.rb +21 -7
- data/lib/active_record/schema_dumper.rb +33 -5
- data/lib/active_record/timestamp.rb +23 -34
- data/lib/active_record/transactions.rb +37 -30
- data/lib/active_record/validations.rb +46 -30
- data/lib/active_record/vendor/mysql.rb +20 -5
- data/lib/active_record/version.rb +2 -2
- data/lib/active_record/wrappings.rb +1 -2
- data/lib/active_record/xml_serialization.rb +308 -0
- data/test/aaa_create_tables_test.rb +5 -1
- data/test/abstract_unit.rb +18 -8
- data/test/{active_schema_mysql.rb → active_schema_test_mysql.rb} +2 -2
- data/test/adapter_test.rb +9 -7
- data/test/adapter_test_sqlserver.rb +81 -0
- data/test/aggregations_test.rb +29 -0
- data/test/{association_callbacks_test.rb → associations/callbacks_test.rb} +10 -8
- data/test/{associations_cascaded_eager_loading_test.rb → associations/cascaded_eager_loading_test.rb} +35 -3
- data/test/{associations_go_eager_test.rb → associations/eager_test.rb} +36 -2
- data/test/{associations_extensions_test.rb → associations/extension_test.rb} +5 -0
- data/test/{associations_join_model_test.rb → associations/join_model_test.rb} +118 -8
- data/test/associations_test.rb +339 -45
- data/test/attribute_methods_test.rb +49 -0
- data/test/base_test.rb +321 -67
- data/test/calculations_test.rb +48 -10
- data/test/callbacks_test.rb +13 -0
- data/test/connection_test_firebird.rb +8 -0
- data/test/connections/native_db2/connection.rb +18 -17
- data/test/connections/native_firebird/connection.rb +19 -17
- data/test/connections/native_frontbase/connection.rb +27 -0
- data/test/connections/native_mysql/connection.rb +18 -15
- data/test/connections/native_openbase/connection.rb +14 -15
- data/test/connections/native_oracle/connection.rb +16 -12
- data/test/connections/native_postgresql/connection.rb +16 -17
- data/test/connections/native_sqlite/connection.rb +3 -6
- data/test/connections/native_sqlite3/connection.rb +3 -6
- data/test/connections/native_sqlserver/connection.rb +16 -17
- data/test/connections/native_sqlserver_odbc/connection.rb +18 -19
- data/test/connections/native_sybase/connection.rb +16 -17
- data/test/datatype_test_postgresql.rb +52 -0
- data/test/defaults_test.rb +52 -10
- data/test/deprecated_associations_test.rb +151 -107
- data/test/deprecated_finder_test.rb +83 -66
- data/test/empty_date_time_test.rb +25 -0
- data/test/finder_test.rb +118 -11
- data/test/fixtures/accounts.yml +6 -1
- data/test/fixtures/author.rb +27 -4
- data/test/fixtures/categorizations.yml +8 -2
- data/test/fixtures/category.rb +1 -2
- data/test/fixtures/comments.yml +0 -6
- data/test/fixtures/companies.yml +6 -1
- data/test/fixtures/company.rb +23 -1
- data/test/fixtures/company_in_module.rb +8 -10
- data/test/fixtures/customer.rb +2 -2
- data/test/fixtures/customers.yml +9 -0
- data/test/fixtures/db_definitions/db2.drop.sql +1 -0
- data/test/fixtures/db_definitions/db2.sql +9 -0
- data/test/fixtures/db_definitions/firebird.drop.sql +3 -0
- data/test/fixtures/db_definitions/firebird.sql +13 -1
- data/test/fixtures/db_definitions/frontbase.drop.sql +31 -0
- data/test/fixtures/db_definitions/frontbase.sql +262 -0
- data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
- data/test/fixtures/db_definitions/frontbase2.sql +4 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +1 -0
- data/test/fixtures/db_definitions/mysql.sql +23 -14
- data/test/fixtures/db_definitions/openbase.sql +13 -1
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +29 -2
- data/test/fixtures/db_definitions/postgresql.drop.sql +3 -1
- data/test/fixtures/db_definitions/postgresql.sql +13 -3
- data/test/fixtures/db_definitions/schema.rb +29 -1
- data/test/fixtures/db_definitions/sqlite.drop.sql +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +12 -3
- data/test/fixtures/db_definitions/sqlserver.drop.sql +3 -0
- data/test/fixtures/db_definitions/sqlserver.sql +35 -0
- data/test/fixtures/db_definitions/sybase.drop.sql +2 -0
- data/test/fixtures/db_definitions/sybase.sql +13 -4
- data/test/fixtures/developer.rb +12 -0
- data/test/fixtures/edge.rb +5 -0
- data/test/fixtures/edges.yml +6 -0
- data/test/fixtures/funny_jokes.yml +3 -7
- data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
- data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
- data/test/fixtures/mixin.rb +15 -0
- data/test/fixtures/mixins.yml +38 -0
- data/test/fixtures/post.rb +3 -2
- data/test/fixtures/project.rb +3 -1
- data/test/fixtures/topic.rb +6 -1
- data/test/fixtures/topics.yml +4 -4
- data/test/fixtures/vertex.rb +9 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures_test.rb +45 -0
- data/test/inheritance_test.rb +67 -6
- data/test/lifecycle_test.rb +40 -19
- data/test/locking_test.rb +170 -26
- data/test/method_scoping_test.rb +2 -2
- data/test/migration_test.rb +387 -110
- data/test/migration_test_firebird.rb +124 -0
- data/test/mixin_nested_set_test.rb +14 -2
- data/test/mixin_test.rb +56 -18
- data/test/modules_test.rb +8 -2
- data/test/multiple_db_test.rb +2 -2
- data/test/pk_test.rb +1 -0
- data/test/reflection_test.rb +8 -2
- data/test/schema_authorization_test_postgresql.rb +75 -0
- data/test/schema_dumper_test.rb +40 -4
- data/test/table_name_test_sqlserver.rb +23 -0
- data/test/threaded_connections_test.rb +19 -16
- data/test/transactions_test.rb +86 -72
- data/test/validations_test.rb +126 -56
- data/test/xml_serialization_test.rb +125 -0
- metadata +45 -11
- data/lib/active_record/locking.rb +0 -79
data/test/calculations_test.rb
CHANGED
@@ -8,19 +8,29 @@ class CalculationsTest < Test::Unit::TestCase
|
|
8
8
|
fixtures :companies, :accounts, :topics
|
9
9
|
|
10
10
|
def test_should_sum_field
|
11
|
-
assert_equal
|
11
|
+
assert_equal 318, Account.sum(:credit_limit)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_should_average_field
|
15
15
|
value = Account.average(:credit_limit)
|
16
|
-
assert_equal 53, value
|
17
16
|
assert_kind_of Float, value
|
17
|
+
assert_in_delta 53.0, value, 0.001
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_should_get_maximum_of_field
|
21
21
|
assert_equal 60, Account.maximum(:credit_limit)
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_should_get_maximum_of_field_with_include
|
25
|
+
assert_equal 50, Account.maximum(:credit_limit, :include => :firm, :conditions => "companies.name != 'Summit'")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_get_maximum_of_field_with_scoped_include
|
29
|
+
Account.with_scope :find => { :include => :firm, :conditions => "companies.name != 'Summit'" } do
|
30
|
+
assert_equal 50, Account.maximum(:credit_limit)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
def test_should_get_minimum_of_field
|
25
35
|
assert_equal 50, Account.minimum(:credit_limit)
|
26
36
|
end
|
@@ -39,13 +49,13 @@ class CalculationsTest < Test::Unit::TestCase
|
|
39
49
|
|
40
50
|
def test_should_order_by_grouped_field
|
41
51
|
c = Account.sum(:credit_limit, :group => :firm_id, :order => "firm_id")
|
42
|
-
assert_equal [1, 2, 6], c.keys.compact
|
52
|
+
assert_equal [1, 2, 6, 9], c.keys.compact
|
43
53
|
end
|
44
54
|
|
45
55
|
def test_should_order_by_calculation
|
46
56
|
c = Account.sum(:credit_limit, :group => :firm_id, :order => "sum_credit_limit desc, firm_id")
|
47
|
-
assert_equal [105, 60, 50, 50], c.keys.collect { |k| c[k] }
|
48
|
-
assert_equal [6, 2, 1], c.keys.compact
|
57
|
+
assert_equal [105, 60, 53, 50, 50], c.keys.collect { |k| c[k] }
|
58
|
+
assert_equal [6, 2, 9, 1], c.keys.compact
|
49
59
|
end
|
50
60
|
|
51
61
|
def test_should_limit_calculation
|
@@ -104,8 +114,8 @@ class CalculationsTest < Test::Unit::TestCase
|
|
104
114
|
end
|
105
115
|
|
106
116
|
def test_should_calculate_with_invalid_field
|
107
|
-
assert_equal
|
108
|
-
assert_equal
|
117
|
+
assert_equal 6, Account.calculate(:count, '*')
|
118
|
+
assert_equal 6, Account.calculate(:count, :all)
|
109
119
|
end
|
110
120
|
|
111
121
|
def test_should_calculate_grouped_with_invalid_field
|
@@ -121,9 +131,17 @@ class CalculationsTest < Test::Unit::TestCase
|
|
121
131
|
assert_equal 2, c[companies(:rails_core)]
|
122
132
|
assert_equal 1, c[companies(:first_client)]
|
123
133
|
end
|
134
|
+
|
135
|
+
def test_should_not_modify_options_when_using_includes
|
136
|
+
options = {:conditions => 'companies.id > 1', :include => :firm}
|
137
|
+
options_copy = options.dup
|
138
|
+
|
139
|
+
Account.count(:all, options)
|
140
|
+
assert_equal options_copy, options
|
141
|
+
end
|
124
142
|
|
125
143
|
def test_should_calculate_grouped_by_function
|
126
|
-
c = Company.count(:all, :group =>
|
144
|
+
c = Company.count(:all, :group => "UPPER(#{QUOTED_TYPE})")
|
127
145
|
assert_equal 2, c[nil]
|
128
146
|
assert_equal 1, c['DEPENDENTFIRM']
|
129
147
|
assert_equal 3, c['CLIENT']
|
@@ -131,12 +149,16 @@ class CalculationsTest < Test::Unit::TestCase
|
|
131
149
|
end
|
132
150
|
|
133
151
|
def test_should_calculate_grouped_by_function_with_table_alias
|
134
|
-
c = Company.count(:all, :group =>
|
152
|
+
c = Company.count(:all, :group => "UPPER(companies.#{QUOTED_TYPE})")
|
135
153
|
assert_equal 2, c[nil]
|
136
154
|
assert_equal 1, c['DEPENDENTFIRM']
|
137
155
|
assert_equal 3, c['CLIENT']
|
138
156
|
assert_equal 2, c['FIRM']
|
139
157
|
end
|
158
|
+
|
159
|
+
def test_should_not_overshadow_enumerable_sum
|
160
|
+
assert_equal 6, [1, 2, 3].sum(&:abs)
|
161
|
+
end
|
140
162
|
|
141
163
|
def test_should_sum_scoped_field
|
142
164
|
assert_equal 15, companies(:rails_core).companies.sum(:id)
|
@@ -174,8 +196,24 @@ class CalculationsTest < Test::Unit::TestCase
|
|
174
196
|
Company.send(:validate_calculation_options, :count, :include => true)
|
175
197
|
end
|
176
198
|
|
177
|
-
assert_raises(ArgumentError) { Company.send(:validate_calculation_options, :sum, :include => :posts) }
|
178
199
|
assert_raises(ArgumentError) { Company.send(:validate_calculation_options, :sum, :foo => :bar) }
|
179
200
|
assert_raises(ArgumentError) { Company.send(:validate_calculation_options, :count, :foo => :bar) }
|
180
201
|
end
|
202
|
+
|
203
|
+
def test_should_count_selected_field_with_include
|
204
|
+
assert_equal 6, Account.count(:distinct => true, :include => :firm)
|
205
|
+
assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_deprecated_count_with_string_parameters
|
209
|
+
assert_deprecated('count') { Account.count('credit_limit > 50') }
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_count_with_no_parameters_isnt_deprecated
|
213
|
+
assert_not_deprecated { Account.count }
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_count_with_too_many_parameters_raises
|
217
|
+
assert_raise(ArgumentError) { Account.count(1, 2, 3) }
|
218
|
+
end
|
181
219
|
end
|
data/test/callbacks_test.rb
CHANGED
@@ -109,6 +109,13 @@ class ImmutableMethodDeveloper < ActiveRecord::Base
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
class CallbackCancellationDeveloper < ActiveRecord::Base
|
113
|
+
set_table_name 'developers'
|
114
|
+
def before_create
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
112
119
|
class CallbacksTest < Test::Unit::TestCase
|
113
120
|
fixtures :developers
|
114
121
|
|
@@ -334,6 +341,12 @@ class CallbacksTest < Test::Unit::TestCase
|
|
334
341
|
assert_raises(ActiveRecord::RecordInvalid) { david.save! }
|
335
342
|
end
|
336
343
|
|
344
|
+
def test_before_create_returning_false
|
345
|
+
someone = CallbackCancellationDeveloper.new
|
346
|
+
assert someone.valid?
|
347
|
+
assert !someone.save
|
348
|
+
end
|
349
|
+
|
337
350
|
def test_before_destroy_returning_false
|
338
351
|
david = ImmutableDeveloper.find(1)
|
339
352
|
assert !david.destroy
|
@@ -4,21 +4,22 @@ require 'logger'
|
|
4
4
|
|
5
5
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'db2',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'arunit',
|
12
|
+
:password => 'arunit',
|
13
|
+
:database => 'arunit'
|
14
|
+
},
|
15
|
+
'arunit2' => {
|
16
|
+
:adapter => 'db2',
|
17
|
+
:host => 'localhost',
|
18
|
+
:username => 'arunit',
|
19
|
+
:password => 'arunit',
|
20
|
+
:database => 'arunit2'
|
21
|
+
}
|
22
|
+
}
|
9
23
|
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
:host => "localhost",
|
13
|
-
:username => "arunit",
|
14
|
-
:password => "arunit",
|
15
|
-
:database => db1
|
16
|
-
)
|
17
|
-
|
18
|
-
Course.establish_connection(
|
19
|
-
:adapter => "db2",
|
20
|
-
:host => "localhost",
|
21
|
-
:username => "arunit2",
|
22
|
-
:password => "arunit2",
|
23
|
-
:database => db2
|
24
|
-
)
|
24
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
25
|
+
Course.establish_connection 'arunit2'
|
@@ -4,21 +4,23 @@ require 'logger'
|
|
4
4
|
|
5
5
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'firebird',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'rails',
|
12
|
+
:password => 'rails',
|
13
|
+
:database => 'activerecord_unittest',
|
14
|
+
:charset => 'UTF8'
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'firebird',
|
18
|
+
:host => 'localhost',
|
19
|
+
:username => 'rails',
|
20
|
+
:password => 'rails',
|
21
|
+
:database => 'activerecord_unittest2'
|
22
|
+
}
|
23
|
+
}
|
9
24
|
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
:host => "localhost",
|
13
|
-
:username => "rails",
|
14
|
-
:password => "rails",
|
15
|
-
:database => db1
|
16
|
-
)
|
17
|
-
|
18
|
-
Course.establish_connection(
|
19
|
-
:adapter => "firebird",
|
20
|
-
:host => "localhost",
|
21
|
-
:username => "rails",
|
22
|
-
:password => "rails",
|
23
|
-
:database => db2
|
24
|
-
)
|
25
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
26
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
puts 'Using native Frontbase'
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'frontbase',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'rails',
|
12
|
+
:password => '',
|
13
|
+
:database => 'activerecord_unittest',
|
14
|
+
:session_name => "unittest-#{$$}"
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'frontbase',
|
18
|
+
:host => 'localhost',
|
19
|
+
:username => 'rails',
|
20
|
+
:password => '',
|
21
|
+
:database => 'activerecord_unittest2',
|
22
|
+
:session_name => "unittest-#{$$}"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
27
|
+
Course.establish_connection 'arunit2'
|
@@ -2,20 +2,23 @@ print "Using native MySQL\n"
|
|
2
2
|
require_dependency 'fixtures/course'
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
-
|
5
|
+
RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
|
6
|
+
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
7
|
+
ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
ActiveRecord::Base.configurations = {
|
10
|
+
'arunit' => {
|
11
|
+
:adapter => 'mysql',
|
12
|
+
:username => 'rails',
|
13
|
+
:encoding => 'utf8',
|
14
|
+
:database => 'activerecord_unittest',
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'mysql',
|
18
|
+
:username => 'rails',
|
19
|
+
:database => 'activerecord_unittest2'
|
20
|
+
}
|
21
|
+
}
|
9
22
|
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
:username => "rails",
|
13
|
-
:encoding => "utf8",
|
14
|
-
:database => db1
|
15
|
-
)
|
16
|
-
|
17
|
-
Course.establish_connection(
|
18
|
-
:adapter => "mysql",
|
19
|
-
:username => "rails",
|
20
|
-
:database => db2
|
21
|
-
)
|
23
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
24
|
+
Course.establish_connection 'arunit2'
|
@@ -4,19 +4,18 @@ require 'logger'
|
|
4
4
|
|
5
5
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'openbase',
|
10
|
+
:username => 'admin',
|
11
|
+
:database => 'activerecord_unittest',
|
12
|
+
},
|
13
|
+
'arunit2' => {
|
14
|
+
:adapter => 'openbase',
|
15
|
+
:username => 'admin',
|
16
|
+
:database => 'activerecord_unittest2'
|
17
|
+
}
|
18
|
+
}
|
9
19
|
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
:username => "admin",
|
13
|
-
:password => "",
|
14
|
-
:database => db1
|
15
|
-
)
|
16
|
-
|
17
|
-
Course.establish_connection(
|
18
|
-
:adapter => "openbase",
|
19
|
-
:username => "admin",
|
20
|
-
:password => "",
|
21
|
-
:database => db2
|
22
|
-
)
|
20
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
21
|
+
Course.establish_connection 'arunit2'
|
@@ -8,16 +8,20 @@ ActiveRecord::Base.logger.level = Logger::WARN
|
|
8
8
|
# Set these to your database connection strings
|
9
9
|
db = ENV['ARUNIT_DB'] || 'activerecord_unittest'
|
10
10
|
|
11
|
-
ActiveRecord::Base.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
ActiveRecord::Base.configurations = {
|
12
|
+
'arunit' => {
|
13
|
+
:adapter => 'oracle',
|
14
|
+
:username => 'arunit',
|
15
|
+
:password => 'arunit',
|
16
|
+
:database => db,
|
17
|
+
},
|
18
|
+
'arunit2' => {
|
19
|
+
:adapter => 'oracle',
|
20
|
+
:username => 'arunit2',
|
21
|
+
:password => 'arunit2',
|
22
|
+
:database => db
|
23
|
+
}
|
24
|
+
}
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
:username => 'arunit2',
|
21
|
-
:password => 'arunit2',
|
22
|
-
:database => db
|
23
|
-
)
|
26
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
27
|
+
Course.establish_connection 'arunit2'
|
@@ -4,21 +4,20 @@ require 'logger'
|
|
4
4
|
|
5
5
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'postgresql',
|
10
|
+
:username => 'postgres',
|
11
|
+
:database => 'activerecord_unittest',
|
12
|
+
:min_messages => 'warning'
|
13
|
+
},
|
14
|
+
'arunit2' => {
|
15
|
+
:adapter => 'postgresql',
|
16
|
+
:username => 'postgres',
|
17
|
+
:database => 'activerecord_unittest2',
|
18
|
+
:min_messages => 'warning'
|
19
|
+
}
|
20
|
+
}
|
9
21
|
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
:username => "postgres",
|
13
|
-
:password => "postgres",
|
14
|
-
:database => db1,
|
15
|
-
:min_messages => "warning"
|
16
|
-
)
|
17
|
-
|
18
|
-
Course.establish_connection(
|
19
|
-
:adapter => "postgresql",
|
20
|
-
:username => "postgres",
|
21
|
-
:password => "postgres",
|
22
|
-
:database => db2,
|
23
|
-
:min_messages => "warning"
|
24
|
-
)
|
22
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
23
|
+
Course.establish_connection 'arunit2'
|
@@ -11,14 +11,13 @@ sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
|
|
11
11
|
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
|
12
12
|
|
13
13
|
def make_connection(clazz, db_file, db_definitions_file)
|
14
|
+
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } }
|
14
15
|
unless File.exist?(db_file)
|
15
16
|
puts "SQLite database not found at #{db_file}. Rebuilding it."
|
16
17
|
sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"}
|
17
18
|
puts "Executing '#{sqlite_command}'"
|
18
19
|
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
|
19
|
-
clazz.establish_connection(
|
20
|
-
:adapter => "sqlite",
|
21
|
-
:database => db_file)
|
20
|
+
clazz.establish_connection(clazz.name)
|
22
21
|
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
|
23
22
|
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
|
24
23
|
script.split(';').each do
|
@@ -26,9 +25,7 @@ def make_connection(clazz, db_file, db_definitions_file)
|
|
26
25
|
clazz.connection.execute(command) unless command.strip.empty?
|
27
26
|
end
|
28
27
|
else
|
29
|
-
clazz.establish_connection(
|
30
|
-
:adapter => "sqlite",
|
31
|
-
:database => db_file)
|
28
|
+
clazz.establish_connection(clazz.name)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
@@ -11,14 +11,13 @@ sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
|
|
11
11
|
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
|
12
12
|
|
13
13
|
def make_connection(clazz, db_file, db_definitions_file)
|
14
|
+
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } }
|
14
15
|
unless File.exist?(db_file)
|
15
16
|
puts "SQLite3 database not found at #{db_file}. Rebuilding it."
|
16
17
|
sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"}
|
17
18
|
puts "Executing '#{sqlite_command}'"
|
18
19
|
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
|
19
|
-
clazz.establish_connection(
|
20
|
-
:adapter => "sqlite3",
|
21
|
-
:database => db_file)
|
20
|
+
clazz.establish_connection(clazz.name)
|
22
21
|
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
|
23
22
|
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
|
24
23
|
script.split(';').each do
|
@@ -26,9 +25,7 @@ def make_connection(clazz, db_file, db_definitions_file)
|
|
26
25
|
clazz.connection.execute(command) unless command.strip.empty?
|
27
26
|
end
|
28
27
|
else
|
29
|
-
clazz.establish_connection(
|
30
|
-
:adapter => "sqlite3",
|
31
|
-
:database => db_file)
|
28
|
+
clazz.establish_connection(clazz.name)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|