activerecord-oracle_enhanced-adapter 1.4.3 → 5.2.0

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.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +1162 -2
  3. data/README.md +567 -155
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +3 -1
  6. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +19 -0
  7. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +132 -0
  8. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +345 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +280 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +64 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +538 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +435 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +196 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +164 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +79 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +194 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +709 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +28 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +353 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +385 -1083
  29. data/lib/active_record/type/oracle_enhanced/boolean.rb +20 -0
  30. data/lib/active_record/type/oracle_enhanced/integer.rb +15 -0
  31. data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
  32. data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
  33. data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
  34. data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
  35. data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
  36. data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
  37. data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
  38. data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
  39. data/lib/activerecord-oracle_enhanced-adapter.rb +5 -13
  40. data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +5 -4
  41. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +469 -0
  42. data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +140 -128
  43. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +112 -0
  44. data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +13 -13
  45. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +365 -0
  46. data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
  47. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
  48. data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1433 -0
  49. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +478 -0
  50. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +385 -550
  51. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +92 -1249
  52. data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
  53. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +208 -0
  54. data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +139 -0
  55. data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
  56. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
  57. data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
  58. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
  59. data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
  60. data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
  61. data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
  62. data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
  63. data/spec/spec_config.yaml.template +11 -0
  64. data/spec/spec_helper.rb +100 -93
  65. data/spec/support/alter_system_set_open_cursors.sql +1 -0
  66. data/spec/support/alter_system_user_password.sql +2 -0
  67. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  68. metadata +105 -152
  69. data/.rspec +0 -2
  70. data/Gemfile +0 -52
  71. data/RUNNING_TESTS.md +0 -45
  72. data/Rakefile +0 -59
  73. data/activerecord-oracle_enhanced-adapter.gemspec +0 -130
  74. data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
  75. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
  76. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
  77. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +0 -151
  78. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -119
  79. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -359
  80. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
  81. data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +0 -21
  82. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -46
  83. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +0 -572
  84. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +0 -497
  85. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +0 -260
  86. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -227
  87. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +0 -260
  88. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -428
  89. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  90. data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +0 -294
  91. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
  92. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
  93. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +0 -334
  94. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
  95. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
  96. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +0 -141
  97. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +0 -378
  98. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +0 -440
  99. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +0 -1400
  100. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +0 -339
@@ -1,29 +1,29 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
3
2
 
4
3
  describe "OracleEnhancedAdapter context index" do
5
4
  include SchemaSpecHelper
6
5
  include LoggerSpecHelper
6
+ include SchemaDumpingHelper
7
7
 
8
8
  def create_table_posts
9
9
  schema_define do
10
- create_table :posts, :force => true do |t|
10
+ create_table :posts, force: true do |t|
11
11
  t.string :title
12
12
  t.text :body
13
13
  t.integer :comments_count
14
- t.timestamps
15
- t.string :all_text, :limit => 2 # will be used for multi-column index
14
+ t.timestamps null: true
15
+ t.string :all_text, limit: 2 # will be used for multi-column index
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
20
  def create_table_comments
21
21
  schema_define do
22
- create_table :comments, :force => true do |t|
22
+ create_table :comments, force: true do |t|
23
23
  t.integer :post_id
24
24
  t.string :author
25
25
  t.text :body
26
- t.timestamps
26
+ t.timestamps null: true
27
27
  end
28
28
  end
29
29
  end
@@ -68,17 +68,21 @@ describe "OracleEnhancedAdapter context index" do
68
68
  class ::Post < ActiveRecord::Base
69
69
  has_context_index
70
70
  end
71
- @post0 = Post.create(:title => "dummy title", :body => "dummy body")
72
- @post1 = Post.create(:title => @title_words.join(' '), :body => @body_words.join(' '))
73
- @post2 = Post.create(:title => (@title_words*2).join(' '), :body => (@body_words*2).join(' '))
74
- @post_with_null_body = Post.create(:title => "withnull", :body => nil)
75
- @post_with_null_title = Post.create(:title => nil, :body => "withnull")
71
+ @post0 = Post.create(title: "dummy title", body: "dummy body")
72
+ @post1 = Post.create(title: @title_words.join(" "), body: @body_words.join(" "))
73
+ @post2 = Post.create(title: (@title_words * 2).join(" "), body: (@body_words * 2).join(" "))
74
+ @post_with_null_body = Post.create(title: "withnull", body: nil)
75
+ @post_with_null_title = Post.create(title: nil, body: "withnull")
76
76
  end
