activerecord-nulldb-adapter 0.3.9 → 0.7.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
- SHA1:
3
- metadata.gz: d5cd5ca699c63224bf641cf3e358137e6ded9a4c
4
- data.tar.gz: 04e46ea2bf9ce3bca28cf96e94e6c8b73321e447
2
+ SHA256:
3
+ metadata.gz: e9b442065de1ab8b6f9a1b9a4c887b4446a50ac777c8a3800f07dc7bd7806d95
4
+ data.tar.gz: 0ccc56568e9610f033361f6229e096966d242edec12e30cfe674bba268da7dc8
5
5
  SHA512:
6
- metadata.gz: b39b59c2cfaefa4874fa2072b1eb128042c526690e12beb211f477b3fdf35ea78a0a838e1f98e43f46fba6ffd3d286e71e0ea855695a8c1b0acd14a7bb95fe3e
7
- data.tar.gz: e33abeaa78ef7d331c02eac7f2538bc3c0837b388f2cbb4e20cdabb7b04fa2f7bcad0ef4e2991d5c4fcd0810138f958a47436d95a54aea6e25a866caa51ed843
6
+ metadata.gz: daa0faddba9520e94ee32f169054623ca1276c2a137e8ee9f329f8c1e3a1ad60f7f08cf3febb1b3a96b71bc5955d7d89c11944f15dc77a9b2ddc555a25d7200e
7
+ data.tar.gz: 3c58d754ec1aeb41c0296e5d1b9d298581588dd40a67701e1eabd12e9c7b1d589bec39774afbf098fadaa19a02f04c902826f80bdaea42d47d6054e90ff6a29d
@@ -0,0 +1,35 @@
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_master,
14
+ ]
15
+ ruby: ["2.5", "2.6", "2.7", "3.0", "jruby-9.2.13.0"]
16
+ exclude:
17
+ - ruby: "3.0"
18
+ gemfile: activerecord_5.2
19
+
20
+ - ruby: "jruby-9.2.13.0"
21
+ gemfile: activerecord_6.1
22
+
23
+ - ruby: "jruby-9.2.13.0"
24
+ gemfile: activerecord_master
25
+
26
+ runs-on: ubuntu-latest
27
+ env:
28
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+ bundler-cache: true
35
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -10,9 +10,11 @@ doc
10
10
  # bundler
11
11
  .bundle
12
12
  *.lock
13
+ vendor
13
14
 
14
15
  # gem
15
16
  pkg
17
+ *.gem
16
18
 
17
19
  # mac os specific
18
20
  .DS_Store
data/Appraisals CHANGED
@@ -1,36 +1,11 @@
1
- appraise "activerecord-2.3" do
2
- gem 'iconv', :platforms => :ruby
3
- gem "activerecord", "~> 2.3.0"
1
+ appraise "activerecord-5.2" do
2
+ gem "activerecord", "~> 5.2.0"
4
3
  end
5
4
 
6
- appraise "activerecord-3.0" do
7
- gem "activerecord", "~> 3.0.0"
5
+ appraise "activerecord-6.0" do
6
+ gem "activerecord", "~> 6.0.0"
8
7
  end
9
8
 
10
- appraise "activerecord-3.1" do
11
- gem "activerecord", "~> 3.1.0"
12
- end
13
-
14
- appraise "activerecord-3.2" do
15
- gem "activerecord", "~> 3.2.0"
16
- end
17
-
18
- appraise "activerecord-4.0" do
19
- gem "activerecord", "~> 4.0.0"
20
- end
21
-
22
- appraise "activerecord-4.1" do
23
- gem "activerecord", "~> 4.1.0"
24
- end
25
-
26
- appraise "activerecord-4.2" do
27
- gem "activerecord", "~> 4.2.0"
28
- end
29
-
30
- appraise "activerecord-5.0" do
31
- gem "activerecord", "~> 5.0.0"
32
- end
33
-
34
- appraise "activerecord-5.1" do
35
- gem "activerecord", "~> 5.1.0"
9
+ appraise "activerecord-master" do
10
+ gem "activerecord", github: 'rails/rails'
36
11
  end
