activerecord-nulldb-adapter 0.3.8 → 0.6.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: a936204a697130ba6be50b69f69a53f33a91bce7
4
- data.tar.gz: 7b72a4a62dcbceb164fdd6abeed448d2671e46cd
2
+ SHA256:
3
+ metadata.gz: 254fde2f4454fe03090b46daf27fffaf379db4cbca87f2a8b83f87fbd4182b74
4
+ data.tar.gz: 9c2d2ddd16aecba5ed25445876184e46b9ea6acdaeef734d0846c60dead3fedb
5
5
  SHA512:
6
- metadata.gz: 9247780b056dc9429814aca02b1340d910b012fa11a749a666faacd3537162356932d5cae20d1a1fee33f55923ffb69011f175de2bf887a995f05c6c1b74dfef
7
- data.tar.gz: 17ee0213ab9a305b612486558f0a6db1e32be0f699b3ca87c36a39490776d40dc663acb6f1e3f2ef22b03f7b238a78649bdab927e9a4fa6f7447ec398fa36861
6
+ metadata.gz: 65a4477a9f589407ec410326114dca64ed342c3be15579a3f5c2467d7ed030521dad205882e48e0cb8d4e6923256baaf9ad13dd479b2f059884c52fc4c55f05f
7
+ data.tar.gz: 434f119afe4c40c0824a7e62f48e6397103b5988fc70e692f5abef18bd33082b81e591b94641b928551e8ddf778cf47f465367d184c06392c0b66f317cf8e319
data/.gitignore CHANGED
@@ -10,6 +10,7 @@ doc
10
10
  # bundler
11
11
  .bundle
12
12
  *.lock
13
+ vendor
13
14
 
14
15
  # gem
15
16
  pkg
@@ -4,46 +4,18 @@ bundler_args: --without development
4
4
  sudo: false
5
5
 
6
6
  rvm:
7
- - 1.9.3
8
- - 2.1.10
9
- - 2.2.5
10
- - 2.3.1
7
+ - 2.5
8
+ - 2.6
9
+ - 2.7
11
10
  - jruby
12
- - rbx
11
+
12
+ gemfile:
13
+ - gemfiles/activerecord_5.2.gemfile
14
+ - gemfiles/activerecord_6.0.gemfile
15
+ - gemfiles/activerecord_master.gemfile
13
16
 
14
17
  matrix:
15
18
  fast_finish: true
16
19
  allow_failures:
17
20
  - rvm: jruby
18
- - rvm: rbx
19
- exclude:
20
- - rvm: 1.9.3
21
- gemfile: gemfiles/activerecord_master.gemfile
22
- - rvm: 2.1.10
23
- gemfile: gemfiles/activerecord_master.gemfile
24
- - rvm: 1.9.3
25
- gemfile: gemfiles/activerecord_5.1.gemfile
26
- - rvm: 2.1.10
27
- gemfile: gemfiles/activerecord_5.1.gemfile
28
- - rvm: 1.9.3
29
- gemfile: gemfiles/activerecord_5.0.gemfile
30
- - rvm: 2.1.10
31
- gemfile: gemfiles/activerecord_5.0.gemfile
32
- - rvm: 2.1.10
33
- gemfile: gemfiles/activerecord_2.3.gemfile
34
- - rvm: 2.2.5
35
- gemfile: gemfiles/activerecord_2.3.gemfile
36
- - rvm: 2.3.1
37
- gemfile: gemfiles/activerecord_2.3.gemfile
38
-
39
- gemfile:
40
- - gemfiles/activerecord_2.3.gemfile
41
- - gemfiles/activerecord_3.0.gemfile
42
- - gemfiles/activerecord_3.1.gemfile
43
- - gemfiles/activerecord_3.2.gemfile
44
- - gemfiles/activerecord_4.0.gemfile
45
- - gemfiles/activerecord_4.1.gemfile
46
- - gemfiles/activerecord_4.2.gemfile
47
- - gemfiles/activerecord_5.0.gemfile
48
- - gemfiles/activerecord_5.1.gemfile
49
- - gemfiles/activerecord_master.gemfile
21
+ - gemfile: gemfiles/activerecord_master.gemfile
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,33 @@
1
+ Unreleased
2
+ ----------
3
+
4
+ 0.6.0 (2021-01-08)
5
+ -----------
6
+
7
+ - *Breaking* Finish dropping support to Rails <= 5.1. #101
8
+
9
+ 0.5.0 (2020-10-15)
10
+ -----------
11
+
12
+ - *Breaking* Drop support to Ruby 2.2, 2.3, 2.4
13
+ - *Breaking* Drop support to Rails 2.X, 3.X, 4.X, 5.0, 5.1
14
+ - Drop support to old versions of Ruby and Rails. #96
15
+ - Added support for postgres column types included jsonb and ability to delete columns #94
16
+
17
+ 0.4.0 (2019-07-22)
18
+ -----------
19
+
20
+ - *Breaking* Drop support to Ruby 1.9
21
+ - Add support for ActiveRecord 6.0 #90
22
+ - Prevent ActiveRecord::Tasks::DatabaseNotSupported #88
23
+
24
+ 0.3.9 (2018-07-07)
25
+ -----------
26
+ - Fix broken count
27
+ - Avoid monkey patching Schema.define
28
+ - Support ruby 2.4 (drop support for ruby 2.1 and rails 3.0/3.1)
29
+ - Support custom TableDefinition (useful for postgres)
30
+
1
31
  0.3.8 (2018-02-06)
