activerecord-nulldb-adapter 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 254fde2f4454fe03090b46daf27fffaf379db4cbca87f2a8b83f87fbd4182b74
4
- data.tar.gz: 9c2d2ddd16aecba5ed25445876184e46b9ea6acdaeef734d0846c60dead3fedb
3
+ metadata.gz: e9b442065de1ab8b6f9a1b9a4c887b4446a50ac777c8a3800f07dc7bd7806d95
4
+ data.tar.gz: 0ccc56568e9610f033361f6229e096966d242edec12e30cfe674bba268da7dc8
5
5
  SHA512:
6
- metadata.gz: 65a4477a9f589407ec410326114dca64ed342c3be15579a3f5c2467d7ed030521dad205882e48e0cb8d4e6923256baaf9ad13dd479b2f059884c52fc4c55f05f
7
- data.tar.gz: 434f119afe4c40c0824a7e62f48e6397103b5988fc70e692f5abef18bd33082b81e591b94641b928551e8ddf778cf47f465367d184c06392c0b66f317cf8e319
6
+ metadata.gz: daa0faddba9520e94ee32f169054623ca1276c2a137e8ee9f329f8c1e3a1ad60f7f08cf3febb1b3a96b71bc5955d7d89c11944f15dc77a9b2ddc555a25d7200e
7
+ data.tar.gz: 3c58d754ec1aeb41c0296e5d1b9d298581588dd40a67701e1eabd12e9c7b1d589bec39774afbf098fadaa19a02f04c902826f80bdaea42d47d6054e90ff6a29d
@@ -0,0 +1,35 @@
1
+ name: build
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ gemfile:
9
+ [
10
+ activerecord_5.2,
11
+ activerecord_6.0,
12
+ activerecord_6.1,
13
+ activerecord_master,
14
+ ]
15
+ ruby: ["2.5", "2.6", "2.7", "3.0", "jruby-9.2.13.0"]
16
+ exclude:
17
+ - ruby: "3.0"
18
+ gemfile: activerecord_5.2
19
+
20
+ - ruby: "jruby-9.2.13.0"
21
+ gemfile: activerecord_6.1
22
+
23
+ - ruby: "jruby-9.2.13.0"
24
+ gemfile: activerecord_master
25
+
26
+ runs-on: ubuntu-latest
27
+ env:
28
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+ bundler-cache: true
35
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -14,6 +14,7 @@ vendor
14
14
 
15
15
  # gem
16
16
  pkg
17
+ *.gem
17
18
 
18
19
  # mac os specific
19
20
  .DS_Store
data/CHANGES.md CHANGED
@@ -1,10 +1,15 @@
1
1
  Unreleased
2
2
  ----------
3
3
 
4
+ 0.7.0 (2021-01-18)
5
+ -----------
6
+
7
+ - Add support to Rails 6.1 #106
8
+
4
9
  0.6.0 (2021-01-08)
5
10
  -----------
6
11
 
7
- - *Breaking* Finish dropping support to Rails <= 5.1. #101
12
+ - *Breaking* Finish dropping support to Rails <= 5.1 by removing custom code for these versions. #101
8
13
 
9
14
  0.5.0 (2020-10-15)
10
15
  -----------
data/Gemfile CHANGED
@@ -1,12 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activerecord', '>= 5.2.0', '< 6.1.0'
3
+ gem 'activerecord', '>= 5.2.0', '< 6.3'
4
4
 
5
5
  group :development, :test do
6
6
  gem 'spec'
7
7
  gem 'rspec', '>= 1.2.9'
8
8
  gem 'rake'
9
9
  gem 'rdoc'
10
+ gem 'pry-byebug'
10
11
  end
11
12
 
12
13
  group :development do