data/CHANGES.md CHANGED
@@ -1,3 +1,31 @@
1
+ Unreleased
2
+ ----------
3
+
4
+ 0.7.0 (2021-01-18)
5
+ -----------
6
+
7
+ - Add support to Rails 6.1 #106
8
+
9
+ 0.6.0 (2021-01-08)
10
+ -----------
11
+
12
+ - *Breaking* Finish dropping support to Rails <= 5.1 by removing custom code for these versions. #101
13
+
14
+ 0.5.0 (2020-10-15)
15
+ -----------
16
+
17
+ - *Breaking* Drop support to Ruby 2.2, 2.3, 2.4
18
+ - *Breaking* Drop support to Rails 2.X, 3.X, 4.X, 5.0, 5.1
19
+ - Drop support to old versions of Ruby and Rails. #96
20
+ - Added support for postgres column types included jsonb and ability to delete columns #94
21
+
22
+ 0.4.0 (2019-07-22)
23
+ -----------
24
+
25
+ - *Breaking* Drop support to Ruby 1.9
26
+ - Add support for ActiveRecord 6.0 #90
27
+ - Prevent ActiveRecord::Tasks::DatabaseNotSupported #88
28
+
1
29
  0.3.9 (2018-07-07)
2
30
  -----------
3
31
  - Fix broken count
data/Gemfile CHANGED
@@ -1,12 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activerecord', '>= 2.0.0'
3
+ gem 'activerecord', '>= 5.2.0', '< 6.3'
4
4
 
5
5
  group :development, :test do
6
6
  gem 'spec'
7
7
  gem 'rspec', '>= 1.2.9'
8
8
  gem 'rake'
9
9
  gem 'rdoc'
10
+ gem 'pry-byebug'
10
11
  end
11
12
 
12
13
  group :development do
@@ -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://travis-ci.org/nulldb/nulldb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/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
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 1.9.3, 2.0.0, 2.1.x, 2.2.x, 2.3.x
19
+ Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x, 3.X.
20
20
 
21
- Experimental support provided for: JRuby, Rubinius (both in 1.9 mode)
21
+ Experimental support provided for: JRuby
22
22
 
23
23
  === ActiveRecord
24
- Any version of ActiveRecord since 2.0, including ActiveRecord 5.0
24
+ Any version of ActiveRecord >= 5.2
25
25
 
26
- It is tested against AR 2.3, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2 and 5.0.
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/spec_helper:
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
 
@@ -136,7 +142,8 @@ nothing will be saved.
136
142
  == Who
137
143
 
138
144
  NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>.