2
32
  -----------
3
33
  - Adds support for ActiveRecord Edge (6.0)
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activerecord', '>= 2.0.0'
3
+ gem 'activerecord', '>= 5.2.0', '< 6.1.0'
4
4
 
5
5
  group :development, :test do
6
6
  gem 'spec'
@@ -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
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
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 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,19 +8,19 @@ 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.1'
24
24
  s.add_development_dependency 'spec'
25
25
  s.add_development_dependency 'rdoc'
26
26
  s.add_development_dependency 'rspec'
@@ -28,4 +28,3 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'appraisal'
29
29
  s.add_development_dependency 'simplecov'
30
30
  end
31
-
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.0.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", "~> 3.0.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,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)
@@ -15,6 +15,8 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
15
15
  # Recognized options:
16
16
  #
17
17
  # [+:schema+] path to the schema file, relative to Rails.root
18
+ # [+:table_definition_class_name+] table definition class
19
+ # (e.g. ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition for Postgres) or nil.
18
20
  def initialize(config={})
19
21
  @log = StringIO.new
20
22
  @logger = Logger.new(@log)
@@ -25,6 +27,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
25
27
  @config = config.merge(:adapter => :nulldb)
26
28
  super *initialize_args
27
29
  @visitor ||= Arel::Visitors::ToSql.new self if defined?(Arel::Visitors::ToSql)
30
+
31
+ if config[:table_definition_class_name]
32
+ ActiveRecord::ConnectionAdapters::NullDBAdapter.send(:remove_const, 'TableDefinition')
33
+ ActiveRecord::ConnectionAdapters::NullDBAdapter.const_set('TableDefinition',
34
+ self.class.const_get(config[:table_definition_class_name]))
35
+ end
36
+
37
+ register_types
28
38
  end
29
39
 
30
40
  # A log of every statement that has been "executed" by this connection adapter
@@ -63,7 +73,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
63
73
 
64
74
  yield table_definition if block_given?
65
75
 
66
- @tables[table_name] = table_definition
76
+ @tables[table_name.to_s] = table_definition
77
+ end
78
+
79
+ def rename_table(table_name, new_name)
80
+ table_definition = @tables.delete(table_name.to_s)
81
+
82
+ table_definition.name = new_name.to_s
83
+ @tables[new_name.to_s] = table_definition
67
84
  end
68
85
 
69
86
  def add_index(table_name, column_names, options = {})
@@ -72,36 +89,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
72
89
  @indexes[table_name] << IndexDefinition.new(table_name, index_name, (index_type == 'UNIQUE'), column_names, [], [])
73
90
  end
74
91
 
75
- unless instance_methods.include? :add_index_options
76
- def add_index_options(table_name, column_name, options = {})
77
- column_names = Array.wrap(column_name)
78
- index_name = index_name(table_name, :column => column_names)
79
-
80
- if Hash === options # legacy support, since this param was a string
81
- index_type = options[:unique] ? "UNIQUE" : ""
82
- index_name = options[:name].to_s if options.key?(:name)
83
- else
84
- index_type = options
85
- end
86
-
87
- if index_name.length > index_name_length
88
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
89
- end
90
- if index_name_exists?(table_name, index_name, false)
91
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
92
- end
93
- index_columns = quoted_columns_for_index(column_names, options).join(", ")
94
-
95
- [index_name, index_type, index_columns]
96
- end
97
- end
98
-
99
- unless instance_methods.include? :index_name_exists?
100
- def index_name_exists?(table_name, index_name, default)
101
- return default unless respond_to?(:indexes)
102
- index_name = index_name.to_s
103
- indexes(table_name).detect { |i| i.name == index_name }
104
- end
92
+ def remove_index(table_name, options = {})
93
+ index_name = index_name_for_remove(table_name, options)
94
+ index = @indexes[table_name].reject! { |index| index.name == index_name }
105
95
  end