@@ -1,6 +1,6 @@
1
1
  {<img src="https://badge.fury.io/rb/activerecord-nulldb-adapter.png" alt="Gem Version" />}[http://badge.fury.io/rb/activerecord-nulldb-adapter]
2
2
  {<img src="https://codeclimate.com/github/nulldb/nulldb.png" />}[https://codeclimate.com/github/nulldb/nulldb]
3
- {<img src="https://travis-ci.org/nulldb/nulldb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/nulldb/nulldb]
3
+ {<img src="https://github.com/nulldb/nulldb/workflows/build/badge.svg?branch=master" alt="Build Status" />}[https://github.com/nulldb/nulldb/actions]
4
4
 
5
5
 
6
6
  = The NullDB Connection Adapter Plugin
@@ -16,14 +16,14 @@ a real database.
16
16
  == Compatibility
17
17
 
18
18
  === Ruby
19
- Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x
19
+ Currently supported Ruby versions: MRI 2.5.x, 2.6.x, 2.7.x, 3.X.
20
20
 
21
21
  Experimental support provided for: JRuby
22
22
 
23
23
  === ActiveRecord
24
- Any version of ActiveRecord >= 5
24
+ Any version of ActiveRecord >= 5.2
25
25
 
26
- It is tested against AR 5.2, 6.0 and master branch.
26
+ It is tested against AR 5.2, 6.0, 6.1 and master branch.
27
27
 
28
28
  == Installation
29
29
 
@@ -51,7 +51,7 @@ spec/rails_helper:
51
51
  require 'nulldb_rspec'
52
52
  include NullDB::RSpec::NullifiedDatabase
53
53
 
54
- after you load your rails environment
54
+ after you load your rails environment
55
55
 
56
56
  require File.expand_path('../config/environment', __dir__)
57
57
 
@@ -20,11 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.homepage = "https://github.com/nulldb/nulldb"
21
21
  s.licenses = ["MIT"]
22
22
 
23
- s.add_runtime_dependency 'activerecord', '>= 5.2.0', '< 6.1'
23
+ s.add_runtime_dependency 'activerecord', '>= 5.2.0', '< 6.3'
24
24
  s.add_development_dependency 'spec'
25
25
  s.add_development_dependency 'rdoc'
26
26
  s.add_development_dependency 'rspec'
27
27
  s.add_development_dependency 'rake'
28
28
  s.add_development_dependency 'appraisal'
29
29
  s.add_development_dependency 'simplecov'
30
+ s.add_development_dependency 'pry-byebug'
30
31
  end
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ gem "rdoc"
12
+ end
13
+
14
+ group :development do
15
+ gem "appraisal"
16
+ gem "simplecov", require: false
17
+ end
@@ -1,20 +1,4 @@
1
1
  class ActiveRecord::ConnectionAdapters::NullDBAdapter
2
2
  class Column < ::ActiveRecord::ConnectionAdapters::Column
3
-
4
- private
5
-
6
- def simplified_type(field_type)
7
- super || simplified_type_from_sql_type
8
- end
9
-
10
- def simplified_type_from_sql_type
11
- case sql_type
12
- when :primary_key
13
- :integer
14
- when :string
15
- :string
16
- end
17
- end
18
-
19
3
  end
20
4
  end
@@ -83,15 +83,31 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
83
83
  @tables[new_name.to_s] = table_definition
84
84
  end
85
85
 
86
- def add_index(table_name, column_names, options = {})
86
+ def add_index(table_name, column_names, **options)
87
+ options[:unique] = false unless options.key?(:unique)
87
88
  column_names = Array.wrap(column_names).map(&:to_s)
88
- index_name, index_type, ignore = add_index_options(table_name, column_names, options)
89
- @indexes[table_name] << IndexDefinition.new(table_name, index_name, (index_type == 'UNIQUE'), column_names, [], [])
89
+
90
+ index, index_type, ignore = add_index_options(table_name, column_names, **options)
91
+
92
+ if index.is_a?(ActiveRecord::ConnectionAdapters::IndexDefinition)
93
+ @indexes[table_name] << index
94
+ else
95
+ # Rails < 6.1
96
+ @indexes[table_name] << IndexDefinition.new(table_name, index, (index_type == 'UNIQUE'), column_names, [], [])
97
+ end
90
98
  end
91
99
 
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 }
100
+ # Rails 6.1+
101
+ if ActiveRecord::VERSION::MAJOR >= 6 and ActiveRecord::VERSION::MINOR > 0
102
+ def remove_index(table_name, column_name = nil, **options )
103
+ index_name = index_name_for_remove(table_name, column_name, options)
104
+ index = @indexes[table_name].reject! { |index| index.name == index_name }
105
+ end
106
+ else
107
+ def remove_index(table_name, options = {} )
108
+ index_name = index_name_for_remove(table_name, options)
109
+ index = @indexes[table_name].reject! { |index| index.name == index_name }
110
+ end
95
111
  end
96
112
 
97
113
  def add_fk_constraint(*args)
@@ -129,7 +145,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
129
145
 
130
146
  if table = @tables[table_name]
131
147
  table.columns.map do |col_def|
132
- col_args = new_column_arguments(col_def)
148
+ col_args = default_column_arguments(col_def)
133
149
  ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(*col_args)
134
150
  end
135
151
  else
@@ -204,16 +220,16 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
204
220
  end
205
221
 
206
222
  def primary_key(table_name)
207
- columns(table_name).detect { |col| col.sql_type == :primary_key }.try(:name)
223
+ columns(table_name).detect { |col| col.type == :primary_key }.try(:name)
208
224
  end
209
225
 
210
- def add_column(table_name, column_name, type, options = {})
226
+ def add_column(table_name, column_name, type, **options)
211
227
  super
212
228
 
213
229
  table_meta = @tables[table_name.to_s]
214
230
  return unless table_meta
215
231
 
216
- table_meta.column column_name, type, options
232
+ table_meta.column column_name, type, **options
217
233
  end
218
234
 
219
235
  def change_column(table_name, column_name, type, options = {})
@@ -306,34 +322,23 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter < ActiveRecord::Connection
306
322
  end
307
323
  end
308
324
 
309
- def new_column_arguments(col_def)
310
- args_with_optional_cast_type(col_def)
311
- end
312
-
313
- def args_with_optional_cast_type(col_def)
314
- default_column_arguments(col_def).tap do |args|
315
- if defined?(ActiveRecord::ConnectionAdapters::SqlTypeMetadata)
316
- meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: col_def.type)
317
- args.insert(2, meta_with_limit!(meta, col_def))
318
- else
319
- args[2] = args[2].to_s + "(#{col_def.limit})" if col_def.limit
320
- end
321
- end
322
- end
323
-
324
- def meta_with_limit!(meta, col_def)
325
- meta.instance_variable_set('@limit', col_def.limit)
326
- meta
327
- end
328
-
329
325
  def default_column_arguments(col_def)
330
326
  [
331
327
  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
328
+ col_def.default.present? ? col_def.default.to_s : nil,
329
+ sql_type_definition(col_def),
330
+ col_def.null.nil? || col_def.null
334
331
  ]
335
332
  end
336
333
 
334
+ def sql_type_definition(col_def)
335
+ ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
336
+ type: col_def.type,
337
+ sql_type: col_def.type.to_s,
338
+ limit: col_def.limit
339
+ )
340
+ end
341
+
337
342
  def initialize_args
338
343
  [nil, @logger, @config]
339
344
  end
@@ -1,3 +1,3 @@
1
1
  module NullDB
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -70,6 +70,7 @@ describe "NullDB" do
70
70
  t.date :hire_date
71
71
  t.integer :employee_number
72
72
  t.decimal :salary
73
+ t.boolean :active, default: true
73
74
  end
74
75
 
75
76
  create_table(:employees_widgets, :id => false, :force => true) do |t|
@@ -108,6 +109,7 @@ describe "NullDB" do
108
109
  should_have_column(Employee, :hire_date, :date)
109
110
  should_have_column(Employee, :employee_number, :integer)
110
111
  should_have_column(Employee, :salary, :decimal)
112
+ should_have_column(Employee, :active, :boolean)
111
113
  end
112
114
 
113
115
  it 'should have limit on name' do
@@ -122,6 +124,14 @@ describe "NullDB" do
122
124
  expect(Employee.columns_hash['name'].null).to be false
123
125
  end
124
126
 
127
+ it "should stringify default values" do
128
+ expect(Employee.columns_hash['active'].default).to eq "true"
129
+ end
130
+
131
+ it "should have no default for employee_number" do
132
+ expect(Employee.columns_hash['employee_number'].default).to eq nil
133
+ end
134
+
125
135
  it "should return the appropriate primary key" do
126
136
  expect( ActiveRecord::Base.connection.primary_key('employees') ).to eq 'id'
127
137
  end
@@ -291,7 +301,13 @@ describe "NullDB" do
291
301
  end
292
302
 
293
303
  # need a fallback db for contextual nullification
294
- ActiveRecord::Base.configurations['test'] = {'adapter' => 'nulldb'}
304
+ if defined?(ActiveRecord::DatabaseConfigurations)
305
+ db_config = { 'test' => {'adapter' => 'nulldb'} }
306
+ ActiveRecord::Base.configurations = ActiveRecord::DatabaseConfigurations.new(db_config)
307
+ else
308
+ # Support ActiveRecord 5
309
+ ActiveRecord::Base.configurations['test'] = {'adapter' => 'nulldb'}
310
+ end
295
311
 
296
312
  describe NullDB::RSpec::NullifiedDatabase do
297
313
  describe 'have_executed rspec matcher' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nulldb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-01-08 00:00:00.000000000 Z
13
+ date: 2021-01-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 5.2.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '6.1'
24
+ version: '6.3'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 5.2.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.1'
34
+ version: '6.3'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: spec
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +116,20 @@ dependencies:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
+ - !ruby/object:Gem::Dependency
120
+ name: pry-byebug
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
119
133
  description: A database backend that translates database interactions into no-ops.
120
134
  Using NullDB enables you to test your model business logic - including after_save
121
135
  hooks - without ever touching a real database.
@@ -126,8 +140,8 @@ extra_rdoc_files:
126
140
  - LICENSE
127
141
  - README.rdoc
128
142
  files:
143
+ - ".github/workflows/ruby.yml"
129
144
  - ".gitignore"
130
- - ".travis.yml"
131
145
  - Appraisals
132
146
  - CHANGES.md
133
147
  - Gemfile
@@ -137,6 +151,7 @@ files:
137
151
  - activerecord-nulldb-adapter.gemspec
138
152
  - gemfiles/activerecord_5.2.gemfile
139
153
  - gemfiles/activerecord_6.0.gemfile
154
+ - gemfiles/activerecord_6.1.gemfile
140
155
  - gemfiles/activerecord_master.gemfile
141
156
  - lib/active_record/connection_adapters/nulldb_adapter.rb
142
157
  - lib/active_record/connection_adapters/nulldb_adapter/checkpoint.rb
@@ -1,21 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without development
4
- sudo: false
5
-
6
- rvm:
7
- - 2.5
8
- - 2.6
9
- - 2.7
10
- - jruby
11
-
12
- gemfile:
13
- - gemfiles/activerecord_5.2.gemfile
14
- - gemfiles/activerecord_6.0.gemfile
15
- - gemfiles/activerecord_master.gemfile
16
-
17
- matrix:
18
- fast_finish: true
19
- allow_failures:
20
- - rvm: jruby
21
- - gemfile: gemfiles/activerecord_master.gemfile