139
- It is currently maintained by {Bram de Vries}[https://github.com/blaet].
145
+ It is currently maintained by {Danilo Cabello}[https://github.com/cabello].
146
+ Previously maintained by: {Bram de Vries}[https://github.com/blaet].
140
147
 
141
148
  == Where
142
149
 
@@ -8,24 +8,24 @@ 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 = "myron.marston@gmail.com"
14
+ s.email = "cabello@users.noreply.github.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = `git ls-files`.split($/)
20
- s.homepage = "http://github.com/nulldb/nulldb"
20
+ s.homepage = "https://github.com/nulldb/nulldb"
21
21
  s.licenses = ["MIT"]
22
22
 
23
- s.add_runtime_dependency 'activerecord', '>= 2.0.0'
23
+ s.add_runtime_dependency 'activerecord', '>= 5.2.0', '< 6.3'
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
-
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.1.0"
5
+ gem "activerecord", "~> 5.2.0"
6
6
 
7
7
  group :development, :test do
8
8
  gem "spec"
9
9
  gem "rspec", ">= 1.2.9"
10
10
  gem "rake"
11
+ gem "rdoc"
11
12
  end
12
13
 
13
14
  group :development do
14
15
  gem "appraisal"
15
- gem "simplecov", :require => false
16
+ gem "simplecov", require: false
16
17
  end
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.2.0"
5
+ gem "activerecord", "~> 6.0.0"
6
6
 
7
7
  group :development, :test do
8
8
  gem "spec"
9
9
  gem "rspec", ">= 1.2.9"
10
10
  gem "rake"
11
+ gem "rdoc"
11
12
  end
12
13
 
13
14
  group :development do
14
15
  gem "appraisal"
15
- gem "simplecov", :require => false
16
+ gem "simplecov", require: false
16
17
  end
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2.0"
5
+ gem "activerecord", "~> 6.1.0"
6
6
 
7
7
  group :development, :test do
8
8
  gem "spec"
9
9
  gem "rspec", ">= 1.2.9"
10
10
  gem "rake"
11
+ gem "rdoc"
11
12
  end
12
13
 
13
14
  group :development do
14
15
  gem "appraisal"
15
- gem "simplecov", :require => false
16
+ gem "simplecov", require: false
16
17
  end
@@ -2,19 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- git 'https://github.com/rails/rails.git' do
6
- gem 'activerecord'
7
- end
8
-
9
- gem 'arel', github: 'rails/arel', branch: 'master'
5
+ gem "activerecord", github: "rails/rails"
10
6
 
11
7
  group :development, :test do
12
8
  gem "spec"
13
9
  gem "rspec", ">= 1.2.9"
14
10
  gem "rake"
11
+ gem "rdoc"
15
12
  end
16
13
 
17
14
  group :development do
18
15
  gem "appraisal"
19
- gem "simplecov", :require => false
16
+ gem "simplecov", require: false
20
17
  end
@@ -19,3 +19,4 @@ require 'active_record/connection_adapters/nulldb_adapter/index_definition'
19
19
  require 'active_record/connection_adapters/nulldb_adapter/null_object'
20
20
  require 'active_record/connection_adapters/nulldb_adapter/table_definition'
21
21
 
22
+ require 'active_record/tasks/nulldb_database_tasks' if defined?(ActiveRecord::Tasks)
@@ -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 unless NullDB::LEGACY_ACTIVERECORD || \
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
@@ -74,44 +73,40 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
74
73
 
75
74
  yield table_definition if block_given?
76
75
 
77
- @tables[table_name] = table_definition
76
+ @tables[table_name.to_s] = table_definition
78
77
  end
79
78
 
80
- def add_index(table_name, column_names, options = {})
81
- column_names = Array.wrap(column_names).map(&:to_s)
82
- index_name, index_type, ignore = add_index_options(table_name, column_names, options)
83
- @indexes[table_name] << IndexDefinition.new(table_name, index_name, (index_type == 'UNIQUE'), column_names, [], [])
84
- end
79
+ def rename_table(table_name, new_name)
80
+ table_definition = @tables.delete(table_name.to_s)
85
81
 
86
- unless instance_methods.include? :add_index_options
87
- def add_index_options(table_name, column_name, options = {})
88
- column_names = Array.wrap(column_name)
89
- index_name = index_name(table_name, :column => column_names)
82
+ table_definition.name = new_name.to_s
83
+ @tables[new_name.to_s] = table_definition
84
+ end
90
85
 
91
- if Hash === options # legacy support, since this param was a string
92
- index_type = options[:unique] ? "UNIQUE" : ""
93
- index_name = options[:name].to_s if options.key?(:name)
94
- else
95
- index_type = options
96
- end
86
+ def add_index(table_name, column_names, **options)
87
+ options[:unique] = false unless options.key?(:unique)
88
+ column_names = Array.wrap(column_names).map(&:to_s)
97
89
 
98
- if index_name.length > index_name_length
99
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
100
- end
101
- if index_name_exists?(table_name, index_name, false)
102
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
103
- end
104
- index_columns = quoted_columns_for_index(column_names, options).join(", ")
90
+ index, index_type, ignore = add_index_options(table_name, column_names, **options)
105
91
 
106
- [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, [], [])
107
97
  end
108
98
  end
109
99
 
110
- unless instance_methods.include? :index_name_exists?
111
- def index_name_exists?(table_name, index_name, default)
112
- return default unless respond_to?(:indexes)
113
- index_name = index_name.to_s
114
- indexes(table_name).detect { |i| i.name == index_name }
100
+ # Rails 6.1+
101
+ if 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 }
115
110
  end
116
111
  end
117
112
 
@@ -150,7 +145,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
150
145
 
151
146
  if table = @tables[table_name]
152
147
  table.columns.map do |col_def|
153
- col_args = new_column_arguments(col_def)
148
+ col_args = default_column_arguments(col_def)
154
149
  ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(*col_args)
155
150
  end
156
151
  else
@@ -225,7 +220,46 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
225
220
  end
226
221
 
227
222
  def primary_key(table_name)
228
- columns(table_name).detect { |col| col.sql_type == :primary_key }.try(:name)
223
+ columns(table_name).detect { |col| col.type == :primary_key }.try(:name)
224
+ end
225
+
226
+ def add_column(table_name, column_name, type, **options)
227
+ super
228
+
229
+ table_meta = @tables[table_name.to_s]
230
+ return unless table_meta
231
+
232
+ table_meta.column column_name, type, **options
233
+ end
234
+
235
+ def change_column(table_name, column_name, type, options = {})
236
+ table_meta = @tables[table_name.to_s]
237
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
238
+ return unless column
239
+
240
+ column.type = type
241
+ column.options = options if options
242
+ end
243
+
244
+ def rename_column(table_name, column_name, new_column_name)
245
+ table_meta = @tables[table_name.to_s]
246
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
247
+ return unless column
248
+
249
+ column.name = new_column_name
250
+ end
251
+
252
+ def change_column_default(table_name, column_name, default_or_changes)
253
+ table_meta = @tables[table_name.to_s]
254
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
255
+
256
+ return unless column
257
+
258
+ if default_or_changes.kind_of? Hash
259
+ column.default = default_or_changes[:to]
260
+ else
261
+ column.default = default_or_changes
262
+ end
229
263
  end
230
264
 
231
265
  protected
@@ -273,80 +307,49 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
273
307
  end
274
308
  end
275
309
 
310
+ def includes_column?
311
+ false
312
+ end
313
+
276
314
  def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
277
315
  case ::ActiveRecord::VERSION::MAJOR
278
- when 5, 6
316
+ when 6
317
+ TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
318
+ when 5
279
319
  TableDefinition.new(table_name, is_temporary, options.except(:id), nil)
280
- when 4
281
- TableDefinition.new(native_database_types, table_name, is_temporary, options)
282
- when 2,3
283
- TableDefinition.new(adapter)
284
320
  else
285
321
  raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
286
322
  end
287
323
  end
288
324
 
289
- def new_column_arguments(col_def)
290
- args_with_optional_cast_type(col_def)
291
- end
292
-
293
- def args_with_optional_cast_type(col_def)
294
- default_column_arguments(col_def).tap do |args|
295
- if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
296
- meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
297
- args.insert(2, meta_with_limit!(meta, col_def))
298
- elsif initialize_column_with_cast_type?
299
- args.insert(2, meta_with_limit!(lookup_cast_type(col_def.type), col_def))
300
- else
301
- args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
302
- end
303
- end
304
- end
305
-
306
- def meta_with_limit!(meta, col_def)
307
- meta.instance_variable_set('@limit', col_def.limit)
308
- meta
309
- end
310
-
311
325
  def default_column_arguments(col_def)
312
- if ActiveRecord::VERSION::MAJOR >= 5
313
- [
314
- col_def.name.to_s,
315
- col_def.default,
316
- col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
317
- ]
318
- else
319
- [
320
- col_def.name.to_s,
321
- col_def.default,
322
- col_def.type,
323
- col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
324
- ]
325
- 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
+ ]
326
332
  end
327
333
 
328
- def initialize_column_with_cast_type?
329
- ::ActiveRecord::VERSION::MAJOR == 4 && ::ActiveRecord::VERSION::MINOR >= 2
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
+ )
330
340
  end