106
96
 
107
97
  def add_fk_constraint(*args)
@@ -217,11 +207,50 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
217
207
  columns(table_name).detect { |col| col.sql_type == :primary_key }.try(:name)
218
208
  end
219
209
 
210
+ def add_column(table_name, column_name, type, options = {})
211
+ super
212
+
213
+ table_meta = @tables[table_name.to_s]
214
+ return unless table_meta
215
+
216
+ table_meta.column column_name, type, options
217
+ end
218
+
219
+ def change_column(table_name, column_name, type, options = {})
220
+ table_meta = @tables[table_name.to_s]
221
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
222
+ return unless column
223
+
224
+ column.type = type
225
+ column.options = options if options
226
+ end
227
+
228
+ def rename_column(table_name, column_name, new_column_name)
229
+ table_meta = @tables[table_name.to_s]
230
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
231
+ return unless column
232
+
233
+ column.name = new_column_name
234
+ end
235
+
236
+ def change_column_default(table_name, column_name, default_or_changes)
237
+ table_meta = @tables[table_name.to_s]
238
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
239
+
240
+ return unless column
241
+
242
+ if default_or_changes.kind_of? Hash
243
+ column.default = default_or_changes[:to]
244
+ else
245
+ column.default = default_or_changes
246
+ end
247
+ end
248
+
220
249
  protected
221
250
 
222
251
  def select(statement, name = nil, binds = [])
223
252
  EmptyResult.new.tap do |r|
224
- r.columns = columns_for(name)
253
+ r.bind_column_meta(columns_for(name))
225
254
  self.execution_log << Statement.new(entry_point, statement)
226
255
  end
227
256
  end
@@ -229,8 +258,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
229
258
  private
230
259
 
231
260
  def columns_for(table_name)
232
- table_def = @tables[table_name]
233
- table_def ? table_def.columns : []
261
+ table_meta = @tables[table_name]
262
+ return [] unless table_meta
263
+ table_meta.columns
234
264
  end
235
265
 
236
266
  def next_unique_id
@@ -261,14 +291,16 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
261
291
  end
262
292
  end
263
293
 
294
+ def includes_column?
295
+ false
296
+ end
297
+
264
298
  def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
265
299
  case ::ActiveRecord::VERSION::MAJOR
266
- when 5, 6
300
+ when 6
301
+ TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
302
+ when 5
267
303
  TableDefinition.new(table_name, is_temporary, options.except(:id), nil)
268
- when 4
269
- TableDefinition.new(native_database_types, table_name, is_temporary, options)
270
- when 2,3
271
- TableDefinition.new(adapter)
272
304
  else
273
305
  raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
274
306
  end
@@ -283,8 +315,6 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
283
315
  if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
284
316
  meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
285
317
  args.insert(2, meta_with_limit!(meta, col_def))
286
- elsif initialize_column_with_cast_type?
287
- args.insert(2, meta_with_limit!(lookup_cast_type(col_def.type), col_def))
288
318
  else
289
319
  args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
290
320
  end
@@ -297,29 +327,24 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
297
327
  end
298
328
 
299
329
  def default_column_arguments(col_def)
300
- if ActiveRecord::VERSION::MAJOR >= 5
301
- [
302
- col_def.name.to_s,
303
- col_def.default,
304
- col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
305
- ]
306
- else
307
- [
308
- col_def.name.to_s,
309
- col_def.default,
310
- col_def.type,
311
- col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
312
- ]
313
- end
314
- end
315
-
316
- def initialize_column_with_cast_type?
317
- ::ActiveRecord::VERSION::MAJOR == 4 && ::ActiveRecord::VERSION::MINOR >= 2
330
+ [
331
+ col_def.name.to_s,
332
+ col_def.default,
333
+ col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
334
+ ]
318
335
  end
319
336
 
320
337
  def initialize_args
