activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.0.beta1

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/Gemfile +20 -11
  4. data/History.md +123 -4
  5. data/RUNNING_TESTS.md +79 -55
  6. data/Rakefile +13 -19
  7. data/VERSION +1 -1
  8. data/activerecord-oracle_enhanced-adapter.gemspec +16 -17
  9. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -59
  11. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
  12. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
  13. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
  14. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +30 -23
  15. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
  16. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +48 -70
  17. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +1 -4
  18. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
  19. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
  20. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
  21. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +13 -42
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +146 -159
  25. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +94 -132
  26. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
  27. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +65 -100
  28. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
  29. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +250 -487
  30. data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
  31. data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
  32. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
  33. data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
  34. data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
  35. data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
  36. data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
  37. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +57 -131
  38. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
  39. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +40 -42
  40. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +83 -85
  41. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +205 -286
  42. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
  43. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
  44. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +42 -49
  45. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -3
  46. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -71
  47. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +51 -92
  48. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +221 -327
  49. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +16 -18
  50. data/spec/spec_helper.rb +59 -57
  51. metadata +10 -10
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "OracleEnhancedConnection" do
4
2
 
5
3
  describe "create connection" do
@@ -61,26 +59,26 @@ describe "OracleEnhancedConnection" do
61
59
 
62
60
  describe "create connection with NLS parameters" do
63
61
  after do
64
- ENV['NLS_DATE_FORMAT'] = nil
62
+ ENV["NLS_DATE_FORMAT"] = nil
65
63
  end
66
64
 
67
65
  it "should use NLS_DATE_FORMAT environment variable" do
68
- ENV['NLS_DATE_FORMAT'] = 'YYYY-MM-DD'
66
+ ENV["NLS_DATE_FORMAT"] = "YYYY-MM-DD"
69
67
  @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
70
- expect(@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'")).to eq([{'value' => 'YYYY-MM-DD'}])
68
+ expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => "YYYY-MM-DD" }])
71
69
  end
72
70
 
73
71
  it "should use configuration value and ignore NLS_DATE_FORMAT environment variable" do
74
- ENV['NLS_DATE_FORMAT'] = 'YYYY-MM-DD'
75
- @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS.merge(:nls_date_format => 'YYYY-MM-DD HH24:MI'))
76
- expect(@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'")).to eq([{'value' => 'YYYY-MM-DD HH24:MI'}])
72
+ ENV["NLS_DATE_FORMAT"] = "YYYY-MM-DD"
73
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS.merge(nls_date_format: "YYYY-MM-DD HH24:MI"))
74
+ expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => "YYYY-MM-DD HH24:MI" }])
77
75
  end
78
76
 
79
77
  it "should use default value when NLS_DATE_FORMAT environment variable is not set" do
80
- ENV['NLS_DATE_FORMAT'] = nil
78
+ ENV["NLS_DATE_FORMAT"] = nil
81
79
  @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
82
80
  default = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS[:nls_date_format]
83
- expect(@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'")).to eq([{'value' => default}])
81
+ expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => default }])
84
82
  end
85
83
  end
86
84
 
@@ -116,7 +114,7 @@ describe "OracleEnhancedConnection" do
116
114
  before(:all) do
117
115
  ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
118
116
  schema_define do
119
- create_table :posts, :force => true do |t|
117
+ create_table :posts, force: true do |t|
120
118
  t.timestamps null: false
121
119
  end
122
120
  end
@@ -143,9 +141,9 @@ describe "OracleEnhancedConnection" do
143
141
  let(:username) { CONNECTION_PARAMS[:username] }
144
142
  let(:password) { CONNECTION_PARAMS[:password] }
145
143
  let(:connection_string) { "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=#{DATABASE_HOST})(PORT=#{DATABASE_PORT})))(CONNECT_DATA=(SERVICE_NAME=#{DATABASE_NAME})))" }
146
- let(:params) { { username: username, password: password, host: 'connection-string', database: connection_string } }
144
+ let(:params) { { username: username, password: password, host: "connection-string", database: connection_string } }
147
145
 
148
- it 'uses the database param as the connection string' do
146
+ it "uses the database param as the connection string" do
149
147
  if ORACLE_ENHANCED_CONNECTION == :jdbc
150
148
  expect(java.sql.DriverManager).to receive(:getConnection).with("jdbc:oracle:thin:@#{connection_string}", anything).and_call_original