331
341
 
332
342
  def initialize_args
333
- return [nil, @logger, @config] if ActiveRecord::VERSION::MAJOR > 3
334
- [nil, @logger]
343
+ [nil, @logger, @config]
335
344
  end
336
345
 
337
- # 4.2 introduced ActiveRecord::Type
338
- # https://github.com/rails/rails/tree/4-2-stable/activerecord/lib/active_record
339
346
  def register_types
340
- if ActiveRecord::VERSION::MAJOR < 5
341
- type_map.register_type(:primary_key, ActiveRecord::Type::Integer.new)
342
- else
343
- require 'active_model/type'
344
- ActiveRecord::Type.register(
345
- :primary_key,
346
- ActiveModel::Type::Integer,
347
- adapter: adapter_name,
348
- override: true
349
- )
350
- 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
+ )
351
354
  end
352
355
  end
@@ -33,6 +33,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter
33
33
  rows.size > num
34
34
  end
35
35
 
36
+ def includes_column?(name)
37
+ false
38
+ end
36
39
  end
37
40
 
38
41
  end
@@ -1,5 +1,11 @@
1
1
  class ActiveRecord::ConnectionAdapters::NullDBAdapter
2
2
 
3
- TableDefinition = ActiveRecord::ConnectionAdapters::TableDefinition
4
-
3
+ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
4
+ attr_accessor :name
5
+ alias_method :uuid, :string
6
+ alias_method :citext, :text
7
+ alias_method :interval, :text
8
+ alias_method :geometry, :text
9
+ alias_method :jsonb, :json if method_defined? :json
10
+ end
5
11
  end
