activerecord-nulldb-adapter 0.3.7 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81d75c5def8b53125f8505b1cde22775cb4cbcbd
4
- data.tar.gz: fa4c888a50ce9aacdaa58c628890319b35ea01bc
2
+ SHA256:
3
+ metadata.gz: e780de7d78de64745ed62212e2adeaef5459888c79ce93bc4329661fa28004c6
4
+ data.tar.gz: fdbb0918d50b97d6c1fdb8a14463812bff0521d3e1bfa35356883844ec1673bb
5
5
  SHA512:
6
- metadata.gz: 9cc5c7db63a7bb752dfcd962d939887bf985a4d0b41fe017ad2310535b0b6747d776ff29976508da9b2f83271c31d1fc77bc4d7a2d9897b8909af3148e13abd5
7
- data.tar.gz: ef64f1a39cc7a96d1a5ea2efc1641a4f1019e23ecd5092bd6b100fafbc7eeac0c43c8716fc759cf00e270177d6dabbbfbf22ede67797e871a6ccb4bcfc1bedd6
6
+ metadata.gz: 18fd320b4f78637b7dae988fcf811ee5e68806903fd57b5acc90a8016c8d49a3272e756428375431a530d3caeea6cb8bc120fdcdd7149b6e5c743c47db667ebd
7
+ data.tar.gz: 9ea3e21644ba7fb2d6fb14a3a07d0b6e840b9bc181fea79bf3aff3c5c0d51a0b721f903c0060d490ca9412ee14a0ef8a6dce1a4ecd0575a96feb94a50bda28c1
@@ -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,37 @@
1
+ Unreleased
2
+ ----------
3
+
4
+ 0.5.1 (2020-11-25)
5
+ -----------
6
+
7
+ - Add support to UUID. #97
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
+
31
+ 0.3.8 (2018-02-06)
32
+ -----------
33
+ - Adds support for ActiveRecord Edge (6.0)
34
+
1
35
  0.3.7 (2017-06-04)
2
36
  -----------
3
37
  - Adds support for ActiveRecord 5.1/5.2.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ group :development, :test do
6
6
  gem 'spec'
7
7
  gem 'rspec', '>= 1.2.9'
8
8
  gem 'rake'
9
+ gem 'rdoc'
9
10
  end
10
11
 
11
12
  group :development do
@@ -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
 
@@ -136,7 +136,8 @@ nothing will be saved.
136
136
  == Who
137
137
 
138
138
  NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>.
