activerecord-nulldb-adapter 1.0.1 → 1.1.1
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 +37 -25
- data/Appraisals +12 -0
- data/CHANGES.md +11 -0
- data/Gemfile +1 -1
- data/README.md +51 -35
- data/activerecord-nulldb-adapter.gemspec +1 -1
- data/gemfiles/{activerecord_5.2.gemfile → activerecord_7.2.gemfile} +1 -1
- data/gemfiles/activerecord_8.0.gemfile +17 -0
- data/lib/active_record/connection_adapters/nulldb_adapter/core.rb +33 -3
- data/lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb +3 -1
- data/lib/active_record/connection_adapters/nulldb_adapter.rb +11 -0
- data/lib/active_record/connection_adapters/quoting.rb +13 -0
- data/lib/nulldb/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af43f27ebeb1eb1c313923392e50c59a234c1942355422e614fb3026ecb3bb13
|
4
|
+
data.tar.gz: 2c60b7ed36c6da832eaf7f0dcfd3e31c555a9735283903fed26e80f168a7905c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b09032c9f0421c412fab061201d1381a4fd3b265b5c8a00d5ced214201aade646ed7a9d8ae207c3c015aeb30cf7ddf5d21f429864262cb7a791f7a1c0ad8fb9
|
7
|
+
data.tar.gz: 8792abf6acf27101e8fc0e1c3a2806a16e629d5cc14fd660a12833d1afff4aed679030948799646dd321746117f5f6282100f8ffa391b598f6f310f08466a93c
|
data/.github/workflows/ruby.yml
CHANGED
@@ -7,47 +7,59 @@ jobs:
|
|
7
7
|
matrix:
|
8
8
|
gemfile:
|
9
9
|
[
|
10
|
-
activerecord_5.2,
|
11
|
-
activerecord_6.0,
|
12
10
|
activerecord_6.1,
|
13
11
|
activerecord_7.0,
|
14
12
|
activerecord_7.1,
|
13
|
+
activerecord_7.2,
|
14
|
+
activerecord_8.0,
|
15
15
|
activerecord_master,
|
16
16
|
]
|
17
|
-
ruby: ["2.
|
17
|
+
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "jruby-9.3.1.0"]
|
18
18
|
exclude:
|
19
|
-
- ruby: "3.0"
|
20
|
-
gemfile:
|
19
|
+
- ruby: "jruby-9.3.1.0"
|
20
|
+
gemfile: "activerecord_7.0"
|
21
21
|
|
22
|
-
- ruby: "3.1"
|
23
|
-
gemfile:
|
22
|
+
- ruby: "jruby-9.3.1.0"
|
23
|
+
gemfile: "activerecord_7.1"
|
24
24
|
|
25
|
-
- ruby: "
|
26
|
-
gemfile:
|
25
|
+
- ruby: "2.7"
|
26
|
+
gemfile: "activerecord_7.2"
|
27
27
|
|
28
|
-
- ruby: "2.
|
29
|
-
gemfile: "
|
28
|
+
- ruby: "2.8"
|
29
|
+
gemfile: "activerecord_7.2"
|
30
30
|
|
31
|
-
- ruby: "
|
32
|
-
gemfile: "
|
31
|
+
- ruby: "3.0"
|
32
|
+
gemfile: "activerecord_7.2"
|
33
33
|
|
34
|
-
- ruby: "
|
35
|
-
gemfile: "activerecord_7.
|
34
|
+
- ruby: "jruby-9.3.1.0"
|
35
|
+
gemfile: "activerecord_7.2"
|
36
36
|
|
37
|
-
- ruby: "2.
|
38
|
-
gemfile: "
|
37
|
+
- ruby: "2.7"
|
38
|
+
gemfile: "activerecord_8.0"
|
39
39
|
|
40
|
-
- ruby: "2.
|
41
|
-
gemfile: "
|
40
|
+
- ruby: "2.8"
|
41
|
+
gemfile: "activerecord_8.0"
|
42
42
|
|
43
|
-
- ruby: "
|
44
|
-
gemfile: "
|
43
|
+
- ruby: "3.0"
|
44
|
+
gemfile: "activerecord_8.0"
|
45
45
|
|
46
|
-
- ruby: "
|
47
|
-
gemfile: "
|
46
|
+
- ruby: "3.1"
|
47
|
+
gemfile: "activerecord_8.0"
|
48
48
|
|
49
49
|
- ruby: "jruby-9.3.1.0"
|
50
|
-
gemfile: "
|
50
|
+
gemfile: "activerecord_8.0"
|
51
|
+
|
52
|
+
- ruby: "2.7"
|
53
|
+
gemfile: "activerecord_master"
|
54
|
+
|
55
|
+
- ruby: "2.8"
|
56
|
+
gemfile: "activerecord_master"
|
57
|
+
|
58
|
+
- ruby: "3.0"
|
59
|
+
gemfile: "activerecord_master"
|
60
|
+
|
61
|
+
- ruby: "3.1"
|
62
|
+
gemfile: "activerecord_master"
|
51
63
|
|
52
64
|
- ruby: "jruby-9.3.1.0"
|
53
65
|
gemfile: "activerecord_master"
|
@@ -56,7 +68,7 @@ jobs:
|
|
56
68
|
env:
|
57
69
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
58
70
|
steps:
|
59
|
-
- uses: actions/checkout@
|
71
|
+
- uses: actions/checkout@v4
|
60
72
|
- uses: ruby/setup-ruby@v1
|
61
73
|
with:
|
62
74
|
ruby-version: ${{ matrix.ruby }}
|
data/Appraisals
CHANGED
@@ -10,6 +10,18 @@ appraise "activerecord-7.0" do
|
|
10
10
|
gem "activerecord", "~> 7.0.0"
|
11
11
|
end
|
12
12
|
|
13
|
+
appraise "activerecord-7.1" do
|
14
|
+
gem "activerecord", "~> 7.1.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "activerecord-7.2" do
|
18
|
+
gem "activerecord", "~> 7.2.0"
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "activerecord-8.0" do
|
22
|
+
gem "activerecord", github: 'rails/rails', branch: "8-0-stable"
|
23
|
+
end
|
24
|
+
|
13
25
|
appraise "activerecord-master" do
|
14
26
|
gem "activerecord", github: 'rails/rails', branch: :main
|
15
27
|
end
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
Unreleased
|
2
2
|
----------
|
3
3
|
|
4
|
+
1.1.1 (20214-11-14)
|
5
|
+
|
6
|
+
- Fix syntax error on 2.7 and 3.0.
|
7
|
+
|
8
|
+
1.1.0 (2024-11-14)
|
9
|
+
-----------
|
10
|
+
|
11
|
+
- Add support to Rails 8 #136
|
12
|
+
- *Breaking* Drop support to Ruby 2.5, 2.6
|
13
|
+
- *Breaking* Drop support to Rails 6.0 (keep 6.1)
|
14
|
+
|
4
15
|
1.0.1 (2023-10-16)
|
5
16
|
-----------
|
6
17
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,42 +17,50 @@ including `after_save` hooks - without ever touching a real database.
|
|
17
17
|
## Compatibility
|
18
18
|
|
19
19
|
### Ruby
|
20
|
-
Currently supported Ruby versions:
|
20
|
+
Currently supported Ruby versions: `2.7.X`, `3.X`.
|
21
21
|
|
22
22
|
Experimental support provided for: JRuby
|
23
23
|
|
24
24
|
### ActiveRecord
|
25
|
-
Any version of ActiveRecord
|
26
|
-
|
27
|
-
It is tested against AR 5.2, 6.0, 6.1 and master branch.
|
25
|
+
Any version of ActiveRecord `>= 6.1`
|
28
26
|
|
29
27
|
## Installation
|
30
28
|
|
31
|
-
|
29
|
+
```bash
|
30
|
+
gem install activerecord-nulldb-adapter
|
31
|
+
```
|
32
32
|
|
33
33
|
## How
|
34
34
|
|
35
35
|
Once installed, NullDB can be used much like any other ActiveRecord database
|
36
36
|
adapter:
|
37
37
|
|
38
|
-
|
38
|
+
```ruby
|
39
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb
|
40
|
+
```
|
39
41
|
|
40
42
|
NullDB needs to know where you keep your schema file in order to reflect table
|
41
43
|
metadata. By default it looks in RAILS_ROOT/db/schema.rb. You can override
|
42
44
|
that by setting the `schema` option:
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
```ruby
|
47
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb,
|
48
|
+
:schema => 'foo/myschema.rb'
|
49
|
+
```
|
46
50
|
|
47
51
|
NullDB comes with RSpec integration. To replace the database with NullDB in
|
48
52
|
all of your specs, put the following in your spec/rails_helper:
|
49
53
|
|
50
|
-
|
51
|
-
|
54
|
+
```ruby
|
55
|
+
require 'nulldb_rspec'
|
56
|
+
include NullDB::RSpec::NullifiedDatabase
|
57
|
+
```
|
52
58
|
|
53
59
|
after you load your rails environment
|
54
60
|
|
55
|
-
|
61
|
+
```ruby
|
62
|
+
require File.expand_path('../config/environment', __dir__)
|
63
|
+
```
|
56
64
|
|
57
65
|
otherwise you will encounter issues such as
|
58
66
|
([bug)](https://github.com/nulldb/nulldb/pull/90#issuecomment-496690958).
|
@@ -60,17 +68,19 @@ otherwise you will encounter issues such as
|
|
60
68
|
Or if you just want to use NullDB in a specific spec context, you can include
|
61
69
|
the same module inside a context:
|
62
70
|
|
63
|
-
|
71
|
+
```ruby
|
72
|
+
require 'nulldb_rspec'
|
64
73
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
74
|
+
describe Employee, "with access to the database" do
|
75
|
+
fixtures :employees
|
76
|
+
# ...
|
77
|
+
end
|
69
78
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
79
|
+
describe Employee, "with NullDB" do
|
80
|
+
include NullDB::RSpec::NullifiedDatabase
|
81
|
+
# ...
|
82
|
+
end
|
83
|
+
```
|
74
84
|
|
75
85
|
If you want to have NullDB enabled by default but disabled for particular
|
76
86
|
contexts then (see this
|
@@ -80,29 +90,35 @@ contexts then (see this
|
|
80
90
|
NullDB::Rspec provides some custom matcher support for verifying expectations
|
81
91
|
about interactions with the database:
|
82
92
|
|
83
|
-
|
84
|
-
|
93
|
+
```ruby
|
94
|
+
describe Employee do
|
95
|
+
include NullDB::RSpec::NullifiedDatabase
|
85
96
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
97
|
+
it "should cause an insert statement to be executed" do
|
98
|
+
Employee.create!
|
99
|
+
Employee.connection.should have_executed(:insert)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
91
103
|
|
92
104
|
UnitRecord-style verification that no database calls have been made at all can
|
93
105
|
be achieved by using the special `:anything` symbol:
|
94
106
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
107
|
+
```ruby
|
108
|
+
describe "stuff that shouldn't touch the database" do
|
109
|
+
after :each do
|
110
|
+
Employee.connection.should_not have_executed(:anything)
|
111
|
+
end
|
112
|
+
# ...
|
113
|
+
end
|
114
|
+
```
|
101
115
|
|
102
116
|
You can also experiment with putting NullDB in your database.yml:
|
103
117
|
|
104
|
-
|
105
|
-
|
118
|
+
```yaml
|
119
|
+
unit_test:
|
120
|
+
adapter: nulldb
|
121
|
+
```
|
106
122
|
|
107
123
|
However, due to the way Rails hard-codes specific database adapters into its
|
108
124
|
standard Rake tasks, you may find that this generates unexpected and
|
@@ -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', '>=
|
23
|
+
s.add_runtime_dependency 'activerecord', '>= 6.0', '< 8.1'
|
24
24
|
s.add_development_dependency 'spec'
|
25
25
|
s.add_development_dependency 'rdoc'
|
26
26
|
s.add_development_dependency 'rspec'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", github: "rails/rails", branch: "8-0-stable"
|
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
|
@@ -197,7 +197,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
197
197
|
|
198
198
|
def delete(statement, name=nil, binds = [])
|
199
199
|
with_entry_point(:delete) do
|
200
|
-
super(statement, name)
|
200
|
+
super(statement, name)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
@@ -268,9 +268,39 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
+
### Rails 8.0+ ###
|
272
|
+
def perform_query(raw_connection, statement, binds, type_casted_binds, prepare:, notification_payload:, batch:)
|
273
|
+
self.execution_log << Statement.new(entry_point, statement)
|
274
|
+
NullObject.new
|
275
|
+
end
|
276
|
+
|
277
|
+
def affected_rows(raw_result)
|
278
|
+
0
|
279
|
+
end
|
280
|
+
|
281
|
+
def valid_column_definition_options
|
282
|
+
super + [:array, :using, :cast_as, :as, :type, :enum_type, :stored, :srid]
|
283
|
+
end
|
284
|
+
|
285
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
286
|
+
:close, :declare, :fetch, :move, :set, :show
|
287
|
+
) # :nodoc:
|
288
|
+
private_constant :READ_QUERY
|
289
|
+
|
290
|
+
def write_query?(sql) # :nodoc:
|
291
|
+
!READ_QUERY.match?(sql)
|
292
|
+
rescue ArgumentError # Invalid encoding
|
293
|
+
!READ_QUERY.match?(sql.b)
|
294
|
+
end
|
295
|
+
|
296
|
+
def reconnect
|
297
|
+
true
|
298
|
+
end
|
299
|
+
### Rails 8.0+ ###
|
300
|
+
|
271
301
|
protected
|
272
302
|
|
273
|
-
def select(statement, name = nil, binds = [], prepare: nil, async: nil)
|
303
|
+
def select(statement, name = nil, binds = [], prepare: nil, async: nil, allow_retry: nil)
|
274
304
|
EmptyResult.new.tap do |r|
|
275
305
|
r.bind_column_meta(columns_for(name))
|
276
306
|
self.execution_log << Statement.new(entry_point, statement)
|
@@ -319,7 +349,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
|
|
319
349
|
|
320
350
|
def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
|
321
351
|
case ::ActiveRecord::VERSION::MAJOR
|
322
|
-
when 6, 7
|
352
|
+
when 6, 7, 8
|
323
353
|
TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
|
324
354
|
when 5
|
325
355
|
TableDefinition.new(table_name, is_temporary, options.except(:id), nil)
|
@@ -13,7 +13,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter
|
|
13
13
|
alias_method :jsonb, :json if method_defined? :json
|
14
14
|
alias_method :hstore, :json
|
15
15
|
|
16
|
-
|
16
|
+
def unique_constraint(*args, **kwargs, &block); end
|
17
|
+
|
18
|
+
if ::ActiveRecord::VERSION::MAJOR >= 7 && ::ActiveRecord::VERSION::MINOR >= 1
|
17
19
|
# Avoid check for option validity
|
18
20
|
def create_column_definition(name, type, options)
|
19
21
|
ActiveRecord::ConnectionAdapters::ColumnDefinition.new(name, type, options)
|
@@ -9,6 +9,8 @@ require 'active_record/connection_adapters/abstract_adapter'
|
|
9
9
|
require 'nulldb/core'
|
10
10
|
require 'nulldb/extensions'
|
11
11
|
|
12
|
+
require 'active_record/connection_adapters/quoting'
|
13
|
+
|
12
14
|
require 'active_record/connection_adapters/nulldb_adapter/core'
|
13
15
|
require 'active_record/connection_adapters/nulldb_adapter/statement'
|
14
16
|
require 'active_record/connection_adapters/nulldb_adapter/checkpoint'
|
@@ -20,3 +22,12 @@ require 'active_record/connection_adapters/nulldb_adapter/null_object'
|
|
20
22
|
require 'active_record/connection_adapters/nulldb_adapter/table_definition'
|
21
23
|
|
22
24
|
require 'active_record/tasks/nulldb_database_tasks' if defined?(ActiveRecord::Tasks)
|
25
|
+
|
26
|
+
module ActiveRecord
|
27
|
+
module ConnectionAdapters
|
28
|
+
if ActiveRecord::VERSION::STRING >= '7.2'
|
29
|
+
register 'nulldb', 'ActiveRecord::ConnectionAdapters::NullDBAdapter', 'active_record/connection_adapters/nulldb_adapter'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/nulldb/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.1.1
|
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: 2024-11-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -18,20 +18,20 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '6.0'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '8.1'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
31
|
+
version: '6.0'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '8.1'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: spec
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,11 +149,12 @@ files:
|
|
149
149
|
- README.md
|
150
150
|
- Rakefile
|
151
151
|
- activerecord-nulldb-adapter.gemspec
|
152
|
-
- gemfiles/activerecord_5.2.gemfile
|
153
152
|
- gemfiles/activerecord_6.0.gemfile
|
154
153
|
- gemfiles/activerecord_6.1.gemfile
|
155
154
|
- gemfiles/activerecord_7.0.gemfile
|
156
155
|
- gemfiles/activerecord_7.1.gemfile
|
156
|
+
- gemfiles/activerecord_7.2.gemfile
|
157
|
+
- gemfiles/activerecord_8.0.gemfile
|
157
158
|
- gemfiles/activerecord_master.gemfile
|
158
159
|
- lib/active_record/connection_adapters/nulldb_adapter.rb
|
159
160
|
- lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- lib/active_record/connection_adapters/nulldb_adapter/null_object.rb
|
166
167
|
- lib/active_record/connection_adapters/nulldb_adapter/statement.rb
|
167
168
|
- lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb
|
169
|
+
- lib/active_record/connection_adapters/quoting.rb
|
168
170
|
- lib/active_record/tasks/nulldb_database_tasks.rb
|
169
171
|
- lib/activerecord-nulldb-adapter.rb
|
170
172
|
- lib/nulldb.rb
|