321
- return [nil, @logger, @config] if ActiveRecord::VERSION::MAJOR > 3
322
- [nil, @logger]
338
+ [nil, @logger, @config]
323
339
  end
324
340
 
341
+ def register_types
342
+ require 'active_model/type'
343
+ ActiveRecord::Type.register(
344
+ :primary_key,
345
+ ActiveModel::Type::Integer,
346
+ adapter: adapter_name,
347
+ override: true
348
+ )
349
+ end
325
350
  end
@@ -1,26 +1,41 @@
1
1
  class ActiveRecord::ConnectionAdapters::NullDBAdapter
2
2
 
3
3
  class EmptyResult < Array
4
- attr_writer :columns
5
- def rows
6
- []
7
- end
4
+ attr_reader :column_types
5
+
6
+ def bind_column_meta(columns)
7
+ @columns = columns
8
+ return if columns.empty?
8
9
 
9
- def column_types
10
- columns.map{|col| col.type}
10
+ @column_types = columns.reduce({}) do |ctypes, col|
11
+ ctypes[col.name] = ActiveRecord::Type.lookup(col.type)
12
+ ctypes
13
+ end
11
14
  end
12
15
 
13
16
  def columns
14
17
  @columns ||= []
15
18
  end
16
19
 
20
+ def column_types
21
+ @column_types ||= {}
22
+ end
23
+
17
24
  def cast_values(type_overrides = nil)
18
25
  rows
19
26
  end
20
27
 
28
+ def rows
29
+ []
30
+ end
31
+
21
32
  def >(num)
22
33
  rows.size > num
23
34
  end
35
+
36
+ def includes_column?(name)
37
+ false
38
+ end
24
39
  end
25
40
 
26
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
@@ -28,15 +28,4 @@ class ActiveRecord::Base
28
28
  def self.nulldb_connection(config)
29
29
  ActiveRecord::ConnectionAdapters::NullDBAdapter.new(config)
30
30
  end
31
- end
32
-
33
-
34
- module ActiveRecord
35
- # Just make sure you have the latest version of your schema
36
- superclass = ActiveRecord::VERSION::MAJOR >= 5 ? Migration.public_send(:[], "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}".to_f) : Migration
37
- class Schema < superclass
38
- def self.define(info={}, &block)
39
- instance_eval(&block)
40
- end
41
- end
42
- end
31
+ end
@@ -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.8"
2
+ VERSION = "0.6.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
@@ -84,6 +79,8 @@ describe "NullDB" do
84
79
 
85
80
  add_index "employees", :name, :name => "index_employees_on_name"
86
81
  add_index "employees", ["employee_number"], :name => "index_employees_on_employee_number", :unique => true
82
+ add_index "employees", :hire_date
83
+ remove_index "employees", :hire_date
87
84
  add_index "employees_widgets", ["employee_id", "widget_id"], :name => "my_index"
88
85
 
89
86
  add_fk_constraint "foo", "bar", "baz", "buz", "bungle"
@@ -265,7 +262,7 @@ describe "NullDB" do
265
262
  end
266
263
 
267
264
 
268
- it "should support adding indexes" do
265
+ it "should support adding and removing indexes" do
269
266
  expect( Employee.connection.indexes('employees').size ).to eq 2
270
267
  expect( Employee.connection.indexes('employees_widgets').size ).to eq 1
271
268
  end
@@ -287,6 +284,10 @@ describe "NullDB" do
287
284
  expect( ActiveRecord::Base ).to receive(:connection_pool).and_raise(ActiveRecord::ConnectionNotEstablished)
288
285
  expect { NullDB.nullify }.to_not raise_error
289
286
  end
287
+
288
+ it 'should handle count queries' do
289
+ expect(Employee.count).to eql(0)
290
+ end
290
291
  end
291
292
 
292
293
  # need a fallback db for contextual nullification
@@ -320,6 +321,131 @@ describe NullDB::RSpec::NullifiedDatabase do
320
321
  end
321
322
  end
322
323
 