77
77
 
78
78
  after(:all) do
79
79
  drop_table_posts
80
80
  Object.send(:remove_const, "Post")
81
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
81
+ ActiveRecord::Base.clear_cache!
82
+ end
83
+
84
+ before(:each) do
85
+ @post = nil
82
86
  end
83
87
 
84
88
  after(:each) do
@@ -88,7 +92,7 @@ describe "OracleEnhancedAdapter context index" do
88
92
  it "should create single VARCHAR2 column index" do
89
93
  @conn.add_context_index :posts, :title
90
94
  @title_words.each do |word|
91
- Post.contains(:title, word).all.should == [@post2, @post1]
95
+ expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
92
96
  end
93
97
  @conn.remove_context_index :posts, :title
94
98
  end
@@ -96,76 +100,84 @@ describe "OracleEnhancedAdapter context index" do
96
100
  it "should create single CLOB column index" do
97
101
  @conn.add_context_index :posts, :body
98
102
  @body_words.each do |word|
99
- Post.contains(:body, word).all.should == [@post2, @post1]
103
+ expect(Post.contains(:body, word).to_a).to eq([@post2, @post1])
100
104
  end
101
105
  @conn.remove_context_index :posts, :body
102
106
  end
103
107
 
104
108
  it "should not include text index secondary tables in user tables list" do
105
109
  @conn.add_context_index :posts, :title
106
- @conn.tables.any?{|t| t =~ /^dr\$/i}.should be_false
110
+ expect(@conn.tables.any? { |t| t =~ /^dr\$/i }).to be_falsey
107
111
  @conn.remove_context_index :posts, :title
108
112
  end
109
113
 
110
114
  it "should create multiple column index" do
111
115
  @conn.add_context_index :posts, [:title, :body]
112
- (@title_words+@body_words).each do |word|
113
- Post.contains(:title, word).all.should == [@post2, @post1]
116
+ (@title_words + @body_words).each do |word|
117
+ expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
114
118
  end
115
119
  @conn.remove_context_index :posts, [:title, :body]
116
120
  end
117
121
 
118
122
  it "should index records with null values" do
119
123
  @conn.add_context_index :posts, [:title, :body]
120
- Post.contains(:title, "withnull").all.should == [@post_with_null_body, @post_with_null_title]
124
+ expect(Post.contains(:title, "withnull").to_a).to eq([@post_with_null_body, @post_with_null_title])
121
125
  @conn.remove_context_index :posts, [:title, :body]
122
126
  end
123
127
 
124
128
  it "should create multiple column index with specified main index column" do
125
129
  @conn.add_context_index :posts, [:title, :body],
126
- :index_column => :all_text, :sync => 'ON COMMIT'
127
- @post = Post.create(:title => "abc", :body => "def")
128
- Post.contains(:all_text, "abc").all.should == [@post]
129
- Post.contains(:all_text, "def").all.should == [@post]
130
- @post.update_attributes!(:title => "ghi")
130
+ index_column: :all_text, sync: "ON COMMIT"
131
+ @post = Post.create(title: "abc", body: "def")
132
+ expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
133
+ expect(Post.contains(:all_text, "def").to_a).to eq([@post])
134
+ @post.update_attributes!(title: "ghi")
131
135
  # index will not be updated as all_text column is not changed
132
- Post.contains(:all_text, "ghi").all.should be_empty
133
- @post.update_attributes!(:all_text => "1")
136
+ expect(Post.contains(:all_text, "ghi").to_a).to be_empty
137
+ @post.update_attributes!(all_text: "1")
134
138
  # index will be updated when all_text column is changed
