activerecord-nulldb-adapter 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e4a403aa1ee43e02dd69b91820f308d5085e99eca0684879e60f7fe3d7872e1
4
- data.tar.gz: 84abce618014d4bb49cb903eea65f15ae830de6216531d3e3af709d70d02c03c
3
+ metadata.gz: 0da8a5f679279b76c36a80995783db057cf0bbc680d4006209619d068c55fbf3
4
+ data.tar.gz: eb7c91fe3bd86f1d8787cd2dc394aeecc1b8c0950e7133fb4a21f74f6e596a8d
5
5
  SHA512:
6
- metadata.gz: 1a6d28b99a18d0705990360b3775d040e78ab4842fc70a20216f8970615115f714112caef2d1b77d0758af32b1420a42d96c8785e1c0580af2523cec77533d32
7
- data.tar.gz: 58b09c97d6777eac6fac477ce39d6297f19a7b8821d5e59af9661144aa673e8cfc5cff642798283bf0e8061e0532b231c802f7ef726ed1463b50deb576b04a82
6
+ metadata.gz: 87e4cb3496818735480c034bb2444bec7cdd60eb6032332d78875d3f1cd8bb769f256d70d8a80b254cc11d9c91564b76f32fe8f863d65dba5d13427a4d6f74d1
7
+ data.tar.gz: ae332ef581de6f46f46940d2f4c6a0011606abbe2432e258a88b7ab9b5c0be50af03a9b140b630c4e79228c3ed65d4569ae50f9e828ad37d3b64dc031de9bcbf
data/Appraisals CHANGED
@@ -7,7 +7,7 @@ appraise "activerecord-6.0" do
7
7
  end
8
8
 
9
9
  appraise "activerecord-7.0" do
10
- gem "activerecord", "~> 7.0.0.alpha2"
10
+ gem "activerecord", "~> 7.0.0"
11
11
  end
12
12
 
13
13
  appraise "activerecord-master" do
data/CHANGES.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Unreleased
2
2
  ----------
3
3
 
4
+ 0.9.0 (2023-03-10)
5
+ -----------
6
+
7
+ - Add support to BigSerial #119
8
+ - Add support to hstore #118
9
+ - Support Postgres type modifiers #117
10
+
11
+
4
12
  0.8.0 (2022-10-28)
5
13
  -----------