324
+ describe 'table changes' do
325
+ before(:each) do
326
+ ActiveRecord::Base.establish_connection :adapter => :nulldb
327
+ ActiveRecord::Migration.verbose = false
328
+
329
+ ActiveRecord::Schema.define do
330
+ create_table(:employees) do |t|
331
+ t.string :name, null: false, limit: 50
332
+ t.date :hire_date
333
+ t.integer :employee_number
334
+ t.decimal :salary
335
+ end
336
+ end
337
+ end
338
+
339
+ def should_have_column(klass, col_name, col_type)
340
+ col = klass.columns_hash[col_name.to_s]
341
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
342
+ end
343
+
344
+ describe 'rename_table' do
345
+ it 'should rename a table' do
346
+ expect{
347
+ ActiveRecord::Schema.define do
348
+ rename_table :employees, :workers
349
+ end
350
+ }.to_not raise_error
351
+
352
+ class Worker < ActiveRecord::Base
353
+ after_save :on_save_finished
354
+
355
+ def on_save_finished
356
+ end
357
+ end
358
+
359
+ should_have_column(Worker, :name, :string)
360
+ should_have_column(Worker, :hire_date, :date)
361
+ should_have_column(Worker, :employee_number, :integer)
362
+ should_have_column(Worker, :salary, :decimal)
363
+
364
+ worker = Worker.create(:name => "Bob Jones")
365
+ expect(worker.name).to eq "Bob Jones"
366
+ end
367
+ end
368
+
369
+ describe 'add_column' do
370
+ it 'should add a column to an existing table' do
371
+ expect{
372
+ ActiveRecord::Schema.define do
373
+ add_column :employees, :title, :string
374
+ end
375
+ Employee.connection.schema_cache.clear!
376
+ Employee.reset_column_information
377
+ }.to_not raise_error
378
+
379
+ should_have_column(Employee, :name, :string)
380
+ should_have_column(Employee, :hire_date, :date)
381
+ should_have_column(Employee, :employee_number, :integer)
382
+ should_have_column(Employee, :salary, :decimal)
383
+ should_have_column(Employee, :title, :string)
384
+ end
385
+ end
386
+
387
+ describe 'change_column' do
388
+ it 'should change the column type' do
389
+ expect{
390
+ ActiveRecord::Schema.define do
391
+ change_column :employees, :name, :text
392
+ end
393
+ Employee.connection.schema_cache.clear!
394
+ Employee.reset_column_information
395
+ }.to_not raise_error
396
+
397
+ should_have_column(Employee, :name, :text)
398
+ should_have_column(Employee, :hire_date, :date)
399
+ should_have_column(Employee, :employee_number, :integer)
400
+ should_have_column(Employee, :salary, :decimal)
401
+ end
402
+ end
403
+
404
+ describe 'rename_column' do
405
+ it 'should rename a column' do
406
+ expect{
407
+ ActiveRecord::Schema.define do
408
+ rename_column :employees, :name, :full_name
409
+ end
410
+ Employee.connection.schema_cache.clear!
411
+ Employee.reset_column_information
412
+ }.to_not raise_error
413
+
414
+ should_have_column(Employee, :full_name, :string)
415
+ should_have_column(Employee, :hire_date, :date)
416
+ should_have_column(Employee, :employee_number, :integer)
417
+ should_have_column(Employee, :salary, :decimal)
418
+ end
419
+ end
420
+
421
+ describe 'change_column_default' do
422
+ it 'should change default value of a column' do
423
+ expect{
424
+ ActiveRecord::Schema.define do
425
+ change_column_default :employees, :name, 'Jon Doe'
426
+ end
427
+ Employee.connection.schema_cache.clear!
428
+ Employee.reset_column_information
429
+ }.to_not raise_error
430
+
431
+ columns = Employee.columns
432
+ expect(columns.second.default).to eq('Jon Doe')
433
+ end
434
+
435
+ it 'should change default value of a with has syntax' do
436
+ expect{
437
+ ActiveRecord::Schema.define do
438
+ change_column_default :employees, :name, from: nil, to: 'Jon Doe'
439
+ end
440
+ Employee.connection.schema_cache.clear!
441
+ Employee.reset_column_information
442
+ }.to_not raise_error
443
+
444
+ columns = Employee.columns
445
+ expect(columns.second.default).to eq('Jon Doe')
446
+ end
447
+ end
448
+ end
323
449
 
324
450
  describe 'adapter-specific extensions' do
325
451
  before(:all) do
@@ -327,6 +453,11 @@ describe 'adapter-specific extensions' do
327
453
  ActiveRecord::Migration.verbose = false
328
454
  end
329
455
 
456
+ def should_have_column(klass, col_name, col_type)
457
+ col = klass.columns_hash[col_name.to_s]
458
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
459
+ end
460
+
330
461
  it "supports 'enable_extension' in the schema definition" do