135
- Post.contains(:all_text, "ghi").all.should == [@post]
136
- @conn.remove_context_index :posts, :index_column => :all_text
139
+ expect(Post.contains(:all_text, "ghi").to_a).to eq([@post])
140
+ @conn.remove_context_index :posts, index_column: :all_text
137
141
  end
138
142
 
139
143
  it "should create multiple column index with trigger updated main index column" do
140
144
  @conn.add_context_index :posts, [:title, :body],
141
- :index_column => :all_text, :index_column_trigger_on => [:created_at, :updated_at],
142
- :sync => 'ON COMMIT'
143
- @post = Post.create(:title => "abc", :body => "def")
144
- Post.contains(:all_text, "abc").all.should == [@post]
145
- Post.contains(:all_text, "def").all.should == [@post]
146
- @post.update_attributes!(:title => "ghi")
145
+ index_column: :all_text, index_column_trigger_on: [:created_at, :updated_at],
146
+ sync: "ON COMMIT"
147
+ @post = Post.create(title: "abc", body: "def")
148
+ expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
149
+ expect(Post.contains(:all_text, "def").to_a).to eq([@post])
150
+ @post.update_attributes!(title: "ghi")
147
151
  # index should be updated as created_at column is changed
148
- Post.contains(:all_text, "ghi").all.should == [@post]
149
- @conn.remove_context_index :posts, :index_column => :all_text
152
+ expect(Post.contains(:all_text, "ghi").to_a).to eq([@post])
153
+ @conn.remove_context_index :posts, index_column: :all_text
150
154
  end
151
155
 
152
156
  it "should use base letter conversion with BASIC_LEXER" do
153
- @post = Post.create!(:title => "āčē", :body => "dummy")
157
+ @post = Post.create!(title: "āčē", body: "dummy")
154
158
  @conn.add_context_index :posts, :title,
155
- :lexer => { :type => "BASIC_LEXER", :base_letter_type => 'GENERIC', :base_letter => true }
156
- Post.contains(:title, "āčē").all.should == [@post]
157
- Post.contains(:title, "ace").all.should == [@post]
158
- Post.contains(:title, "ACE").all.should == [@post]
159
+ lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true }
160
+ expect(Post.contains(:title, "āčē").to_a).to eq([@post])
161
+ expect(Post.contains(:title, "ace").to_a).to eq([@post])
162
+ expect(Post.contains(:title, "ACE").to_a).to eq([@post])
159
163
  @conn.remove_context_index :posts, :title
160
164
  end
161
165
 
162
166
  it "should create transactional index and sync index within transaction on inserts and updates" do
163
- @conn.add_context_index :posts, :title, :transactional => true
167
+ @conn.add_context_index :posts, :title, transactional: true
164
168
  Post.transaction do
165
- @post = Post.create(:title => "abc")
166
- Post.contains(:title, "abc").all.should == [@post]
167
- @post.update_attributes!(:title => "ghi")
168
- Post.contains(:title, "ghi").all.should == [@post]
169
+ @post = Post.create(title: "abc")
170
+ expect(Post.contains(:title, "abc").to_a).to eq([@post])
171
+ @post.update_attributes!(title: "ghi")
172
+ expect(Post.contains(:title, "ghi").to_a).to eq([@post])
173
+ end
174
+ @conn.remove_context_index :posts, :title
175
+ end
176
+
177
+ it "should use index when contains has schema_name.table_name syntax" do
178
+ @conn.add_context_index :posts, :title
179
+ @title_words.each do |word|
180
+ expect(Post.contains("posts.title", word).to_a).to eq([@post2, @post1])
169
181
  end
170
182
  @conn.remove_context_index :posts, :title
171
183
  end
@@ -176,11 +188,11 @@ describe "OracleEnhancedAdapter context index" do
176
188
  @conn = ActiveRecord::Base.connection
177
189
  create_tables
178
190
  class ::Post < ActiveRecord::Base
179
- has_many :comments, :dependent => :destroy
191
+ has_many :comments, dependent: :destroy
180
192
  has_context_index
181
193
  end
182
194
  class ::Comment < ActiveRecord::Base
