activerecord-nulldb-adapter 0.3.6 → 0.5.0

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: e7a2b38931986ca22035d58a578fa13a21f74360
4
- data.tar.gz: 5700dffe9b6c19f8ff9c9e0b8cb3c81887c9dde1
2
+ SHA256:
3
+ metadata.gz: e28ca94f06b2337cd9493abfad27346a67d83e2b1d2c62502d36488b141c8ce9
4
+ data.tar.gz: 8ba786f431c4869ffd2679a6306da5d80fcb93d10514cb78fc0c9e6a34d13f94
5
5
  SHA512:
6
- metadata.gz: ace3f7f82325a86cb9744fa365f740ab9317961f724412d07dfc0b8f6e83948a8b98375a228ab9721a230466908f1ed4440c268edfc555be3fd7081c0c119890
7
- data.tar.gz: 745b6c3543a7e59563cfbf78edf65345e248641d5b7e9fb90389686ee0375718ca523dc52e4db39a2a12a420a9d1e2829ed2a32242fea5e7f3038cec91f09d84
6
+ metadata.gz: 7b482f6fc83e8ed912bd7157799bca3765000656744b54edc60c9c9dacde90e0ce1218f047c17ca02825d8c0224be44bda810db446ff2dd54054916f7f273720
7
+ data.tar.gz: 8ebc55bd87b24ce9355be8b435512cb01c84608acfe036a5835a059a85f9300fe95a968220edc441bbe7dd796670c3c27f22076ae2e20888620b0b068fb2450b
@@ -4,36 +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_5.0.gemfile
22
- - rvm: 2.1.10
23
- gemfile: gemfiles/activerecord_5.0.gemfile
24
- - rvm: 2.1.10
25
- gemfile: gemfiles/activerecord_2.3.gemfile
26
- - rvm: 2.2.5
27
- gemfile: gemfiles/activerecord_2.3.gemfile
28
- - rvm: 2.3.1
29
- gemfile: gemfiles/activerecord_2.3.gemfile
30
-
31
- gemfile:
32
- - gemfiles/activerecord_2.3.gemfile
33
- - gemfiles/activerecord_3.0.gemfile
34
- - gemfiles/activerecord_3.1.gemfile
35
- - gemfiles/activerecord_3.2.gemfile
36
- - gemfiles/activerecord_4.0.gemfile
37
- - gemfiles/activerecord_4.1.gemfile
38
- - gemfiles/activerecord_4.2.gemfile
39
- - gemfiles/activerecord_5.0.gemfile
21
+ - gemfile: gemfiles/activerecord_master.gemfile
data/Appraisals CHANGED
@@ -1,32 +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"
9
+ appraise "activerecord-master" do
10
+ gem "activerecord", github: 'rails/rails'
32
11
  end
data/CHANGES.md CHANGED
@@ -1,3 +1,38 @@
1
+ Unreleased
2
+ ----------
3
+
4
+ 0.5.0 (2020-10-15)
5
+ -----------
6
+
7
+ - *Breaking* Drop support to Ruby 2.2, 2.3, 2.4
8
+ - *Breaking* Drop support to Rails 2.X, 3.X, 4.X, 5.0, 5.1
9
+ - Drop support to old versions of Ruby and Rails. #96
10
+ - Added support for postgres column types included jsonb and ability to delete columns #94
11
+
12
+ 0.4.0 (2019-07-22)
13
+ -----------
14
+
15
+ - *Breaking* Drop support to Ruby 1.9
16
+ - Add support for ActiveRecord 6.0 #90
17
+ - Prevent ActiveRecord::Tasks::DatabaseNotSupported #88
18
+
19
+ 0.3.9 (2018-07-07)
20
+ -----------
21
+ - Fix broken count
22
+ - Avoid monkey patching Schema.define
23
+ - Support ruby 2.4 (drop support for ruby 2.1 and rails 3.0/3.1)
24
+ - Support custom TableDefinition (useful for postgres)
25
+
26
+ 0.3.8 (2018-02-06)
27
+ -----------
28
+ - Adds support for ActiveRecord Edge (6.0)
29
+
30
+ 0.3.7 (2017-06-04)
31
+ -----------
32
+ - Adds support for ActiveRecord 5.1/5.2.
33
+ - Support limit and null
34
+
35
+
1
36
  0.3.6 (2016-11-23)