151
149
  else
@@ -156,7 +154,7 @@ describe "OracleEnhancedConnection" do
156
154
  end
157
155
  end
158
156
 
159
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
157
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
160
158
 
161
159
  describe "create JDBC connection" do
162
160
 
@@ -189,11 +187,11 @@ describe "OracleEnhancedConnection" do
189
187
  it "should create a new connection using JNDI" do
190
188
 
191
189
  begin
192
- import 'oracle.jdbc.driver.OracleDriver'
193
- import 'org.apache.commons.pool.impl.GenericObjectPool'
194
- import 'org.apache.commons.dbcp.PoolingDataSource'
195
- import 'org.apache.commons.dbcp.PoolableConnectionFactory'
196
- import 'org.apache.commons.dbcp.DriverManagerConnectionFactory'
190
+ import "oracle.jdbc.driver.OracleDriver"
191
+ import "org.apache.commons.pool.impl.GenericObjectPool"
192
+ import "org.apache.commons.dbcp.PoolingDataSource"
193
+ import "org.apache.commons.dbcp.PoolableConnectionFactory"
194
+ import "org.apache.commons.dbcp.DriverManagerConnectionFactory"
197
195
  rescue NameError => e
198
196
  return skip e.message
199
197
  end
@@ -203,12 +201,12 @@ describe "OracleEnhancedConnection" do
203
201
  connection_pool = GenericObjectPool.new(nil)
204
202
  uri = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
205
203
  connection_factory = DriverManagerConnectionFactory.new(uri, DATABASE_USER, DATABASE_PASSWORD)
206
- poolable_connection_factory = PoolableConnectionFactory.new(connection_factory,connection_pool,nil,nil,false,true)
204
+ poolable_connection_factory = PoolableConnectionFactory.new(connection_factory, connection_pool, nil, nil, false, true)
207
205
  @data_source = PoolingDataSource.new(connection_pool)
208
206
  @data_source.access_to_underlying_connection_allowed = true
209
207
  end
210
208
  def lookup(path)
211
- if (path == 'java:/comp/env')
209
+ if (path == "java:/comp/env")
212
210
  return self
213
211
  else
214
212
  return @data_source
@@ -219,7 +217,7 @@ describe "OracleEnhancedConnection" do
219
217
  allow(javax.naming.InitialContext).to receive(:new).and_return(InitialContextMock.new)
220
218
 
221
219
  params = {}
222
- params[:jndi] = 'java:comp/env/jdbc/test'
220
+ params[:jndi] = "java:comp/env/jdbc/test"
223
221
  @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
224
222
  expect(@conn).to be_active
225
223
  end
@@ -231,7 +229,7 @@ describe "OracleEnhancedConnection" do
231
229
  params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "//#{DATABASE_HOST}#{DATABASE_PORT && ":#{DATABASE_PORT}"}/"}#{DATABASE_NAME}"
232
230
  params[:host] = nil
233
231
  params[:database] = nil
234
- allow(java.sql.DriverManager).to receive(:getConnection).and_raise('no suitable driver found')
232
+ allow(java.sql.DriverManager).to receive(:getConnection).and_raise("no suitable driver found")
235
233
  @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
236
234
  expect(@conn).to be_active
237
235
  end
@@ -248,11 +246,11 @@ describe "OracleEnhancedConnection" do
248
246
  end
249
247
 
250
248
  it "should execute SQL select" do
251
- expect(@conn.select("SELECT * FROM dual")).to eq([{'dummy' => 'X'}])
249
+ expect(@conn.select("SELECT * FROM dual")).to eq([{ "dummy" => "X" }])
252
250
  end
253
251
 
254
252
  it "should execute SQL select and return also columns" do
255
- expect(@conn.select("SELECT * FROM dual", nil, true)).to eq([ [{'dummy' => 'X'}], ['dummy'] ])
253
+ expect(@conn.select("SELECT * FROM dual", nil, true)).to eq([ [{ "dummy" => "X" }], ["dummy"] ])
256
254
  end
257
255
 
258
256
  end
@@ -266,7 +264,7 @@ describe "OracleEnhancedConnection" do
266
264
  cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
267
265
  cursor.bind_param(1, 1)
268
266
  cursor.exec