@@ -0,0 +1,29 @@
1
+ class ActiveRecord::Tasks::NullDBDatabaseTasks
2
+ def initialize(configuration)
3
+ @configuration = configuration
4
+ end
5
+
6
+ def create(master_established = false)
7
+ # NO-OP
8
+ end
9
+
10
+ def drop
11
+ # NO-OP
12
+ end
13
+
14
+ def purge
15
+ # NO-OP
16
+ end
17
+
18
+ def structure_dump(filename, extra_flags)
19
+ # NO-OP
20
+ end
21
+
22
+ def structure_load(filename, extra_flags)
23
+ # NO-OP
24
+ end
25
+
26
+ def clear_active_connections!
27
+ # NO-OP
28
+ end
29
+ end
@@ -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
@@ -2,3 +2,5 @@ require 'nulldb/core'
2
2
 
3
3
  # Need to defer calling Rails.root because when bundler loads, Rails.root is nil
4
4
  NullDB.configure {|ndb| def ndb.project_root;Rails.root;end}
5
+
6
+ ActiveRecord::Tasks::DatabaseTasks.register_task(/nulldb/, ActiveRecord::Tasks::NullDBDatabaseTasks) if defined?(ActiveRecord::Tasks)
@@ -1,3 +1,3 @@
1
1
  module NullDB
2
- VERSION = "0.3.9"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -11,12 +11,7 @@ require 'active_record'
11
11
  require 'active_record/version'
12
12
  $: << File.join(File.dirname(__FILE__), "..", "lib")
13
13
 
14
- if ActiveRecord::VERSION::MAJOR > 2
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|
@@ -84,6 +80,8 @@ describe "NullDB" do
84
80
 
85
81
  add_index "employees", :name, :name => "index_employees_on_name"
86
82
  add_index "employees", ["employee_number"], :name => "index_employees_on_employee_number", :unique => true
83
+ add_index "employees", :hire_date
84
+ remove_index "employees", :hire_date
87
85
  add_index "employees_widgets", ["employee_id", "widget_id"], :name => "my_index"
88
86
 
89
87
  add_fk_constraint "foo", "bar", "baz", "buz", "bungle"
@@ -111,6 +109,7 @@ describe "NullDB" do
111
109
  should_have_column(Employee, :hire_date, :date)
112
110
  should_have_column(Employee, :employee_number, :integer)
113
111
  should_have_column(Employee, :salary, :decimal)
112
+ should_have_column(Employee, :active, :boolean)
114
113
  end
115
114
 
116
115
  it 'should have limit on name' do
@@ -125,6 +124,14 @@ describe "NullDB" do
125
124
  expect(Employee.columns_hash['name'].null).to be false
126
125
  end
127
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
+
128
135
  it "should return the appropriate primary key" do
129
136
  expect( ActiveRecord::Base.connection.primary_key('employees') ).to eq 'id'
130
137
  end
@@ -265,7 +272,7 @@ describe "NullDB" do
265
272
  end
266
273
 
267
274
 
268
- it "should support adding indexes" do
275
+ it "should support adding and removing indexes" do
269
276
  expect( Employee.connection.indexes('employees').size ).to eq 2
270
277
  expect( Employee.connection.indexes('employees_widgets').size ).to eq 1
271
278
  end
@@ -288,13 +295,19 @@ describe "NullDB" do
288
295
  expect { NullDB.nullify }.to_not raise_error
289
296
  end
290
297
 
291
- it 'should handle count queries' do
298
+ it 'should handle count queries' do
292
299
  expect(Employee.count).to eql(0)
293
300
  end
294
301
  end
295
302
 
296
303
  # need a fallback db for contextual nullification
297
- ActiveRecord::Base.configurations['test'] = {'adapter' => 'nulldb'}
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
298
311
 