2
37
  -----------
3
38
  - Adds support for ActiveRecord 5.0.
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,8 +1,11 @@
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.6"
8
+ s.version = NullDB::VERSION
6
9
 
7
10
  s.require_paths = ["lib"]
8
11
  s.authors = ["Avdi Grimm", "Myron Marston"]
@@ -14,11 +17,12 @@ Gem::Specification.new do |s|
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,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.0.0"
5
+ gem "activerecord", github: "rails/rails"
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
@@ -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
@@ -279,21 +349,37 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
279
349
 
280
350
  def args_with_optional_cast_type(col_def)
281
351
  default_column_arguments(col_def).tap do |args|
282
- if respond_to? :fetch_type_metadata
283
- args.insert(2, fetch_type_metadata(col_def.type))
352
+ if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
353
+ meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
354
+ args.insert(2, meta_with_limit!(meta, col_def))
284
355
  elsif initialize_column_with_cast_type?
285
- args.insert(2, lookup_cast_type(col_def.type))
356
+ args.insert(2, meta_with_limit!(lookup_cast_type(col_def.type), col_def))
357
+ else
358
+ args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
286
359
  end
287
360
  end
288
361
  end
289
362
 
363
+ def meta_with_limit!(meta, col_def)
364
+ meta.instance_variable_set('@limit', col_def.limit)
365
+ meta
366
+ end
367
+
290
368
  def default_column_arguments(col_def)
291
- [
292
- col_def.name.to_s,
293
- col_def.default,
294
- col_def.type,
295
- col_def.null
296
- ]
369
+ if ActiveRecord::VERSION::MAJOR >= 5
370
+ [
371
+ col_def.name.to_s,
372
+ col_def.default,
373
+ col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
374
+ ]
375
+ else
376
+ [
377
+ col_def.name.to_s,
378
+ col_def.default,
379
+ col_def.type,
380
+ col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
381
+ ]
382
+ end
297
383
  end
298
384
 
299
385
  def initialize_column_with_cast_type?
@@ -305,4 +391,19 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
305
391
  [nil, @logger]
306
392
  end
307
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
308
409
  end
@@ -1,22 +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
27
+
28
+ def rows
29
+ []
30
+ end
31
+
32
+ def >(num)
33
+ rows.size > num
34
+ end
35
+
36
+ def includes_column?(name)
37
+ false
38
+ end
20
39
  end
21
40
 
22
41
  end
@@ -1,5 +1,10 @@
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 :citext, :text
6
+ alias_method :interval, :text
7
+ alias_method :geometry, :text
8
+ alias_method :jsonb, :json if method_defined? :json
9
+ end
5
10
  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[5.0] : 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.0"
3
+ end
@@ -71,7 +71,7 @@ describe "NullDB" do
71
71
  ActiveRecord::Migration.verbose = false
72
72
  ActiveRecord::Schema.define do
73
73
  create_table(:employees) do |t|
74
- t.string :name
74
+ t.string :name, null: false, limit: 50
75
75
  t.date :hire_date
76
76
  t.integer :employee_number
77
77
  t.decimal :salary
@@ -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"
@@ -113,6 +115,18 @@ describe "NullDB" do
113
115
  should_have_column(Employee, :salary, :decimal)
114
116
  end
115
117
 
118
+ it 'should have limit on name' do
119
+ expect(Employee.columns_hash['name'].limit).to eq 50
120
+ end
121
+
122
+ it "should return true on nullable field" do
123
+ expect(Employee.columns_hash['salary'].null).to be true
124
+ end
125
+
126
+ it "should return false on non-nullable field" do
127
+ expect(Employee.columns_hash['name'].null).to be false
128
+ end
129
+
116
130
  it "should return the appropriate primary key" do
117
131
  expect( ActiveRecord::Base.connection.primary_key('employees') ).to eq 'id'
118
132
  end
@@ -249,11 +263,11 @@ describe "NullDB" do
249
263
 
250
264
  def should_have_column(klass, col_name, col_type)
251
265
  col = klass.columns_hash[col_name.to_s]