269
- expect(cursor.get_col_names).to eq(['DUMMY'])
267
+ expect(cursor.get_col_names).to eq(["DUMMY"])
270
268
  expect(cursor.fetch).to eq(["X"])
271
269
  cursor.close
272
270
  end
@@ -285,20 +283,20 @@ describe "OracleEnhancedConnection" do
285
283
 
286
284
  describe "SQL with bind parameters when NLS_NUMERIC_CHARACTERS is set to ', '" do
287
285
  before(:all) do
288
- ENV['NLS_NUMERIC_CHARACTERS'] = ", "
286
+ ENV["NLS_NUMERIC_CHARACTERS"] = ", "
289
287
  @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
290
288
  @conn.exec "CREATE TABLE test_employees (age NUMBER(10,2))"
291
289
  end
292
290
 
293
291
  after(:all) do
294
- ENV['NLS_NUMERIC_CHARACTERS'] = nil
292
+ ENV["NLS_NUMERIC_CHARACTERS"] = nil
295
293
  @conn.exec "DROP TABLE test_employees" rescue nil
296
294
  end
297
295
 
298
296
  it "should execute prepared statement with decimal bind parameter " do
299
297
  cursor = @conn.prepare("INSERT INTO test_employees VALUES(:1)")
300
298
  type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "NUMBER", type: :decimal, limit: 10, precision: nil, scale: 2)
301
- column = ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.new('age', nil, type_metadata, false, "test_employees", false, false, nil)
299
+ column = ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.new("age", nil, type_metadata, false, "test_employees", false, false, nil)
302
300
  expect(column.type).to eq(:decimal)
303
301
  # Here 1.5 expects that this value has been type casted already
304
302
  # it should use bind_params in the long term.
@@ -324,10 +322,10 @@ describe "OracleEnhancedConnection" do
324
322
  end
325
323
 
326
324
  def kill_current_session
327
- audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first['audsid']
325
+ audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first["audsid"]
328
326
  sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
329
327
  FROM v$session s
330
- WHERE audsid = '#{audsid}'").first['sid_serial']
328
+ WHERE audsid = '#{audsid}'").first["sid_serial"]
331
329
  @sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
332
330
  end
333
331
 
@@ -342,7 +340,7 @@ describe "OracleEnhancedConnection" do
342
340
  # @conn.auto_retry = false
343
341
  ActiveRecord::Base.connection.auto_retry = false
344
342
  kill_current_session
345
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
343
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
346
344
  expect { @conn.exec("SELECT * FROM dual") }.to raise_error(NativeException)
347
345
  else
348
346
  expect { @conn.exec("SELECT * FROM dual") }.to raise_error(OCIError)
@@ -353,14 +351,14 @@ describe "OracleEnhancedConnection" do
353
351
  # @conn.auto_retry = true
354
352
  ActiveRecord::Base.connection.auto_retry = true
355
353
  kill_current_session
356
- expect(@conn.select("SELECT * FROM dual")).to eq([{'dummy' => 'X'}])
354
+ expect(@conn.select("SELECT * FROM dual")).to eq([{ "dummy" => "X" }])
357
355
  end
358
356
 
359
357
  it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
360
358
  # @conn.auto_retry = false
361
359
  ActiveRecord::Base.connection.auto_retry = false
362
360
  kill_current_session
363
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
361
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
364
362
  expect { @conn.select("SELECT * FROM dual") }.to raise_error(NativeException)
365
363
  else
366
364
  expect { @conn.select("SELECT * FROM dual") }.to raise_error(OCIError)
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "OracleEnhancedAdapter context index" do
4
2
  include SchemaSpecHelper
5
3
  include LoggerSpecHelper
@@ -68,8 +66,8 @@ describe "OracleEnhancedAdapter context index" do
68
66
  has_context_index
69
67
  end
70
68
  @post0 = Post.create(title: "dummy title", body: "dummy body")
71
- @post1 = Post.create(title: @title_words.join(' '), body: @body_words.join(' '))
72
- @post2 = Post.create(title: (@title_words*2).join(' '), body: (@body_words*2).join(' '))
69
+ @post1 = Post.create(title: @title_words.join(" "), body: @body_words.join(" "))
70
+ @post2 = Post.create(title: (@title_words * 2).join(" "), body: (@body_words * 2).join(" "))
73
71
  @post_with_null_body = Post.create(title: "withnull", body: nil)