183
- belongs_to :post, :counter_cache => true
195
+ belongs_to :post, counter_cache: true
184
196
  end
185
197
  end
186
198
 
@@ -188,10 +200,12 @@ describe "OracleEnhancedAdapter context index" do
188
200
  drop_tables
189
201
  Object.send(:remove_const, "Comment")
190
202
  Object.send(:remove_const, "Post")
191
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
203
+ ActiveRecord::Base.clear_cache!
192
204
  end
193
205
 
194
206
  after(:each) do
207
+ @conn.remove_context_index :posts, name: "post_and_comments_index" rescue nil
208
+ @conn.remove_context_index :posts, index_column: :all_text rescue nil
195
209
  Post.destroy_all
196
210
  end
197
211
 
@@ -201,16 +215,15 @@ describe "OracleEnhancedAdapter context index" do
201
215
  # specify aliases always with AS keyword
202
216
  "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
203
217
  ],
204
- :name => 'post_and_comments_index',
205
- :index_column => :all_text, :index_column_trigger_on => [:updated_at, :comments_count],
206
- :sync => 'ON COMMIT'
207
- @post = Post.create!(:title => "aaa", :body => "bbb")
208
- @post.comments.create!(:author => "ccc", :body => "ddd")
209
- @post.comments.create!(:author => "eee", :body => "fff")
218
+ name: "post_and_comments_index",
219
+ index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
220
+ sync: "ON COMMIT"
221
+ @post = Post.create!(title: "aaa", body: "bbb")
222
+ @post.comments.create!(author: "ccc", body: "ddd")
223
+ @post.comments.create!(author: "eee", body: "fff")
210
224
  ["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
211
- Post.contains(:all_text, word).all.should == [@post]
225
+ expect(Post.contains(:all_text, word).to_a).to eq([@post])
212
226
  end
213
- @conn.remove_context_index :posts, :name => 'post_and_comments_index'
214
227
  end
215
228
 
216
229
  it "should create multiple table index with specified main index column (when subquery has newlines)" do
@@ -223,36 +236,34 @@ describe "OracleEnhancedAdapter context index" do
223
236
  FROM comments
224
237
  WHERE comments.post_id = :id }
225
238
  ],