139
- It is currently maintained by {Bram de Vries}[https://github.com/blaet].
139
+ It is currently maintained by {Danilo Cabello}[https://github.com/cabello].
140
+ Previously maintained by: {Bram de Vries}[https://github.com/blaet].
140
141
 
141
142
  == Where
142
143
 
@@ -1,24 +1,28 @@
1
1
  # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nulldb/version'
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = "activerecord-nulldb-adapter"
5
- s.version = "0.3.7"
8
+ s.version = NullDB::VERSION
6
9
 
7
10
  s.require_paths = ["lib"]
8
- s.authors = ["Avdi Grimm", "Myron Marston"]
11
+ s.authors = ["Avdi Grimm", "Myron Marston", "Danilo Cabello"]
9
12
  s.summary = "The Null Object pattern as applied to ActiveRecord database adapters"
10
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."
11
- s.email = "myron.marston@gmail.com"
14
+ s.email = "cabello@users.noreply.github.com"
12
15
  s.extra_rdoc_files = [
13
16
  "LICENSE",
14
17
  "README.rdoc"
15
18
  ]
16
19
  s.files = `git ls-files`.split($/)
17
- s.homepage = "http://github.com/nulldb/nulldb"
20
+ s.homepage = "https://github.com/nulldb/nulldb"
18
21
  s.licenses = ["MIT"]
19
22
 
20
- s.add_runtime_dependency 'activerecord', '>= 2.0.0'
23
+ s.add_runtime_dependency 'activerecord', '>= 5.2.0'
21
24
  s.add_development_dependency 'spec'
25
+ s.add_development_dependency 'rdoc'
22
26
  s.add_development_dependency 'rspec'
23
27
  s.add_development_dependency 'rake'
24
28
  s.add_development_dependency 'appraisal'
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2.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.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,17 +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
5
+ gem "activerecord", github: "rails/rails"
8
6
 
9
7
  group :development, :test do
10
8
  gem "spec"
11
9
  gem "rspec", ">= 1.2.9"
12
10
  gem "rake"
11
+ gem "rdoc"
13
12
  end
14
13
 
15
14
  group :development do
16
15
  gem "appraisal"
17
- gem "simplecov", :require => false
16
+ gem "simplecov", require: false
18
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,15 @@ 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 unless NullDB::LEGACY_ACTIVERECORD || \
38
+ ActiveRecord::VERSION::MAJOR < 4
28
39
  end
29
40
 
30
41
  # A log of every statement that has been "executed" by this connection adapter
@@ -63,7 +74,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
63
74
 
64
75
  yield table_definition if block_given?
65
76
 
66
- @tables[table_name] = table_definition
77
+ @tables[table_name.to_s] = table_definition
78
+ end
79
+
80
+ def rename_table(table_name, new_name)
81
+ table_definition = @tables.delete(table_name.to_s)
82
+
83
+ table_definition.name = new_name.to_s
84
+ @tables[new_name.to_s] = table_definition
67
85
  end
68
86
 
69
87
  def add_index(table_name, column_names, options = {})
@@ -72,6 +90,11 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
72
90
  @indexes[table_name] << IndexDefinition.new(table_name, index_name, (index_type == 'UNIQUE'), column_names, [], [])
73
91
  end
74
92
 
93
+ def remove_index(table_name, options = {})
94
+ index_name = index_name_for_remove(table_name, options)
95
+ index = @indexes[table_name].reject! { |index| index.name == index_name }
96
+ end
97
+
75
98
  unless instance_methods.include? :add_index_options
76
99
  def add_index_options(table_name, column_name, options = {})
77
100
  column_names = Array.wrap(column_name)
@@ -139,7 +162,8 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
139
162
 
140
163
  if table = @tables[table_name]
141
164
  table.columns.map do |col_def|
142
- ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(*new_column_arguments(col_def))
165
+ col_args = new_column_arguments(col_def)
166
+ ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(*col_args)
143
167
  end
144
168
  else
145
169
  []
@@ -216,11 +240,50 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
216
240
  columns(table_name).detect { |col| col.sql_type == :primary_key }.try(:name)
217
241
  end
218
242
 
243
+ def add_column(table_name, column_name, type, options = {})
244
+ super
245
+
246
+ table_meta = @tables[table_name.to_s]
247
+ return unless table_meta
248
+
249
+ table_meta.column column_name, type, options
250
+ end
251
+
252
+ def change_column(table_name, column_name, type, options = {})
253
+ table_meta = @tables[table_name.to_s]
254
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
255
+ return unless column
256
+
257
+ column.type = type
258
+ column.options = options if options
259
+ end
260
+
261
+ def rename_column(table_name, column_name, new_column_name)
262
+ table_meta = @tables[table_name.to_s]
263
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
264
+ return unless column
265
+
266
+ column.name = new_column_name
267
+ end
268
+
269
+ def change_column_default(table_name, column_name, default_or_changes)
270
+ table_meta = @tables[table_name.to_s]
271
+ column = table_meta.columns.find { |column| column.name == column_name.to_s }
272
+
273
+ return unless column
274
+
275
+ if default_or_changes.kind_of? Hash
276
+ column.default = default_or_changes[:to]
277
+ else
278
+ column.default = default_or_changes
279
+ end
280
+ end
281
+
219
282
  protected
220
283
 
221
284
  def select(statement, name = nil, binds = [])
222
285
  EmptyResult.new.tap do |r|
223
- r.columns = columns_for(name)
286
+ r.bind_column_meta(columns_for(name))
224
287
  self.execution_log << Statement.new(entry_point, statement)
225
288
  end
226
289
  end
@@ -228,8 +291,9 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
228
291
  private
229
292
 
230
293
  def columns_for(table_name)
231
- table_def = @tables[table_name]
232
- table_def ? table_def.columns : []
294
+ table_meta = @tables[table_name]
295
+ return [] unless table_meta
296
+ table_meta.columns
233
297
  end
234
298
 
235
299
  def next_unique_id
@@ -260,8 +324,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
260
324
  end
261
325
  end
262
326
 
327
+ def includes_column?
328
+ false
329
+ end
330
+
263
331
  def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
264
332
  case ::ActiveRecord::VERSION::MAJOR
333
+ when 6
334
+ TableDefinition.new(self, table_name, temporary: is_temporary, options: options.except(:id))
265
335
  when 5
266
336
  TableDefinition.new(table_name, is_temporary, options.except(:id), nil)
267
337
  when 4
@@ -296,7 +366,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
296
366
  end
297
367
 
298
368
  def default_column_arguments(col_def)
299
- if ActiveRecord::VERSION::MAJOR == 5
369
+ if ActiveRecord::VERSION::MAJOR >= 5
300
370
  [
301
371
  col_def.name.to_s,
302
372
  col_def.default,
@@ -321,4 +391,19 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
321
391
  [nil, @logger]
322
392
  end
323
393
 
394
+ # 4.2 introduced ActiveRecord::Type
395
+ # https://github.com/rails/rails/tree/4-2-stable/activerecord/lib/active_record
396
+ def register_types
397
+ if ActiveRecord::VERSION::MAJOR < 5
398
+ type_map.register_type(:primary_key, ActiveRecord::Type::Integer.new)
399
+ else
400
+ require 'active_model/type'
401
+ ActiveRecord::Type.register(
402
+ :primary_key,
403
+ ActiveModel::Type::Integer,
404
+ adapter: adapter_name,
405
+ override: true
406
+ )
407
+ end
408
+ end
324
409
  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
@@ -3,6 +3,9 @@ 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
+
6
9
  class Configuration < Struct.new(:project_root); end
7
10
 
8
11
  class << self
@@ -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)
@@ -0,0 +1,3 @@
1
+ module NullDB
2
+ VERSION = "0.5.1"
3
+ end
@@ -84,6 +84,8 @@ describe "NullDB" do
84
84
 
85
85
  add_index "employees", :name, :name => "index_employees_on_name"
86
86
  add_index "employees", ["employee_number"], :name => "index_employees_on_employee_number", :unique => true
87
+ add_index "employees", :hire_date
88
+ remove_index "employees", :hire_date
87
89
  add_index "employees_widgets", ["employee_id", "widget_id"], :name => "my_index"
88
90
 
89
91
  add_fk_constraint "foo", "bar", "baz", "buz", "bungle"
@@ -265,7 +267,7 @@ describe "NullDB" do
265
267
  end
266
268
 
267
269
 
268
- it "should support adding indexes" do
270
+ it "should support adding and removing indexes" do
269
271
  expect( Employee.connection.indexes('employees').size ).to eq 2
270
272
  expect( Employee.connection.indexes('employees_widgets').size ).to eq 1
271
273
  end
@@ -287,6 +289,10 @@ describe "NullDB" do
287
289
  expect( ActiveRecord::Base ).to receive(:connection_pool).and_raise(ActiveRecord::ConnectionNotEstablished)
288
290
  expect { NullDB.nullify }.to_not raise_error
289
291
  end
292
+
293
+ it 'should handle count queries' do
294
+ expect(Employee.count).to eql(0)
295
+ end
290
296
  end
291
297
 
292
298
  # need a fallback db for contextual nullification
@@ -320,6 +326,131 @@ describe NullDB::RSpec::NullifiedDatabase do
320
326
  end
321
327
  end
322
328
 
329
+ describe 'table changes' do
330
+ before(:each) do
331
+ ActiveRecord::Base.establish_connection :adapter => :nulldb
332
+ ActiveRecord::Migration.verbose = false
333
+
334
+ ActiveRecord::Schema.define do
335
+ create_table(:employees) do |t|
336
+ t.string :name, null: false, limit: 50
337
+ t.date :hire_date
338
+ t.integer :employee_number
339
+ t.decimal :salary
340
+ end
341
+ end
342
+ end
343
+
344
+ def should_have_column(klass, col_name, col_type)
345
+ col = klass.columns_hash[col_name.to_s]
346
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
347
+ end
348
+
349
+ describe 'rename_table' do
350
+ it 'should rename a table' do
351
+ expect{
352
+ ActiveRecord::Schema.define do
353
+ rename_table :employees, :workers
354
+ end
355
+ }.to_not raise_error
356
+
357
+ class Worker < ActiveRecord::Base
358
+ after_save :on_save_finished
359
+
360
+ def on_save_finished
361
+ end
362
+ end
363
+
364
+ should_have_column(Worker, :name, :string)
365
+ should_have_column(Worker, :hire_date, :date)
366
+ should_have_column(Worker, :employee_number, :integer)
367
+ should_have_column(Worker, :salary, :decimal)
368
+
369
+ worker = Worker.create(:name => "Bob Jones")
370
+ expect(worker.name).to eq "Bob Jones"
371
+ end
372
+ end
373
+
374
+ describe 'add_column' do
375
+ it 'should add a column to an existing table' do
376
+ expect{
377
+ ActiveRecord::Schema.define do
378
+ add_column :employees, :title, :string
379
+ end
380
+ Employee.connection.schema_cache.clear!
381
+ Employee.reset_column_information
382
+ }.to_not raise_error
383
+
384
+ should_have_column(Employee, :name, :string)
385
+ should_have_column(Employee, :hire_date, :date)
386
+ should_have_column(Employee, :employee_number, :integer)
387
+ should_have_column(Employee, :salary, :decimal)
388
+ should_have_column(Employee, :title, :string)
389
+ end
390
+ end
391
+
392
+ describe 'change_column' do
393
+ it 'should change the column type' do
394
+ expect{
395
+ ActiveRecord::Schema.define do
396
+ change_column :employees, :name, :text
397
+ end
398
+ Employee.connection.schema_cache.clear!
399
+ Employee.reset_column_information
400
+ }.to_not raise_error
401
+
402
+ should_have_column(Employee, :name, :text)
403
+ should_have_column(Employee, :hire_date, :date)
404
+ should_have_column(Employee, :employee_number, :integer)
405
+ should_have_column(Employee, :salary, :decimal)
406
+ end
407
+ end
408
+
409
+ describe 'rename_column' do
410
+ it 'should rename a column' do
411
+ expect{
412
+ ActiveRecord::Schema.define do
413
+ rename_column :employees, :name, :full_name
414
+ end
415
+ Employee.connection.schema_cache.clear!
416
+ Employee.reset_column_information
417
+ }.to_not raise_error
418
+
419
+ should_have_column(Employee, :full_name, :string)
420
+ should_have_column(Employee, :hire_date, :date)
421
+ should_have_column(Employee, :employee_number, :integer)
422
+ should_have_column(Employee, :salary, :decimal)
423
+ end
424
+ end
425
+
426
+ describe 'change_column_default' do
427
+ it 'should change default value of a column' do
428
+ expect{
429
+ ActiveRecord::Schema.define do
430
+ change_column_default :employees, :name, 'Jon Doe'
431
+ end
432
+ Employee.connection.schema_cache.clear!
433
+ Employee.reset_column_information
434
+ }.to_not raise_error
435
+
436
+ columns = Employee.columns
437
+ expect(columns.second.default).to eq('Jon Doe')
438
+ end
439
+
440
+ it 'should change default value of a with has syntax' do
441
+ expect{
442
+ ActiveRecord::Schema.define do
443
+ change_column_default :employees, :name, from: nil, to: 'Jon Doe'
444
+ end
445
+ Employee.connection.schema_cache.clear!
446
+ Employee.reset_column_information
447
+ }.to_not raise_error
448
+
449
+ columns = Employee.columns
450
+ expect(columns.second.default).to eq('Jon Doe')
451
+ end
452
+ end
453
+ end
323
454
 
324
455
  describe 'adapter-specific extensions' do
325
456
  before(:all) do
@@ -327,6 +458,11 @@ describe 'adapter-specific extensions' do
327
458
  ActiveRecord::Migration.verbose = false
328
459
  end
329
460
 
461
+ def should_have_column(klass, col_name, col_type)
462
+ col = klass.columns_hash[col_name.to_s]
463
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
464
+ end
465
+
330
466
  it "supports 'enable_extension' in the schema definition" do
331
467
  expect{
332
468
  ActiveRecord::Schema.define do
@@ -334,6 +470,34 @@ describe 'adapter-specific extensions' do
334
470
  end
335
471
  }.to_not raise_error
336
472
  end
473
+
474
+ it 'supports postgres extension columns' do
475
+ expect {
476
+ ActiveRecord::Schema.define do
477
+ create_table :extended_models do |t|
478
+ t.citext :text
479
+ t.interval :time_interval
480
+ t.geometry :feature_geometry, srid: 4326, type: "multi_polygon"
481
+ t.jsonb :jsonb_column
482
+ end
483
+ end
484
+ }.to_not raise_error
485
+
486
+ class ExtendedModel < ActiveRecord::Base
487
+ end
488
+
489
+ should_have_column(ExtendedModel, :text, :text)
490
+ should_have_column(ExtendedModel, :time_interval, :text)
491
+ should_have_column(ExtendedModel, :feature_geometry, :text)
492
+ should_have_column(ExtendedModel, :jsonb_column, :json)
493
+ end
494
+
495
+ if ActiveRecord::VERSION::MAJOR > 4
496
+ it 'registers a primary_key type' do
497
+ expect(ActiveRecord::Type.lookup(:primary_key, adapter: 'NullDB'))
498
+ .to be_a(ActiveModel::Type::Integer)
499
+ end
500
+ end
337
501
  end
338
502
 
339
503
  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.7
4
+ version: 0.5.1
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: 2017-06-04 00:00:00.000000000 Z
13
+ date: 2020-11-25 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activerecord
@@ -17,14 +18,14 @@ dependencies:
17
18
  requirements:
18
19
  - - ">="
19
20
  - !ruby/object:Gem::Version
20
- version: 2.0.0
21
+ version: 5.2.0
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
27
- version: 2.0.0
28
+ version: 5.2.0
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: spec
30
31
  requirement: !ruby/object:Gem::Requirement
@@ -39,6 +40,20 @@ dependencies:
39
40
  - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rdoc
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
42
57
  - !ruby/object:Gem::Dependency
43
58
  name: rspec
44
59
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +113,7 @@ dependencies:
98
113
  description: A database backend that translates database interactions into no-ops.
99
114
  Using NullDB enables you to test your model business logic - including after_save
100
115
  hooks - without ever touching a real database.
101
- email: myron.marston@gmail.com
116
+ email: cabello@users.noreply.github.com
102
117
  executables: []
103
118
  extensions: []
104
119
  extra_rdoc_files:
@@ -113,17 +128,9 @@ files:
113
128
  - LICENSE
114
129
  - README.rdoc
115
130
  - Rakefile
116
- - VERSION
117
131
  - activerecord-nulldb-adapter.gemspec
118
- - gemfiles/activerecord_2.3.gemfile
119
- - gemfiles/activerecord_3.0.gemfile
120
- - gemfiles/activerecord_3.1.gemfile
121
- - gemfiles/activerecord_3.2.gemfile
122
- - gemfiles/activerecord_4.0.gemfile
123
- - gemfiles/activerecord_4.1.gemfile
124
- - gemfiles/activerecord_4.2.gemfile
125
- - gemfiles/activerecord_5.0.gemfile
126
- - gemfiles/activerecord_5.1.gemfile
132
+ - gemfiles/activerecord_5.2.gemfile
133
+ - gemfiles/activerecord_6.0.gemfile
127
134
  - gemfiles/activerecord_master.gemfile
128
135
  - lib/active_record/connection_adapters/nulldb_adapter.rb
129
136
  - lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
@@ -135,21 +142,23 @@ files:
135
142
  - lib/active_record/connection_adapters/nulldb_adapter/null_object.rb
136
143
  - lib/active_record/connection_adapters/nulldb_adapter/statement.rb
137
144
  - lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb
145
+ - lib/active_record/tasks/nulldb_database_tasks.rb
138
146
  - lib/activerecord-nulldb-adapter.rb
139
147
  - lib/nulldb.rb
140
148
  - lib/nulldb/arel_compiler.rb
141
149
  - lib/nulldb/core.rb
142
150
  - lib/nulldb/extensions.rb
143
151
  - lib/nulldb/rails.rb
152
+ - lib/nulldb/version.rb
144
153
  - lib/nulldb_rspec.rb
145
154
  - lib/tasks/database.rake
146
155
  - spec/nulldb_spec.rb
147
156
  - spec/spec.opts
148
- homepage: http://github.com/nulldb/nulldb
157
+ homepage: https://github.com/nulldb/nulldb
149
158
  licenses:
150
159
  - MIT
151
160
  metadata: {}
152
- post_install_message:
161
+ post_install_message:
153
162
  rdoc_options: []
154
163
  require_paths:
155
164
  - lib
@@ -164,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
173
  - !ruby/object:Gem::Version
165
174
  version: '0'
166
175
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.5.2
169
- signing_key:
176
+ rubygems_version: 3.0.3
177
+ signing_key:
170
178
  specification_version: 4
171
179
  summary: The Null Object pattern as applied to ActiveRecord database adapters
172
180
  test_files: []
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.5
@@ -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.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", "~> 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", "~> 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