pmacs-activerecord-oracle_enhanced-adapter 1.4.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.rspec +2 -0
  2. data/Gemfile +52 -0
  3. data/History.md +284 -0
  4. data/License.txt +20 -0
  5. data/README.md +403 -0
  6. data/RUNNING_TESTS.md +45 -0
  7. data/Rakefile +59 -0
  8. data/VERSION +1 -0
  9. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced.rake +105 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +41 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +1408 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +118 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +141 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +135 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +359 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +25 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +21 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +44 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +565 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +491 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +260 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +231 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +257 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +397 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +265 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +294 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +17 -0
  29. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -0
  30. data/lib/pmacs-activerecord-oracle_enhanced-adapter.rb +25 -0
  31. data/pmacs-activerecord-oracle_enhanced-adapter.gemspec +131 -0
  32. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +778 -0
  33. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +332 -0
  34. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +427 -0
  35. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +19 -0
  36. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +113 -0
  37. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +1376 -0
  38. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +69 -0
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +141 -0
  40. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +25 -0
  41. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +378 -0
  42. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +438 -0
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +1280 -0
  44. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +339 -0
  45. data/spec/spec_helper.rb +187 -0
  46. metadata +302 -0
@@ -0,0 +1,339 @@
1
+ require 'spec_helper'
2
+
3
+ describe "OracleEnhancedAdapter structure dump" do
4
+ include LoggerSpecHelper
5
+
6
+ before(:all) do
7
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
+ @conn = ActiveRecord::Base.connection
9
+ @oracle11g = !! @conn.select_value("SELECT * FROM v$version WHERE banner LIKE 'Oracle%11g%'")
10
+ end
11
+ describe "structure dump" do
12
+ before(:each) do
13
+ @conn.create_table :test_posts, :force => true do |t|
14
+ t.string :title
15
+ t.string :foo
16
+ t.integer :foo_id
17
+ end
18
+ @conn.create_table :foos do |t|
19
+ end
20
+ class ::TestPost < ActiveRecord::Base
21
+ end
22
+ if TestPost.respond_to?(:table_name=)
23
+ TestPost.table_name = "test_posts"
24
+ else
25
+ TestPost.set_table_name "test_posts"
26
+ end
27
+ end
28
+
29
+ after(:each) do
30
+ @conn.drop_table :test_posts
31
+ @conn.drop_table :foos
32
+ @conn.execute "DROP SEQUENCE test_posts_seq" rescue nil
33
+ @conn.execute "ALTER TABLE test_posts drop CONSTRAINT fk_test_post_foo" rescue nil
34
+ @conn.execute "DROP TRIGGER test_post_trigger" rescue nil
35
+ @conn.execute "DROP TYPE TEST_TYPE" rescue nil
36
+ @conn.execute "DROP TABLE bars" rescue nil
37
+ @conn.execute "ALTER TABLE foos drop CONSTRAINT UK_BAZ" rescue nil
38
+ @conn.execute "ALTER TABLE foos drop CONSTRAINT UK_FOOZ_BAZ" rescue nil
39
+ @conn.execute "ALTER TABLE foos drop column fooz_id" rescue nil
40
+ @conn.execute "ALTER TABLE foos drop column baz_id" rescue nil
41
+ @conn.execute "ALTER TABLE test_posts drop column fooz_id" rescue nil
42
+ @conn.execute "ALTER TABLE test_posts drop column baz_id" rescue nil
43
+ end
44
+
45
+ it "should dump single primary key" do
46
+ dump = ActiveRecord::Base.connection.structure_dump
47
+ dump.should =~ /CONSTRAINT (.+) PRIMARY KEY \(ID\)\n/
48
+ end
49
+
50
+ it "should dump composite primary keys" do
51
+ pk = @conn.send(:select_one, <<-SQL)
52
+ select constraint_name from user_constraints where table_name = 'TEST_POSTS' and constraint_type='P'
53
+ SQL
54
+ @conn.execute <<-SQL
55
+ alter table test_posts drop constraint #{pk["constraint_name"]}
56
+ SQL
57
+ @conn.execute <<-SQL
58
+ ALTER TABLE TEST_POSTS
59
+ add CONSTRAINT pk_id_title PRIMARY KEY (id, title)
60
+ SQL
61
+ dump = ActiveRecord::Base.connection.structure_dump
62
+ dump.should =~ /CONSTRAINT (.+) PRIMARY KEY \(ID,TITLE\)\n/
63
+ end
64
+
65
+ it "should dump foreign keys" do
66
+ @conn.execute <<-SQL
67
+ ALTER TABLE TEST_POSTS
68
+ ADD CONSTRAINT fk_test_post_foo FOREIGN KEY (foo_id) REFERENCES foos(id)
69
+ SQL
70
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
71
+ dump.split('\n').length.should == 1
72
+ dump.should =~ /ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOO\"? FOREIGN KEY \(\"?FOO_ID\"?\) REFERENCES \"?FOOS\"?\(\"?ID\"?\)/i
73
+ end
74
+
75
+ it "should dump foreign keys when reference column name is not 'id'" do
76
+ @conn.add_column :foos, :baz_id, :integer
77
+
78
+ @conn.execute <<-SQL
79
+ ALTER TABLE FOOS
80
+ ADD CONSTRAINT UK_BAZ UNIQUE (BAZ_ID)
81
+ SQL
82
+
83
+ @conn.add_column :test_posts, :baz_id, :integer
84
+
85
+ @conn.execute <<-SQL
86
+ ALTER TABLE TEST_POSTS
87
+ ADD CONSTRAINT fk_test_post_baz FOREIGN KEY (baz_id) REFERENCES foos(baz_id)
88
+ SQL
89
+
90
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
91
+ dump.split('\n').length.should == 1
92
+ dump.should =~ /ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\)/i
93
+ end
94
+
95
+ it "should dump composite foreign keys" do
96
+ @conn.add_column :foos, :fooz_id, :integer
97
+ @conn.add_column :foos, :baz_id, :integer
98
+
99
+ @conn.execute <<-SQL
100
+ ALTER TABLE FOOS
101
+ ADD CONSTRAINT UK_FOOZ_BAZ UNIQUE (BAZ_ID,FOOZ_ID)
102
+ SQL
103
+
104
+ @conn.add_column :test_posts, :fooz_id, :integer
105
+ @conn.add_column :test_posts, :baz_id, :integer
106
+
107
+ @conn.execute <<-SQL
108
+ ALTER TABLE TEST_POSTS
109
+ ADD CONSTRAINT fk_test_post_fooz_baz FOREIGN KEY (baz_id,fooz_id) REFERENCES foos(baz_id,fooz_id)
110
+ SQL
111
+
112
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
113
+ dump.split('\n').length.should == 1
114
+ dump.should =~ /ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOOZ_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\,\"?FOOZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\,\"?FOOZ_ID\"?\)/i
115
+ end
116
+
117
+ it "should not error when no foreign keys are present" do
118
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
119
+ dump.split('\n').length.should == 0
120
+ dump.should == ''
121
+ end
122
+
123
+ it "should dump triggers" do
124
+ @conn.execute <<-SQL
125
+ create or replace TRIGGER TEST_POST_TRIGGER
126
+ BEFORE INSERT
127
+ ON TEST_POSTS
128
+ FOR EACH ROW
129
+ BEGIN
130
+ SELECT 'bar' INTO :new.FOO FROM DUAL;
131
+ END;
132
+ SQL
133
+ dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
134
+ dump.should =~ /CREATE OR REPLACE TRIGGER TEST_POST_TRIGGER/
135
+ end
136
+
137
+ it "should dump types" do
138
+ @conn.execute <<-SQL
139
+ create or replace TYPE TEST_TYPE AS TABLE OF VARCHAR2(10);
140
+ SQL
141
+ dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
142
+ dump.should =~ /CREATE OR REPLACE TYPE TEST_TYPE/
143
+ end
144
+
145
+ it "should dump virtual columns" do
146
+ pending "Not supported in this database version" unless @oracle11g
147
+ @conn.execute <<-SQL
148
+ CREATE TABLE bars (
149
+ id NUMBER(38,0) NOT NULL,
150
+ id_plus NUMBER GENERATED ALWAYS AS(id + 2) VIRTUAL,
151
+ PRIMARY KEY (ID)
152
+ )
153
+ SQL
154
+ dump = ActiveRecord::Base.connection.structure_dump
155
+ dump.should =~ /\"?ID_PLUS\"? NUMBER GENERATED ALWAYS AS \(ID\+2\) VIRTUAL/
156
+ end
157
+
158
+ it "should dump unique keys" do
159
+ @conn.execute <<-SQL
160
+ ALTER TABLE test_posts
161
+ add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
162
+ SQL
163
+ dump = ActiveRecord::Base.connection.structure_dump_unique_keys("test_posts")
164
+ dump.should == ["ALTER TABLE TEST_POSTS ADD CONSTRAINT UK_FOO_FOO_ID UNIQUE (FOO,FOO_ID)"]
165
+
166
+ dump = ActiveRecord::Base.connection.structure_dump
167
+ dump.should =~ /CONSTRAINT UK_FOO_FOO_ID UNIQUE \(FOO,FOO_ID\)/
168
+ end
169
+
170
+ it "should dump indexes" do
171
+ ActiveRecord::Base.connection.add_index(:test_posts, :foo, :name => :ix_test_posts_foo)
172
+ ActiveRecord::Base.connection.add_index(:test_posts, :foo_id, :name => :ix_test_posts_foo_id, :unique => true)
173
+
174
+ @conn.execute <<-SQL
175
+ ALTER TABLE test_posts
176
+ add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
177
+ SQL
178
+
179
+ dump = ActiveRecord::Base.connection.structure_dump
180
+ dump.should =~ /CREATE UNIQUE INDEX "?IX_TEST_POSTS_FOO_ID"? ON "?TEST_POSTS"? \("?FOO_ID"?\)/i
181
+ dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FOO\"? ON "?TEST_POSTS"? \("?FOO"?\)/i
182
+ dump.should_not =~ /CREATE UNIQUE INDEX "?UK_TEST_POSTS_/i
183
+ end
184
+
185
+ it "should dump multi-value and function value indexes" do
186
+ ActiveRecord::Base.connection.add_index(:test_posts, [:foo, :foo_id], :name => :ix_test_posts_foo_foo_id)
187
+
188
+ @conn.execute <<-SQL
189
+ CREATE INDEX "IX_TEST_POSTS_FUNCTION" ON "TEST_POSTS" (TO_CHAR(LENGTH("FOO"))||"FOO")
190
+ SQL
191
+
192
+ dump = ActiveRecord::Base.connection.structure_dump
193
+ dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FOO_FOO_ID\"? ON "?TEST_POSTS"? \("?FOO"?, "?FOO_ID"?\)/i
194
+ dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FUNCTION\"? ON "?TEST_POSTS"? \(TO_CHAR\(LENGTH\("?FOO"?\)\)\|\|"?FOO"?\)/i
195
+ end
196
+ end
197
+ describe "temporary tables" do
198
+ after(:all) do
199
+ @conn.drop_table :test_comments rescue nil
200
+ end
201
+ it "should dump correctly" do
202
+ @conn.create_table :test_comments, :temporary => true, :id => false do |t|
203
+ t.integer :post_id
204
+ end
205
+ dump = ActiveRecord::Base.connection.structure_dump
206
+ dump.should =~ /CREATE GLOBAL TEMPORARY TABLE "?TEST_COMMENTS"?/i
207
+ end
208
+ end
209
+
210
+ describe "database stucture dump extentions" do
211
+ before(:all) do
212
+ @conn.execute <<-SQL
213
+ CREATE TABLE nvarchartable (
214
+ unq_nvarchar NVARCHAR2(255) DEFAULT NULL
215
+ )
216
+ SQL
217
+ end
218
+
219
+ after(:all) do
220
+ @conn.execute "DROP TABLE nvarchartable"
221
+ end
222
+
223
+ it "should return the character size of nvarchar fields" do
224
+ if /.*unq_nvarchar nvarchar2\((\d+)\).*/ =~ @conn.structure_dump
225
+ "#$1".should == "255"
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "temp_table_drop" do
231
+ before(:each) do
232
+ @conn.create_table :temp_tbl, :temporary => true do |t|
233
+ t.string :foo
234
+ end
235
+ @conn.create_table :not_temp_tbl do |t|
236
+ t.string :foo
237
+ end
238
+ end
239
+ it "should dump drop sql for just temp tables" do
240
+ dump = @conn.temp_table_drop
241
+ dump.should =~ /DROP TABLE "TEMP_TBL"/
242
+ dump.should_not =~ /DROP TABLE "?NOT_TEMP_TBL"?/i
243
+ end
244
+ after(:each) do
245
+ @conn.drop_table :temp_tbl
246
+ @conn.drop_table :not_temp_tbl
247
+ end
248
+ end
249
+
250
+ describe "full drop" do
251
+ before(:each) do
252
+ @conn.create_table :full_drop_test do |t|
253
+ t.integer :id
254
+ end
255
+ @conn.create_table :full_drop_test_temp, :temporary => true do |t|
256
+ t.string :foo
257
+ end
258
+ #view
259
+ @conn.execute <<-SQL
260
+ create or replace view full_drop_test_view (foo) as select id as "foo" from full_drop_test
261
+ SQL
262
+ #materialized view
263
+ @conn.execute <<-SQL
264
+ create materialized view full_drop_test_mview (foo) as select id as "foo" from full_drop_test
265
+ SQL
266
+ #package
267
+ @conn.execute <<-SQL
268
+ create or replace package full_drop_test_package as
269
+ function test_func return varchar2;
270
+ end test_package;
271
+ SQL
272
+ @conn.execute <<-SQL
273
+ create or replace package body full_drop_test_package as
274
+ function test_func return varchar2 is
275
+ begin
276
+ return ('foo');
277
+ end test_func;
278
+ end test_package;
279
+ SQL
280
+ #function
281
+ @conn.execute <<-SQL
282
+ create or replace function full_drop_test_function
283
+ return varchar2
284
+ is
285
+ foo varchar2(3);
286
+ begin
287
+ return('foo');
288
+ end;
289
+ SQL
290
+ #procedure
291
+ @conn.execute <<-SQL
292
+ create or replace procedure full_drop_test_procedure
293
+ begin
294
+ delete from full_drop_test where id=1231231231
295
+ exception
296
+ when no_data_found then
297
+ dbms_output.put_line('foo');
298
+ end;
299
+ SQL
300
+ #synonym
301
+ @conn.execute <<-SQL
302
+ create or replace synonym full_drop_test_synonym for full_drop_test
303
+ SQL
304
+ #type
305
+ @conn.execute <<-SQL
306
+ create or replace type full_drop_test_type as table of number
307
+ SQL
308
+ end
309
+ after(:each) do
310
+ @conn.drop_table :full_drop_test
311
+ @conn.drop_table :full_drop_test_temp
312
+ @conn.execute "DROP VIEW FULL_DROP_TEST_VIEW" rescue nil
313
+ @conn.execute "DROP MATERIALIZED VIEW FULL_DROP_TEST_MVIEW" rescue nil
314
+ @conn.execute "DROP SYNONYM FULL_DROP_TEST_SYNONYM" rescue nil
315
+ @conn.execute "DROP PACKAGE FULL_DROP_TEST_PACKAGE" rescue nil
316
+ @conn.execute "DROP FUNCTION FULL_DROP_TEST_FUNCTION" rescue nil
317
+ @conn.execute "DROP PROCEDURE FULL_DROP_TEST_PROCEDURE" rescue nil
318
+ @conn.execute "DROP TYPE FULL_DROP_TEST_TYPE" rescue nil
319
+ end
320
+ it "should contain correct sql" do
321
+ drop = @conn.full_drop
322
+ drop.should =~ /DROP TABLE "FULL_DROP_TEST" CASCADE CONSTRAINTS/
323
+ drop.should =~ /DROP SEQUENCE "FULL_DROP_TEST_SEQ"/
324
+ drop.should =~ /DROP VIEW "FULL_DROP_TEST_VIEW"/
325
+ drop.should_not =~ /DROP TABLE "?FULL_DROP_TEST_MVIEW"?/i
326
+ drop.should =~ /DROP MATERIALIZED VIEW "FULL_DROP_TEST_MVIEW"/
327
+ drop.should =~ /DROP PACKAGE "FULL_DROP_TEST_PACKAGE"/
328
+ drop.should =~ /DROP FUNCTION "FULL_DROP_TEST_FUNCTION"/
329
+ drop.should =~ /DROP PROCEDURE "FULL_DROP_TEST_PROCEDURE"/
330
+ drop.should =~ /DROP SYNONYM "FULL_DROP_TEST_SYNONYM"/
331
+ drop.should =~ /DROP TYPE "FULL_DROP_TEST_TYPE"/
332
+ end
333
+ it "should not drop tables when preserve_tables is true" do
334
+ drop = @conn.full_drop(true)
335
+ drop.should =~ /DROP TABLE "FULL_DROP_TEST_TEMP"/
336
+ drop.should_not =~ /DROP TABLE "?FULL_DROP_TEST"? CASCADE CONSTRAINTS/i
337
+ end
338
+ end
339
+ end
@@ -0,0 +1,187 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup(:default, :development)
4
+
5
+ $:.unshift(File.expand_path('../../lib', __FILE__))
6
+
7
+ require 'rspec'
8
+
9
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
10
+ puts "==> Running specs with MRI version #{RUBY_VERSION}"
11
+ require 'oci8'
12
+ elsif RUBY_ENGINE == 'jruby'
13
+ puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
14
+ end
15
+
16
+ ENV['RAILS_GEM_VERSION'] ||= '3.2-master'
17
+ NO_COMPOSITE_PRIMARY_KEYS = true if ENV['RAILS_GEM_VERSION'] >= '2.3.5' || ENV['RAILS_GEM_VERSION'] =~ /^2\.3\.1\d$/
18
+
19
+ puts "==> Running specs with Rails version #{ENV['RAILS_GEM_VERSION']}"
20
+
21
+ require 'active_record'
22
+
23
+ if ENV['RAILS_GEM_VERSION'] >= '3.0'
24
+ require 'action_dispatch'
25
+ require 'active_support/core_ext/module/attribute_accessors'
26
+ require 'active_support/core_ext/class/attribute_accessors'
27
+
28
+ if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
29
+ require "rails/log_subscriber"
30
+ require 'active_record/railties/log_subscriber'
31
+ else
32
+ require "active_support/log_subscriber"
33
+ require 'active_record/log_subscriber'
34
+ end
35
+
36
+ require 'logger'
37
+ elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3/
38
+ require 'action_pack'
39
+ require 'action_controller/session/abstract_store'
40
+ require 'active_record/session_store'
41
+ elsif ENV['RAILS_GEM_VERSION'] <= '2.3'
42
+ require 'action_pack'
43
+ require 'action_controller/session/active_record_store'
44
+ end
45
+
46
+ require 'active_record/connection_adapters/oracle_enhanced_adapter'
47
+ require 'ruby-plsql'
48
+
49
+ module LoggerSpecHelper
50
+ def set_logger
51
+ @logger = MockLogger.new
52
+ @old_logger = ActiveRecord::Base.logger
53
+
54
+ if ENV['RAILS_GEM_VERSION'] >= '3.0'
55
+ @notifier = ActiveSupport::Notifications::Fanout.new
56
+
57
+ ActiveSupport::LogSubscriber.colorize_logging = false
58
+
59
+ ActiveRecord::Base.logger = @logger
60
+ @old_notifier = ActiveSupport::Notifications.notifier
61
+ ActiveSupport::Notifications.notifier = @notifier
62
+
63
+ ActiveRecord::LogSubscriber.attach_to(:active_record)
64
+ if ENV['RAILS_GEM_VERSION'] >= '3.2'
65
+ ActiveSupport::Notifications.subscribe("sql.active_record", ActiveRecord::ExplainSubscriber.new)
66
+ end
67
+ else # ActiveRecord 2.x
68
+ if ActiveRecord::Base.respond_to?(:connection_pool)
69
+ ActiveRecord::Base.connection_pool.clear_reloadable_connections!
70
+ else
71
+ ActiveRecord::Base.clear_active_connections!
72
+ end
73
+ ActiveRecord::Base.logger = @logger
74
+ ActiveRecord::Base.colorize_logging = false
75
+ # ActiveRecord::Base.logger.level = Logger::DEBUG
76
+ end
77
+
78
+ end
79
+
80
+ class MockLogger
81
+ attr_reader :flush_count
82
+
83
+ def initialize
84
+ @flush_count = 0
85
+ @logged = Hash.new { |h,k| h[k] = [] }
86
+ end
87
+
88
+ # used in AtiveRecord 2.x
89
+ def debug?
90
+ true
91
+ end
92
+
93
+ def method_missing(level, message)
94
+ @logged[level] << message
95
+ end
96
+
97
+ def logged(level)
98
+ @logged[level].compact.map { |l| l.to_s.strip }
99
+ end
100
+
101
+ def output(level)
102
+ logged(level).join("\n")
103
+ end
104
+
105
+ def flush
106
+ @flush_count += 1
107
+ end
108
+
109
+ def clear(level)
110
+ @logged[level] = []
111
+ end
112
+ end
113
+
114
+ def clear_logger
115
+ ActiveRecord::Base.logger = @old_logger
116
+ @logger = nil
117
+
118
+ if ENV['RAILS_GEM_VERSION'] >= '3.0'
119
+ ActiveSupport::Notifications.notifier = @old_notifier
120
+ @notifier = nil
121
+ end
122
+
123
+ end
124
+
125
+ # Wait notifications to be published (for Rails 3.0)
126
+ # should not be currently used with sync queues in tests
127
+ def wait
128
+ @notifier.wait if @notifier
129
+ end
130
+
131
+ end
132
+
133
+ module SchemaSpecHelper
134
+ def schema_define(&block)
135
+ ActiveRecord::Schema.define do
136
+ suppress_messages do
137
+ instance_eval(&block)
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
144
+ DATABASE_HOST = ENV['DATABASE_HOST']
145
+ DATABASE_PORT = ENV['DATABASE_PORT']
146
+ DATABASE_USER = ENV['DATABASE_USER'] || 'oracle_enhanced'
147
+ DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'oracle_enhanced'
148
+ DATABASE_SYS_PASSWORD = ENV['DATABASE_SYS_PASSWORD'] || 'admin'
149
+
150
+ CONNECTION_PARAMS = {
151
+ :adapter => "oracle_enhanced",
152
+ :database => DATABASE_NAME,
153
+ :host => DATABASE_HOST,
154
+ :port => DATABASE_PORT,
155
+ :username => DATABASE_USER,
156
+ :password => DATABASE_PASSWORD
157
+ }
158
+
159
+ SYS_CONNECTION_PARAMS = {
160
+ :adapter => "oracle_enhanced",
161
+ :database => DATABASE_NAME,
162
+ :host => DATABASE_HOST,
163
+ :port => DATABASE_PORT,
164
+ :username => "sys",
165
+ :password => DATABASE_SYS_PASSWORD,
166
+ :privilege => "SYSDBA"
167
+ }
168
+
169
+ SYSTEM_CONNECTION_PARAMS = {
170
+ :adapter => "oracle_enhanced",
171
+ :database => DATABASE_NAME,
172
+ :host => DATABASE_HOST,
173
+ :port => DATABASE_PORT,
174
+ :username => "system",
175
+ :password => DATABASE_SYS_PASSWORD
176
+ }
177
+
178
+ DATABASE_NON_DEFAULT_TABLESPACE = ENV['DATABASE_NON_DEFAULT_TABLESPACE'] || "SYSTEM"
179
+
180
+ # Set default $KCODE to UTF8
181
+ if RUBY_VERSION < "1.9"
182
+ $KCODE = "UTF8"
183
+ end
184
+
185
+ # set default time zone in TZ environment variable
186
+ # which will be used to set session time zone
187
+ ENV['TZ'] ||= 'Europe/Riga'