74
72
  @post_with_null_title = Post.create(title: nil, body: "withnull")
75
73
  end
@@ -77,7 +75,7 @@ describe "OracleEnhancedAdapter context index" do
77
75
  after(:all) do
78
76
  drop_table_posts
79
77
  Object.send(:remove_const, "Post")
80
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
78
+ ActiveRecord::Base.clear_cache!
81
79
  end
82
80
 
83
81
  after(:each) do
@@ -102,13 +100,13 @@ describe "OracleEnhancedAdapter context index" do
102
100
 
103
101
  it "should not include text index secondary tables in user tables list" do
104
102
  @conn.add_context_index :posts, :title
105
- expect(@conn.tables.any?{|t| t =~ /^dr\$/i}).to be_falsey
103
+ expect(@conn.tables.any? { |t| t =~ /^dr\$/i }).to be_falsey
106
104
  @conn.remove_context_index :posts, :title
107
105
  end
108
106
 
109
107
  it "should create multiple column index" do
110
108
  @conn.add_context_index :posts, [:title, :body]
111
- (@title_words+@body_words).each do |word|
109
+ (@title_words + @body_words).each do |word|
112
110
  expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
113
111
  end
114
112
  @conn.remove_context_index :posts, [:title, :body]
@@ -122,7 +120,7 @@ describe "OracleEnhancedAdapter context index" do
122
120
 
123
121
  it "should create multiple column index with specified main index column" do
124
122
  @conn.add_context_index :posts, [:title, :body],
125
- index_column: :all_text, sync: 'ON COMMIT'
123
+ index_column: :all_text, sync: "ON COMMIT"
126
124
  @post = Post.create(title: "abc", body: "def")
127
125
  expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
128
126
  expect(Post.contains(:all_text, "def").to_a).to eq([@post])
@@ -138,7 +136,7 @@ describe "OracleEnhancedAdapter context index" do
138
136
  it "should create multiple column index with trigger updated main index column" do
139
137
  @conn.add_context_index :posts, [:title, :body],
140
138
  index_column: :all_text, index_column_trigger_on: [:created_at, :updated_at],
141
- sync: 'ON COMMIT'
139
+ sync: "ON COMMIT"
142
140
  @post = Post.create(title: "abc", body: "def")
143
141
  expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
144
142
  expect(Post.contains(:all_text, "def").to_a).to eq([@post])
@@ -151,7 +149,7 @@ describe "OracleEnhancedAdapter context index" do
151
149
  it "should use base letter conversion with BASIC_LEXER" do
152
150
  @post = Post.create!(title: "āčē", body: "dummy")
153
151
  @conn.add_context_index :posts, :title,
154
- lexer: { type: "BASIC_LEXER", base_letter_type: 'GENERIC', base_letter: true }
152
+ lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true }
155
153
  expect(Post.contains(:title, "āčē").to_a).to eq([@post])
156
154
  expect(Post.contains(:title, "ace").to_a).to eq([@post])
157
155
  expect(Post.contains(:title, "ACE").to_a).to eq([@post])
@@ -172,7 +170,7 @@ describe "OracleEnhancedAdapter context index" do
172
170
  it "should use index when contains has schema_name.table_name syntax" do
173
171
  @conn.add_context_index :posts, :title
174
172
  @title_words.each do |word|
175
- Post.contains('posts.title', word).to_a.should == [@post2, @post1]
173
+ expect(Post.contains("posts.title", word).to_a).to eq([@post2, @post1])
176
174
  end
177
175
  @conn.remove_context_index :posts, :title
178
176
  end
@@ -195,11 +193,11 @@ describe "OracleEnhancedAdapter context index" do
195
193
  drop_tables
196
194
  Object.send(:remove_const, "Comment")
197
195
  Object.send(:remove_const, "Post")
198
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
196
+ ActiveRecord::Base.clear_cache!
199
197
  end
200
198
 
201
199
  after(:each) do
202
- @conn.remove_context_index :posts, name: 'post_and_comments_index' rescue nil
200
+ @conn.remove_context_index :posts, name: "post_and_comments_index" rescue nil
203
201
  @conn.remove_context_index :posts, index_column: :all_text rescue nil
204
202
  Post.destroy_all
205
203
  end
@@ -210,9 +208,9 @@ describe "OracleEnhancedAdapter context index" do
210
208
  # specify aliases always with AS keyword