299
312
  describe NullDB::RSpec::NullifiedDatabase do
300
313
  describe 'have_executed rspec matcher' do
@@ -324,6 +337,131 @@ describe NullDB::RSpec::NullifiedDatabase do
324
337
  end
325
338
  end
326
339
 
340
+ describe 'table changes' do
341
+ before(:each) do
342
+ ActiveRecord::Base.establish_connection :adapter => :nulldb
343
+ ActiveRecord::Migration.verbose = false
344
+
345
+ ActiveRecord::Schema.define do
346
+ create_table(:employees) do |t|
347
+ t.string :name, null: false, limit: 50
348
+ t.date :hire_date
349
+ t.integer :employee_number
350
+ t.decimal :salary
351
+ end
352
+ end
353
+ end
354
+
355
+ def should_have_column(klass, col_name, col_type)
356
+ col = klass.columns_hash[col_name.to_s]
357
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
358
+ end
359
+
360
+ describe 'rename_table' do
361
+ it 'should rename a table' do
362
+ expect{
363
+ ActiveRecord::Schema.define do
364
+ rename_table :employees, :workers
365
+ end
366
+ }.to_not raise_error
367
+
368
+ class Worker < ActiveRecord::Base
369
+ after_save :on_save_finished
370
+
371
+ def on_save_finished
372
+ end
373
+ end
374
+
375
+ should_have_column(Worker, :name, :string)
376
+ should_have_column(Worker, :hire_date, :date)
377
+ should_have_column(Worker, :employee_number, :integer)
378
+ should_have_column(Worker, :salary, :decimal)
379
+
380
+ worker = Worker.create(:name => "Bob Jones")
381
+ expect(worker.name).to eq "Bob Jones"
382
+ end
383
+ end
384
+
385
+ describe 'add_column' do
386
+ it 'should add a column to an existing table' do
387
+ expect{
388
+ ActiveRecord::Schema.define do
389
+ add_column :employees, :title, :string
390
+ end
391
+ Employee.connection.schema_cache.clear!
392
+ Employee.reset_column_information
393
+ }.to_not raise_error
394
+
395
+ should_have_column(Employee, :name, :string)
396
+ should_have_column(Employee, :hire_date, :date)
397
+ should_have_column(Employee, :employee_number, :integer)
398
+ should_have_column(Employee, :salary, :decimal)
399
+ should_have_column(Employee, :title, :string)
400
+ end
401
+ end
402
+
403
+ describe 'change_column' do
404
+ it 'should change the column type' do
405
+ expect{
406
+ ActiveRecord::Schema.define do
407
+ change_column :employees, :name, :text
408
+ end
409
+ Employee.connection.schema_cache.clear!
410
+ Employee.reset_column_information
411
+ }.to_not raise_error
412
+
413
+ should_have_column(Employee, :name, :text)
414
+ should_have_column(Employee, :hire_date, :date)
415
+ should_have_column(Employee, :employee_number, :integer)
416
+ should_have_column(Employee, :salary, :decimal)
417
+ end
418
+ end
419
+
420
+ describe 'rename_column' do
421
+ it 'should rename a column' do
422
+ expect{
423
+ ActiveRecord::Schema.define do
424
+ rename_column :employees, :name, :full_name
425
+ end
426
+ Employee.connection.schema_cache.clear!
427
+ Employee.reset_column_information
428
+ }.to_not raise_error
429
+
430
+ should_have_column(Employee, :full_name, :string)
431
+ should_have_column(Employee, :hire_date, :date)
432
+ should_have_column(Employee, :employee_number, :integer)
433
+ should_have_column(Employee, :salary, :decimal)
434
+ end
435
+ end
436
+
437
+ describe 'change_column_default' do
438
+ it 'should change default value of a column' do
439
+ expect{
440
+ ActiveRecord::Schema.define do
441
+ change_column_default :employees, :name, 'Jon Doe'
442
+ end
443
+ Employee.connection.schema_cache.clear!
444
+ Employee.reset_column_information
445
+ }.to_not raise_error
446
+
447
+ columns = Employee.columns
448
+ expect(columns.second.default).to eq('Jon Doe')
449
+ end
450
+
451
+ it 'should change default value of a with has syntax' do
452
+ expect{
453
+ ActiveRecord::Schema.define do
454
+ change_column_default :employees, :name, from: nil, to: 'Jon Doe'
455
+ end
456
+ Employee.connection.schema_cache.clear!
457
+ Employee.reset_column_information
458
+ }.to_not raise_error
459
+
460
+ columns = Employee.columns
461
+ expect(columns.second.default).to eq('Jon Doe')
462
+ end
463
+ end
464
+ end
327
465
 