331
462
  expect{
332
463
  ActiveRecord::Schema.define do
@@ -334,6 +465,32 @@ describe 'adapter-specific extensions' do
334
465
  end
335
466
  }.to_not raise_error
336
467
  end
468
+
469
+ it 'supports postgres extension columns' do
470
+ expect {
471
+ ActiveRecord::Schema.define do
472
+ create_table :extended_models do |t|
473
+ t.citext :text
474
+ t.interval :time_interval
475
+ t.geometry :feature_geometry, srid: 4326, type: "multi_polygon"
476
+ t.jsonb :jsonb_column
477
+ end
478
+ end
479
+ }.to_not raise_error
480
+
481
+ class ExtendedModel < ActiveRecord::Base
482
+ end
483
+
484
+ should_have_column(ExtendedModel, :text, :text)
485
+ should_have_column(ExtendedModel, :time_interval, :text)
486
+ should_have_column(ExtendedModel, :feature_geometry, :text)
487
+ should_have_column(ExtendedModel, :jsonb_column, :json)
488
+ end
489
+
490
+ it 'registers a primary_key type' do
491
+ expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
492
+ .to be_a(ActiveModel::Type::Integer)
493
+ end
337
494
  end
338
495
 
339
496
  describe ActiveRecord::ConnectionAdapters::NullDBAdapter::EmptyResult do
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.8
4
+ version: 0.6.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-02-06 00:00:00.000000000 Z
13
+ date: 2021-01-08 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.1'
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.1'
28
35
  - !ruby/object:Gem::Dependency
29
36
  name: spec
30
37
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +119,7 @@ dependencies:
112
119
  description: A database backend that translates database interactions into no-ops.
113
120
  Using NullDB enables you to test your model business logic - including after_save
114
121
  hooks - without ever touching a real database.
115
- email: myron.marston@gmail.com
122
+ email: cabello@users.noreply.github.com
116
123
  executables: []
117
124
  extensions: []
118
125
  extra_rdoc_files:
@@ -128,15 +135,8 @@ files:
128
135
  - README.rdoc
129
136
  - Rakefile
130
137
  - activerecord-nulldb-adapter.gemspec
131
- - gemfiles/activerecord_2.3.gemfile
132
- - gemfiles/activerecord_3.0.gemfile
133
- - gemfiles/activerecord_3.1.gemfile
134
- - gemfiles/activerecord_3.2.gemfile
135
- - gemfiles/activerecord_4.0.gemfile
136
- - gemfiles/activerecord_4.1.gemfile
137
- - gemfiles/activerecord_4.2.gemfile
138
- - gemfiles/activerecord_5.0.gemfile
139
- - gemfiles/activerecord_5.1.gemfile
138
+ - gemfiles/activerecord_5.2.gemfile
139
+ - gemfiles/activerecord_6.0.gemfile
140
140
  - gemfiles/activerecord_master.gemfile
141
141
  - lib/active_record/connection_adapters/nulldb_adapter.rb
142
142
  - lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
@@ -148,6 +148,7 @@ files:
148
148
  - lib/active_record/connection_adapters/nulldb_adapter/null_object.rb
149
149
  - lib/active_record/connection_adapters/nulldb_adapter/statement.rb
150
150
  - lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb
151
+ - lib/active_record/tasks/nulldb_database_tasks.rb
151
152
  - lib/activerecord-nulldb-adapter.rb
152
153
  - lib/nulldb.rb
153
154
  - lib/nulldb/arel_compiler.rb
@@ -159,11 +160,11 @@ files:
159
160
  - lib/tasks/database.rake
160
161
  - spec/nulldb_spec.rb
161
162
  - spec/spec.opts
162
- homepage: http://github.com/nulldb/nulldb
163
+ homepage: https://github.com/nulldb/nulldb
163
164
  licenses:
164
165
  - MIT
165
166
  metadata: {}
166
- post_install_message:
167
+ post_install_message:
167
168
  rdoc_options: []
168
169
  require_paths:
169
170
  - lib
@@ -178,9 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.5.1
183
- signing_key:
182
+ rubygems_version: 3.0.3
183
+ signing_key:
184
184
  specification_version: 4
185
185
  summary: The Null Object pattern as applied to ActiveRecord database adapters
186
186
  test_files: []
@@ -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", "~> 3.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
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 3.2.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", "~> 4.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
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.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