oracle_enhanced 1.3.0.pre → 1.3.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/History.txt +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +3 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +223 -154
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +227 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +6 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +2 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +24 -9
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
- data/lib/{oracle_enhanced.rb → active_record/oracle_enhanced.rb} +0 -2
- data/oracle_enhanced.gemspec +7 -4
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +37 -10
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_structure_dumper_spec.rb +27 -20
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +292 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +24 -28
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +13 -11
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +70 -68
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +14 -1
- data/spec/spec_helper.rb +97 -24
- metadata +8 -5
@@ -0,0 +1,292 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter context index" do
|
4
|
+
include SchemaSpecHelper
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
# database user should have CTXAPP role to be able to set CONTEXT index parameters
|
8
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
9
|
+
@conn = ActiveRecord::Base.connection
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "on single table" do
|
13
|
+
before(:all) do
|
14
|
+
@title_words = %w{aaa bbb ccc}
|
15
|
+
@body_words = %w{foo bar baz}
|
16
|
+
|
17
|
+
schema_define do
|
18
|
+
create_table :posts, :force => true do |t|
|
19
|
+
t.string :title
|
20
|
+
t.text :body
|
21
|
+
t.timestamps
|
22
|
+
t.string :all_text, :limit => 1 # will be used for multi-column index
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class ::Post < ActiveRecord::Base
|
26
|
+
has_context_index
|
27
|
+
end
|
28
|
+
@post0 = Post.create(:title => "dummy title", :body => "dummy body")
|
29
|
+
@post1 = Post.create(:title => @title_words.join(' '), :body => @body_words.join(' '))
|
30
|
+
@post2 = Post.create(:title => (@title_words*2).join(' '), :body => (@body_words*2).join(' '))
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:all) do
|
34
|
+
schema_define { drop_table :posts }
|
35
|
+
Object.send(:remove_const, "Post")
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
@post.destroy if @post
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create single VARCHAR2 column index" do
|
43
|
+
@conn.add_context_index :posts, :title
|
44
|
+
@title_words.each do |word|
|
45
|
+
Post.contains(:title, word).all.should == [@post2, @post1]
|
46
|
+
end
|
47
|
+
@conn.remove_context_index :posts, :title
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create single CLOB column index" do
|
51
|
+
@conn.add_context_index :posts, :body
|
52
|
+
@body_words.each do |word|
|
53
|
+
Post.contains(:body, word).all.should == [@post2, @post1]
|
54
|
+
end
|
55
|
+
@conn.remove_context_index :posts, :body
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not include text index secondary tables in user tables list" do
|
59
|
+
@conn.add_context_index :posts, :title
|
60
|
+
@conn.tables.any?{|t| t =~ /^dr\$/i}.should be_false
|
61
|
+
@conn.remove_context_index :posts, :title
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create multiple column index" do
|
65
|
+
@conn.add_context_index :posts, [:title, :body]
|
66
|
+
(@title_words+@body_words).each do |word|
|
67
|
+
Post.contains(:title, word).all.should == [@post2, @post1]
|
68
|
+
end
|
69
|
+
@conn.remove_context_index :posts, [:title, :body]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create multiple column index with specified main index column" do
|
73
|
+
@conn.add_context_index :posts, [:title, :body],
|
74
|
+
:index_column => :all_text, :sync => 'ON COMMIT'
|
75
|
+
@post = Post.create(:title => "abc", :body => "def")
|
76
|
+
Post.contains(:all_text, "abc").all.should == [@post]
|
77
|
+
Post.contains(:all_text, "def").all.should == [@post]
|
78
|
+
@post.update_attributes!(:title => "ghi")
|
79
|
+
# index will not be updated as all_text column is not changed
|
80
|
+
Post.contains(:all_text, "ghi").all.should be_empty
|
81
|
+
@post.update_attributes!(:all_text => "1")
|
82
|
+
# index will be updated when all_text column is changed
|
83
|
+
Post.contains(:all_text, "ghi").all.should == [@post]
|
84
|
+
@conn.remove_context_index :posts, :index_column => :all_text
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create multiple column index with trigger updated main index column" do
|
88
|
+
@conn.add_context_index :posts, [:title, :body],
|
89
|
+
:index_column => :all_text, :index_column_trigger_on => [:created_at, :updated_at],
|
90
|
+
:sync => 'ON COMMIT'
|
91
|
+
@post = Post.create(:title => "abc", :body => "def")
|
92
|
+
Post.contains(:all_text, "abc").all.should == [@post]
|
93
|
+
Post.contains(:all_text, "def").all.should == [@post]
|
94
|
+
@post.update_attributes!(:title => "ghi")
|
95
|
+
# index should be updated as created_at column is changed
|
96
|
+
Post.contains(:all_text, "ghi").all.should == [@post]
|
97
|
+
@conn.remove_context_index :posts, :index_column => :all_text
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "on multiple tables" do
|
103
|
+
before(:all) do
|
104
|
+
schema_define do
|
105
|
+
create_table :posts, :force => true do |t|
|
106
|
+
t.string :title
|
107
|
+
t.text :body
|
108
|
+
t.integer :comments_count
|
109
|
+
t.timestamps
|
110
|
+
t.string :all_text, :limit => 1 # will be used for multi-column index
|
111
|
+
end
|
112
|
+
create_table :comments, :force => true do |t|
|
113
|
+
t.integer :post_id
|
114
|
+
t.string :author
|
115
|
+
t.text :body
|
116
|
+
t.timestamps
|
117
|
+
end
|
118
|
+
end
|
119
|
+
class ::Post < ActiveRecord::Base
|
120
|
+
has_many :comments, :dependent => :destroy
|
121
|
+
has_context_index
|
122
|
+
end
|
123
|
+
class ::Comment < ActiveRecord::Base
|
124
|
+
belongs_to :post, :counter_cache => true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
after(:all) do
|
129
|
+
schema_define { drop_table :comments; drop_table :posts }
|
130
|
+
Object.send(:remove_const, "Comment")
|
131
|
+
Object.send(:remove_const, "Post")
|
132
|
+
end
|
133
|
+
|
134
|
+
after(:each) do
|
135
|
+
Post.destroy_all
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should create multiple table index with specified main index column" do
|
139
|
+
@conn.add_context_index :posts,
|
140
|
+
[:title, :body,
|
141
|
+
# specify aliases always with AS keyword
|
142
|
+
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
143
|
+
],
|
144
|
+
:name => 'post_and_comments_index',
|
145
|
+
:index_column => :all_text, :index_column_trigger_on => [:updated_at, :comments_count],
|
146
|
+
:sync => 'ON COMMIT'
|
147
|
+
@post = Post.create!(:title => "aaa", :body => "bbb")
|
148
|
+
@post.comments.create!(:author => "ccc", :body => "ddd")
|
149
|
+
@post.comments.create!(:author => "eee", :body => "fff")
|
150
|
+
["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
|
151
|
+
Post.contains(:all_text, word).all.should == [@post]
|
152
|
+
end
|
153
|
+
@conn.remove_context_index :posts, :name => 'post_and_comments_index'
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should find by search term within specified field" do
|
157
|
+
@post = Post.create!(:title => "aaa", :body => "bbb")
|
158
|
+
@post.comments.create!(:author => "ccc", :body => "ddd")
|
159
|
+
@conn.add_context_index :posts,
|
160
|
+
[:title, :body,
|
161
|
+
# specify aliases always with AS keyword
|
162
|
+
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
163
|
+
],
|
164
|
+
:index_column => :all_text
|
165
|
+
Post.contains(:all_text, "aaa within title").all.should == [@post]
|
166
|
+
Post.contains(:all_text, "aaa within body").all.should be_empty
|
167
|
+
Post.contains(:all_text, "bbb within body").all.should == [@post]
|
168
|
+
Post.contains(:all_text, "bbb within title").all.should be_empty
|
169
|
+
Post.contains(:all_text, "ccc within comment_author").all.should == [@post]
|
170
|
+
Post.contains(:all_text, "ccc within comment_body").all.should be_empty
|
171
|
+
Post.contains(:all_text, "ddd within comment_body").all.should == [@post]
|
172
|
+
Post.contains(:all_text, "ddd within comment_author").all.should be_empty
|
173
|
+
@conn.remove_context_index :posts, :index_column => :all_text
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "schema dump" do
|
179
|
+
|
180
|
+
def standard_dump
|
181
|
+
stream = StringIO.new
|
182
|
+
ActiveRecord::SchemaDumper.ignore_tables = []
|
183
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
184
|
+
stream.string
|
185
|
+
end
|
186
|
+
|
187
|
+
def create_tables
|
188
|
+
schema_define do
|
189
|
+
create_table :posts, :force => true do |t|
|
190
|
+
t.string :title
|
191
|
+
t.text :body
|
192
|
+
t.integer :comments_count
|
193
|
+
t.timestamps
|
194
|
+
t.string :all_text, :limit => 1 # will be used for multi-column index
|
195
|
+
end
|
196
|
+
create_table :comments, :force => true do |t|
|
197
|
+
t.integer :post_id
|
198
|
+
t.string :author
|
199
|
+
t.text :body
|
200
|
+
t.timestamps
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def drop_tables
|
206
|
+
schema_define { drop_table :comments; drop_table :posts }
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "without table prefixe and suffix" do
|
210
|
+
|
211
|
+
before(:all) do
|
212
|
+
create_tables
|
213
|
+
end
|
214
|
+
|
215
|
+
after(:all) do
|
216
|
+
drop_tables
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should dump definition of single column index" do
|
220
|
+
@conn.add_context_index :posts, :title
|
221
|
+
standard_dump.should =~ /add_context_index "posts", \["title"\], :name => \"index_posts_on_title\"$/
|
222
|
+
@conn.remove_context_index :posts, :title
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should dump definition of multiple column index" do
|
226
|
+
@conn.add_context_index :posts, [:title, :body]
|
227
|
+
standard_dump.should =~ /add_context_index "posts", \[:title, :body\]$/
|
228
|
+
@conn.remove_context_index :posts, [:title, :body]
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should dump definition of multiple table index with options" do
|
232
|
+
options = {
|
233
|
+
:name => 'post_and_comments_index',
|
234
|
+
:index_column => :all_text, :index_column_trigger_on => :updated_at,
|
235
|
+
:sync => 'ON COMMIT'
|
236
|
+
}
|
237
|
+
@conn.add_context_index :posts,
|
238
|
+
[:title, :body,
|
239
|
+
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
240
|
+
], options
|
241
|
+
standard_dump.should =~ /add_context_index "posts", \[:title, :body, "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"\], #{options.inspect[1..-2]}$/
|
242
|
+
@conn.remove_context_index :posts, :name => 'post_and_comments_index'
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
describe "with table prefix and suffix" do
|
248
|
+
before(:all) do
|
249
|
+
ActiveRecord::Base.table_name_prefix = 'xxx_'
|
250
|
+
ActiveRecord::Base.table_name_suffix = '_xxx'
|
251
|
+
create_tables
|
252
|
+
end
|
253
|
+
|
254
|
+
after(:all) do
|
255
|
+
drop_tables
|
256
|
+
ActiveRecord::Base.table_name_prefix = ''
|
257
|
+
ActiveRecord::Base.table_name_suffix = ''
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should dump definition of single column index" do
|
261
|
+
schema_define { add_context_index :posts, :title }
|
262
|
+
standard_dump.should =~ /add_context_index "posts", \["title"\], :name => "i_xxx_posts_xxx_title"$/
|
263
|
+
schema_define { remove_context_index :posts, :title }
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should dump definition of multiple column index" do
|
267
|
+
schema_define { add_context_index :posts, [:title, :body] }
|
268
|
+
standard_dump.should =~ /add_context_index "posts", \[:title, :body\]$/
|
269
|
+
schema_define { remove_context_index :posts, [:title, :body] }
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should dump definition of multiple table index with options" do
|
273
|
+
options = {
|
274
|
+
:name => 'xxx_post_and_comments_i',
|
275
|
+
:index_column => :all_text, :index_column_trigger_on => :updated_at,
|
276
|
+
:sync => 'ON COMMIT'
|
277
|
+
}
|
278
|
+
schema_define do
|
279
|
+
add_context_index :posts,
|
280
|
+
[:title, :body,
|
281
|
+
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
282
|
+
], options
|
283
|
+
end
|
284
|
+
standard_dump.should =~ /add_context_index "posts", \[:title, :body, "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"\], #{options.inspect[1..-2]}$/
|
285
|
+
schema_define { remove_context_index :posts, :name => 'xxx_post_and_comments_i' }
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
@@ -6,7 +6,7 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
6
6
|
@conn = ActiveRecord::Base.connection
|
7
7
|
@conn.execute <<-SQL
|
8
8
|
CREATE TABLE test_employees (
|
9
|
-
employee_id NUMBER(6,0),
|
9
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
10
10
|
first_name VARCHAR2(20),
|
11
11
|
last_name VARCHAR2(25),
|
12
12
|
email VARCHAR2(25),
|
@@ -192,7 +192,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
192
192
|
@conn = ActiveRecord::Base.connection
|
193
193
|
@conn.execute <<-SQL
|
194
194
|
CREATE TABLE test2_employees (
|
195
|
-
id
|
195
|
+
id NUMBER PRIMARY KEY,
|
196
196
|
first_name VARCHAR2(20),
|
197
197
|
last_name VARCHAR2(25),
|
198
198
|
email VARCHAR2(25),
|
@@ -338,7 +338,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
338
338
|
@conn = ActiveRecord::Base.connection
|
339
339
|
@conn.execute <<-SQL
|
340
340
|
CREATE TABLE test3_employees (
|
341
|
-
id NUMBER,
|
341
|
+
id NUMBER PRIMARY KEY,
|
342
342
|
first_name VARCHAR2(20),
|
343
343
|
last_name VARCHAR2(25),
|
344
344
|
email VARCHAR2(25),
|
@@ -521,7 +521,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
521
521
|
@conn = ActiveRecord::Base.connection
|
522
522
|
@conn.execute <<-SQL
|
523
523
|
CREATE TABLE test_employees (
|
524
|
-
employee_id NUMBER(6,0),
|
524
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
525
525
|
first_name VARCHAR2(20),
|
526
526
|
last_name VARCHAR2(25),
|
527
527
|
email VARCHAR2(25),
|
@@ -604,7 +604,7 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
604
604
|
@conn = ActiveRecord::Base.connection
|
605
605
|
@conn.execute <<-SQL
|
606
606
|
CREATE TABLE test_employees (
|
607
|
-
employee_id NUMBER(6,0),
|
607
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
608
608
|
first_name VARCHAR2(20),
|
609
609
|
last_name VARCHAR2(25),
|
610
610
|
email VARCHAR2(25),
|
@@ -709,7 +709,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
709
709
|
@conn = ActiveRecord::Base.connection
|
710
710
|
@conn.execute <<-SQL
|
711
711
|
CREATE TABLE test_employees (
|
712
|
-
employee_id NUMBER(6,0),
|
712
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
713
713
|
first_name VARCHAR2(20),
|
714
714
|
last_name VARCHAR2(25),
|
715
715
|
hire_date DATE,
|
@@ -750,6 +750,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
750
750
|
:last_name => "Last",
|
751
751
|
:hire_date => @today_iso
|
752
752
|
)
|
753
|
+
@employee.hire_date.should == @today
|
753
754
|
@employee.reload
|
754
755
|
@employee.hire_date.should == @today
|
755
756
|
end
|
@@ -761,6 +762,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
761
762
|
:last_name => "Last",
|
762
763
|
:hire_date => @today_nls
|
763
764
|
)
|
765
|
+
@employee.hire_date.should == @today
|
764
766
|
@employee.reload
|
765
767
|
@employee.hire_date.should == @today
|
766
768
|
end
|
@@ -771,6 +773,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
771
773
|
:last_name => "Last",
|
772
774
|
:hire_date => @now_iso
|
773
775
|
)
|
776
|
+
@employee.hire_date.should == @today
|
774
777
|
@employee.reload
|
775
778
|
@employee.hire_date.should == @today
|
776
779
|
end
|
@@ -783,6 +786,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
783
786
|
:last_name => "Last",
|
784
787
|
:hire_date => @now_nls
|
785
788
|
)
|
789
|
+
@employee.hire_date.should == @today
|
786
790
|
@employee.reload
|
787
791
|
@employee.hire_date.should == @today
|
788
792
|
end
|
@@ -793,6 +797,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
793
797
|
:last_name => "Last",
|
794
798
|
:last_login_at => @now_iso
|
795
799
|
)
|
800
|
+
@employee.last_login_at.should == @now
|
796
801
|
@employee.reload
|
797
802
|
@employee.last_login_at.should == @now
|
798
803
|
end
|
@@ -805,6 +810,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
805
810
|
:last_name => "Last",
|
806
811
|
:last_login_at => @now_nls
|
807
812
|
)
|
813
|
+
@employee.last_login_at.should == @now
|
808
814
|
@employee.reload
|
809
815
|
@employee.last_login_at.should == @now
|
810
816
|
end
|
@@ -815,6 +821,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
815
821
|
:last_name => "Last",
|
816
822
|
:last_login_at => @today_iso
|
817
823
|
)
|
824
|
+
@employee.last_login_at.should == @today.to_time
|
818
825
|
@employee.reload
|
819
826
|
@employee.last_login_at.should == @today.to_time
|
820
827
|
end
|
@@ -827,6 +834,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
827
834
|
:last_name => "Last",
|
828
835
|
:last_login_at => @today_nls
|
829
836
|
)
|
837
|
+
@employee.last_login_at.should == @today.to_time
|
830
838
|
@employee.reload
|
831
839
|
@employee.last_login_at.should == @today.to_time
|
832
840
|
end
|
@@ -839,7 +847,7 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
839
847
|
@conn = ActiveRecord::Base.connection
|
840
848
|
@conn.execute <<-SQL
|
841
849
|
CREATE TABLE test_employees (
|
842
|
-
employee_id NUMBER(6,0),
|
850
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
843
851
|
first_name VARCHAR2(20),
|
844
852
|
last_name VARCHAR2(25),
|
845
853
|
comments CLOB
|
@@ -849,20 +857,23 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
849
857
|
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
850
858
|
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
851
859
|
SQL
|
852
|
-
class ::TestEmployee < ActiveRecord::Base
|
853
|
-
set_primary_key :employee_id
|
854
|
-
end
|
855
860
|
end
|
856
861
|
|
857
862
|
after(:all) do
|
858
|
-
Object.send(:remove_const, "TestEmployee")
|
859
863
|
@conn.execute "DROP TABLE test_employees"
|
860
864
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
861
865
|
end
|
862
866
|
|
863
867
|
before(:each) do
|
868
|
+
class ::TestEmployee < ActiveRecord::Base
|
869
|
+
set_primary_key :employee_id
|
870
|
+
end
|
864
871
|
end
|
865
|
-
|
872
|
+
|
873
|
+
after(:each) do
|
874
|
+
Object.send(:remove_const, "TestEmployee")
|
875
|
+
end
|
876
|
+
|
866
877
|
it "should create record without CLOB data when attribute is serialized" do
|
867
878
|
TestEmployee.serialize :comments
|
868
879
|
@employee = TestEmployee.create!(
|
@@ -870,21 +881,6 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
870
881
|
:last_name => "Last"
|
871
882
|
)
|
872
883
|
@employee.should be_valid
|
873
|
-
TestEmployee.serialized_attributes.delete('comments')
|
874
|
-
end
|
875
|
-
|
876
|
-
it "should order by CLOB column" do
|
877
|
-
@employee = TestEmployee.create!(
|
878
|
-
:first_name => "First",
|
879
|
-
:last_name => "Last",
|
880
|
-
:comments => "comments"
|
881
|
-
)
|
882
|
-
TestEmployee.find(:all, :order => "comments ASC").should_not be_empty
|
883
|
-
TestEmployee.find(:all, :order => " comments ASC ").should_not be_empty
|
884
|
-
TestEmployee.find(:all, :order => "comments").should_not be_empty
|
885
|
-
TestEmployee.find(:all, :order => " comments ").should_not be_empty
|
886
|
-
TestEmployee.find(:all, :order => :comments).should_not be_empty
|
887
|
-
TestEmployee.find(:all, :order => " first_name DESC, last_name ASC ").should_not be_empty
|
888
884
|
end
|
889
885
|
|
890
886
|
it "should accept Symbol value for CLOB column" do
|
@@ -902,7 +898,7 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
902
898
|
@conn = ActiveRecord::Base.connection
|
903
899
|
@conn.execute <<-SQL
|
904
900
|
CREATE TABLE test_employees (
|
905
|
-
employee_id NUMBER(6,0),
|
901
|
+
employee_id NUMBER(6,0) PRIMARY KEY,
|
906
902
|
first_name VARCHAR2(20),
|
907
903
|
last_name VARCHAR2(25),
|
908
904
|
binary_data BLOB
|
@@ -4,7 +4,6 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
|
|
4
4
|
include LoggerSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
@buffer = StringIO.new
|
8
7
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
9
8
|
ActiveRecord::Base.connection.execute <<-SQL
|
10
9
|
CREATE or REPLACE
|
@@ -31,18 +30,21 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
|
|
31
30
|
end
|
32
31
|
|
33
32
|
before(:each) do
|
34
|
-
|
35
|
-
log_to @buffer
|
33
|
+
set_logger
|
36
34
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
37
35
|
@conn = ActiveRecord::Base.connection
|
38
36
|
end
|
39
37
|
|
38
|
+
after(:each) do
|
39
|
+
clear_logger
|
40
|
+
end
|
41
|
+
|
40
42
|
it "should NOT log dbms output when dbms output is disabled" do
|
41
43
|
@conn.disable_dbms_output
|
42
44
|
|
43
45
|
@conn.select_all("select more_than_five_characters_long('hi there') is_it_long from dual").should == [{'is_it_long'=>1}]
|
44
|
-
|
45
|
-
@
|
46
|
+
|
47
|
+
@logger.output(:debug).should_not match(/^DBMS_OUTPUT/)
|
46
48
|
end
|
47
49
|
|
48
50
|
it "should log dbms output lines to the rails log" do
|
@@ -50,9 +52,9 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
|
|
50
52
|
|
51
53
|
@conn.select_all("select more_than_five_characters_long('hi there') is_it_long from dual").should == [{'is_it_long'=>1}]
|
52
54
|
|
53
|
-
@
|
54
|
-
@
|
55
|
-
@
|
55
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: before the if -hi there-$/)
|
56
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: it is longer than 5$/)
|
57
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: about to return: 1$/)
|
56
58
|
end
|
57
59
|
|
58
60
|
it "should log dbms output lines to the rails log" do
|
@@ -60,8 +62,8 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
|
|
60
62
|
|
61
63
|
@conn.select_all("select more_than_five_characters_long('short') is_it_long from dual").should == [{'is_it_long'=>0}]
|
62
64
|
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
65
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: before the if -short-$/)
|
66
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: it is 5 or shorter$/)
|
67
|
+
@logger.output(:debug).should match(/^DBMS_OUTPUT: about to return: 0$/)
|
66
68
|
end
|
67
69
|
end
|
@@ -9,7 +9,7 @@ if ActiveRecord::Base.instance_methods.include?('changed?')
|
|
9
9
|
@conn = ActiveRecord::Base.connection
|
10
10
|
@conn.execute <<-SQL
|
11
11
|
CREATE TABLE test_employees (
|
12
|
-
id NUMBER,
|
12
|
+
id NUMBER PRIMARY KEY,
|
13
13
|
first_name VARCHAR2(20),
|
14
14
|
last_name VARCHAR2(25),
|
15
15
|
job_id NUMBER(6,0) NULL,
|