328
466
  describe 'adapter-specific extensions' do
329
467
  before(:all) do
@@ -331,6 +469,11 @@ describe 'adapter-specific extensions' do
331
469
  ActiveRecord::Migration.verbose = false
332
470
  end
333
471
 
472
+ def should_have_column(klass, col_name, col_type)
473
+ col = klass.columns_hash[col_name.to_s]
474
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
475
+ end
476
+
334
477
  it "supports 'enable_extension' in the schema definition" do
335
478
  expect{
336
479
  ActiveRecord::Schema.define do
@@ -339,11 +482,30 @@ describe 'adapter-specific extensions' do
339
482
  }.to_not raise_error
340
483
  end
341
484
 
342
- if ActiveRecord::VERSION::MAJOR > 4
343
- it 'registers a primary_key type' do
344
- expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
345
- .to be_a(ActiveModel::Type::Integer)
485
+ it 'supports postgres extension columns' do
486
+ expect {
487
+ ActiveRecord::Schema.define do
488
+ create_table :extended_models do |t|
489
+ t.citext :text
490
+ t.interval :time_interval
491
+ t.geometry :feature_geometry, srid: 4326, type: "multi_polygon"
492
+ t.jsonb :jsonb_column
493
+ end
494
+ end
495
+ }.to_not raise_error
496
+
497
+ class ExtendedModel < ActiveRecord::Base
346
498
  end
499
+
500
+ should_have_column(ExtendedModel, :text, :text)
501
+ should_have_column(ExtendedModel, :time_interval, :text)
502
+ should_have_column(ExtendedModel, :feature_geometry, :text)
503
+ should_have_column(ExtendedModel, :jsonb_column, :json)
504
+ end
505
+
506
+ it 'registers a primary_key type' do
507
+ expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
508
+ .to be_a(ActiveModel::Type::Integer)
347
509
  end
348
510
  end
349
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.3.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
8
8
  - Myron Marston
9
- autorequire:
9
+ - Danilo Cabello
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2018-07-07 00:00:00.000000000 Z
13
+ date: 2021-01-18 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activerecord
@@ -17,14 +18,20 @@ dependencies:
17
18
  requirements:
18
19
  - - ">="
19
20
  - !ruby/object:Gem::Version
20
- version: 2.0.0
21
+ version: 5.2.0
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '6.3'
21
25
  type: :runtime
22
26
  prerelease: false
23
27
  version_requirements: !ruby/object:Gem::Requirement
24
28
  requirements:
25
29
  - - ">="
26
30
  - !ruby/object:Gem::Version
27
- version: 2.0.0
31
+ version: 5.2.0
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '6.3'
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: myron.marston@gmail.com
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
@@ -128,13 +149,9 @@ files:
128
149
  - README.rdoc
129
150
  - Rakefile
130
151
  - activerecord-nulldb-adapter.gemspec
131
- - gemfiles/activerecord_2.3.gemfile
132
- - gemfiles/activerecord_3.2.gemfile
133
- - gemfiles/activerecord_4.0.gemfile
134
- - gemfiles/activerecord_4.1.gemfile
135
- - gemfiles/activerecord_4.2.gemfile
136
- - gemfiles/activerecord_5.0.gemfile
137
- - gemfiles/activerecord_5.1.gemfile
152
+ - gemfiles/activerecord_5.2.gemfile
153
+ - gemfiles/activerecord_6.0.gemfile
154
+ - gemfiles/activerecord_6.1.gemfile
138
155
  - gemfiles/activerecord_master.gemfile
139
156
  - lib/active_record/connection_adapters/nulldb_adapter.rb
140
157
  - lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
@@ -146,6 +163,7 @@ files:
146
163
  - lib/active_record/connection_adapters/nulldb_adapter/null_object.rb
147
164
  - lib/active_record/connection_adapters/nulldb_adapter/statement.rb
148
165
  - lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb
