activerecord-oracle_enhanced-adapter 1.6.9 → 1.7.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -11
  3. data/History.md +126 -14
  4. data/README.md +9 -6
  5. data/RUNNING_TESTS.md +1 -1
  6. data/Rakefile +1 -16
  7. data/VERSION +1 -1
  8. data/activerecord-oracle_enhanced-adapter.gemspec +15 -52
  9. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +8 -22
  10. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +53 -45
  11. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +6 -1
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +23 -62
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +46 -56
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +35 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +34 -21
  16. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +36 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +1 -1
  18. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +174 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +17 -8
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +17 -11
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +160 -178
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +42 -94
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +50 -54
  24. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +15 -11
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +197 -301
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +3 -2
  27. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +25 -0
  28. data/lib/active_record/oracle_enhanced/type/raw.rb +14 -2
  29. data/lib/active_record/oracle_enhanced/type/string.rb +28 -0
  30. data/lib/active_record/oracle_enhanced/type/text.rb +32 -0
  31. data/lib/activerecord-oracle_enhanced-adapter.rb +12 -17
  32. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +113 -135
  33. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +51 -59
  34. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +40 -41
  35. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +6 -6
  36. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +281 -233
  37. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +7 -7
  38. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +10 -10
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +22 -22
  40. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -2
  41. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +36 -37
  42. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +86 -46
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +194 -294
  44. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +53 -39
  45. data/spec/spec_helper.rb +0 -6
  46. metadata +42 -143
  47. data/.travis.yml +0 -39
  48. data/.travis/oracle/download.sh +0 -14
  49. data/.travis/oracle/install.sh +0 -31
  50. data/.travis/setup_accounts.sh +0 -9
  51. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +0 -40
  52. data/lib/active_record/oracle_enhanced/type/timestamp.rb +0 -11
  53. data/spec/spec_config.yaml.template +0 -11
  54. data/spec/support/alter_system_user_password.sql +0 -2
  55. data/spec/support/create_oracle_enhanced_users.sql +0 -31
@@ -1,7 +1,8 @@
1
- module ActiveRecord
1
+ #TODO Need to consider namespace change since paremt class moved to ActiveModel
2
+ module ActiveRecord
2
3
  module OracleEnhanced
3
4
  module Type
4
- class Integer < ActiveRecord::Type::Integer # :nodoc:
5
+ class Integer < ActiveModel::Type::Integer # :nodoc:
5
6
  private
6
7
 
7
8
  def max_value
@@ -0,0 +1,25 @@
1
+ require 'active_model/type/string'
2
+
3
+ module ActiveRecord
4
+ module OracleEnhanced
5
+ module Type
6
+ class NationalCharacterString < ActiveRecord::OracleEnhanced::Type::String # :nodoc:
7
+
8
+ def serialize(value)
9
+ return unless value
10
+ Data.new(super)
11
+ end
12
+
13
+ class Data # :nodoc:
14
+ def initialize(value)
15
+ @value = value
16
+ end
17
+
18
+ def to_s
19
+ @value
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,12 +1,24 @@
1
- require 'active_record/type/string'
1
+ require 'active_model/type/string'
2
2
 
3
+ #TODO Need to consider namespace change since paremt class moved to ActiveModel
3
4
  module ActiveRecord
4
5
  module OracleEnhanced
5
6
  module Type
6
- class Raw < ActiveRecord::Type::String # :nodoc:
7
+ class Raw < ActiveModel::Type::String # :nodoc:
7
8
  def type
8
9
  :raw
9
10
  end
11
+
12
+ def serialize(value)
13
+ # Encode a string or byte array as string of hex codes
14
+ if value.nil?
15
+ super
16
+ else
17
+ value = value.unpack('C*')
18
+ value.map { |x| "%02X" % x }.join
19
+ end
20
+ end
21
+
10
22
  end
11
23
  end
12
24
  end
