ctreatma-activerecord-oracle_enhanced-adapter 1.4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Gemfile +51 -0
- data/History.md +269 -0
- data/License.txt +20 -0
- data/README.md +378 -0
- data/RUNNING_TESTS.md +45 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/activerecord-oracle_enhanced-adapter.gemspec +130 -0
- data/ctreatma-activerecord-oracle_enhanced-adapter.gemspec +129 -0
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +105 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +41 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +1390 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +106 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +136 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +119 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +328 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +25 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +21 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +39 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +553 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +492 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +260 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +213 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +252 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +373 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +265 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +290 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +17 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +25 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +749 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +310 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +426 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +19 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +113 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +1330 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +69 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +121 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +25 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +374 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +380 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +1112 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +323 -0
- data/spec/spec_helper.rb +185 -0
- metadata +287 -0
@@ -0,0 +1,323 @@
|
|
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
|
+
TestPost.set_table_name "test_posts"
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:each) do
|
26
|
+
@conn.drop_table :test_posts
|
27
|
+
@conn.drop_table :foos
|
28
|
+
@conn.execute "DROP SEQUENCE test_posts_seq" rescue nil
|
29
|
+
@conn.execute "ALTER TABLE test_posts drop CONSTRAINT fk_test_post_foo" rescue nil
|
30
|
+
@conn.execute "DROP TRIGGER test_post_trigger" rescue nil
|
31
|
+
@conn.execute "DROP TYPE TEST_TYPE" rescue nil
|
32
|
+
@conn.execute "DROP TABLE bars" rescue nil
|
33
|
+
@conn.execute "ALTER TABLE foos drop CONSTRAINT UK_BAZ" rescue nil
|
34
|
+
@conn.execute "ALTER TABLE foos drop CONSTRAINT UK_FOOZ_BAZ" rescue nil
|
35
|
+
@conn.execute "ALTER TABLE foos drop column fooz_id" rescue nil
|
36
|
+
@conn.execute "ALTER TABLE foos drop column baz_id" rescue nil
|
37
|
+
@conn.execute "ALTER TABLE test_posts drop column fooz_id" rescue nil
|
38
|
+
@conn.execute "ALTER TABLE test_posts drop column baz_id" rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should dump single primary key" do
|
42
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
43
|
+
dump.should =~ /CONSTRAINT (.+) PRIMARY KEY \(ID\)\n/
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should dump composite primary keys" do
|
47
|
+
pk = @conn.send(:select_one, <<-SQL)
|
48
|
+
select constraint_name from user_constraints where table_name = 'TEST_POSTS' and constraint_type='P'
|
49
|
+
SQL
|
50
|
+
@conn.execute <<-SQL
|
51
|
+
alter table test_posts drop constraint #{pk["constraint_name"]}
|
52
|
+
SQL
|
53
|
+
@conn.execute <<-SQL
|
54
|
+
ALTER TABLE TEST_POSTS
|
55
|
+
add CONSTRAINT pk_id_title PRIMARY KEY (id, title)
|
56
|
+
SQL
|
57
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
58
|
+
dump.should =~ /CONSTRAINT (.+) PRIMARY KEY \(ID,TITLE\)\n/
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should dump foreign keys" do
|
62
|
+
@conn.execute <<-SQL
|
63
|
+
ALTER TABLE TEST_POSTS
|
64
|
+
ADD CONSTRAINT fk_test_post_foo FOREIGN KEY (foo_id) REFERENCES foos(id)
|
65
|
+
SQL
|
66
|
+
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
|
67
|
+
dump.split('\n').length.should == 1
|
68
|
+
dump.should =~ /ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOO\"? FOREIGN KEY \(\"?FOO_ID\"?\) REFERENCES \"?FOOS\"?\(\"?ID\"?\)/i
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should dump foreign keys when reference column name is not 'id'" do
|
72
|
+
@conn.add_column :foos, :baz_id, :integer
|
73
|
+
|
74
|
+
@conn.execute <<-SQL
|
75
|
+
ALTER TABLE FOOS
|
76
|
+
ADD CONSTRAINT UK_BAZ UNIQUE (BAZ_ID)
|
77
|
+
SQL
|
78
|
+
|
79
|
+
@conn.add_column :test_posts, :baz_id, :integer
|
80
|
+
|
81
|
+
@conn.execute <<-SQL
|
82
|
+
ALTER TABLE TEST_POSTS
|
83
|
+
ADD CONSTRAINT fk_test_post_baz FOREIGN KEY (baz_id) REFERENCES foos(baz_id)
|
84
|
+
SQL
|
85
|
+
|
86
|
+
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
|
87
|
+
dump.split('\n').length.should == 1
|
88
|
+
dump.should =~ /ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\)/i
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should dump composite foreign keys" do
|
92
|
+
@conn.add_column :foos, :fooz_id, :integer
|
93
|
+
@conn.add_column :foos, :baz_id, :integer
|
94
|
+
|
95
|
+
@conn.execute <<-SQL
|
96
|
+
ALTER TABLE FOOS
|
97
|
+
ADD CONSTRAINT UK_FOOZ_BAZ UNIQUE (BAZ_ID,FOOZ_ID)
|
98
|
+
SQL
|
99
|
+
|
100
|
+
@conn.add_column :test_posts, :fooz_id, :integer
|
101
|
+
@conn.add_column :test_posts, :baz_id, :integer
|
102
|
+
|
103
|
+
@conn.execute <<-SQL
|
104
|
+
ALTER TABLE TEST_POSTS
|
105
|
+
ADD CONSTRAINT fk_test_post_fooz_baz FOREIGN KEY (baz_id,fooz_id) REFERENCES foos(baz_id,fooz_id)
|
106
|
+
SQL
|
107
|
+
|
108
|
+
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
|
109
|
+
dump.split('\n').length.should == 1
|
110
|
+
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
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not error when no foreign keys are present" do
|
114
|
+
dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
|
115
|
+
dump.split('\n').length.should == 0
|
116
|
+
dump.should == ''
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should dump triggers" do
|
120
|
+
@conn.execute <<-SQL
|
121
|
+
create or replace TRIGGER TEST_POST_TRIGGER
|
122
|
+
BEFORE INSERT
|
123
|
+
ON TEST_POSTS
|
124
|
+
FOR EACH ROW
|
125
|
+
BEGIN
|
126
|
+
SELECT 'bar' INTO :new.FOO FROM DUAL;
|
127
|
+
END;
|
128
|
+
SQL
|
129
|
+
dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
|
130
|
+
dump.should =~ /CREATE OR REPLACE TRIGGER TEST_POST_TRIGGER/
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should dump types" do
|
134
|
+
@conn.execute <<-SQL
|
135
|
+
create or replace TYPE TEST_TYPE AS TABLE OF VARCHAR2(10);
|
136
|
+
SQL
|
137
|
+
dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
|
138
|
+
dump.should =~ /CREATE OR REPLACE TYPE TEST_TYPE/
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should dump virtual columns" do
|
142
|
+
pending "Not supported in this database version" unless @oracle11g
|
143
|
+
@conn.execute <<-SQL
|
144
|
+
CREATE TABLE bars (
|
145
|
+
id NUMBER(38,0) NOT NULL,
|
146
|
+
id_plus NUMBER GENERATED ALWAYS AS(id + 2) VIRTUAL,
|
147
|
+
PRIMARY KEY (ID)
|
148
|
+
)
|
149
|
+
SQL
|
150
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
151
|
+
dump.should =~ /\"?ID_PLUS\"? NUMBER GENERATED ALWAYS AS \(ID\+2\) VIRTUAL/
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should dump unique keys" do
|
155
|
+
@conn.execute <<-SQL
|
156
|
+
ALTER TABLE test_posts
|
157
|
+
add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
|
158
|
+
SQL
|
159
|
+
dump = ActiveRecord::Base.connection.structure_dump_unique_keys("test_posts")
|
160
|
+
dump.should == ["ALTER TABLE TEST_POSTS ADD CONSTRAINT UK_FOO_FOO_ID UNIQUE (FOO,FOO_ID)"]
|
161
|
+
|
162
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
163
|
+
dump.should =~ /CONSTRAINT UK_FOO_FOO_ID UNIQUE \(FOO,FOO_ID\)/
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should dump indexes" do
|
167
|
+
ActiveRecord::Base.connection.add_index(:test_posts, :foo, :name => :ix_test_posts_foo)
|
168
|
+
ActiveRecord::Base.connection.add_index(:test_posts, :foo_id, :name => :ix_test_posts_foo_id, :unique => true)
|
169
|
+
|
170
|
+
@conn.execute <<-SQL
|
171
|
+
ALTER TABLE test_posts
|
172
|
+
add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
|
173
|
+
SQL
|
174
|
+
|
175
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
176
|
+
dump.should =~ /CREATE UNIQUE INDEX "?IX_TEST_POSTS_FOO_ID"? ON "?TEST_POSTS"? \("?FOO_ID"?\)/i
|
177
|
+
dump.should =~ /CREATE INDEX "?IX_TEST_POSTS_FOO\"? ON "?TEST_POSTS"? \("?FOO"?\)/i
|
178
|
+
dump.should_not =~ /CREATE UNIQUE INDEX "?UK_TEST_POSTS_/i
|
179
|
+
end
|
180
|
+
end
|
181
|
+
describe "temporary tables" do
|
182
|
+
after(:all) do
|
183
|
+
@conn.drop_table :test_comments rescue nil
|
184
|
+
end
|
185
|
+
it "should dump correctly" do
|
186
|
+
@conn.create_table :test_comments, :temporary => true, :id => false do |t|
|
187
|
+
t.integer :post_id
|
188
|
+
end
|
189
|
+
dump = ActiveRecord::Base.connection.structure_dump
|
190
|
+
dump.should =~ /CREATE GLOBAL TEMPORARY TABLE "?TEST_COMMENTS"?/i
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "database stucture dump extentions" do
|
195
|
+
before(:all) do
|
196
|
+
@conn.execute <<-SQL
|
197
|
+
CREATE TABLE nvarchartable (
|
198
|
+
unq_nvarchar NVARCHAR2(255) DEFAULT NULL
|
199
|
+
)
|
200
|
+
SQL
|
201
|
+
end
|
202
|
+
|
203
|
+
after(:all) do
|
204
|
+
@conn.execute "DROP TABLE nvarchartable"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return the character size of nvarchar fields" do
|
208
|
+
if /.*unq_nvarchar nvarchar2\((\d+)\).*/ =~ @conn.structure_dump
|
209
|
+
"#$1".should == "255"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "temp_table_drop" do
|
215
|
+
before(:each) do
|
216
|
+
@conn.create_table :temp_tbl, :temporary => true do |t|
|
217
|
+
t.string :foo
|
218
|
+
end
|
219
|
+
@conn.create_table :not_temp_tbl do |t|
|
220
|
+
t.string :foo
|
221
|
+
end
|
222
|
+
end
|
223
|
+
it "should dump drop sql for just temp tables" do
|
224
|
+
dump = @conn.temp_table_drop
|
225
|
+
dump.should =~ /DROP TABLE "TEMP_TBL"/
|
226
|
+
dump.should_not =~ /DROP TABLE "?NOT_TEMP_TBL"?/i
|
227
|
+
end
|
228
|
+
after(:each) do
|
229
|
+
@conn.drop_table :temp_tbl
|
230
|
+
@conn.drop_table :not_temp_tbl
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "full drop" do
|
235
|
+
before(:each) do
|
236
|
+
@conn.create_table :full_drop_test do |t|
|
237
|
+
t.integer :id
|
238
|
+
end
|
239
|
+
@conn.create_table :full_drop_test_temp, :temporary => true do |t|
|
240
|
+
t.string :foo
|
241
|
+
end
|
242
|
+
#view
|
243
|
+
@conn.execute <<-SQL
|
244
|
+
create or replace view full_drop_test_view (foo) as select id as "foo" from full_drop_test
|
245
|
+
SQL
|
246
|
+
#materialized view
|
247
|
+
@conn.execute <<-SQL
|
248
|
+
create materialized view full_drop_test_mview (foo) as select id as "foo" from full_drop_test
|
249
|
+
SQL
|
250
|
+
#package
|
251
|
+
@conn.execute <<-SQL
|
252
|
+
create or replace package full_drop_test_package as
|
253
|
+
function test_func return varchar2;
|
254
|
+
end test_package;
|
255
|
+
SQL
|
256
|
+
@conn.execute <<-SQL
|
257
|
+
create or replace package body full_drop_test_package as
|
258
|
+
function test_func return varchar2 is
|
259
|
+
begin
|
260
|
+
return ('foo');
|
261
|
+
end test_func;
|
262
|
+
end test_package;
|
263
|
+
SQL
|
264
|
+
#function
|
265
|
+
@conn.execute <<-SQL
|
266
|
+
create or replace function full_drop_test_function
|
267
|
+
return varchar2
|
268
|
+
is
|
269
|
+
foo varchar2(3);
|
270
|
+
begin
|
271
|
+
return('foo');
|
272
|
+
end;
|
273
|
+
SQL
|
274
|
+
#procedure
|
275
|
+
@conn.execute <<-SQL
|
276
|
+
create or replace procedure full_drop_test_procedure
|
277
|
+
begin
|
278
|
+
delete from full_drop_test where id=1231231231
|
279
|
+
exception
|
280
|
+
when no_data_found then
|
281
|
+
dbms_output.put_line('foo');
|
282
|
+
end;
|
283
|
+
SQL
|
284
|
+
#synonym
|
285
|
+
@conn.execute <<-SQL
|
286
|
+
create or replace synonym full_drop_test_synonym for full_drop_test
|
287
|
+
SQL
|
288
|
+
#type
|
289
|
+
@conn.execute <<-SQL
|
290
|
+
create or replace type full_drop_test_type as table of number
|
291
|
+
SQL
|
292
|
+
end
|
293
|
+
after(:each) do
|
294
|
+
@conn.drop_table :full_drop_test
|
295
|
+
@conn.drop_table :full_drop_test_temp
|
296
|
+
@conn.execute "DROP VIEW FULL_DROP_TEST_VIEW" rescue nil
|
297
|
+
@conn.execute "DROP MATERIALIZED VIEW FULL_DROP_TEST_MVIEW" rescue nil
|
298
|
+
@conn.execute "DROP SYNONYM FULL_DROP_TEST_SYNONYM" rescue nil
|
299
|
+
@conn.execute "DROP PACKAGE FULL_DROP_TEST_PACKAGE" rescue nil
|
300
|
+
@conn.execute "DROP FUNCTION FULL_DROP_TEST_FUNCTION" rescue nil
|
301
|
+
@conn.execute "DROP PROCEDURE FULL_DROP_TEST_PROCEDURE" rescue nil
|
302
|
+
@conn.execute "DROP TYPE FULL_DROP_TEST_TYPE" rescue nil
|
303
|
+
end
|
304
|
+
it "should contain correct sql" do
|
305
|
+
drop = @conn.full_drop
|
306
|
+
drop.should =~ /DROP TABLE "FULL_DROP_TEST" CASCADE CONSTRAINTS/
|
307
|
+
drop.should =~ /DROP SEQUENCE "FULL_DROP_TEST_SEQ"/
|
308
|
+
drop.should =~ /DROP VIEW "FULL_DROP_TEST_VIEW"/
|
309
|
+
drop.should_not =~ /DROP TABLE "?FULL_DROP_TEST_MVIEW"?/i
|
310
|
+
drop.should =~ /DROP MATERIALIZED VIEW "FULL_DROP_TEST_MVIEW"/
|
311
|
+
drop.should =~ /DROP PACKAGE "FULL_DROP_TEST_PACKAGE"/
|
312
|
+
drop.should =~ /DROP FUNCTION "FULL_DROP_TEST_FUNCTION"/
|
313
|
+
drop.should =~ /DROP PROCEDURE "FULL_DROP_TEST_PROCEDURE"/
|
314
|
+
drop.should =~ /DROP SYNONYM "FULL_DROP_TEST_SYNONYM"/
|
315
|
+
drop.should =~ /DROP TYPE "FULL_DROP_TEST_TYPE"/
|
316
|
+
end
|
317
|
+
it "should not drop tables when preserve_tables is true" do
|
318
|
+
drop = @conn.full_drop(true)
|
319
|
+
drop.should =~ /DROP TABLE "FULL_DROP_TEST_TEMP"/
|
320
|
+
drop.should_not =~ /DROP TABLE "?FULL_DROP_TEST"? CASCADE CONSTRAINTS/i
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,185 @@
|
|
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
|
+
$KCODE = "UTF8"
|
182
|
+
|
183
|
+
# set default time zone in TZ environment variable
|
184
|
+
# which will be used to set session time zone
|
185
|
+
ENV['TZ'] ||= 'Europe/Riga'
|