activerecord-nulldb-adapter 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +48 -0
- data/.gitignore +2 -0
- data/Appraisals +5 -1
- data/CHANGES.md +15 -0
- data/Gemfile +1 -1
- data/README.rdoc +11 -5
- data/activerecord-nulldb-adapter.gemspec +4 -4
- data/gemfiles/activerecord_6.1.gemfile +17 -0
- data/gemfiles/activerecord_7.0.gemfile +17 -0
- data/gemfiles/activerecord_master.gemfile +1 -1
- data/lib/active_record/connection_adapters/nulldb_adapter/column.rb +0 -16
- data/lib/active_record/connection_adapters/nulldb_adapter/core.rb +45 -99
- data/lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb +3 -0
- data/lib/nulldb/core.rb +0 -3
- data/lib/nulldb/version.rb +1 -1
- data/spec/nulldb_spec.rb +21 -12
- metadata +31 -8
- data/.travis.yml +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e4a403aa1ee43e02dd69b91820f308d5085e99eca0684879e60f7fe3d7872e1
|
4
|
+
data.tar.gz: 84abce618014d4bb49cb903eea65f15ae830de6216531d3e3af709d70d02c03c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a6d28b99a18d0705990360b3775d040e78ab4842fc70a20216f8970615115f714112caef2d1b77d0758af32b1420a42d96c8785e1c0580af2523cec77533d32
|
7
|
+
data.tar.gz: 58b09c97d6777eac6fac477ce39d6297f19a7b8821d5e59af9661144aa673e8cfc5cff642798283bf0e8061e0532b231c802f7ef726ed1463b50deb576b04a82
|
@@ -0,0 +1,48 @@
|
|
1
|
+
name: build
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
gemfile:
|
9
|
+
[
|
10
|
+
activerecord_5.2,
|
11
|
+
activerecord_6.0,
|
12
|
+
activerecord_6.1,
|
13
|
+
activerecord_7.0,
|
14
|
+
activerecord_master,
|
15
|
+
]
|
16
|
+
ruby: ["2.5", "2.6", "2.7", "3.0", "jruby-9.3.1.0"]
|
17
|
+
exclude:
|
18
|
+
- ruby: "3.0"
|
19
|
+
gemfile: activerecord_5.2
|
20
|
+
|
21
|
+
- ruby: "2.5"
|
22
|
+
gemfile: "activerecord_master"
|
23
|
+
|
24
|
+
- ruby: "2.6"
|
25
|
+
gemfile: "activerecord_master"
|
26
|
+
|
27
|
+
- ruby: "2.5"
|
28
|
+
gemfile: "activerecord_7.0"
|
29
|
+
|
30
|
+
- ruby: "2.6"
|
31
|
+
gemfile: "activerecord_7.0"
|
32
|
+
|
33
|
+
- ruby: "jruby-9.3.1.0"
|
34
|
+
gemfile: "activerecord_7.0"
|
35
|
+
|
36
|
+
- ruby: "jruby-9.3.1.0"
|
37
|
+
gemfile: "activerecord_master"
|
38
|
+
|
39
|
+
runs-on: ubuntu-latest
|
40
|
+
env:
|
41
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: ${{ matrix.ruby }}
|
47
|
+
bundler-cache: true
|
48
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -6,6 +6,10 @@ appraise "activerecord-6.0" do
|
|
6
6
|
gem "activerecord", "~> 6.0.0"
|
7
7
|
end
|
8
8
|
|
9
|
+
appraise "activerecord-7.0" do
|
10
|
+
gem "activerecord", "~> 7.0.0.alpha2"
|
11
|
+
end
|
12
|
+
|
9
13
|
appraise "activerecord-master" do
|
10
|
-
gem "activerecord", github: 'rails/rails'
|
14
|
+
gem "activerecord", github: 'rails/rails', branch: :main
|
11
15
|
end
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
Unreleased
|
2
2
|
----------
|
3
3
|
|
4
|
+
0.8.0 (2022-10-28)
|
5
|
+
-----------
|
6
|
+
|
7
|
+
- Add support for Rails 7. #111 #112
|
8
|
+
|
9
|
+
0.7.0 (2021-01-18)
|
10
|
+
-----------
|
11
|
+
|
12
|
+
- Add support to Rails 6.1 #106
|
13
|
+
|
14
|
+
0.6.0 (2021-01-08)
|
15
|
+
-----------
|
16
|
+
|
17
|
+
- *Breaking* Finish dropping support to Rails <= 5.1 by removing custom code for these versions. #101
|
18
|
+
|
4
19
|
0.5.0 (2020-10-15)
|
5
20
|
-----------
|
6
21
|
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{<img src="https://badge.fury.io/rb/activerecord-nulldb-adapter.png" alt="Gem Version" />}[http://badge.fury.io/rb/activerecord-nulldb-adapter]
|
2
2
|
{<img src="https://codeclimate.com/github/nulldb/nulldb.png" />}[https://codeclimate.com/github/nulldb/nulldb]
|
3
|
-
{<img src="https://
|
3
|
+
{<img src="https://github.com/nulldb/nulldb/workflows/build/badge.svg?branch=master" alt="Build Status" />}[https://github.com/nulldb/nulldb/actions]
|
4
4
|
|
5
5
|
|
6
6
|
= The NullDB Connection Adapter Plugin
|
@@ -16,14 +16,14 @@ a real database.
|
|
16
16
|
== Compatibility
|
17
17
|
|
18
18
|
=== Ruby
|
19
|
-
Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x
|
19
|
+
Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x, 3.X.
|
20
20
|
|
21
21
|
Experimental support provided for: JRuby
|
22
22
|
|
23
23
|
=== ActiveRecord
|
24
|
-
Any version of ActiveRecord >= 5
|
24
|
+
Any version of ActiveRecord >= 5.2
|
25
25
|
|
26
|
-
It is tested against AR 5.2, 6.0 and master branch.
|
26
|
+
It is tested against AR 5.2, 6.0, 6.1 and master branch.
|
27
27
|
|
28
28
|
== Installation
|
29
29
|
|
@@ -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
|
|
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = NullDB::VERSION
|
9
9
|
|
10
10
|
s.require_paths = ["lib"]
|
11
|
-
s.authors = ["Avdi Grimm", "Myron Marston"]
|
11
|
+
s.authors = ["Avdi Grimm", "Myron Marston", "Danilo Cabello"]
|
12
12
|
s.summary = "The Null Object pattern as applied to ActiveRecord database adapters"
|
13
13
|
s.description = "A database backend that translates database interactions into no-ops. Using NullDB enables you to test your model business logic - including after_save hooks - without ever touching a real database."
|
14
|
-
s.email = "
|
14
|
+
s.email = "cabello@users.noreply.github.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -20,12 +20,12 @@ 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', '< 7.1'
|
24
24
|
s.add_development_dependency 'spec'
|
25
25
|
s.add_development_dependency 'rdoc'
|
26
26
|
s.add_development_dependency 'rspec'
|
27
27
|
s.add_development_dependency 'rake'
|
28
28
|
s.add_development_dependency 'appraisal'
|
29
29
|
s.add_development_dependency 'simplecov'
|
30
|
+
s.add_development_dependency 'pry-byebug'
|
30
31
|
end
|
31
|
-
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 6.1.0"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "spec"
|
9
|
+
gem "rspec", ">= 1.2.9"
|
10
|
+
gem "rake"
|
11
|
+
gem "rdoc"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "appraisal"
|
16
|
+
gem "simplecov", require: false
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 7.0.0.alpha2"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "spec"
|
9
|
+
gem "rspec", ">= 1.2.9"
|
10
|
+
gem "rake"
|
11
|
+
gem "rdoc"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "appraisal"
|
16
|
+
gem "simplecov", require: false
|
17
|
+
end
|
@@ -1,20 +1,4 @@
|
|
1
1
|
class ActiveRecord::ConnectionAdapters::NullDBAdapter
|
2
2
|
class Column < ::ActiveRecord::ConnectionAdapters::Column
|
3
|
-
|
4
|
-
private
|
5
|
-
|
6
|
-
def simplified_type(field_type)
|
7
|
-
super || simplified_type_from_sql_type
|
8
|
-
end
|
9
|
-
|
10
|
-
def simplified_type_from_sql_type
|
11
|
-
case sql_type
|
12
|
-
when :primary_key
|
13
|
-
:integer
|
14
|
-
when :string
|
15
|
-
:string
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
3
|
end
|
20
4
|
end
|
@@ -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
|
@@ -84,46 +83,30 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
84
83
|
@tables[new_name.to_s] = table_definition
|
85
84
|
end
|
86
85
|
|
87
|
-
def add_index(table_name, column_names, options
|
86
|
+
def add_index(table_name, column_names, **options)
|
87
|
+
options[:unique] = false unless options.key?(:unique)
|
88
88
|
column_names = Array.wrap(column_names).map(&:to_s)
|
89
|
-
index_name, index_type, ignore = add_index_options(table_name, column_names, options)
|
90
|
-
@indexes[table_name] << IndexDefinition.new(table_name, index_name, (index_type == 'UNIQUE'), column_names, [], [])
|
91
|
-
end
|
92
|
-
|
93
|
-
def remove_index(table_name, options = {})
|
94
|
-
index_name = index_name_for_remove(table_name, options)
|
95
|
-
index = @indexes[table_name].reject! { |index| index.name == index_name }
|
96
|
-
end
|
97
89
|
|
98
|
-
|
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)
|
90
|
+
index, index_type, ignore = add_index_options(table_name, column_names, **options)
|
102
91
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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]
|
92
|
+
if index.is_a?(ActiveRecord::ConnectionAdapters::IndexDefinition)
|
93
|
+
@indexes[table_name] << index
|
94
|
+
else
|
95
|
+
# Rails < 6.1
|
96
|
+
@indexes[table_name] << IndexDefinition.new(table_name, index, (index_type == 'UNIQUE'), column_names, [], [])
|
119
97
|
end
|
120
98
|
end
|
121
99
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
index_name =
|
126
|
-
indexes
|
100
|
+
# Rails 6.1+
|
101
|
+
if ActiveRecord::VERSION::MAJOR >= 7 || (ActiveRecord::VERSION::MAJOR >= 6 and ActiveRecord::VERSION::MINOR > 0)
|
102
|
+
def remove_index(table_name, column_name = nil, **options )
|
103
|
+
index_name = index_name_for_remove(table_name, column_name, options)
|
104
|
+
index = @indexes[table_name].reject! { |index| index.name == index_name }
|
105
|
+
end
|
106
|
+
else
|
107
|
+
def remove_index(table_name, options = {} )
|
108
|
+
index_name = index_name_for_remove(table_name, options)
|
109
|
+
index = @indexes[table_name].reject! { |index| index.name == index_name }
|
127
110
|
end
|
128
111
|
end
|
129
112
|
|
@@ -162,7 +145,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
162
145
|
|
163
146
|
if table = @tables[table_name]
|
164
147
|
table.columns.map do |col_def|
|
165
|
-
col_args =
|
148
|
+
col_args = default_column_arguments(col_def)
|
166
149
|
ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(*col_args)
|
167
150
|
end
|
168
151
|
else
|
@@ -237,16 +220,16 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
237
220
|
end
|
238
221
|
|
239
222
|
def primary_key(table_name)
|
240
|
-
columns(table_name).detect { |col| col.
|
223
|
+
columns(table_name).detect { |col| col.type == :primary_key }.try(:name)
|
241
224
|
end
|
242
225
|
|
243
|
-
def add_column(table_name, column_name, type, options
|
226
|
+
def add_column(table_name, column_name, type, **options)
|
244
227
|
super
|
245
228
|
|
246
229
|
table_meta = @tables[table_name.to_s]
|
247
230
|
return unless table_meta
|
248
231
|
|
249
|
-
table_meta.column column_name, type, options
|
232
|
+
table_meta.column column_name, type, **options
|
250
233
|
end
|
251
234
|
|
252
235
|
def change_column(table_name, column_name, type, options = {})
|
@@ -281,7 +264,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
281
264
|
|
282
265
|
protected
|
283
266
|
|
284
|
-
def select(statement, name = nil, binds = [])
|
267
|
+
def select(statement, name = nil, binds = [], prepare: nil, async: nil)
|
285
268
|
EmptyResult.new.tap do |r|
|
286
269
|
r.bind_column_meta(columns_for(name))
|
287
270
|
self.execution_log << Statement.new(entry_point, statement)
|
@@ -330,80 +313,43 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
330
313
|
|
331
314
|
def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
|
332
315
|
case ::ActiveRecord::VERSION::MAJOR
|
333
|
-
when 6
|
316
|
+
when 6, 7
|
334
317
|
TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
|
335
318
|
when 5
|
336
319
|
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
320
|
else
|
342
321
|
raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
|
343
322
|
end
|
344
323
|
end
|
345
324
|
|
346
|
-
def new_column_arguments(col_def)
|
347
|
-
args_with_optional_cast_type(col_def)
|
348
|
-
end
|
349
|
-
|
350
|
-
def args_with_optional_cast_type(col_def)
|
351
|
-
default_column_arguments(col_def).tap do |args|
|
352
|
-
if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
|
353
|
-
meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
|
354
|
-
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
|
-
else
|
358
|
-
args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
def meta_with_limit!(meta, col_def)
|
364
|
-
meta.instance_variable_set('@limit', col_def.limit)
|
365
|
-
meta
|
366
|
-
end
|
367
|
-
|
368
325
|
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
|
326
|
+
[
|
327
|
+
col_def.name.to_s,
|
328
|
+
col_def.default.present? ? col_def.default.to_s : nil,
|
329
|
+
sql_type_definition(col_def),
|
330
|
+
col_def.null.nil? || col_def.null
|
331
|
+
]
|
383
332
|
end
|
384
333
|
|
385
|
-
def
|
386
|
-
|
334
|
+
def sql_type_definition(col_def)
|
335
|
+
ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
|
336
|
+
type: col_def.type,
|
337
|
+
sql_type: col_def.type.to_s,
|
338
|
+
limit: col_def.limit
|
339
|
+
)
|
387
340
|
end
|
388
341
|
|
389
342
|
def initialize_args
|
390
|
-
|
391
|
-
[nil, @logger]
|
343
|
+
[nil, @logger, @config]
|
392
344
|
end
|
393
345
|
|
394
|
-
# 4.2 introduced ActiveRecord::Type
|
395
|
-
# https://github.com/rails/rails/tree/4-2-stable/activerecord/lib/active_record
|
396
346
|
def register_types
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
adapter: adapter_name,
|
405
|
-
override: true
|
406
|
-
)
|
407
|
-
end
|
347
|
+
require 'active_model/type'
|
348
|
+
ActiveRecord::Type.register(
|
349
|
+
:primary_key,
|
350
|
+
ActiveModel::Type::Integer,
|
351
|
+
adapter: adapter_name,
|
352
|
+
override: true
|
353
|
+
)
|
408
354
|
end
|
409
355
|
end
|
@@ -2,9 +2,12 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter
|
|
2
2
|
|
3
3
|
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
|
4
4
|
attr_accessor :name
|
5
|
+
alias_method :uuid, :string
|
5
6
|
alias_method :citext, :text
|
6
7
|
alias_method :interval, :text
|
7
8
|
alias_method :geometry, :text
|
9
|
+
alias_method :serial, :integer
|
10
|
+
alias_method :inet, :string
|
8
11
|
alias_method :jsonb, :json if method_defined? :json
|
9
12
|
end
|
10
13
|
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
|
@@ -75,6 +70,7 @@ describe "NullDB" do
|
|
75
70
|
t.date :hire_date
|
76
71
|
t.integer :employee_number
|
77
72
|
t.decimal :salary
|
73
|
+
t.boolean :active, default: true
|
78
74
|
end
|
79
75
|
|
80
76
|
create_table(:employees_widgets, :id => false, :force => true) do |t|
|
@@ -113,6 +109,7 @@ describe "NullDB" do
|
|
113
109
|
should_have_column(Employee, :hire_date, :date)
|
114
110
|
should_have_column(Employee, :employee_number, :integer)
|
115
111
|
should_have_column(Employee, :salary, :decimal)
|
112
|
+
should_have_column(Employee, :active, :boolean)
|
116
113
|
end
|
117
114
|
|
118
115
|
it 'should have limit on name' do
|
@@ -127,6 +124,14 @@ describe "NullDB" do
|
|
127
124
|
expect(Employee.columns_hash['name'].null).to be false
|
128
125
|
end
|
129
126
|
|
127
|
+
it "should stringify default values" do
|
128
|
+
expect(Employee.columns_hash['active'].default).to eq "true"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should have no default for employee_number" do
|
132
|
+
expect(Employee.columns_hash['employee_number'].default).to eq nil
|
133
|
+
end
|
134
|
+
|
130
135
|
it "should return the appropriate primary key" do
|
131
136
|
expect( ActiveRecord::Base.connection.primary_key('employees') ).to eq 'id'
|
132
137
|
end
|
@@ -296,7 +301,13 @@ describe "NullDB" do
|
|
296
301
|
end
|
297
302
|
|
298
303
|
# need a fallback db for contextual nullification
|
299
|
-
ActiveRecord::
|
304
|
+
if defined?(ActiveRecord::DatabaseConfigurations)
|
305
|
+
db_config = { 'test' => {'adapter' => 'nulldb'} }
|
306
|
+
ActiveRecord::Base.configurations = ActiveRecord::DatabaseConfigurations.new(db_config)
|
307
|
+
else
|
308
|
+
# Support ActiveRecord 5
|
309
|
+
ActiveRecord::Base.configurations['test'] = {'adapter' => 'nulldb'}
|
310
|
+
end
|
300
311
|
|
301
312
|
describe NullDB::RSpec::NullifiedDatabase do
|
302
313
|
describe 'have_executed rspec matcher' do
|
@@ -492,11 +503,9 @@ describe 'adapter-specific extensions' do
|
|
492
503
|
should_have_column(ExtendedModel, :jsonb_column, :json)
|
493
504
|
end
|
494
505
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
.to be_a(ActiveModel::Type::Integer)
|
499
|
-
end
|
506
|
+
it 'registers a primary_key type' do
|
507
|
+
expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
|
508
|
+
.to be_a(ActiveModel::Type::Integer)
|
500
509
|
end
|
501
510
|
end
|
502
511
|
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avdi Grimm
|
8
8
|
- Myron Marston
|
9
|
-
|
9
|
+
- Danilo Cabello
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: activerecord
|
@@ -18,6 +19,9 @@ dependencies:
|
|
18
19
|
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: 5.2.0
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '7.1'
|
21
25
|
type: :runtime
|
22
26
|
prerelease: false
|
23
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,6 +29,9 @@ dependencies:
|
|
25
29
|
- - ">="
|
26
30
|
- !ruby/object:Gem::Version
|
27
31
|
version: 5.2.0
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '7.1'
|
28
35
|
- !ruby/object:Gem::Dependency
|
29
36
|
name: spec
|
30
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,18 +116,32 @@ dependencies:
|
|
109
116
|
- - ">="
|
110
117
|
- !ruby/object:Gem::Version
|
111
118
|
version: '0'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: pry-byebug
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
112
133
|
description: A database backend that translates database interactions into no-ops.
|
113
134
|
Using NullDB enables you to test your model business logic - including after_save
|
114
135
|
hooks - without ever touching a real database.
|
115
|
-
email:
|
136
|
+
email: cabello@users.noreply.github.com
|
116
137
|
executables: []
|
117
138
|
extensions: []
|
118
139
|
extra_rdoc_files:
|
119
140
|
- LICENSE
|
120
141
|
- README.rdoc
|
121
142
|
files:
|
143
|
+
- ".github/workflows/ruby.yml"
|
122
144
|
- ".gitignore"
|
123
|
-
- ".travis.yml"
|
124
145
|
- Appraisals
|
125
146
|
- CHANGES.md
|
126
147
|
- Gemfile
|
@@ -130,6 +151,8 @@ files:
|
|
130
151
|
- activerecord-nulldb-adapter.gemspec
|
131
152
|
- gemfiles/activerecord_5.2.gemfile
|
132
153
|
- gemfiles/activerecord_6.0.gemfile
|
154
|
+
- gemfiles/activerecord_6.1.gemfile
|
155
|
+
- gemfiles/activerecord_7.0.gemfile
|
133
156
|
- gemfiles/activerecord_master.gemfile
|
134
157
|
- lib/active_record/connection_adapters/nulldb_adapter.rb
|
135
158
|
- lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
|
@@ -157,7 +180,7 @@ homepage: https://github.com/nulldb/nulldb
|
|
157
180
|
licenses:
|
158
181
|
- MIT
|
159
182
|
metadata: {}
|
160
|
-
post_install_message:
|
183
|
+
post_install_message:
|
161
184
|
rdoc_options: []
|
162
185
|
require_paths:
|
163
186
|
- lib
|
@@ -172,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
195
|
- !ruby/object:Gem::Version
|
173
196
|
version: '0'
|
174
197
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
-
signing_key:
|
198
|
+
rubygems_version: 3.1.4
|
199
|
+
signing_key:
|
177
200
|
specification_version: 4
|
178
201
|
summary: The Null Object pattern as applied to ActiveRecord database adapters
|
179
202
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
bundler_args: --without development
|
4
|
-
sudo: false
|
5
|
-
|
6
|
-
rvm:
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
9
|
-
- 2.7
|
10
|
-
- jruby
|
11
|
-
|
12
|
-
gemfile:
|
13
|
-
- gemfiles/activerecord_5.2.gemfile
|
14
|
-
- gemfiles/activerecord_6.0.gemfile
|
15
|
-
- gemfiles/activerecord_master.gemfile
|
16
|
-
|
17
|
-
matrix:
|
18
|
-
fast_finish: true
|
19
|
-
allow_failures:
|
20
|
-
- rvm: jruby
|
21
|
-
- gemfile: gemfiles/activerecord_master.gemfile
|