252
- expect(col.sql_type.to_sym).to eq col_type
266
+ expect(col.sql_type.to_s.gsub(/\([0-9]+\)/, "").to_sym).to eq col_type
253
267
  end
254
268
 
255
269
 
256
- it "should support adding indexes" do
270
+ it "should support adding and removing indexes" do
257
271
  expect( Employee.connection.indexes('employees').size ).to eq 2
258
272
  expect( Employee.connection.indexes('employees_widgets').size ).to eq 1
259
273
  end
@@ -275,6 +289,10 @@ describe "NullDB" do
275
289
  expect( ActiveRecord::Base ).to receive(:connection_pool).and_raise(ActiveRecord::ConnectionNotEstablished)
276
290
  expect { NullDB.nullify }.to_not raise_error
277
291
  end
292
+
293
+ it 'should handle count queries' do
294
+ expect(Employee.count).to eql(0)
295
+ end
278
296
  end
279
297
 
280
298
  # need a fallback db for contextual nullification
@@ -308,6 +326,131 @@ describe NullDB::RSpec::NullifiedDatabase do
308
326
  end
309
327
  end
310
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
311
454
 
312
455
  describe 'adapter-specific extensions' do
313
456
  before(:all) do
@@ -315,6 +458,11 @@ describe 'adapter-specific extensions' do
315
458
  ActiveRecord::Migration.verbose = false
316
459
  end
317
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
+
318
466
  it "supports 'enable_extension' in the schema definition" do
319
467
  expect{
320
468
  ActiveRecord::Schema.define do
@@ -322,6 +470,34 @@ describe 'adapter-specific extensions' do
322
470
  end
323
471
  }.to_not raise_error
324
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
325
501
  end
326
502
 
327
503
  describe ActiveRecord::ConnectionAdapters::NullDBAdapter::EmptyResult do
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nulldb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
8
8
  - Myron Marston
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-30 00:00:00.000000000 Z
12
+ date: 2020-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 2.0.0
20
+ version: 5.2.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 2.0.0
27
+ version: 5.2.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: spec
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rspec
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +127,10 @@ files:
113
127
  - LICENSE
114
128
  - README.rdoc
115
129
  - Rakefile
116
- - VERSION
117
130
  - 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
131
+ - gemfiles/activerecord_5.2.gemfile
132
+ - gemfiles/activerecord_6.0.gemfile
133
+ - gemfiles/activerecord_master.gemfile
126
134
  - lib/active_record/connection_adapters/nulldb_adapter.rb
127
135
  - lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
128
136
  - lib/active_record/connection_adapters/nulldb_adapter/column.rb
@@ -133,21 +141,23 @@ files:
133
141
  - lib/active_record/connection_adapters/nulldb_adapter/null_object.rb
134
142
  - lib/active_record/connection_adapters/nulldb_adapter/statement.rb
135
143
  - lib/active_record/connection_adapters/nulldb_adapter/table_definition.rb
144
+ - lib/active_record/tasks/nulldb_database_tasks.rb
136
145
  - lib/activerecord-nulldb-adapter.rb
137
146
  - lib/nulldb.rb
138
147
  - lib/nulldb/arel_compiler.rb
139
148
  - lib/nulldb/core.rb
140
149
  - lib/nulldb/extensions.rb
141
150
  - lib/nulldb/rails.rb
151
+ - lib/nulldb/version.rb
142
152
  - lib/nulldb_rspec.rb
143
153
  - lib/tasks/database.rake
144
154
  - spec/nulldb_spec.rb
145
155
  - spec/spec.opts
146
- homepage: http://github.com/nulldb/nulldb
156
+ homepage: https://github.com/nulldb/nulldb
147
157
  licenses:
148
158
  - MIT
149
159
  metadata: {}
150
- post_install_message:
160
+ post_install_message:
151
161
  rdoc_options: []
152
162
  require_paths:
153
163
  - lib
@@ -162,9 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
172
  - !ruby/object:Gem::Version
163
173
  version: '0'
164
174
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.4.8
167
- signing_key:
175
+ rubygems_version: 3.0.3
176
+ signing_key:
168
177
  specification_version: 4
169
178
  summary: The Null Object pattern as applied to ActiveRecord database adapters
170
179
  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.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