activerecord-nulldb-adapter 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +2 -2
- data/Gemfile +1 -1
- data/README.rdoc +7 -1
- data/activerecord-nulldb-adapter.gemspec +1 -2
- data/lib/active_record/connection_adapters/nulldb_adapter/core.rb +14 -73
- data/lib/nulldb/core.rb +0 -3
- data/lib/nulldb/version.rb +1 -1
- data/spec/nulldb_spec.rb +4 -11
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 254fde2f4454fe03090b46daf27fffaf379db4cbca87f2a8b83f87fbd4182b74
|
4
|
+
data.tar.gz: 9c2d2ddd16aecba5ed25445876184e46b9ea6acdaeef734d0846c60dead3fedb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a4477a9f589407ec410326114dca64ed342c3be15579a3f5c2467d7ed030521dad205882e48e0cb8d4e6923256baaf9ad13dd479b2f059884c52fc4c55f05f
|
7
|
+
data.tar.gz: 434f119afe4c40c0824a7e62f48e6397103b5988fc70e692f5abef18bd33082b81e591b94641b928551e8ddf778cf47f465367d184c06392c0b66f317cf8e319
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -46,11 +46,17 @@ RAILS_ROOT/db/schema.rb. You can override that by setting the
|
|
46
46
|
|
47
47
|
NullDB comes with RSpec integration. To replace the database with
|
48
48
|
NullDB in all of your specs, put the following in your
|
49
|
-
spec/
|
49
|
+
spec/rails_helper:
|
50
50
|
|
51
51
|
require 'nulldb_rspec'
|
52
52
|
include NullDB::RSpec::NullifiedDatabase
|
53
53
|
|
54
|
+
after you load your rails environment
|
55
|
+
|
56
|
+
require File.expand_path('../config/environment', __dir__)
|
57
|
+
|
58
|
+
otherwise you will encounter issues such as (bug)[https://github.com/nulldb/nulldb/pull/90#issuecomment-496690958].
|
59
|
+
|
54
60
|
Or if you just want to use NullDB in a specific spec context, you can
|
55
61
|
include the same module inside a context:
|
56
62
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.homepage = "https://github.com/nulldb/nulldb"
|
21
21
|
s.licenses = ["MIT"]
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'activerecord', '>= 5.2.0'
|
23
|
+
s.add_runtime_dependency 'activerecord', '>= 5.2.0', '< 6.1'
|
24
24
|
s.add_development_dependency 'spec'
|
25
25
|
s.add_development_dependency 'rdoc'
|
26
26
|
s.add_development_dependency 'rspec'
|
@@ -28,4 +28,3 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency 'appraisal'
|
29
29
|
s.add_development_dependency 'simplecov'
|
30
30
|
end
|
31
|
-
|
@@ -34,8 +34,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
34
34
|
self.class.const_get(config[:table_definition_class_name]))
|
35
35
|
end
|
36
36
|
|
37
|
-
register_types
|
38
|
-
ActiveRecord::VERSION::MAJOR < 4
|
37
|
+
register_types
|
39
38
|
end
|
40
39
|
|
41
40
|
# A log of every statement that has been "executed" by this connection adapter
|
@@ -95,38 +94,6 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
95
94
|
index = @indexes[table_name].reject! { |index| index.name == index_name }
|
96
95
|
end
|
97
96
|
|
98
|
-
unless instance_methods.include? :add_index_options
|
99
|
-
def add_index_options(table_name, column_name, options = {})
|
100
|
-
column_names = Array.wrap(column_name)
|
101
|
-
index_name = index_name(table_name, :column => column_names)
|
102
|
-
|
103
|
-
if Hash === options # legacy support, since this param was a string
|
104
|
-
index_type = options[:unique] ? "UNIQUE" : ""
|
105
|
-
index_name = options[:name].to_s if options.key?(:name)
|
106
|
-
else
|
107
|
-
index_type = options
|
108
|
-
end
|
109
|
-
|
110
|
-
if index_name.length > index_name_length
|
111
|
-
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
|
112
|
-
end
|
113
|
-
if index_name_exists?(table_name, index_name, false)
|
114
|
-
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
115
|
-
end
|
116
|
-
index_columns = quoted_columns_for_index(column_names, options).join(", ")
|
117
|
-
|
118
|
-
[index_name, index_type, index_columns]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
unless instance_methods.include? :index_name_exists?
|
123
|
-
def index_name_exists?(table_name, index_name, default)
|
124
|
-
return default unless respond_to?(:indexes)
|
125
|
-
index_name = index_name.to_s
|
126
|
-
indexes(table_name).detect { |i| i.name == index_name }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
97
|
def add_fk_constraint(*args)
|
131
98
|
# NOOP
|
132
99
|
end
|
@@ -334,10 +301,6 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
334
301
|
TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
|
335
302
|
when 5
|
336
303
|
TableDefinition.new(table_name, is_temporary, options.except(:id), nil)
|
337
|
-
when 4
|
338
|
-
TableDefinition.new(native_database_types, table_name, is_temporary, options)
|
339
|
-
when 2,3
|
340
|
-
TableDefinition.new(adapter)
|
341
304
|
else
|
342
305
|
raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
|
343
306
|
end
|
@@ -352,8 +315,6 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
352
315
|
if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
|
353
316
|
meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
|
354
317
|
args.insert(2, meta_with_limit!(meta, col_def))
|
355
|
-
elsif initialize_column_with_cast_type?
|
356
|
-
args.insert(2, meta_with_limit!(lookup_cast_type(col_def.type), col_def))
|
357
318
|
else
|
358
319
|
args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
|
359
320
|
end
|
@@ -366,44 +327,24 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
366
327
|
end
|
367
328
|
|
368
329
|
def default_column_arguments(col_def)
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
]
|
375
|
-
else
|
376
|
-
[
|
377
|
-
col_def.name.to_s,
|
378
|
-
col_def.default,
|
379
|
-
col_def.type,
|
380
|
-
col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
|
381
|
-
]
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
def initialize_column_with_cast_type?
|
386
|
-
::ActiveRecord::VERSION::MAJOR == 4 && ::ActiveRecord::VERSION::MINOR >= 2
|
330
|
+
[
|
331
|
+
col_def.name.to_s,
|
332
|
+
col_def.default,
|
333
|
+
col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
|
334
|
+
]
|
387
335
|
end
|
388
336
|
|
389
337
|
def initialize_args
|
390
|
-
|
391
|
-
[nil, @logger]
|
338
|
+
[nil, @logger, @config]
|
392
339
|
end
|
393
340
|
|
394
|
-
# 4.2 introduced ActiveRecord::Type
|
395
|
-
# https://github.com/rails/rails/tree/4-2-stable/activerecord/lib/active_record
|
396
341
|
def register_types
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
adapter: adapter_name,
|
405
|
-
override: true
|
406
|
-
)
|
407
|
-
end
|
342
|
+
require 'active_model/type'
|
343
|
+
ActiveRecord::Type.register(
|
344
|
+
:primary_key,
|
345
|
+
ActiveModel::Type::Integer,
|
346
|
+
adapter: adapter_name,
|
347
|
+
override: true
|
348
|
+
)
|
408
349
|
end
|
409
350
|
end
|
data/lib/nulldb/core.rb
CHANGED
@@ -3,9 +3,6 @@ require 'active_support/deprecation'
|
|
3
3
|
require 'active_record/connection_adapters/nulldb_adapter'
|
4
4
|
|
5
5
|
module NullDB
|
6
|
-
LEGACY_ACTIVERECORD =
|
7
|
-
Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.2.0')
|
8
|
-
|
9
6
|
class Configuration < Struct.new(:project_root); end
|
10
7
|
|
11
8
|
class << self
|
data/lib/nulldb/version.rb
CHANGED
data/spec/nulldb_spec.rb
CHANGED
@@ -11,12 +11,7 @@ require 'active_record'
|
|
11
11
|
require 'active_record/version'
|
12
12
|
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
13
13
|
|
14
|
-
|
15
|
-
require 'rspec' # rspec 2
|
16
|
-
else
|
17
|
-
require 'spec' # rspec 1
|
18
|
-
end
|
19
|
-
|
14
|
+
require 'rspec'
|
20
15
|
require 'nulldb_rspec'
|
21
16
|
|
22
17
|
class Employee < ActiveRecord::Base
|
@@ -492,11 +487,9 @@ describe 'adapter-specific extensions' do
|
|
492
487
|
should_have_column(ExtendedModel, :jsonb_column, :json)
|
493
488
|
end
|
494
489
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
.to be_a(ActiveModel::Type::Integer)
|
499
|
-
end
|
490
|
+
it 'registers a primary_key type' do
|
491
|
+
expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
|
492
|
+
.to be_a(ActiveModel::Type::Integer)
|
500
493
|
end
|
501
494
|
end
|
502
495
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-nulldb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avdi Grimm
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -19,6 +19,9 @@ dependencies:
|
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 5.2.0
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '6.1'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,6 +29,9 @@ dependencies:
|
|
26
29
|
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: 5.2.0
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.1'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: spec
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|