226
- :name => 'post_and_comments_index',
227
- :index_column => :all_text, :index_column_trigger_on => [:updated_at, :comments_count],
228
- :sync => 'ON COMMIT'
229
- @post = Post.create!(:title => "aaa", :body => "bbb")
230
- @post.comments.create!(:author => "ccc", :body => "ddd")
231
- @post.comments.create!(:author => "eee", :body => "fff")
239
+ name: "post_and_comments_index",
240
+ index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
241
+ sync: "ON COMMIT"
242
+ @post = Post.create!(title: "aaa", body: "bbb")
243
+ @post.comments.create!(author: "ccc", body: "ddd")
244
+ @post.comments.create!(author: "eee", body: "fff")
232
245
  ["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
233
- Post.contains(:all_text, word).all.should == [@post]
246
+ expect(Post.contains(:all_text, word).to_a).to eq([@post])
234
247
  end
235
- @conn.remove_context_index :posts, :name => 'post_and_comments_index'
236
248
  end
237
249
 
238
250
  it "should find by search term within specified field" do
239
- @post = Post.create!(:title => "aaa", :body => "bbb")
240
- @post.comments.create!(:author => "ccc", :body => "ddd")
251
+ @post = Post.create!(title: "aaa", body: "bbb")
252
+ @post.comments.create!(author: "ccc", body: "ddd")
241
253
  @conn.add_context_index :posts,
242
254
  [:title, :body,
243
255
  # specify aliases always with AS keyword
244
256
  "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
245
257
  ],
246
- :index_column => :all_text
247
- Post.contains(:all_text, "aaa within title").all.should == [@post]
248
- Post.contains(:all_text, "aaa within body").all.should be_empty
249
- Post.contains(:all_text, "bbb within body").all.should == [@post]
250
- Post.contains(:all_text, "bbb within title").all.should be_empty
251
- Post.contains(:all_text, "ccc within comment_author").all.should == [@post]
252
- Post.contains(:all_text, "ccc within comment_body").all.should be_empty
253
- Post.contains(:all_text, "ddd within comment_body").all.should == [@post]
254
- Post.contains(:all_text, "ddd within comment_author").all.should be_empty
255
- @conn.remove_context_index :posts, :index_column => :all_text
258
+ index_column: :all_text
259
+ expect(Post.contains(:all_text, "aaa within title").to_a).to eq([@post])
260
+ expect(Post.contains(:all_text, "aaa within body").to_a).to be_empty
261
+ expect(Post.contains(:all_text, "bbb within body").to_a).to eq([@post])
262
+ expect(Post.contains(:all_text, "bbb within title").to_a).to be_empty
263
+ expect(Post.contains(:all_text, "ccc within comment_author").to_a).to eq([@post])
264
+ expect(Post.contains(:all_text, "ccc within comment_body").to_a).to be_empty
265
+ expect(Post.contains(:all_text, "ddd within comment_body").to_a).to eq([@post])
266
+ expect(Post.contains(:all_text, "ddd within comment_author").to_a).to be_empty
256
267
  end
257
268
 
258
269
  end
@@ -264,7 +275,7 @@ describe "OracleEnhancedAdapter context index" do
264
275
  class ::Post < ActiveRecord::Base
265
276
  has_context_index
266
277
  end
267
- @post = Post.create(:title => 'aaa', :body => 'bbb')
278
+ @post = Post.create(title: "aaa", body: "bbb")
268
279
  @tablespace = @conn.default_tablespace
269
280
  set_logger
270
281
  @conn = ActiveRecord::Base.connection
@@ -273,7 +284,7 @@ describe "OracleEnhancedAdapter context index" do
273
284
  after(:all) do
274
285
  drop_table_posts
275
286
  Object.send(:remove_const, "Post")
276
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
287
+ ActiveRecord::Base.clear_cache!
277
288
  end
278
289
 
279
290
  after(:each) do
@@ -281,37 +292,30 @@ describe "OracleEnhancedAdapter context index" do
281
292
  end
282
293
 
283
294
  def verify_logged_statements
284
- ['K_TABLE_CLAUSE', 'R_TABLE_CLAUSE', 'N_TABLE_CLAUSE', 'I_INDEX_CLAUSE', 'P_TABLE_CLAUSE'].each do |clause|
285
- @logger.output(:debug).should =~ /CTX_DDL\.SET_ATTRIBUTE\('index_posts_on_title_sto', '#{clause}', '.*TABLESPACE #{@tablespace}'\)/
295
+ ["K_TABLE_CLAUSE", "R_TABLE_CLAUSE", "N_TABLE_CLAUSE", "I_INDEX_CLAUSE", "P_TABLE_CLAUSE"].each do |clause|
296
+ expect(@logger.output(:debug)).to match(/CTX_DDL\.SET_ATTRIBUTE\('index_posts_on_title_sto', '#{clause}', '.*TABLESPACE #{@tablespace}'\)/)
286
297
  end
287
- @logger.output(:debug).should =~ /CREATE INDEX .* PARAMETERS \('STORAGE index_posts_on_title_sto'\)/
298
+ expect(@logger.output(:debug)).to match(/CREATE INDEX .* PARAMETERS \('STORAGE index_posts_on_title_sto'\)/)
288
299
  end
289
300
 
290
301
  it "should create index on single column" do
291
- @conn.add_context_index :posts, :title, :tablespace => @tablespace
302
+ @conn.add_context_index :posts, :title, tablespace: @tablespace
292
303
  verify_logged_statements
293
- Post.contains(:title, 'aaa').all.should == [@post]
304
+ expect(Post.contains(:title, "aaa").to_a).to eq([@post])
294
305
  @conn.remove_context_index :posts, :title
295
306
  end
296
307
 
297
308
  it "should create index on multiple columns" do
298
- @conn.add_context_index :posts, [:title, :body], :name => 'index_posts_text', :tablespace => @conn.default_tablespace
309
+ @conn.add_context_index :posts, [:title, :body], name: "index_posts_text", tablespace: @conn.default_tablespace
299
310
  verify_logged_statements
300
- Post.contains(:title, 'aaa AND bbb').all.should == [@post]
301
- @conn.remove_context_index :posts, :name => 'index_posts_text'
311
+ expect(Post.contains(:title, "aaa AND bbb").to_a).to eq([@post])
312
+ @conn.remove_context_index :posts, name: "index_posts_text"
302
313
  end
303
314
 
304
315
  end
305
316
 
306
317
  describe "schema dump" do
307
318
 
308
- def standard_dump
309
- stream = StringIO.new
310
- ActiveRecord::SchemaDumper.ignore_tables = []
311
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
312
- stream.string
313
- end
314
-
315
319
  describe "without table prefixe and suffix" do
316
320
 
317
321
  before(:all) do
@@ -325,89 +329,96 @@ describe "OracleEnhancedAdapter context index" do
325
329
 
326
330
  it "should dump definition of single column index" do
327
331
  @conn.add_context_index :posts, :title
328
- standard_dump.should =~ /add_context_index "posts", \["title"\], :name => \"index_posts_on_title\"$/
332
+ output = dump_table_schema "posts"
333
+ expect(output).to match(/add_context_index "posts", \["title"\], name: \"index_posts_on_title\"$/)
329
334
  @conn.remove_context_index :posts, :title
330
335
  end
331
336
 
332
337
  it "should dump definition of multiple column index" do
333
338
  @conn.add_context_index :posts, [:title, :body]
334
- standard_dump.should =~ /add_context_index "posts", \[:title, :body\]$/
339
+ output = dump_table_schema "posts"
340
+ expect(output).to match(/add_context_index "posts", \[:title, :body\]$/)
335
341
  @conn.remove_context_index :posts, [:title, :body]
336
342
  end
337
343
 
338
344
  it "should dump definition of multiple table index with options" do
339
345
  options = {
340
- :name => 'post_and_comments_index',
341
- :index_column => :all_text, :index_column_trigger_on => :updated_at,
342
- :transactional => true,
343
- :sync => 'ON COMMIT'
346
+ name: "post_and_comments_index",
347
+ index_column: :all_text, index_column_trigger_on: :updated_at,
348
+ transactional: true,
349
+ sync: "ON COMMIT"
344
350
  }
345
351
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
346
352
  @conn.add_context_index :posts, [:title, :body, sub_query], options
347
- standard_dump.should =~ /add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/
348
- @conn.remove_context_index :posts, :name => 'post_and_comments_index'
353
+ output = dump_table_schema "posts"
354
+ expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
355
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
349
356
  end
350
357
 
351
358
  it "should dump definition of multiple table index with options (when definition is larger than 4000 bytes)" do
352
359
  options = {
353
- :name => 'post_and_comments_index',
354
- :index_column => :all_text, :index_column_trigger_on => :updated_at,
355
- :transactional => true,
356
- :sync => 'ON COMMIT'
360
+ name: "post_and_comments_index",
361
+ index_column: :all_text, index_column_trigger_on: :updated_at,
362
+ transactional: true,
363
+ sync: "ON COMMIT"
357
364
  }
358
365
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id#{' AND 1=1' * 500}"
359
366
  @conn.add_context_index :posts, [:title, :body, sub_query], options
360
- standard_dump.should =~ /add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/
361
- @conn.remove_context_index :posts, :name => 'post_and_comments_index'
367
+ output = dump_table_schema "posts"
368
+ expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
369
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
362
370
  end
363
371
 
364
372
  it "should dump definition of multiple table index with options (when subquery has newlines)" do
365
373
  options = {
366
- :name => 'post_and_comments_index',
367
- :index_column => :all_text, :index_column_trigger_on => :updated_at,
368
- :transactional => true,
369
- :sync => 'ON COMMIT'
374
+ name: "post_and_comments_index",
375
+ index_column: :all_text, index_column_trigger_on: :updated_at,
376
+ transactional: true,
377
+ sync: "ON COMMIT"
370
378
  }
371
379
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body\nFROM comments\nWHERE comments.post_id = :id"
372
380
  @conn.add_context_index :posts, [:title, :body, sub_query], options
373
- standard_dump.should =~ /add_context_index "posts", \[:title, :body, "#{sub_query.gsub(/\n/, ' ')}"\], #{options.inspect[1..-2]}$/
374
- @conn.remove_context_index :posts, :name => 'post_and_comments_index'
381
+ output = dump_table_schema "posts"
382
+ expect(output).to match(/add_context_index "posts", \[:title, :body, "#{sub_query.gsub(/\n/, ' ')}"\], #{options.inspect[1..-2]}$/)
383
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
375
384
  end
376
385
 
377
386
  end
378
387
 
379
388
  describe "with table prefix and suffix" do
380
389
  before(:all) do
381
- ActiveRecord::Base.table_name_prefix = 'xxx_'
382
- ActiveRecord::Base.table_name_suffix = '_xxx'
390
+ ActiveRecord::Base.table_name_prefix = "xxx_"
391
+ ActiveRecord::Base.table_name_suffix = "_xxx"
383
392
  create_tables
384
393
  end
385
394
 
386
395
  after(:all) do
387
396
  drop_tables
388
- ActiveRecord::Base.table_name_prefix = ''
389
- ActiveRecord::Base.table_name_suffix = ''
397
+ ActiveRecord::Base.table_name_prefix = ""
398
+ ActiveRecord::Base.table_name_suffix = ""
390
399
  end
391
400
 
392
401
  it "should dump definition of single column index" do
393
402
  schema_define { add_context_index :posts, :title }
394
- standard_dump.should =~ /add_context_index "posts", \["title"\], :name => "i_xxx_posts_xxx_title"$/
403
+ output = dump_table_schema "posts"
404
+ expect(output).to match(/add_context_index "posts", \["title"\], name: "i_xxx_posts_xxx_title"$/)
395
405
  schema_define { remove_context_index :posts, :title }
396
406
  end
397
407
 
398
408
  it "should dump definition of multiple column index" do
399
409
  schema_define { add_context_index :posts, [:title, :body] }
400
- standard_dump.should =~ /add_context_index "posts", \[:title, :body\]$/
410
+ output = dump_table_schema "posts"
411
+ expect(output).to match(/add_context_index "posts", \[:title, :body\]$/)
401
412
  schema_define { remove_context_index :posts, [:title, :body] }
402
413
  end
403
414
 
404
415
  it "should dump definition of multiple table index with options" do
405
416
  options = {
406
- :name => 'xxx_post_and_comments_i',
407
- :index_column => :all_text, :index_column_trigger_on => :updated_at,
408
- :lexer => { :type => "BASIC_LEXER", :base_letter_type => 'GENERIC', :base_letter => true },
409
- :wordlist => { :type => "BASIC_WORDLIST", :prefix_index => true },
410
- :sync => 'ON COMMIT'
417
+ name: "xxx_post_and_comments_i",
418
+ index_column: :all_text, index_column_trigger_on: :updated_at,
419
+ lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true },
420
+ wordlist: { type: "BASIC_WORDLIST", prefix_index: true },
421
+ sync: "ON COMMIT"
411
422
  }
412
423
  schema_define do
413
424
  add_context_index :posts,
@@ -415,9 +426,10 @@ describe "OracleEnhancedAdapter context index" do
415
426
  "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
416
427
  ], options
417
428
  end
418
- 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"\], #{
419
- options.inspect[1..-2].gsub(/[{}]/){|s| '\\'<<s }}$/
420
- schema_define { remove_context_index :posts, :name => 'xxx_post_and_comments_i' }
429
+ output = dump_table_schema "posts"
430
+ expect(output).to match(/add_context_index "posts", \[:title, :body, "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"\], #{
431
+ options.inspect[1..-2].gsub(/[{}]/) { |s| '\\'.dup << s }}$/)
432
+ schema_define { remove_context_index :posts, name: "xxx_post_and_comments_i" }
421
433
  end
422
434
 
423
435
  end