@@ -0,0 +1,28 @@
1
+ require 'active_model/type/string'
2
+
3
+ module ActiveRecord
4
+ module OracleEnhanced
5
+ module Type
6
+ class String < ActiveModel::Type::String # :nodoc:
7
+ def changed?(old_value, new_value, _new_value_before_type_cast)
8
+ if old_value.nil?
9
+ new_value = nil if new_value == ""
10
+ old_value != new_value
11
+ else
12
+ super
13
+ end
14
+ end
15
+
16
+ def changed_in_place?(raw_old_value, new_value)
17
+ if raw_old_value.nil?
18
+ new_value = nil if new_value == ''
19
+ raw_old_value != new_value
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_model/type/string'
2
+
3
+ module ActiveRecord
4
+ module OracleEnhanced
5
+ module Type
6
+ class Text < ActiveModel::Type::Text # :nodoc:
7
+
8
+ def changed_in_place?(raw_old_value, new_value)
9
+ #TODO: Needs to find a way not to cast here.
10
+ raw_old_value = cast(raw_old_value)
11
+ super
12
+ end
13
+
14
+ def serialize(value)
15
+ return unless value
16
+ Data.new(super)
17
+ end
18
+
19
+ class Data # :nodoc:
20
+ def initialize(value)
21
+ @value = value
22
+ end
23
+
24
+ def to_s
25
+ @value
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,25 +1,20 @@
1
- # define railtie which will be executed in Rails 3
2
- if defined?(::Rails::Railtie)
3
-
4
- module ActiveRecord
5
- module ConnectionAdapters
6
- class OracleEnhancedRailtie < ::Rails::Railtie
7
- rake_tasks do
8
- load 'active_record/connection_adapters/oracle_enhanced/database_tasks.rb'
9
- end
10
-
11
- ActiveSupport.on_load(:active_record) do
12
- require 'active_record/connection_adapters/oracle_enhanced_adapter'
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class OracleEnhancedRailtie < ::Rails::Railtie
4
+ rake_tasks do
5
+ load 'active_record/connection_adapters/oracle_enhanced/database_tasks.rb'
6
+ end
13
7
 
14
- # Cache column descriptions between requests in test and production environments
15
- if Rails.env.test? || Rails.env.production?
16
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
17
- end
8
+ ActiveSupport.on_load(:active_record) do
9
+ require 'active_record/connection_adapters/oracle_enhanced_adapter'
18
10
 
11
+ # Cache column descriptions between requests in test and production environments
12
+ if Rails.env.test? || Rails.env.production?
13
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
19
14
  end
20
15
 
21
16
  end
17
+
22
18
  end
23
19
  end
24
-
25
20
  end
@@ -4,33 +4,33 @@ describe "OracleEnhancedAdapter establish connection" do
4
4
 
5
5
  it "should connect to database" do
