activerecord-oracle_enhanced-adapter 1.8.0.beta1 → 1.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -4
  3. data/History.md +30 -0
  4. data/RUNNING_TESTS.md +2 -0
  5. data/VERSION +1 -1
  6. data/activerecord-oracle_enhanced-adapter.gemspec +5 -7
  7. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +1 -1
  8. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +3 -2
  9. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +2 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +4 -2
  11. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +1 -1
  12. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +1 -1
  13. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +39 -49
  14. data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
  15. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +0 -33
  16. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +4 -0
  17. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +55 -0
  18. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -117
  19. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -0
  20. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +0 -1
  21. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +26 -1
  22. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +2 -2
  23. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +2 -2
  24. data/spec/spec_helper.rb +0 -2
  25. metadata +7 -9
  26. data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
  27. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -111
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f1beed345101483212d25e0040e52c3fd04c727
4
- data.tar.gz: 75338dd46c82d721a9d5762e900444ecc41b563f
3
+ metadata.gz: 4a86ef85ec7e673fd5ce17f5c7b3310b556f28a2
4
+ data.tar.gz: 997989db47ecd4c360ae34536309e25b983ad7f7
5
5
  SHA512:
6
- metadata.gz: 821f716a5eb0bed68a572bd2c2e848e8800bedbec6fe2132fcc7bd97fd76e8e9c8d0e630b781deccc196165764afac8fc1ee65d1e5bd6019e2facfc4db2d8511
7
- data.tar.gz: b1bcd32cb0b630b2db83c44dccf398620ff84a6032dc0876d0c38f1cb4993045b57cb6b604498e78f34928d819fc163241aeb2960021876157d4bf6aac53446e
6
+ metadata.gz: 42b2013124fe69b031243f33a5c1f2be3b483259975d593d7b5d4d523988246581df3369baa9e6581fda2c10dd4a90887ecc043cd03ee3f1dc67805f59d0e66b
7
+ data.tar.gz: a08ff57547d9f528d0dce8d6d8f026ba82256d889c1415d142b5df2a18a2e26ccda255af4da40274927d8a0f9b971eb108d363c18f15222bb44d46725444876d
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) do |repo_name|
4
4
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
@@ -10,9 +10,7 @@ group :development do
10
10
  gem "rdoc"
11
11
  gem "rake"
12
12
 
13
- gem "activerecord", github: "rails/rails", branch: "master"
14
- gem "rack", github: "rack/rack", branch: "master"
15
-
13
+ gem "activerecord", github: "rails/rails", branch: "5-1-stable"
16
14
  gem "ruby-plsql", github: "rsim/ruby-plsql", branch: "master"
17
15
 
18
16
  platforms :ruby do