6
14
 
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ [<img src="https://badge.fury.io/rb/activerecord-nulldb-adapter.png" alt="Gem
2
+ Version" />](http://badge.fury.io/rb/activerecord-nulldb-adapter) [<img
3
+ src="https://codeclimate.com/github/nulldb/nulldb.png"
4
+ />](https://codeclimate.com/github/nulldb/nulldb) [<img
5
+ src="https://github.com/nulldb/nulldb/workflows/build/badge.svg?branch=master"
6
+ alt="Build Status" />](https://github.com/nulldb/nulldb/actions)
7
+
8
+ # The NullDB Connection Adapter Plugin
9
+
10
+ ## What
11
+
12
+ NullDB is the Null Object pattern as applied to ActiveRecord database
13
+ adapters. It is a database backend that translates database interactions into
14
+ no-ops. Using NullDB enables you to test your model business logic -
15
+ including `after_save` hooks - without ever touching a real database.
16
+
17
+ ## Compatibility
18
+
19
+ ### Ruby
20
+ Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x, 3.X.
21
+
22
+ Experimental support provided for: JRuby
23
+
24
+ ### ActiveRecord
25
+ Any version of ActiveRecord >= 5.2
26
+
27
+ It is tested against AR 5.2, 6.0, 6.1 and master branch.
28
+
29
+ ## Installation
30
+
31
+ gem install activerecord-nulldb-adapter
32
+
33
+ ## How
34
+
35
+ Once installed, NullDB can be used much like any other ActiveRecord database
36
+ adapter:
37
+
38
+ ActiveRecord::Base.establish_connection :adapter => :nulldb
39
+
40
+ NullDB needs to know where you keep your schema file in order to reflect table
41
+ metadata. By default it looks in RAILS_ROOT/db/schema.rb. You can override
42
+ that by setting the `schema` option:
43
+
44
+ ActiveRecord::Base.establish_connection :adapter => :nulldb,
45
+ :schema => 'foo/myschema.rb'
46
+
47
+ NullDB comes with RSpec integration. To replace the database with NullDB in
48
+ all of your specs, put the following in your spec/rails_helper:
49
+
50
+ require 'nulldb_rspec'
51
+ include NullDB::RSpec::NullifiedDatabase
52
+
53
+ after you load your rails environment
54
+
55
+ require File.expand_path('../config/environment', __dir__)
56
+
57
+ otherwise you will encounter issues such as
58
+ ([bug)](https://github.com/nulldb/nulldb/pull/90#issuecomment-496690958).
59
+
60
+ Or if you just want to use NullDB in a specific spec context, you can include
61
+ the same module inside a context:
62
+
63
+ require 'nulldb_rspec'
64
+
65
+ describe Employee, "with access to the database" do
66
+ fixtures :employees
67
+ # ...
68
+ end
69
+
70
+ describe Employee, "with NullDB" do
71
+ include NullDB::RSpec::NullifiedDatabase
72
+ # ...
73
+ end
74
+
75
+ If you want to have NullDB enabled by default but disabled for particular
76
+ contexts then (see this
77
+ [post)](https://web.archive.org/web/20120419204019/http://andywaite.com/2011/5
78
+ /18/rspec-disable-nulldb)
79
+
80
+ NullDB::Rspec provides some custom matcher support for verifying expectations
81
+ about interactions with the database:
82
+
83
+ describe Employee do
84
+ include NullDB::RSpec::NullifiedDatabase
85
+
86
+ it "should cause an insert statement to be executed" do
87
+ Employee.create!
88
+ Employee.connection.should have_executed(:insert)
89
+ end
90
+ end
91
+
92
+ UnitRecord-style verification that no database calls have been made at all can
93
+ be achieved by using the special `:anything` symbol:
94
+
95
+ describe "stuff that shouldn't touch the database" do
96
+ after :each do
97
+ Employee.connection.should_not have_executed(:anything)
98
+ end
99
+ # ...
100
+ end
101
+
102
+ You can also experiment with putting NullDB in your database.yml:
103
+
104
+ unit_test:
105
+ adapter: nulldb
106
+
107
+ However, due to the way Rails hard-codes specific database adapters into its
108
+ standard Rake tasks, you may find that this generates unexpected and
109
+ difficult-to-debug behavior. Workarounds for this are under development.
110
+
111
+ ## Why
112
+
113
+ There are a number of advantages to writing unit tests that never touch the
114
+ database. The biggest is probably speed of execution - unit tests must be
115
+ fast for test-driven development to be practical. Another is separation of
116
+ concerns: unit tests should be exercising only the business logic contained in
117
+ your models, not ActiveRecord. For more on why testing-sans-database is a good
118
+ idea, see:
119
+ http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database.
120
+
121
+ NullDB is one way to separate your unit tests from the database. It was
122
+ inspired by the [ARBS](http://arbs.rubyforge.org/) and
123
+ [UnitRecord](http://unit-test-ar.rubyforge.org/) libraries. It differs from
124
+ them in that rather than modifying parts of ActiveRecord, it implements the
125
+ same [semi-]well-documented public interface that the other standard database
126
+ adapters, like MySQL and SQLServer, implement. This has enabled it to evolve
127
+ to support new ActiveRecord versions relatively easily.
128
+
129
+ One concrete advantage of this null-object pattern design is that it is
130
+ possible with NullDB to test `after_save` hooks. With NullDB, you can call
131
+ `#save` and all of the usual callbacks will be called - but nothing will be
132
+ saved.
133
+
134
+ ## Limitations
135
+
136
+ * It is **not** an in-memory database. Finds will not work. Neither will
137
+ `reload`, currently. Test fixtures won't work either, for obvious
138
+ reasons.
139
+ * It has only the most rudimentery schema/migration support. Complex
140
+ migrations will probably break it.
141
+ * Lots of other things probably don't work. Patches welcome!
142
+
143
+
144
+ ## Who
145
+
146
+ NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>. It is
147
+ currently maintained by [Danilo Cabello](https://github.com/cabello).
148
+ Previously maintained by: [Bram de Vries](https://github.com/blaet).
149
+
150
+ ## Where
151
+
152
+ * Homepage: https://github.com/nulldb/nulldb
153
+
154
+
155
+ ## License
156
+
157
+ See the LICENSE file for licensing information.
data/Rakefile CHANGED
@@ -9,6 +9,6 @@ task :default => :spec
9
9
 
10
10
  require 'rdoc/task'
11
11
  Rake::RDocTask.new do |rd|
12
- rd.main = "README.rdoc"
13
- rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
12
+ rd.main = "README.md"
13
+ rd.rdoc_files.include("README.md", "LICENSE", "lib/**/*.rb")
14
14
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.email = "cabello@users.noreply.github.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = `git ls-files`.split($/)
20
20
  s.homepage = "https://github.com/nulldb/nulldb"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 7.0.0.alpha2"
5
+ gem "activerecord", "~> 7.0.0"
6
6
 
7
7
  group :development, :test do
8
8
  gem "spec"
@@ -343,13 +343,37 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
343
343
  [nil, @logger, @config]
344
344
  end
345
345
 
346
+ # Register types only once to avoid ActiveRecord::TypeConflictError
347
+ # in ActiveRecord::Type::Registration#<=>
348
+ REGISTRATION_MUTEX = Mutex.new
349
+
346
350
  def register_types
347
- require 'active_model/type'
351
+ REGISTRATION_MUTEX.synchronize do
352
+ return if self.class.types_registered
353
+
354
+ self.class.types_registered = true
355
+ end
356
+
348
357
  ActiveRecord::Type.register(
349
358
  :primary_key,
350
359
  ActiveModel::Type::Integer,
351
360
  adapter: adapter_name,
352
361
  override: true
353
362
  )
363
+
364
+ ActiveRecord::Type.add_modifier({ array: true }, DummyOID, adapter: :nulldb)
365
+ ActiveRecord::Type.add_modifier({ range: true }, DummyOID, adapter: :nulldb)
366
+ end
367
+
368
+ class << self
369
+ attr_accessor :types_registered
370
+ end
371
+
372
+ class DummyOID < ActiveModel::Type::Value
373
+ attr_reader :subtype
374
+
375
+ def initialize(*args)
376
+ @subtype = args.first
377
+ end
354
378
  end
355
379
  end
@@ -7,7 +7,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter
7
7
  alias_method :interval, :text
8
8
  alias_method :geometry, :text
9
9
  alias_method :serial, :integer
10
+ alias_method :bigserial, :integer
10
11
  alias_method :inet, :string
11
12
  alias_method :jsonb, :json if method_defined? :json
13
+ alias_method :hstore, :json
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module NullDB
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/spec/nulldb_spec.rb CHANGED
@@ -490,6 +490,7 @@ describe 'adapter-specific extensions' do
490
490
  t.interval :time_interval
491
491
  t.geometry :feature_geometry, srid: 4326, type: "multi_polygon"
492
492
  t.jsonb :jsonb_column
493
+ t.hstore :hstore_column
493
494
  end
494
495
  end
495
496
  }.to_not raise_error
@@ -503,6 +504,20 @@ describe 'adapter-specific extensions' do
503
504
  should_have_column(ExtendedModel, :jsonb_column, :json)
504
505
  end
505
506
 
507
+ it 'supports ActiveModel attributes with postgres modifiers' do
508
+ class ExtendedModel < ActiveRecord::Base
509
+ attribute :strings, :string, array: true
510
+ attribute :size, :integer, range: true
511
+ end
512
+
513
+ expect(ExtendedModel.type_for_attribute(:strings))
514
+ .to be_a ActiveRecord::ConnectionAdapters::NullDBAdapter::DummyOID
515
+ expect(ExtendedModel.new(strings: %w[a b]).strings).to eq %w[a b]
516
+ expect(ExtendedModel.type_for_attribute(:size))
517
+ .to be_a ActiveRecord::ConnectionAdapters::NullDBAdapter::DummyOID
518
+ expect(ExtendedModel.new(size: 1..5).size).to eq 1..5
519
+ end
520
+
506
521
  it 'registers a primary_key type' do
507
522
  expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
508
523
  .to be_a(ActiveModel::Type::Integer)
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nulldb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
8
8
  - Myron Marston
9
9
  - Danilo Cabello
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-10-29 00:00:00.000000000 Z
13
+ date: 2023-03-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -138,7 +138,7 @@ executables: []
138
138
  extensions: []
139
139
  extra_rdoc_files:
140
140
  - LICENSE
141
- - README.rdoc
141
+ - README.md
142
142
  files:
143
143
  - ".github/workflows/ruby.yml"
144
144
  - ".gitignore"
@@ -146,7 +146,7 @@ files:
146
146
  - CHANGES.md
147
147
  - Gemfile
148
148
  - LICENSE
149
- - README.rdoc
149
+ - README.md
150
150
  - Rakefile
151
151
  - activerecord-nulldb-adapter.gemspec
152
152
  - gemfiles/activerecord_5.2.gemfile
@@ -180,7 +180,7 @@ homepage: https://github.com/nulldb/nulldb
180
180
  licenses:
181
181
  - MIT
182
182
  metadata: {}
183
- post_install_message:
183
+ post_install_message:
184
184
  rdoc_options: []
185
185
  require_paths:
186
186
  - lib
@@ -195,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubygems_version: 3.1.4
199
- signing_key:
198
+ rubygems_version: 3.3.26
199
+ signing_key:
200
200
  specification_version: 4
201
201
  summary: The Null Object pattern as applied to ActiveRecord database adapters
202
202
  test_files: []
data/README.rdoc DELETED
@@ -1,154 +0,0 @@
1
- {<img src="https://badge.fury.io/rb/activerecord-nulldb-adapter.png" alt="Gem Version" />}[http://badge.fury.io/rb/activerecord-nulldb-adapter]
2
- {<img src="https://codeclimate.com/github/nulldb/nulldb.png" />}[https://codeclimate.com/github/nulldb/nulldb]
3
- {<img src="https://github.com/nulldb/nulldb/workflows/build/badge.svg?branch=master" alt="Build Status" />}[https://github.com/nulldb/nulldb/actions]
4
-
5
-
6
- = The NullDB Connection Adapter Plugin
7
-
8
- == What
9
-
10
- NullDB is the Null Object pattern as applied to ActiveRecord database
11
- adapters. It is a database backend that translates database
12
- interactions into no-ops. Using NullDB enables you to test your model
13
- business logic - including +after_save+ hooks - without ever touching
14
- a real database.
15
-
16
- == Compatibility
17
-
18
- === Ruby
19
- Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x, 3.X.
20
-
21
- Experimental support provided for: JRuby
22
-
23
- === ActiveRecord
24
- Any version of ActiveRecord >= 5.2
25
-
26
- It is tested against AR 5.2, 6.0, 6.1 and master branch.
27
-
28
- == Installation
29
-
30
- gem install activerecord-nulldb-adapter
31
-
32
- == How
33
-
34
- Once installed, NullDB can be used much like any other ActiveRecord
35
- database adapter:
36
-
37
- ActiveRecord::Base.establish_connection :adapter => :nulldb
38
-
39
- NullDB needs to know where you keep your schema file in order to
40
- reflect table metadata. By default it looks in
41
- RAILS_ROOT/db/schema.rb. You can override that by setting the
42
- +schema+ option:
43
-
44
- ActiveRecord::Base.establish_connection :adapter => :nulldb,
45
- :schema => 'foo/myschema.rb'
46
-
47
- NullDB comes with RSpec integration. To replace the database with
48
- NullDB in all of your specs, put the following in your
49
- spec/rails_helper:
50
-
51
- require 'nulldb_rspec'
52
- include NullDB::RSpec::NullifiedDatabase
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
-
60
- Or if you just want to use NullDB in a specific spec context, you can
61
- include the same module inside a context:
62
-
63
- require 'nulldb_rspec'
64
-
65
- describe Employee, "with access to the database" do
66
- fixtures :employees
67
- # ...
68
- end
69
-
70
- describe Employee, "with NullDB" do
71
- include NullDB::RSpec::NullifiedDatabase
72
- # ...
73
- end
74
-
75
- If you want to have NullDB enabled by default but disabled for particular contexts then (see this post)[https://web.archive.org/web/20120419204019/http://andywaite.com/2011/5/18/rspec-disable-nulldb]
76
-
77
- NullDB::Rspec provides some custom matcher support for verifying
78
- expectations about interactions with the database:
79
-
80
- describe Employee do
81
- include NullDB::RSpec::NullifiedDatabase
82
-
83
- it "should cause an insert statement to be executed" do
84
- Employee.create!
85
- Employee.connection.should have_executed(:insert)
86
- end
87
- end
88
-
89
- UnitRecord-style verification that no database calls have been made at
90
- all can be achieved by using the special +:anything+ symbol:
91
-
92
- describe "stuff that shouldn't touch the database" do
93
- after :each do
94
- Employee.connection.should_not have_executed(:anything)
95
- end
96
- # ...
97
- end
98
-
99
- You can also experiment with putting NullDB in your database.yml:
100
-
101
- unit_test:
102
- adapter: nulldb
103
-
104
- However, due to the way Rails hard-codes specific database adapters
105
- into its standard Rake tasks, you may find that this generates
106
- unexpected and difficult-to-debug behavior. Workarounds for this are
107
- under development.
108
-
109
- == Why
110
-
111
- There are a number of advantages to writing unit tests that never
112
- touch the database. The biggest is probably speed of execution - unit
113
- tests must be fast for test-driven development to be practical.
114
- Another is separation of concerns: unit tests should be exercising
115
- only the business logic contained in your models, not ActiveRecord.
116
- For more on why testing-sans-database is a good idea, see:
117
- http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database.
118
-
119
- NullDB is one way to separate your unit tests from the database. It
120
- was inspired by the ARBS[http://arbs.rubyforge.org/] and
121
- UnitRecord[http://unit-test-ar.rubyforge.org/] libraries. It differs
122
- from them in that rather than modifying parts of ActiveRecord, it
123
- implements the same [semi-]well-documented public interface that the
124
- other standard database adapters, like MySQL and SQLServer,
125
- implement. This has enabled it to evolve to support new ActiveRecord
126
- versions relatively easily.
127
-
128
- One concrete advantage of this null-object pattern design is that it
129
- is possible with NullDB to test +after_save+ hooks. With NullDB, you
130
- can call +#save+ and all of the usual callbacks will be called - but
131
- nothing will be saved.
132
-
133
- == Limitations
134
-
135
- * It is *not* an in-memory database. Finds will not work. Neither
136
- will +reload+, currently. Test fixtures won't work either, for
137
- obvious reasons.
138
- * It has only the most rudimentery schema/migration support. Complex
139
- migrations will probably break it.
140
- * Lots of other things probably don't work. Patches welcome!
141
-
142
- == Who
143
-
144
- NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>.
145
- It is currently maintained by {Danilo Cabello}[https://github.com/cabello].
146
- Previously maintained by: {Bram de Vries}[https://github.com/blaet].
147
-
148
- == Where
149
-
150
- * Homepage: https://github.com/nulldb/nulldb
151
-
152
- == License
153
-
154
- See the LICENSE file for licensing information.