6
6
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
7
- ActiveRecord::Base.connection.should_not be_nil
8
- ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
7
+ expect(ActiveRecord::Base.connection).not_to be_nil
8
+ expect(ActiveRecord::Base.connection.class).to eq(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
9
9
  end
10
10
 
11
11
  it "should connect to database as SYSDBA" do
12
12
  ActiveRecord::Base.establish_connection(SYS_CONNECTION_PARAMS)
13
- ActiveRecord::Base.connection.should_not be_nil
14
- ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
13
+ expect(ActiveRecord::Base.connection).not_to be_nil
14
+ expect(ActiveRecord::Base.connection.class).to eq(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
15
15
  end
16
16
 
17
17
  it "should be active after connection to database" do
18
18
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
19
- ActiveRecord::Base.connection.should be_active
19
+ expect(ActiveRecord::Base.connection).to be_active
20
20
  end
21
21
 
22
22
  it "should not be active after disconnection to database" do
23
23
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
24
24
  ActiveRecord::Base.connection.disconnect!
25
- ActiveRecord::Base.connection.should_not be_active
25
+ expect(ActiveRecord::Base.connection).not_to be_active
26
26
  end
27
27
 
28
28
  it "should be active after reconnection to database" do
29
29
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
30
30
  ActiveRecord::Base.connection.reconnect!
31
- ActiveRecord::Base.connection.should be_active
31
+ expect(ActiveRecord::Base.connection).to be_active
32
32
  end
33
-
33
+
34
34
  end
35
35
 
36
36
  describe "OracleEnhancedAdapter" do
@@ -40,7 +40,7 @@ describe "OracleEnhancedAdapter" do
40
40
  before(:all) do
41
41
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
42
42
  end
43
-
43
+
44
44
  describe "ignore specified table columns" do
45
45
  before(:all) do
46
46
  @conn = ActiveRecord::Base.connection
@@ -83,7 +83,7 @@ describe "OracleEnhancedAdapter" do
83
83
  class ::TestEmployee < ActiveRecord::Base
84
84
  ignore_table_columns :phone_number, :hire_date
85
85
  end
86
- TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
86
+ expect(TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
87
87
  end
88
88
 
89
89
  it "should ignore specified table columns specified in several lines" do
@@ -91,14 +91,14 @@ describe "OracleEnhancedAdapter" do
91
91
  ignore_table_columns :phone_number
92
92
  ignore_table_columns :hire_date
93
93
  end
94
- TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
94
+ expect(TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
95
95
  end
96
96
 
97
97
  it "should not ignore unspecified table columns" do
98
98
  class ::TestEmployee < ActiveRecord::Base
99
99
  ignore_table_columns :phone_number, :hire_date
100
100
  end
101
- TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }.should_not be_empty
101
+ expect(TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }).not_to be_empty
102
102
  end
103
103
 
104
104
  it "should ignore specified table columns in other connection" do
@@ -107,7 +107,7 @@ describe "OracleEnhancedAdapter" do
107
107
  end
108
108
  # establish other connection
109
109
  other_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
110
- other_conn.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
110
+ expect(other_conn.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
111
111
  end
112
112
 
113
113
  end
@@ -173,37 +173,37 @@ describe "OracleEnhancedAdapter" do
173
173
  it 'should identify virtual columns as such' do
174
174
  skip "Not supported in this database version" unless @oracle11g_or_higher
175
175
  te = TestEmployee.connection.columns('test_employees').detect(&:virtual?)
176
- te.name.should == 'full_name'
176
+ expect(te.name).to eq('full_name')
177
177
  end
178
178
 
179
179
  it "should get columns from database at first time" do
180
- TestEmployee.connection.columns('test_employees').map(&:name).should == @column_names
181
- @logger.logged(:debug).last.should =~ /select .* from all_tab_cols/im
180
+ expect(TestEmployee.connection.columns('test_employees').map(&:name)).to eq(@column_names)
181
+ expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
182
182
  end
183
183
 
184
184
  it "should get columns from database at second time" do
185
185
  TestEmployee.connection.columns('test_employees')
186
186
  @logger.clear(:debug)
187
- TestEmployee.connection.columns('test_employees').map(&:name).should == @column_names
188
- @logger.logged(:debug).last.should =~ /select .* from all_tab_cols/im
187
+ expect(TestEmployee.connection.columns('test_employees').map(&:name)).to eq(@column_names)
188
+ expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
189
189
  end
190
190
 
191
191
  it "should get primary key from database at first time" do
192
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
193
- @logger.logged(:debug).last.should =~ /select .* from all_constraints/im
192
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
193
+ expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
194
194
  end
195
195
 
196
196
  it "should get primary key from database at first time" do
197
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
197
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
198
198
  @logger.clear(:debug)
199
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
200
- @logger.logged(:debug).last.should =~ /select .* from all_constraints/im
199
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
200
+ expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
201
201
  end
202
202
 
203
203
  it "should have correct sql types when 2 models are using the same table and AR query cache is enabled" do
204
204
  @conn.cache do
205
- TestEmployee.columns.map(&:sql_type).should == @column_sql_types
206
- TestEmployee2.columns.map(&:sql_type).should == @column_sql_types
205
+ expect(TestEmployee.columns.map(&:sql_type)).to eq(@column_sql_types)
206
+ expect(TestEmployee2.columns.map(&:sql_type)).to eq(@column_sql_types)
207
207
  end
208
208
  end
209
209
 
@@ -216,34 +216,34 @@ describe "OracleEnhancedAdapter" do
216
216
  end
217
217
 
218
218
  it "should get columns from database at first time" do
219
- TestEmployee.connection.columns('test_employees').map(&:name).should == @column_names
220
- @logger.logged(:debug).last.should =~ /select .* from all_tab_cols/im
219
+ expect(TestEmployee.connection.columns('test_employees').map(&:name)).to eq(@column_names)
220
+ expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
221
221
  end
222
222
 
223
223
  it "should get columns from cache at second time" do
224
224
  TestEmployee.connection.columns('test_employees')
225
225
  @logger.clear(:debug)
226
- TestEmployee.connection.columns('test_employees').map(&:name).should == @column_names
227
- @logger.logged(:debug).last.should be_blank
226
+ expect(TestEmployee.connection.columns('test_employees').map(&:name)).to eq(@column_names)
227
+ expect(@logger.logged(:debug).last).to be_blank
228
228
  end
229
229
 
230
230
  it "should get primary key from database at first time" do
231
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
232
- @logger.logged(:debug).last.should =~ /select .* from all_constraints/im
231
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
232
+ expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
233
233
  end
234
234
 
235
235
  it "should get primary key from cache at first time" do
236
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
236
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
237
237
  @logger.clear(:debug)
238
- TestEmployee.connection.pk_and_sequence_for('test_employees').should == ['id', nil]
239
- @logger.logged(:debug).last.should be_blank
238
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees')).to eq(['id', nil])
239
+ expect(@logger.logged(:debug).last).to be_blank
240
240
  end
241
241
 
242
242
  it "should store primary key as nil in cache at first time for table without primary key" do
243
- TestEmployee.connection.pk_and_sequence_for('test_employees_without_pk').should == nil
243
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees_without_pk')).to eq(nil)
244
244
  @logger.clear(:debug)
245
- TestEmployee.connection.pk_and_sequence_for('test_employees_without_pk').should == nil
246
- @logger.logged(:debug).last.should be_blank
245
+ expect(TestEmployee.connection.pk_and_sequence_for('test_employees_without_pk')).to eq(nil)
246
+ expect(@logger.logged(:debug).last).to be_blank
247
247
  end
248
248
 
249
249
  end
@@ -274,11 +274,11 @@ describe "OracleEnhancedAdapter" do
274
274
  end
275
275
 
276
276
  it "should tell ActiveRecord that count distinct is supported" do
277
- ActiveRecord::Base.connection.supports_count_distinct?.should be true
277
+ expect(ActiveRecord::Base.connection.supports_count_distinct?).to be_truthy
278
278
  end
279
279
 
280
280
  it "should execute correct SQL COUNT DISTINCT statement" do
281
- lambda { TestEmployee.distinct.count(:employee_id) }.should_not raise_error
281
+ expect { TestEmployee.distinct.count(:employee_id) }.not_to raise_error
282
282
  end
283
283
 
284
284
  end
@@ -316,7 +316,7 @@ describe "OracleEnhancedAdapter" do
316
316
 
317
317
  it "should create table" do
318
318
  [:varchar2, :integer, :comment].each do |attr|
319
- TestReservedWord.columns_hash[attr.to_s].name.should == attr.to_s
319
+ expect(TestReservedWord.columns_hash[attr.to_s].name).to eq(attr.to_s)
320
320
  end
321
321
  end
322
322
 
@@ -329,72 +329,72 @@ describe "OracleEnhancedAdapter" do
329
329
  record = TestReservedWord.create!(attrs)
330
330
  record.reload
331
331
  attrs.each do |k, v|
332
- record.send(k).should == v
332
+ expect(record.send(k)).to eq(v)
333
333
  end
334
334
  end
335
335
 
336
336
  it "should remove double quotes in column quoting" do
337
- ActiveRecord::Base.connection.quote_column_name('aaa "bbb" ccc').should == '"aaa bbb ccc"'
337
+ expect(ActiveRecord::Base.connection.quote_column_name('aaa "bbb" ccc')).to eq('"aaa bbb ccc"')
338
338
  end
339
339
 
340
340
  end
341
341
 
342
342
  describe "valid table names" do
343
343
  before(:all) do
344
- @adapter = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
344
+ @adapter = ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting
345
345
  end
346
346
 
347
347
  it "should be valid with letters and digits" do
348
- @adapter.valid_table_name?("abc_123").should be true
348
+ expect(@adapter.valid_table_name?("abc_123")).to be_truthy
349
349
  end
350
350
 
351
351
  it "should be valid with schema name" do
352
- @adapter.valid_table_name?("abc_123.def_456").should be true
352
+ expect(@adapter.valid_table_name?("abc_123.def_456")).to be_truthy
353
353
  end
354
354
 
355
355
  it "should be valid with $ in name" do
356
- @adapter.valid_table_name?("sys.v$session").should be true
356
+ expect(@adapter.valid_table_name?("sys.v$session")).to be_truthy
357
357
  end
358
358
 
359
359
  it "should be valid with upcase schema name" do
360
- @adapter.valid_table_name?("ABC_123.DEF_456").should be true
360
+ expect(@adapter.valid_table_name?("ABC_123.DEF_456")).to be_truthy
361
361
  end
362
362
 
363
363
  it "should be valid with irregular schema name and database links" do
364
- @adapter.valid_table_name?('abc$#_123.abc$#_123@abc$#@._123').should be true
364
+ expect(@adapter.valid_table_name?('abc$#_123.abc$#_123@abc$#@._123')).to be_truthy
365
365
  end
366
366
 
367
367
  it "should not be valid with two dots in name" do
368
- @adapter.valid_table_name?("abc_123.def_456.ghi_789").should be false
368
+ expect(@adapter.valid_table_name?("abc_123.def_456.ghi_789")).to be_falsey
369
369
  end
370
370
 
371
371
  it "should not be valid with invalid characters" do
372
- @adapter.valid_table_name?("warehouse-things").should be false
372
+ expect(@adapter.valid_table_name?("warehouse-things")).to be_falsey
373
373
  end
374
374
 
375
375
  it "should not be valid with for camel-case" do
376
- @adapter.valid_table_name?("Abc").should be false
377
- @adapter.valid_table_name?("aBc").should be false
378
- @adapter.valid_table_name?("abC").should be false
376
+ expect(@adapter.valid_table_name?("Abc")).to be_falsey
377
+ expect(@adapter.valid_table_name?("aBc")).to be_falsey
378
+ expect(@adapter.valid_table_name?("abC")).to be_falsey
379
379
  end
380
-
380
+
381
381
  it "should not be valid for names > 30 characters" do
382
- @adapter.valid_table_name?("a" * 31).should be false
382
+ expect(@adapter.valid_table_name?("a" * 31)).to be_falsey
383
383
  end
384
-
384
+
385
385
  it "should not be valid for schema names > 30 characters" do
386
- @adapter.valid_table_name?(("a" * 31) + ".validname").should be false
386
+ expect(@adapter.valid_table_name?(("a" * 31) + ".validname")).to be_falsey
387
387
  end
388
-
388
+
389
389
  it "should not be valid for database links > 128 characters" do
390
- @adapter.valid_table_name?("name@" + "a" * 129).should be false
390
+ expect(@adapter.valid_table_name?("name@" + "a" * 129)).to be_falsey
391
391
  end
392
-
392
+
393
393
  it "should not be valid for names that do not begin with alphabetic characters" do
394
- @adapter.valid_table_name?("1abc").should be false
395
- @adapter.valid_table_name?("_abc").should be false
396
- @adapter.valid_table_name?("abc.1xyz").should be false
397
- @adapter.valid_table_name?("abc._xyz").should be false
394
+ expect(@adapter.valid_table_name?("1abc")).to be_falsey
395
+ expect(@adapter.valid_table_name?("_abc")).to be_falsey
396
+ expect(@adapter.valid_table_name?("abc.1xyz")).to be_falsey
397
+ expect(@adapter.valid_table_name?("abc._xyz")).to be_falsey
398
398
  end
399
399
  end
400
400
 
@@ -444,9 +444,9 @@ describe "OracleEnhancedAdapter" do
444
444
  end
445
445
 
446
446
  wh = WarehouseThing.create!(:name => "Foo", :foo => 2)
447
- wh.id.should_not be_nil
447
+ expect(wh.id).not_to be_nil
448
448
 
449
- @conn.tables.should include("warehouse-things")
449
+ expect(@conn.tables).to include("warehouse-things")
450
450
  end
451
451
 
452
452
  it "should allow creation of a table with CamelCase name" do
@@ -456,13 +456,13 @@ describe "OracleEnhancedAdapter" do
456
456
  end
457
457
 
458
458
  cc = CamelCase.create!(:name => "Foo", :foo => 2)
459
- cc.id.should_not be_nil
460
-
461
- @conn.tables.should include("CamelCase")
459
+ expect(cc.id).not_to be_nil
460
+
461
+ expect(@conn.tables).to include("CamelCase")
462
462
  end
463
463
 
464
464
  it "properly quotes database links" do
465
- @conn.quote_table_name('asdf@some.link').should eq('"ASDF"@"SOME.LINK"')
465
+ expect(@conn.quote_table_name('asdf@some.link')).to eq('"ASDF"@"SOME.LINK"')
466
466
  end
467
467
  end
468
468
 
@@ -504,13 +504,13 @@ describe "OracleEnhancedAdapter" do
504
504
  end
505
505
 
506
506
  it "should get column names" do
507
- TestPost.column_names.should == ["id", "title", "body", "created_at", "updated_at"]
507
+ expect(TestPost.column_names).to eq(["id", "title", "body", "created_at", "updated_at"])
508
508
  end
509
509
 
510
510
  it "should create record" do
511
511
  p = TestPost.create(:title => "Title", :body => "Body")
512
- p.id.should_not be_nil
513
- TestPost.find(p.id).should_not be_nil
512
+ expect(p.id).not_to be_nil
513
+ expect(TestPost.find(p.id)).not_to be_nil
514
514
  end
515
515
 
516
516
  end
@@ -523,11 +523,11 @@ describe "OracleEnhancedAdapter" do
523
523
  it "should get current database name" do
524
524
  # get database name if using //host:port/database connection string
525
525
  database_name = CONNECTION_PARAMS[:database].split('/').last
526
- @conn.current_database.upcase.should == database_name.upcase
526
+ expect(@conn.current_database.upcase).to eq(database_name.upcase)
527
527
  end
528
528
 
529
529
  it "should get current database session user" do
530
- @conn.current_user.upcase.should == CONNECTION_PARAMS[:username].upcase
530
+ expect(@conn.current_user.upcase).to eq(CONNECTION_PARAMS[:username].upcase)
531
531
  end
532
532
  end
533
533
 
@@ -554,7 +554,7 @@ describe "OracleEnhancedAdapter" do
554
554
  @conn.create_table :foos, :temporary => true, :id => false do |t|
555
555
  t.integer :id
556
556
  end
557
- @conn.temporary_table?("foos").should be true
557
+ expect(@conn.temporary_table?("foos")).to be_truthy
558
558
  end
559
559
  end
560
560
 
@@ -597,7 +597,7 @@ describe "OracleEnhancedAdapter" do
597
597
 
598
598
  it "should load included association with more than 1000 records" do
599
599
  posts = TestPost.includes(:test_comments).to_a
600
- posts.size.should == @ids.size
600
+ expect(posts.size).to eq(@ids.size)
601
601
  end
602
602
 
603
603
  end
@@ -629,30 +629,30 @@ describe "OracleEnhancedAdapter" do
629
629
 
630
630
  it "should clear older cursors when statement limit is reached" do
631
631
  pk = TestPost.columns_hash[TestPost.primary_key]
632
- sub = @conn.substitute_at(pk, 0).to_sql
633
- binds = [[pk, 1]]
632
+ sub = Arel::Nodes::BindParam.new.to_sql
633
+ binds = [ActiveRecord::Relation::QueryAttribute.new(pk, 1, ActiveRecord::Type::Integer.new)]
634
634
 
635
- lambda {
635
+ expect {
636
636
  4.times do |i|
637
637
  @conn.exec_query("SELECT * FROM test_posts WHERE #{i}=#{i} AND id = #{sub}", "SQL", binds)
638
638
  end
639
- }.should change(@statements, :length).by(+3)
639
+ }.to change(@statements, :length).by(+3)
640
640
  end
641
641
 
642
642
  it "should cache UPDATE statements with bind variables" do
643
- lambda {
643
+ expect {
644
644
  pk = TestPost.columns_hash[TestPost.primary_key]
645
- sub = @conn.substitute_at(pk, 0).to_sql
646
- binds = [[pk, 1]]
645
+ sub = Arel::Nodes::BindParam.new.to_sql
646
+ binds = [ActiveRecord::Relation::QueryAttribute.new(pk, 1, ActiveRecord::Type::Integer.new)]
647
647
  @conn.exec_update("UPDATE test_posts SET id = #{sub}", "SQL", binds)
648
- }.should change(@statements, :length).by(+1)
648
+ }.to change(@statements, :length).by(+1)
649
649
  end
650
650
 
651
651
  it "should not cache UPDATE statements without bind variables" do
652
- lambda {
652
+ expect {
653
653
  binds = []
654
654
  @conn.exec_update("UPDATE test_posts SET id = 1", "SQL", binds)
655
- }.should_not change(@statements, :length)
655
+ }.not_to change(@statements, :length)
656
656
  end
657
657
  end
658
658
 
@@ -677,16 +677,17 @@ describe "OracleEnhancedAdapter" do
677
677
 
678
678
  it "should explain query" do
679
679
  explain = TestPost.where(:id => 1).explain
680
- explain.should include("Cost")
681
- explain.should include("INDEX UNIQUE SCAN")
680
+ expect(explain).to include("Cost")
681
+ expect(explain).to include("INDEX UNIQUE SCAN")
682
682
  end
683
683
 
684
684
  it "should explain query with binds" do
685
685
  pk = TestPost.columns_hash[TestPost.primary_key]
686
- sub = @conn.substitute_at(pk, 0)
687
- explain = TestPost.where(TestPost.arel_table[pk.name].eq(sub)).bind([pk, 1]).explain
688
- explain.should include("Cost")
689
- explain.should include("INDEX UNIQUE SCAN")
686
+ sub = Arel::Nodes::BindParam.new.to_sql
687
+ binds = [ActiveRecord::Relation::QueryAttribute.new(pk, 1, ActiveRecord::Type::Integer.new)]
688
+ explain = @conn.explain(TestPost.where(TestPost.arel_table[pk.name].eq(sub)), binds)
689
+ expect(explain).to include("Cost")
690
+ expect(explain).to include("INDEX UNIQUE SCAN")
690
691
  end
691
692
  end
692
693
 
@@ -731,65 +732,42 @@ describe "OracleEnhancedAdapter" do
731
732
  end
732
733
 
733
734
  it "should return n records with limit(n)" do
734
- @employee.limit(3).to_a.size.should be(3)
735
+ expect(@employee.limit(3).to_a.size).to be(3)
735
736
  end
736
737
 
737
738
  it "should return less than n records with limit(n) if there exist less than n records" do
738
- @employee.limit(10).to_a.size.should be(5)
739
+ expect(@employee.limit(10).to_a.size).to be(5)
739
740
  end
740
741
 
741
742
  it "should return the records starting from offset n with offset(n)" do
742
- expect(@employee.order(:sort_order).first.first_name.should).to eq("Peter")
743
- expect(@employee.order(:sort_order).offset(0).first.first_name.should).to eq("Peter")
744
- expect(@employee.order(:sort_order).offset(1).first.first_name.should).to eq("Tony")
745
- expect(@employee.order(:sort_order).offset(4).first.first_name.should).to eq("Natasha")
743
+ expect(@employee.order(:sort_order).first.first_name).to eq("Peter")
744
+ expect(@employee.order(:sort_order).offset(0).first.first_name).to eq("Peter")
745
+ expect(@employee.order(:sort_order).offset(1).first.first_name).to eq("Tony")
746
+ expect(@employee.order(:sort_order).offset(4).first.first_name).to eq("Natasha")
746
747
  end
747
748
  end
748
749
 
749
- describe 'serialized column' do
750
-
750
+ describe "valid_type?" do
751
751
  before(:all) do
752
- schema_define do
753
- create_table :test_serialized_columns do |t|
754
- t.text :serialized
755
- end
756
- end
757
- class ::TestSerializedColumn < ActiveRecord::Base
758
- serialize :serialized, Array
759
- end
752
+ @conn = ActiveRecord::Base.connection
753
+ @conn.execute <<-SQL
754
+ CREATE TABLE test_employees (
755
+ first_name VARCHAR2(20)
756
+ )
757
+ SQL
760
758
  end
761
759
 
762
760
  after(:all) do
763
- schema_define do
764
- drop_table :test_serialized_columns
765
- end
766
- Object.send(:remove_const, 'TestSerializedColumn')
767
- ActiveRecord::Base.table_name_prefix = nil
768
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
769
- end
770
-
771
- before(:each) do
772
- set_logger
761
+ @conn.execute "DROP TABLE test_employees"
773
762
  end
774
763
 
775
- after(:each) do
776
- clear_logger
764
+ it "returns true when passed a valid type" do
765
+ column = @conn.columns('test_employees').find { |col| col.name == 'first_name' }
766
+ expect(@conn.valid_type?(column.type)).to be true
777
767
  end
778
768
 
779
- it 'should serialize' do
780
- new_value = 'new_value'
781
- serialized_column = TestSerializedColumn.new
782
-
783
- expect(serialized_column.serialized.should).to eq([])
784
- serialized_column.serialized << new_value
785
- expect(serialized_column.serialized.should).to eq([new_value])
786
- serialized_column.save
787
- expect(serialized_column.save!.should).to eq(true)
788
-
789
- serialized_column.reload
790
- expect(serialized_column.serialized.should).to eq([new_value])
791
- serialized_column.serialized = []
792
- expect(serialized_column.save!.should).to eq(true)
769
+ it "returns false when passed an invalid type" do
770
+ expect(@conn.valid_type?(:foobar)).to be false
793
771
  end
794
772
  end
795
773
  end