211
209
  "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
212
210
  ],
213
- name: 'post_and_comments_index',
211
+ name: "post_and_comments_index",
214
212
  index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
215
- sync: 'ON COMMIT'
213
+ sync: "ON COMMIT"
216
214
  @post = Post.create!(title: "aaa", body: "bbb")
217
215
  @post.comments.create!(author: "ccc", body: "ddd")
218
216
  @post.comments.create!(author: "eee", body: "fff")
@@ -231,9 +229,9 @@ describe "OracleEnhancedAdapter context index" do
231
229
  FROM comments
232
230
  WHERE comments.post_id = :id }
233
231
  ],
234
- name: 'post_and_comments_index',
232
+ name: "post_and_comments_index",
235
233
  index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
236
- sync: 'ON COMMIT'
234
+ sync: "ON COMMIT"
237
235
  @post = Post.create!(title: "aaa", body: "bbb")
238
236
  @post.comments.create!(author: "ccc", body: "ddd")
239
237
  @post.comments.create!(author: "eee", body: "fff")
@@ -270,7 +268,7 @@ describe "OracleEnhancedAdapter context index" do
270
268
  class ::Post < ActiveRecord::Base
271
269
  has_context_index
272
270
  end
273
- @post = Post.create(title: 'aaa', body: 'bbb')
271
+ @post = Post.create(title: "aaa", body: "bbb")
274
272
  @tablespace = @conn.default_tablespace
275
273
  set_logger
276
274
  @conn = ActiveRecord::Base.connection
@@ -279,7 +277,7 @@ describe "OracleEnhancedAdapter context index" do
279
277
  after(:all) do
280
278
  drop_table_posts
281
279
  Object.send(:remove_const, "Post")
282
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
280
+ ActiveRecord::Base.clear_cache!
283
281
  end
284
282
 
285
283
  after(:each) do
@@ -287,7 +285,7 @@ describe "OracleEnhancedAdapter context index" do
287
285
  end
288
286
 
289
287
  def verify_logged_statements
290
- ['K_TABLE_CLAUSE', 'R_TABLE_CLAUSE', 'N_TABLE_CLAUSE', 'I_INDEX_CLAUSE', 'P_TABLE_CLAUSE'].each do |clause|
288
+ ["K_TABLE_CLAUSE", "R_TABLE_CLAUSE", "N_TABLE_CLAUSE", "I_INDEX_CLAUSE", "P_TABLE_CLAUSE"].each do |clause|
291
289
  expect(@logger.output(:debug)).to match(/CTX_DDL\.SET_ATTRIBUTE\('index_posts_on_title_sto', '#{clause}', '.*TABLESPACE #{@tablespace}'\)/)
292
290
  end
293
291
  expect(@logger.output(:debug)).to match(/CREATE INDEX .* PARAMETERS \('STORAGE index_posts_on_title_sto'\)/)
@@ -296,15 +294,15 @@ describe "OracleEnhancedAdapter context index" do
296
294
  it "should create index on single column" do
297
295
  @conn.add_context_index :posts, :title, tablespace: @tablespace
298
296
  verify_logged_statements
299
- expect(Post.contains(:title, 'aaa').to_a).to eq([@post])
297
+ expect(Post.contains(:title, "aaa").to_a).to eq([@post])
300
298
  @conn.remove_context_index :posts, :title
301
299
  end
302
300
 
303
301
  it "should create index on multiple columns" do
304
- @conn.add_context_index :posts, [:title, :body], name: 'index_posts_text', tablespace: @conn.default_tablespace
302
+ @conn.add_context_index :posts, [:title, :body], name: "index_posts_text", tablespace: @conn.default_tablespace
305
303
  verify_logged_statements
306
- expect(Post.contains(:title, 'aaa AND bbb').to_a).to eq([@post])
307
- @conn.remove_context_index :posts, name: 'index_posts_text'
304
+ expect(Post.contains(:title, "aaa AND bbb").to_a).to eq([@post])
305
+ @conn.remove_context_index :posts, name: "index_posts_text"
308
306
  end
309
307
 
310
308
  end
@@ -343,56 +341,56 @@ describe "OracleEnhancedAdapter context index" do
343
341
 
344
342
  it "should dump definition of multiple table index with options" do