data/History.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## 1.8.0.rc1 / 2017-03-20
2
+
3
+ * Major enhancements
4
+ * Support Rails 5.1.0.rc1
5
+ * Add JSON attribute support #1240
6
+ * Update `database.yml` when `rails new <new_app> -d oracle` specified [rails/rails#28257]
7
+
8
+ * Changes and bug fixes
9
+ * Eliminate a redundant empty lines in schema.rb generated by SchemaDumper [#1232]
10
+ * Align the columns of db/structure.sql [#1242]
11
+ * Use Abstract StatementPool [#1228]
12
+ * Decouple Composite Primary Key code [#1224, #1225]
13
+ * Push `valid_type?` up to abstract adapter [#1208]
14
+ * Oracle12 visitor is also available for 12.2 [#1217]
15
+ * Oracle Database 12c Release 2 bundles new ojdbc8.jar [#1218]
16
+ * Deprecate `supports_migrations?` on connection adapters [#1209]
17
+ * Use `ActiveRecord::SchemaMigration.table_name` [#1221]
18
+ * No need to check if `changed?` defined [#1226]
19
+ * No need to initialize `@quoted_column_names` and `@quoted_table_names` [#1227]
20
+ * Hard code `empty_blob()` or `empty_clob()` based on types [#1229]
21
+ * ruby-plsql 0.6.0 or higher version is required [#1216]
22
+ * No need to specify `rack` in Gemfile [#1230]
23
+ * Bundle from more secure source [#1243]
24
+ * Add Travis CI build status [#1231]
25
+ * Bump JRuby to 9.1.8.0 [#1222]
26
+ * Remove a duplicate spec testing `Model.distinct.count` [#1235]
27
+ * Suppress unused and not initialized warnings [#1215]
28
+ * Suppress `WARNING: Using the `raise_error` matcher without providing a specific error` [#1219]
29
+ * Suppress `WARNING: Using `expect { }.not_to raise_error(...)` risks false positives` [#1220]
30
+
1
31
  ## 1.8.0.beta1 / 2017-02-27
2
32
 
3
33
  * Major enhancements
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/rsim/oracle-enhanced.svg?branch=master)](https://travis-ci.org/rsim/oracle-enhanced)
2
+
1
3
  # When and Which tests need to be executed
2
4
 
3
5
  When you are creating a fix and/or some new features for Oracle enhanced adapter,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0.beta1
1
+ 1.8.0.rc1
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "activerecord-oracle_enhanced-adapter"
3
- s.version = "1.8.0.beta1"
3
+ s.version = "1.8.0.rc1"
4
4
 
5
5
  s.required_rubygems_version = ">= 1.8.11"
6
6
  s.required_ruby_version = ">= 2.2.2"
7
7
  s.license = "MIT"
8
8
  s.authors = ["Raimonds Simanovskis"]
9
- s.date = "2016-12-26"
9
+ s.date = "2017-03-20"
10
10
  s.description = 'Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
11
11
  This adapter is superset of original ActiveRecord Oracle adapter.
12
12
  '
@@ -30,7 +30,6 @@ This adapter is superset of original ActiveRecord Oracle adapter.
30
30
  "lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb",
31
31
  "lib/active_record/connection_adapters/oracle_enhanced/connection.rb",
32
32
  "lib/active_record/connection_adapters/oracle_enhanced/context_index.rb",
33
- "lib/active_record/connection_adapters/oracle_enhanced/cpk.rb",
34
33
  "lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb",
35
34
  "lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb",
36
35
  "lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb",
@@ -48,6 +47,7 @@ This adapter is superset of original ActiveRecord Oracle adapter.
48
47
  "lib/active_record/connection_adapters/oracle_enhanced/version.rb",
49
48
  "lib/active_record/oracle_enhanced/type/boolean.rb",
50
49
  "lib/active_record/oracle_enhanced/type/integer.rb",
50
+ "lib/active_record/oracle_enhanced/type/json.rb",
51
51
  "lib/active_record/oracle_enhanced/type/national_character_string.rb",
52
52
  "lib/active_record/oracle_enhanced/type/raw.rb",
53
53
  "lib/active_record/oracle_enhanced/type/string.rb",
@@ -56,7 +56,6 @@ This adapter is superset of original ActiveRecord Oracle adapter.
56
56
  "spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
57
57
  "spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
58
58
  "spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
59
- "spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
60
59
  "spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb",
61
60
  "spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
62
61
  "spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
@@ -75,7 +74,6 @@ This adapter is superset of original ActiveRecord Oracle adapter.
75
74
  "spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
76
75
  "spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
77
76
  "spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
78
- "spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
79
77
  "spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb",
80
78
  "spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
81
79
  "spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
@@ -87,7 +85,7 @@ This adapter is superset of original ActiveRecord Oracle adapter.
87
85
  "spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb",
88
86
  "spec/spec_helper.rb"
89
87
  ]
90
- s.add_runtime_dependency("activerecord", ["~> 5.1.0.beta"])
88
+ s.add_runtime_dependency("activerecord", ["~> 5.1.0.rc"])
91
89
  s.add_runtime_dependency("arel", ["~> 8.0"])
92
- s.add_runtime_dependency("ruby-plsql")
90
+ s.add_runtime_dependency("ruby-plsql", [">= 0.6.0"])
93
91
  end
@@ -79,7 +79,7 @@ module ActiveRecord
79
79
  # New method in ActiveRecord 3.1
80
80
  # Will add RETURNING clause in case of trigger generated primary keys
81
81
  def sql_for_insert(sql, pk, id_value, sequence_name, binds)
82
- unless id_value || pk == false || pk.nil? || (defined?(CompositePrimaryKeys) && pk.kind_of?(CompositePrimaryKeys::CompositeKeys))
82
+ unless id_value || pk == false || pk.nil? || pk.is_a?(Array)
83
83
  sql = "#{sql} RETURNING #{quote_column_name(pk)} INTO :returning_id"
84
84
  (binds = binds.dup) << ActiveRecord::Relation::QueryAttribute.new("returning_id", nil, ActiveRecord::OracleEnhanced::Type::Integer.new)
85
85
  end
@@ -12,8 +12,9 @@ begin
12
12
  end
13
13
 
14
14
  # Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
15
- # Oracle 12c client provides new ojdbc7.jar
16
- ojdbc_jars = %w(ojdbc7.jar ojdbc6.jar)
15
+ # Oracle 12c Release 1 client provides ojdbc7.jar
16
+ # Oracle 12c Release 2 client provides ojdbc8.jar
17
+ ojdbc_jars = %w(ojdbc8.jar ojdbc7.jar ojdbc6.jar)
17
18
 
18
19
  if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
19
20
  # On Unix environment variable should be PATH, on Windows it is sometimes Path
@@ -89,9 +89,9 @@ module ActiveRecord
89
89
  when ActiveRecord::OracleEnhanced::Type::NationalCharacterString::Data then
90
90
  "N" << "'#{quote_string(value.to_s)}'"
91
91
  when ActiveModel::Type::Binary::Data then
92
- "empty_#{ type_to_sql(column.type.to_sym).downcase rescue 'blob' }()"
92
+ "empty_blob()"
93
93
  when ActiveRecord::OracleEnhanced::Type::Text::Data then
94
- "empty_#{ type_to_sql(column.type.to_sym).downcase rescue 'clob' }()"
94
+ "empty_clob()"
95
95
  else
96
96
  super
97
97
  end
@@ -72,8 +72,10 @@ module ActiveRecord #:nodoc:
72
72
  # unrecognized index type
73
73
  statement_parts = ["# unrecognized index #{index.name.inspect} with type #{index.type.inspect}"]
74
74
  end
75
- " " + statement_parts.join(", ")
76
- end
75
+ " " + statement_parts.join(", ") unless statement_parts.empty?
76
+ end.compact
77
+
78
+ return if add_index_statements.empty?
77
79
 
78
80
  stream.puts add_index_statements.sort.join("\n")
79
81
  stream.puts
@@ -114,7 +114,7 @@ module ActiveRecord
114
114
  end
115
115
 
116
116
  def insert_versions_sql(versions) # :nodoc:
117
- sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
117
+ sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
118
118
 
119
119
  if supports_multi_insert?
120
120
  versions.inject("INSERT ALL\n") { |sql, version|
@@ -28,7 +28,7 @@ module ActiveRecord #:nodoc:
28
28
  structure_dump_column(row)
29
29
  end
30
30
  end
31
- ddl << cols.join(",\n ")
31
+ ddl << cols.map { |col| " #{col}" }.join(",\n")
32
32
  ddl << structure_dump_primary_key(table_name)
33
33
  ddl << "\n)"
34
34
  structure << ddl
@@ -29,6 +29,7 @@
29
29
  # portions Copyright 2005 Graham Jenkins
30
30
 
31
31
  require "active_record/connection_adapters/abstract_adapter"
32
+ require "active_record/connection_adapters/statement_pool"
32
33
  require "active_record/connection_adapters/oracle_enhanced/connection"
33
34
  require "active_record/connection_adapters/oracle_enhanced/database_statements"
34
35
  require "active_record/connection_adapters/oracle_enhanced/schema_statements"
@@ -212,40 +213,17 @@ module ActiveRecord
212
213
  cattr_accessor :use_old_oracle_visitor
213
214
  self.use_old_oracle_visitor = false
214
215
 
215
- class StatementPool
216
- include Enumerable
216
+ class StatementPool < ConnectionAdapters::StatementPool
217
+ private
217
218
 
218
- def initialize(connection, max = 300)
219
- @connection = connection
220
- @max = max
221
- @cache = {}
222
- end
223
-
224
- def each(&block); @cache.each(&block); end
225
- def key?(key); @cache.key?(key); end
226
- def [](key); @cache[key]; end
227
- def length; @cache.length; end
228
- def delete(key); @cache.delete(key); end
229
-
230
- def []=(sql, key)
231
- while @max <= @cache.size
232
- @cache.shift.last.close
219
+ def dealloc(stmt)
220
+ stmt.close
233
221
  end
234
- @cache[sql] = key
235
- end
236
-
237
- def clear
238
- @cache.values.each do |cursor|
239
- cursor.close
240
- end
241
- @cache.clear
242
- end
243
222
  end
244
223
 
245
224
  def initialize(connection, logger = nil, config = {}) # :nodoc:
246
225
  super(connection, logger, config)
247
- @quoted_column_names, @quoted_table_names = {}, {}
248
- @statements = StatementPool.new(connection, config.fetch(:statement_limit) { 250 })
226
+ @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
249
227
  @enable_dbms_output = false
250
228
  end
251
229
 
@@ -263,10 +241,6 @@ module ActiveRecord
263
241
  end
264
242
  end
265
243
 
266
- def supports_migrations? #:nodoc:
267
- true
268
- end
269
-
270
244
  def supports_savepoints? #:nodoc:
271
245
  true
272
246
  end
@@ -288,7 +262,7 @@ module ActiveRecord
288
262
  end
289
263
 
290
264
  def supports_fetch_first_n_rows_and_offset?
291
- if !use_old_oracle_visitor && @connection.database_version == [12, 1]
265
+ if !use_old_oracle_visitor && @connection.database_version.first >= 12
292
266
  true
293
267
  else
294
268
  false
@@ -311,6 +285,32 @@ module ActiveRecord
311
285
  @connection.database_version.first >= 11
312
286
  end
313
287
 
288
+ def supports_json?
289
+ # No migration supported for :json type due to there is no `JSON` data type
290
+ # in Oracle Database itself.
291
+ #
292
+ # 1.Define :string or :text in migration
293
+ #
294
+ # create_table :test_posts, force: true do |t|
295
+ # t.string :title
296
+ # t.text :article
297
+ # end
298
+ #
299
+ # 2. Set :json attributes
300
+ #
301
+ # class TestPost < ActiveRecord::Base
302
+ # attribute :title, :json
303
+ # attribute :article, :json
304
+ # end
305
+ #
306
+ # 3. Add `is json` database constraints by running sql statements
307
+ #
308
+ # alter table test_posts add constraint test_posts_title_is_json check (title is json)
309
+ # alter table test_posts add constraint test_posts_article_is_json check (article is json)
310
+ #
311
+ @connection.database_version.first >= 12
312
+ end
313
+
314
314
  #:stopdoc:
315
315
  DEFAULT_NLS_PARAMETERS = {
316
316
  nls_calendar: nil,
@@ -517,13 +517,7 @@ module ActiveRecord
517
517
 
518
518
  # Writes LOB values from attributes for specified columns
519
519
  def write_lobs(table_name, klass, attributes, columns) #:nodoc:
520
- # is class with composite primary key>
521
- is_with_cpk = klass.respond_to?(:composite?) && klass.composite?
522
- if is_with_cpk
523
- id = klass.primary_key.map { |pk| attributes[pk.to_s] }
524
- else
525
- id = quote(attributes[klass.primary_key])
526
- end
520
+ id = quote(attributes[klass.primary_key])
527
521
  columns.each do |col|
528
522
  value = attributes[col.name]
529
523
  # changed sequence of next two lines - should check if value is nil before converting to yaml
@@ -532,8 +526,7 @@ module ActiveRecord
532
526
  value = klass.attribute_types[col.name].serialize(value)
533
527
  end
534
528
  uncached do
535
- sql = is_with_cpk ? "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{klass.composite_where_clause(id)} FOR UPDATE" :
536
- "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE"
529
+ sql = "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE"
537
530
  unless lob_record = select_one(sql, "Writable Large Object")
538
531
  raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
539
532
  end
@@ -919,10 +912,6 @@ module ActiveRecord
919
912
  select_value("SELECT temporary FROM all_tables WHERE table_name = '#{table_name.upcase}' and owner = SYS_CONTEXT('userenv', 'session_user')") == "Y"
920
913
  end
921
914
 
922
- def valid_type?(type)
923
- !native_database_types[type].nil?
924
- end
925
-
926
915
  def combine_bind_parameters(
927
916
  from_clause: [],
928
917
  join_clause: [],
@@ -1080,9 +1069,6 @@ require "active_record/connection_adapters/oracle_enhanced/schema_definitions"
1080
1069
  # Extensions for context index definition
1081
1070
  require "active_record/connection_adapters/oracle_enhanced/context_index"
1082
1071
 
1083
- # Load additional methods for composite_primary_keys support
1084
- require "active_record/connection_adapters/oracle_enhanced/cpk"
1085
-
1086
1072
  # Patches and enhancements for schema dumper
1087
1073
  require "active_record/connection_adapters/oracle_enhanced/schema_dumper"
1088
1074
 
@@ -1124,3 +1110,7 @@ require "active_record/oracle_enhanced/type/boolean"
1124
1110
 
1125
1111
  # To use :boolean type for Attribute API, each type needs registered explicitly.
1126
1112
  ActiveRecord::Type.register(:boolean, ActiveRecord::OracleEnhanced::Type::Boolean, adapter: :oracleenhanced)
1113
+
1114
+ # Add JSON attribute support
1115
+ require "active_record/oracle_enhanced/type/json"
1116
+ ActiveRecord::Type.register(:json, ActiveRecord::OracleEnhanced::Type::Json, adapter: :oracleenhanced)
@@ -0,0 +1,8 @@
1
+ module ActiveRecord
2
+ module OracleEnhanced
3
+ module Type
4
+ class Json < ActiveRecord::Type::Internal::AbstractJson
5
+ end
6
+ end
7
+ end
8
+ end
@@ -177,39 +177,6 @@ describe "OracleEnhancedAdapter" do
177
177
 
178
178
  end
179
179
 
180
- describe "without composite_primary_keys" do
181
-
182
- before(:all) do
183
- @conn = ActiveRecord::Base.connection
184
- @conn.execute "DROP TABLE test_employees" rescue nil
185
- @conn.execute <<-SQL
186
- CREATE TABLE test_employees (
187
- employee_id NUMBER PRIMARY KEY,
188
- name VARCHAR2(50)
189
- )
190
- SQL
191
- Object.send(:remove_const, "CompositePrimaryKeys") if defined?(CompositePrimaryKeys)
192
- class ::TestEmployee < ActiveRecord::Base
193
- self.primary_key = :employee_id
194
- end
195
- end
196
-
197
- after(:all) do
198
- Object.send(:remove_const, "TestEmployee")
199
- @conn.execute "DROP TABLE test_employees"
200
- ActiveRecord::Base.clear_cache!
201
- end
202
-
203
- it "should tell ActiveRecord that count distinct is supported" do
204
- expect(ActiveRecord::Base.connection.supports_count_distinct?).to be_truthy
205
- end
206
-
207
- it "should execute correct SQL COUNT DISTINCT statement" do
208
- expect { TestEmployee.distinct.count(:employee_id) }.not_to raise_error
209
- end
210
-
211
- end
212
-
213
180
  describe "reserved words column quoting" do
214
181
 
215
182
  before(:all) do
@@ -78,6 +78,10 @@ describe "OracleEnhancedAdapter context index" do
78
78
  ActiveRecord::Base.clear_cache!
79
79
  end
80
80
 
81
+ before(:each) do
82
+ @post = nil
83
+ end
84
+
81
85
  after(:each) do
82
86
  @post.destroy if @post
83
87
  end
@@ -1346,3 +1346,58 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
1346
1346
  expect(column.type).to eq(:float)
1347
1347
  end
1348
1348
  end
1349
+
1350
+ describe "OracleEnhancedAdapter attribute API support for JSON type" do
1351
+
1352
+ include SchemaSpecHelper
1353
+
1354
+ before(:each) do
1355
+ @conn = ActiveRecord::Base.connection
1356
+ @oracle12c_or_higher = !! @conn.select_value(
1357
+ "select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 12")
1358
+ skip "Not supported in this database version" unless @oracle12c_or_higher
1359
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
1360
+ schema_define do
1361
+ create_table :test_posts, force: true do |t|
1362
+ t.string :title
1363
+ t.text :article
1364
+ end
1365
+ end
1366
+ @conn.execute <<-SQL
1367
+ alter table test_posts add constraint test_posts_title_is_json check (title is json)
1368
+ SQL
1369
+ @conn.execute <<-SQL
1370
+ alter table test_posts add constraint test_posts_article_is_json check (article is json)
1371
+ SQL
1372
+
1373
+ class TestPost < ActiveRecord::Base
1374
+ attribute :title, :json
1375
+ attribute :article, :json
1376
+ end
1377
+ end
1378
+
1379
+ after(:each) do
1380
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
1381
+ schema_define do
1382
+ drop_table :test_posts, if_exists: true
1383
+ end
1384
+ end
1385
+
1386
+ it "should support attribute api for JSON" do
1387
+ post = TestPost.create!(title: { "publish" => true, "foo" => "bar" }, article: { "bar" => "baz" })
1388
+ post.reload
1389
+ expect(post.title).to eq ({ "publish" => true, "foo" => "bar" })
1390
+ expect(post.article).to eq ({ "bar" => "baz" })
1391
+ post.title = ({ "publish" => false, "foo" => "bar2" })
1392
+ post.save
1393
+ expect(post.reload.title).to eq ({ "publish" => false, "foo" => "bar2" })
1394
+ end
1395
+
1396
+ it "should support IS JSON" do
1397
+ post = TestPost.create!(title: { "publish" => true, "foo" => "bar" })
1398
+ count_json = TestPost.where("title is json")
1399
+ expect(count_json.size).to eq 1
1400
+ count_non_json = TestPost.where("title is not json")
1401
+ expect(count_non_json.size).to eq 0
1402
+ end
1403
+ end
@@ -1,139 +1,137 @@
1
- if ActiveRecord::Base.method_defined?(:changed?)
2
-
3
- describe "OracleEnhancedAdapter dirty object tracking" do
4
- include SchemaSpecHelper
5
-
6
- before(:all) do
7
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
- schema_define do
9
- create_table :test_employees, force: true do |t|
10
- t.string :first_name, limit: 20
11
- t.string :last_name, limit: 25
12
- t.integer :job_id, limit: 6, null: true
13
- t.decimal :salary, precision: 8, scale: 2
14
- t.text :comments
15
- t.date :hire_date
16
- end
17
- end
18
-
19
- class TestEmployee < ActiveRecord::Base
1
+ describe "OracleEnhancedAdapter dirty object tracking" do
2
+ include SchemaSpecHelper
3
+
4
+ before(:all) do
5
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
6
+ schema_define do
7
+ create_table :test_employees, force: true do |t|
8
+ t.string :first_name, limit: 20
9
+ t.string :last_name, limit: 25
10
+ t.integer :job_id, limit: 6, null: true
11
+ t.decimal :salary, precision: 8, scale: 2
12
+ t.text :comments
13
+ t.date :hire_date
20
14
  end
21
15
  end
22
16
 
23
- after(:all) do
24
- schema_define do
25
- drop_table :test_employees
26
- end
27
- Object.send(:remove_const, "TestEmployee")
28
- ActiveRecord::Base.clear_cache!
17
+ class TestEmployee < ActiveRecord::Base
29
18
  end
19
+ end
30
20
 
31
- it "should not mark empty string (stored as NULL) as changed when reassigning it" do
32
- @employee = TestEmployee.create!(first_name: "")
33
- @employee.first_name = ""
34
- expect(@employee).not_to be_changed
35
- @employee.reload
36
- @employee.first_name = ""
37
- expect(@employee).not_to be_changed
21
+ after(:all) do
22
+ schema_define do
23
+ drop_table :test_employees
38
24
  end
25
+ Object.send(:remove_const, "TestEmployee")
26
+ ActiveRecord::Base.clear_cache!
27
+ end
39
28
 
40
- it "should not mark empty integer (stored as NULL) as changed when reassigning it" do
41
- @employee = TestEmployee.create!(job_id: "")
42
- @employee.job_id = ""
43
- expect(@employee).not_to be_changed
44
- @employee.reload
45
- @employee.job_id = ""
46
- expect(@employee).not_to be_changed
47
- end
29
+ it "should not mark empty string (stored as NULL) as changed when reassigning it" do
30
+ @employee = TestEmployee.create!(first_name: "")
31
+ @employee.first_name = ""
32
+ expect(@employee).not_to be_changed
33
+ @employee.reload
34
+ @employee.first_name = ""
35
+ expect(@employee).not_to be_changed
36
+ end
48
37
 
49
- it "should not mark empty decimal (stored as NULL) as changed when reassigning it" do
50
- @employee = TestEmployee.create!(salary: "")
51
- @employee.salary = ""
52
- expect(@employee).not_to be_changed
53
- @employee.reload
54
- @employee.salary = ""
55
- expect(@employee).not_to be_changed
56
- end
38
+ it "should not mark empty integer (stored as NULL) as changed when reassigning it" do
39
+ @employee = TestEmployee.create!(job_id: "")
40
+ @employee.job_id = ""
41
+ expect(@employee).not_to be_changed
42
+ @employee.reload
43
+ @employee.job_id = ""
44
+ expect(@employee).not_to be_changed
45
+ end
57
46
 
58
- it "should not mark empty text (stored as NULL) as changed when reassigning it" do
59
- @employee = TestEmployee.create!(comments: nil)
60
- @employee.comments = nil
61
- expect(@employee).not_to be_changed
62
- @employee.reload
63
- @employee.comments = nil
64
- expect(@employee).not_to be_changed
65
- end
47
+ it "should not mark empty decimal (stored as NULL) as changed when reassigning it" do
48
+ @employee = TestEmployee.create!(salary: "")
49
+ @employee.salary = ""
50
+ expect(@employee).not_to be_changed
51
+ @employee.reload
52
+ @employee.salary = ""
53
+ expect(@employee).not_to be_changed
54
+ end
66
55
 
67
- it "should not mark empty text (stored as empty_clob()) as changed when reassigning it" do
68
- @employee = TestEmployee.create!(comments: "")
69
- @employee.comments = ""
70
- expect(@employee).not_to be_changed
71
- @employee.reload
72
- @employee.comments = ""
73
- expect(@employee).not_to be_changed
74
- end
56
+ it "should not mark empty text (stored as NULL) as changed when reassigning it" do
57
+ @employee = TestEmployee.create!(comments: nil)
58
+ @employee.comments = nil
59
+ expect(@employee).not_to be_changed
60
+ @employee.reload
61
+ @employee.comments = nil
62
+ expect(@employee).not_to be_changed
63
+ end
75
64
 
76
- it "should mark empty text (stored as empty_clob()) as changed when assigning nil to it" do
77
- @employee = TestEmployee.create!(comments: "")
78
- @employee.comments = nil
79
- expect(@employee).to be_changed
80
- @employee.reload
81
- @employee.comments = nil
82
- expect(@employee).to be_changed
83
- end
65
+ it "should not mark empty text (stored as empty_clob()) as changed when reassigning it" do
66
+ @employee = TestEmployee.create!(comments: "")
67
+ @employee.comments = ""
68
+ expect(@employee).not_to be_changed
69
+ @employee.reload
70
+ @employee.comments = ""
71
+ expect(@employee).not_to be_changed
72
+ end
84
73
 
85
- it "should mark empty text (stored as NULL) as changed when assigning '' to it" do
86
- @employee = TestEmployee.create!(comments: nil)
87
- @employee.comments = ""
88
- expect(@employee).to be_changed
89
- @employee.reload
90
- @employee.comments = ""
91
- expect(@employee).to be_changed
92
- end
74
+ it "should mark empty text (stored as empty_clob()) as changed when assigning nil to it" do
75
+ @employee = TestEmployee.create!(comments: "")
76
+ @employee.comments = nil
77
+ expect(@employee).to be_changed
78
+ @employee.reload
79
+ @employee.comments = nil
80
+ expect(@employee).to be_changed
81
+ end
93
82
 
94
- it "should not mark empty date (stored as NULL) as changed when reassigning it" do
95
- @employee = TestEmployee.create!(hire_date: "")
96
- @employee.hire_date = ""
97
- expect(@employee).not_to be_changed
98
- @employee.reload
99
- @employee.hire_date = ""
100
- expect(@employee).not_to be_changed
101
- end
83
+ it "should mark empty text (stored as NULL) as changed when assigning '' to it" do
84
+ @employee = TestEmployee.create!(comments: nil)
85
+ @employee.comments = ""
86
+ expect(@employee).to be_changed
87
+ @employee.reload
88
+ @employee.comments = ""
89
+ expect(@employee).to be_changed
90
+ end
102
91
 
103
- it "should not mark integer as changed when reassigning it" do
104
- @employee = TestEmployee.new
105
- @employee.job_id = 0
106
- expect(@employee.save!).to be_truthy
92
+ it "should not mark empty date (stored as NULL) as changed when reassigning it" do
93
+ @employee = TestEmployee.create!(hire_date: "")
94
+ @employee.hire_date = ""
95
+ expect(@employee).not_to be_changed
96
+ @employee.reload
97
+ @employee.hire_date = ""
98
+ expect(@employee).not_to be_changed
99
+ end
107
100
 
108
- expect(@employee).not_to be_changed
101
+ it "should not mark integer as changed when reassigning it" do
102
+ @employee = TestEmployee.new
103
+ @employee.job_id = 0
104
+ expect(@employee.save!).to be_truthy
109
105
 
110
- @employee.job_id = "0"
111
- expect(@employee).not_to be_changed
112
- end
106
+ expect(@employee).not_to be_changed
113
107
 
114
- it "should not update unchanged CLOBs" do
115
- @employee = TestEmployee.create!(
116
- comments: "initial"
117
- )
118
- expect(@employee.save!).to be_truthy
119
- @employee.reload
120
- expect(@employee.comments).to eq("initial")
121
-
122
- oci_conn = @conn.instance_variable_get("@connection")
123
- class << oci_conn
124
- def write_lob(lob, value, is_binary = false); raise "don't do this'"; end
125
- end
126
- expect { @employee.save! }.not_to raise_exception(RuntimeError, "don't do this'")
127
- class << oci_conn
128
- remove_method :write_lob
129
- end
130
- end
108
+ @employee.job_id = "0"
109
+ expect(@employee).not_to be_changed
110
+ end
131
111
 
132
- it "should be able to handle attributes which are not backed by a column" do
133
- TestEmployee.create!(comments: "initial")
134
- @employee = TestEmployee.select("#{TestEmployee.quoted_table_name}.*, 24 ranking").first
135
- expect { @employee.ranking = 25 }.to_not raise_error
112
+ it "should not update unchanged CLOBs" do
113
+ @conn = nil
114
+ @connection = nil
115
+ @employee = TestEmployee.create!(
116
+ comments: "initial"
117
+ )
118
+ expect(@employee.save!).to be_truthy
119
+ @employee.reload
120
+ expect(@employee.comments).to eq("initial")
121
+
122
+ oci_conn = @conn.instance_variable_get("@connection")
123
+ class << oci_conn
124
+ def write_lob(lob, value, is_binary = false); raise "don't do this'"; end
125
+ end
126
+ expect { @employee.save! }.not_to raise_error
127
+ class << oci_conn
128
+ remove_method :write_lob
136
129
  end
137
130
  end
138
131
 
132
+ it "should be able to handle attributes which are not backed by a column" do
133
+ TestEmployee.create!(comments: "initial")
134
+ @employee = TestEmployee.select("#{TestEmployee.quoted_table_name}.*, 24 ranking").first
135
+ expect { @employee.ranking = 25 }.to_not raise_error
136
+ end
139
137
  end
@@ -1,6 +1,7 @@
1
1
  describe "OracleEnhancedAdapter emulate OracleAdapter" do
2
2
 
3
3
  before(:all) do
4
+ @old_oracle_adapter = nil
4
5
  if defined?(ActiveRecord::ConnectionAdapters::OracleAdapter)
5
6
  @old_oracle_adapter = ActiveRecord::ConnectionAdapters::OracleAdapter
6
7
  ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
@@ -210,7 +210,6 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
210
210
  hire_date: @today,
211
211
  description: "description"
212
212
  )
213
- empl_id = @employee.id
214
213
  @employee.reload
215
214
  @employee.first_name = "Second"
216
215
  expect {
@@ -74,7 +74,7 @@ describe "OracleEnhancedAdapter schema dump" do
74
74
  describe "table prefixes and suffixes" do
75
75
  after(:each) do
76
76
  drop_test_posts_table
77
- @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
77
+ @conn.drop_table(ActiveRecord::SchemaMigration.table_name) if @conn.table_exists?(ActiveRecord::SchemaMigration.table_name)
78
78
  @conn.drop_table(ActiveRecord::InternalMetadata.table_name) if @conn.table_exists?(ActiveRecord::InternalMetadata.table_name)
79
79
  ActiveRecord::Base.table_name_prefix = ""
80
80
  ActiveRecord::Base.table_name_suffix = ""
@@ -493,4 +493,29 @@ describe "OracleEnhancedAdapter schema dump" do
493
493
  end
494
494
  end
495
495
 
496
+ describe "schema.rb format" do
497
+ before do
498
+ create_test_posts_table
499
+
500
+ schema_define do
501
+ create_table :test_comments, force: true do |t|
502
+ t.string :title
503
+ end
504
+
505
+ add_index :test_comments, :title
506
+ end
507
+ end
508
+
509
+ it "should be only one blank line between create_table methods in schema dump" do
510
+ expect(standard_dump).to match(/end\n\n create_table/)
511
+ end
512
+
513
+ after do
514
+ schema_define do
515
+ drop_table :test_comments rescue nil
516
+ end
517
+
518
+ drop_test_posts_table
519
+ end
520
+ end
496
521
  end
@@ -214,7 +214,7 @@ describe "OracleEnhancedAdapter schema definition" do
214
214
  it "should not generate NoMethodError for :returning_id:Symbol" do
215
215
  set_logger
216
216
  @conn.reconnect! unless @conn.active?
217
- insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
217
+ @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
218
218
  expect(@logger.output(:error)).not_to match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
219
219
  clear_logger
220
220
  end
@@ -1107,7 +1107,7 @@ end
1107
1107
  t.virtual :field2
1108
1108
  end
1109
1109
  end
1110
- }.to raise_error
1110
+ }.to raise_error(RuntimeError, "No virtual column definition found.")
1111
1111
  end
1112
1112
  end
1113
1113
 
@@ -147,7 +147,7 @@ describe "OracleEnhancedAdapter structure dump" do
147
147
  )
148
148
  SQL
149
149
  dump = ActiveRecord::Base.connection.structure_dump
150
- expect(dump).to match(/CREATE TABLE \"BARS\" \(\n\"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\) GENERATED ALWAYS AS \(HEXTORAW\(TO_CHAR\(ID\)\)\) VIRTUAL/)
150
+ expect(dump).to match(/CREATE TABLE \"BARS\" \(\n \"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\) GENERATED ALWAYS AS \(HEXTORAW\(TO_CHAR\(ID\)\)\) VIRTUAL/)
151
151
  end
152
152
 
153
153
  it "should dump unique keys" do
@@ -198,7 +198,7 @@ describe "OracleEnhancedAdapter structure dump" do
198
198
  )
199
199
  SQL
200
200
  dump = ActiveRecord::Base.connection.structure_dump
201
- expect(dump).to match(/CREATE TABLE \"BARS\" \(\n\"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\)/)
201
+ expect(dump).to match(/CREATE TABLE \"BARS\" \(\n \"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\)/)
202
202
  end
203
203
 
204
204
  it "should dump table comments" do
@@ -24,8 +24,6 @@ elsif RUBY_ENGINE == "jruby"
24
24
  puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
25
25
  end
26
26
 
27
- NO_COMPOSITE_PRIMARY_KEYS = true
28
-
29
27
  require "active_record"
30
28
 
31
29
  require "active_support/core_ext/module/attribute_accessors"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-oracle_enhanced-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0.beta1
4
+ version: 1.8.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.0.beta
19
+ version: 5.1.0.rc
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.0.beta
26
+ version: 5.1.0.rc
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: arel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.6.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.6.0
55
55
  description: |
56
56
  Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
57
57
  This adapter is superset of original ActiveRecord Oracle adapter.
@@ -75,7 +75,6 @@ files:
75
75
  - lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb
76
76
  - lib/active_record/connection_adapters/oracle_enhanced/connection.rb
77
77
  - lib/active_record/connection_adapters/oracle_enhanced/context_index.rb
78
- - lib/active_record/connection_adapters/oracle_enhanced/cpk.rb
79
78
  - lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb
80
79
  - lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb
81
80
  - lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb
@@ -94,6 +93,7 @@ files:
94
93
  - lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
95
94
  - lib/active_record/oracle_enhanced/type/boolean.rb
96
95
  - lib/active_record/oracle_enhanced/type/integer.rb
96
+ - lib/active_record/oracle_enhanced/type/json.rb
97
97
  - lib/active_record/oracle_enhanced/type/national_character_string.rb
98
98
  - lib/active_record/oracle_enhanced/type/raw.rb
99
99
  - lib/active_record/oracle_enhanced/type/string.rb
@@ -102,7 +102,6 @@ files:
102
102
  - spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb
103
103
  - spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb
104
104
  - spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb
105
- - spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb
106
105
  - spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb
107
106
  - spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb
108
107
  - spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb
@@ -141,7 +140,6 @@ test_files:
141
140
  - spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb
142
141
  - spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb
143
142
  - spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb
144
- - spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb
145
143
  - spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb
146
144
  - spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb
147
145
  - spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb
@@ -1,19 +0,0 @@
1
- module ActiveRecord #:nodoc:
2
- module ConnectionAdapters #:nodoc:
3
- module OracleEnhancedCpk #:nodoc:
4
- # This mightn't be in Core, but count(distinct x,y) doesn't work for me.
5
- # Return that not supported if composite_primary_keys gem is required.
6
- def supports_count_distinct? #:nodoc:
7
- @supports_count_distinct ||= ! defined?(CompositePrimaryKeys)
8
- end
9
-
10
- def concat(*columns) #:nodoc:
11
- "(#{columns.join('||')})"
12
- end
13
- end
14
- end
15
- end
16
-
17
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
18
- include ActiveRecord::ConnectionAdapters::OracleEnhancedCpk
19
- end
@@ -1,111 +0,0 @@
1
- unless defined?(NO_COMPOSITE_PRIMARY_KEYS)
2
-
3
- describe "OracleEnhancedAdapter composite_primary_keys support" do
4
- include SchemaSpecHelper
5
-
6
- before(:all) do
7
- if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
8
- @old_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
9
- ::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
10
- end
11
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
12
- if $cpk_oracle_adapter
13
- ::ActiveRecord::ConnectionAdapters::OracleAdapter = $cpk_oracle_adapter
14
- $cpk_oracle_adapter = nil
15
- end
16
- require "composite_primary_keys"
17
- end
18
-
19
- after(:all) do
20
- # Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
21
- if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
22
- $cpk_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
23
- ::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
24
- end
25
- if @old_oracle_adapter
26
- ::ActiveRecord::ConnectionAdapters::OracleAdapter = @old_oracle_adapter
27
- @old_oracle_adapter = nil
28
- end
29
- end
30
-
31
- describe "do not use count distinct" do
32
- before(:all) do
33
- schema_define do
34
- create_table :job_history, primary_key: [:employee_id, :start_date], force: true do |t|
35
- t.integer :employee_id
36
- t.date :start_date
37
- end
38
- end
39
- class ::JobHistory < ActiveRecord::Base
40
- set_table_name "job_history"
41
- set_primary_keys :employee_id, :start_date
42
- end
43
- end
44
-
45
- after(:all) do
46
- Object.send(:remove_const, "JobHistory") if defined?(JobHistory)
47
- schema_define do
48
- drop_table :job_history
49
- end
50
- end
51
-
52
- it "should tell ActiveRecord that count distinct is not supported" do
53
- expect(ActiveRecord::Base.connection.supports_count_distinct?).to be_falsey
54
- end
55
-
56
- it "should execute correct SQL COUNT DISTINCT statement on table with composite primary keys" do
57
- expect { JobHistory.count(distinct: true) }.not_to raise_error
58
- end
59
- end
60
-
61
- describe "table with LOB" do
62
- before(:all) do
63
- schema_define do
64
- create_table :cpk_write_lobs_test, primary_key: [:type_category, :date_value], force: true do |t|
65
- t.string :type_category, limit: 15, null: false
66
- t.date :date_value, null: false
67
- t.text :results, null: false
68
- t.timestamps null: true
69
- end
70
- create_table :non_cpk_write_lobs_test, force: true do |t|
71
- t.date :date_value, null: false
72
- t.text :results, null: false
73
- t.timestamps null: true
74
- end
75
- end
76
- class ::CpkWriteLobsTest < ActiveRecord::Base
77
- set_table_name "cpk_write_lobs_test"
78
- set_primary_keys :type_category, :date_value
79
- end
80
- class ::NonCpkWriteLobsTest < ActiveRecord::Base
81
- set_table_name "non_cpk_write_lobs_test"
82
- end
83
- end
84
-
85
- after(:all) do
86
- schema_define do
87
- drop_table :cpk_write_lobs_test
88
- drop_table :non_cpk_write_lobs_test
89
- end
90
- Object.send(:remove_const, "CpkWriteLobsTest")
91
- Object.send(:remove_const, "NonCpkWriteLobsTest")
92
- end
93
-
94
- it "should create new record in table with CPK and LOB" do
95
- expect {
96
- CpkWriteLobsTest.create(type_category: "AAA", date_value: Date.today, results: "DATA " * 10)
97
- }.not_to raise_error
98
- end
99
-
100
- it "should create new record in table without CPK and with LOB" do
101
- expect {
102
- NonCpkWriteLobsTest.create(date_value: Date.today, results: "DATA " * 10)
103
- }.not_to raise_error
104
- end
105
- end
106
-
107
- # Other testing was done based on composite_primary_keys tests
108
-
109
- end
110
-
111
- end