166
+ - lib/active_record/tasks/nulldb_database_tasks.rb
149
167
  - lib/activerecord-nulldb-adapter.rb
150
168
  - lib/nulldb.rb
151
169
  - lib/nulldb/arel_compiler.rb
@@ -157,11 +175,11 @@ files:
157
175
  - lib/tasks/database.rake
158
176
  - spec/nulldb_spec.rb
159
177
  - spec/spec.opts
160
- homepage: http://github.com/nulldb/nulldb
178
+ homepage: https://github.com/nulldb/nulldb
161
179
  licenses:
162
180
  - MIT
163
181
  metadata: {}
164
- post_install_message:
182
+ post_install_message:
165
183
  rdoc_options: []
166
184
  require_paths:
167
185
  - lib
@@ -176,9 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
194
  - !ruby/object:Gem::Version
177
195
  version: '0'
178
196
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.5.1
181
- signing_key:
197
+ rubygems_version: 3.0.3
198
+ signing_key:
182
199
  specification_version: 4
183
200
  summary: The Null Object pattern as applied to ActiveRecord database adapters
184
201
  test_files: []
@@ -1,51 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without development
4
- sudo: false
5
-
6
- rvm:
7
- - 1.9.3
8
- - 2.2.5
9
- - 2.3.1
10
- - 2.4
11
- - jruby
12
- - rbx
13
-
14
- matrix:
15
- fast_finish: true
16
- allow_failures:
17
- - rvm: jruby
18
- - rvm: rbx
19
- exclude:
20
- - rvm: 1.9.3
21
- gemfile: gemfiles/activerecord_master.gemfile
22
- - rvm: 2.2.5
23
- gemfile: gemfiles/activerecord_master.gemfile
24
- - rvm: 2.3.1
25
- gemfile: gemfiles/activerecord_master.gemfile
26
- - rvm: 1.9.3
27
- gemfile: gemfiles/activerecord_5.1.gemfile
28
- - rvm: 1.9.3
29
- gemfile: gemfiles/activerecord_5.0.gemfile
30
- - rvm: 2.4
31
- gemfile: gemfiles/activerecord_4.1.gemfile
32
- - rvm: 2.4
33
- gemfile: gemfiles/activerecord_4.0.gemfile
34
- - rvm: 2.4
35
- gemfile: gemfiles/activerecord_3.2.gemfile
36
- - rvm: 2.2.5
37
- gemfile: gemfiles/activerecord_2.3.gemfile
38
- - rvm: 2.3.1
39
- gemfile: gemfiles/activerecord_2.3.gemfile
40
- - rvm: 2.4
41
- gemfile: gemfiles/activerecord_2.3.gemfile
42
-
43
- gemfile:
44
- - gemfiles/activerecord_2.3.gemfile
45
- - gemfiles/activerecord_3.2.gemfile
46
- - gemfiles/activerecord_4.0.gemfile
47
- - gemfiles/activerecord_4.1.gemfile
48
- - gemfiles/activerecord_4.2.gemfile
49
- - gemfiles/activerecord_5.0.gemfile
50
- - gemfiles/activerecord_5.1.gemfile
51
- - gemfiles/activerecord_master.gemfile
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 2.3.0"
6
- gem "iconv", :platforms => :ruby
7
-
8
- group :development, :test do
9
- gem "spec"
10
- gem "rspec", ">= 1.2.9"
11
- gem "rake"
12
- end
13
-
14
- group :development do
15
- gem "appraisal"
16
- gem "simplecov", :require => false
17
- end
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.0"
6
-
7
- group :development, :test do
8
- gem "spec"
9
- gem "rspec", ">= 1.2.9"
10
- gem "rake"
11
- end
12
-
13
- group :development do
14
- gem "appraisal"
15
- gem "simplecov", :require => false
16
- end
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0"
6
-
7
- group :development, :test do
8
- gem "spec"
9
- gem "rspec", ">= 1.2.9"
10
- gem "rake"
11
- end
12
-
13
- group :development do
14
- gem "appraisal"
15
- gem "simplecov", :require => false
16
- end
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.0"
6
-
7
- group :development, :test do
8
- gem "spec"
9
- gem "rspec", ">= 1.2.9"
10
- gem "rake"
11
- end
12
-
13
- group :development do
14
- gem "appraisal"
15
- gem "simplecov", :require => false
16
- end