345
343
  options = {
346
- name: 'post_and_comments_index',
344
+ name: "post_and_comments_index",
347
345
  index_column: :all_text, index_column_trigger_on: :updated_at,
348
346
  transactional: true,
349
- sync: 'ON COMMIT'
347
+ sync: "ON COMMIT"
350
348
  }
351
349
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
352
350
  @conn.add_context_index :posts, [:title, :body, sub_query], options
353
351
  expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
354
- @conn.remove_context_index :posts, name: 'post_and_comments_index'
352
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
355
353
  end
356
354
 
357
355
  it "should dump definition of multiple table index with options (when definition is larger than 4000 bytes)" do
358
356
  options = {
359
- name: 'post_and_comments_index',
357
+ name: "post_and_comments_index",
360
358
  index_column: :all_text, index_column_trigger_on: :updated_at,
361
359
  transactional: true,
362
- sync: 'ON COMMIT'
360
+ sync: "ON COMMIT"
363
361
  }
364
362
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id#{' AND 1=1' * 500}"
365
363
  @conn.add_context_index :posts, [:title, :body, sub_query], options
366
364
  expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
367
- @conn.remove_context_index :posts, name: 'post_and_comments_index'
365
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
368
366
  end
369
367
 
370
368
  it "should dump definition of multiple table index with options (when subquery has newlines)" do
371
369
  options = {
372
- name: 'post_and_comments_index',
370
+ name: "post_and_comments_index",
373
371
  index_column: :all_text, index_column_trigger_on: :updated_at,
374
372
  transactional: true,
375
- sync: 'ON COMMIT'
373
+ sync: "ON COMMIT"
376
374
  }
377
375
  sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body\nFROM comments\nWHERE comments.post_id = :id"
378
376
  @conn.add_context_index :posts, [:title, :body, sub_query], options
379
377
  expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query.gsub(/\n/, ' ')}"\], #{options.inspect[1..-2]}$/)
380
- @conn.remove_context_index :posts, name: 'post_and_comments_index'
378
+ @conn.remove_context_index :posts, name: "post_and_comments_index"
381
379
  end
382
380
 
383
381
  end
384
382
 
385
383
  describe "with table prefix and suffix" do
386
384
  before(:all) do
387
- ActiveRecord::Base.table_name_prefix = 'xxx_'
388
- ActiveRecord::Base.table_name_suffix = '_xxx'
385
+ ActiveRecord::Base.table_name_prefix = "xxx_"
386
+ ActiveRecord::Base.table_name_suffix = "_xxx"
389
387
  create_tables
390
388
  end
391
389
 
392
390
  after(:all) do
393
391
  drop_tables
394
- ActiveRecord::Base.table_name_prefix = ''
395
- ActiveRecord::Base.table_name_suffix = ''
392
+ ActiveRecord::Base.table_name_prefix = ""
393
+ ActiveRecord::Base.table_name_suffix = ""
396
394
  end
397
395
 
398
396
  it "should dump definition of single column index" do
@@ -409,11 +407,11 @@ describe "OracleEnhancedAdapter context index" do
409
407
 
410
408
  it "should dump definition of multiple table index with options" do
411
409
  options = {
412
- name: 'xxx_post_and_comments_i',
410
+ name: "xxx_post_and_comments_i",
413
411
  index_column: :all_text, index_column_trigger_on: :updated_at,
414
- lexer: { type: "BASIC_LEXER", base_letter_type: 'GENERIC', base_letter: true },
412
+ lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true },
415
413
  wordlist: { type: "BASIC_WORDLIST", prefix_index: true },
416
- sync: 'ON COMMIT'
414
+ sync: "ON COMMIT"
417
415
  }
418
416
  schema_define do
419
417
  add_context_index :posts,
@@ -422,8 +420,8 @@ describe "OracleEnhancedAdapter context index" do
422
420
  ], options
423
421
  end
424
422
  expect(standard_dump).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"\], #{
425
- options.inspect[1..-2].gsub(/[{}]/){|s| '\\'<<s }}$/)
426
- schema_define { remove_context_index :posts, name: 'xxx_post_and_comments_i' }
423
+ options.inspect[1..-2].gsub(/[{}]/) { |s| '\\' << s }}$/)
424
+ schema_define { remove_context_index :posts, name: "xxx_post_and_comments_i" }
427
425
  end
428
426
 
429
427
  end