sequel-rails 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +121 -0
- data/.rubocop.yml +9 -3
- data/.rubocop_todo.yml +490 -0
- data/Gemfile +0 -1
- data/History.md +19 -2
- data/README.md +41 -8
- data/Rakefile +1 -4
- data/ci/rails-5.2.gemfile +2 -3
- data/ci/rails-6.0.gemfile +2 -3
- data/ci/{rails-5.0.gemfile → rails-6.1.gemfile} +5 -5
- data/ci/{rails-4.0.gemfile → rails-7.0.gemfile} +5 -4
- data/lib/sequel_rails/configuration.rb +2 -0
- data/lib/sequel_rails/migrations.rb +0 -1
- data/lib/sequel_rails/railtie.rb +6 -9
- data/lib/sequel_rails/storage/abstract.rb +2 -0
- data/lib/sequel_rails/version.rb +1 -1
- data/sequel-rails.gemspec +7 -6
- data/spec/helpers/io.rb +5 -0
- data/spec/integration/sessions_controller_spec.rb +1 -1
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/db/schema.rb.init +2 -2
- data/spec/lib/sequel_rails/configuration_spec.rb +31 -10
- data/spec/lib/sequel_rails/migrations_spec.rb +9 -3
- data/spec/lib/sequel_rails/railtie_spec.rb +6 -2
- data/spec/lib/sequel_rails/storage/postgres_spec.rb +11 -0
- data/spec/lib/sequel_rails/storage/sqlite_spec.rb +4 -1
- data/spec/spec_helper.rb +1 -1
- metadata +41 -37
- data/.travis.yml +0 -63
- data/ci/rails-4.1.gemfile +0 -26
- data/ci/rails-4.2.gemfile +0 -26
- data/ci/rails-5.1.gemfile +0 -28
- data/lib/sequel_rails/railties/spring_support.rb +0 -14
- data/rubocop-todo.yml +0 -39
data/README.md
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# sequel-rails
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/sequel-rails.svg)][gem]
|
4
|
-
|
4
|
+
![Build Status](https://github.com/TalentBox/sequel-rails/actions/workflows/ci.yml/badge.svg)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/TalentBox/sequel-rails.svg)][codeclimate]
|
6
6
|
|
7
7
|
[gem]: https://rubygems.org/gems/sequel-rails
|
8
|
-
[travis]: http://travis-ci.org/TalentBox/sequel-rails
|
9
8
|
[codeclimate]: https://codeclimate.com/github/TalentBox/sequel-rails
|
10
9
|
|
11
10
|
This gem provides the railtie that allows
|
12
11
|
[sequel](http://github.com/jeremyevans/sequel) to hook into
|
13
|
-
[Rails (
|
12
|
+
[Rails (5.2.x, 6.x, 7.x)](http://github.com/rails/rails) and thus behave like a
|
14
13
|
rails framework component. Just like activerecord does in rails,
|
15
14
|
[sequel-rails](http://github.com/talentbox/sequel-rails) uses the railtie API to
|
16
15
|
hook into rails. The two are actually hooked into rails almost identically.
|
@@ -28,7 +27,7 @@ Since January 2013, we've become the official maintainers of the gem after
|
|
28
27
|
Using sequel-rails
|
29
28
|
==================
|
30
29
|
|
31
|
-
Using sequel with Rails (
|
30
|
+
Using sequel with Rails (5.2.x, 6.x, 7.x) requires a couple minor changes.
|
32
31
|
|
33
32
|
First, add the following to your Gemfile (after the `Rails` lines):
|
34
33
|
|
@@ -195,6 +194,17 @@ You can configure some options with the usual rails mechanism, in
|
|
195
194
|
# to fail early
|
196
195
|
config.sequel.test_connect = true
|
197
196
|
|
197
|
+
# Configure what should happend after SequelRails will create new connection with Sequel (applicable only for the first new connection)
|
198
|
+
# config.sequel.after_connect = proc do
|
199
|
+
# Sequel::Model.plugin :timestamps, update_on_create: true
|
200
|
+
# end
|
201
|
+
|
202
|
+
# Configure what should happend after new connection in connection pool is created (applicable only for all connections)
|
203
|
+
# to fail early
|
204
|
+
# config.sequel.after_new_connection = proc do |db|
|
205
|
+
# db.execute('SET statement_timeout = 30000;')
|
206
|
+
# end
|
207
|
+
|
198
208
|
# If you want to use a specific logger
|
199
209
|
config.sequel.logger = MyLogger.new($stdout)
|
200
210
|
```
|
@@ -259,6 +269,25 @@ Here's some examples:
|
|
259
269
|
database: ":memory:"
|
260
270
|
```
|
261
271
|
|
272
|
+
after_connect hooks
|
273
|
+
================
|
274
|
+
|
275
|
+
There are 2 options how to set after_connect hooks in `config/application.rb`
|
276
|
+
|
277
|
+
1. `config.sequel.after_connect` will be called only on the first new connection. It can be used for enabling plugins or to set some global sequel settings.
|
278
|
+
```ruby
|
279
|
+
config.sequel.after_connect = proc do
|
280
|
+
Sequel::Model.plugin :timestamps, update_on_create: true
|
281
|
+
end
|
282
|
+
```
|
283
|
+
|
284
|
+
2. `config.sequel.after_new_connection` will be called after every new connection in connection pool is created. It can be used to run some specific `SET` commands on every new connection. It's using default `after_connect` hook in sequel. https://sequel.jeremyevans.net/rdoc/classes/Sequel/ConnectionPool.html#attribute-i-after_connect
|
285
|
+
```ruby
|
286
|
+
config.sequel.after_new_connection = proc do |db|
|
287
|
+
db.execute('SET statement_timeout = 30000;')
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
262
291
|
Enabling plugins
|
263
292
|
================
|
264
293
|
|
@@ -358,15 +387,15 @@ Note on Patches/Pull Requests
|
|
358
387
|
The sequel-rails team
|
359
388
|
=====================
|
360
389
|
|
361
|
-
* Jonathan Tron (JonathanTron) - Current maintainer
|
362
|
-
* Joseph Halter (JosephHalter) - Current maintainer
|
390
|
+
* Jonathan Tron (@JonathanTron) - Current maintainer
|
391
|
+
* Joseph Halter (@JosephHalter) - Current maintainer
|
363
392
|
|
364
393
|
Previous maintainer
|
365
394
|
===================
|
366
395
|
|
367
396
|
[Original project](https://github.com/brasten/sequel-rails):
|
368
397
|
|
369
|
-
* Brasten Sager (brasten) - Project creator
|
398
|
+
* Brasten Sager (@brasten) - Project creator
|
370
399
|
|
371
400
|
Contributors
|
372
401
|
============
|
@@ -417,6 +446,10 @@ Improvements have been made by those awesome contributors:
|
|
417
446
|
* p-leger (@p-leger)
|
418
447
|
* Semyon Pupkov (@artofhuman)
|
419
448
|
* Ben Koshy (@BKSpurgeon)
|
449
|
+
* Janko Marohnić (@janko)
|
450
|
+
* Adrián Mugnolo (@xymbol)
|
451
|
+
* Ivan (@AnotherRegularDude)
|
452
|
+
* kamilpavlicko (@kamilpavlicko)
|
420
453
|
|
421
454
|
Credits
|
422
455
|
=======
|
@@ -426,4 +459,4 @@ The [dm-rails](http://github.com/datamapper/dm-rails) team wrote most of the ori
|
|
426
459
|
Copyright
|
427
460
|
=========
|
428
461
|
|
429
|
-
Copyright (c) 2010-
|
462
|
+
Copyright (c) 2010-2022 The sequel-rails team. See [LICENSE](http://github.com/brasten/sequel-rails/blob/master/LICENSE) for details.
|
data/Rakefile
CHANGED
@@ -19,6 +19,7 @@ begin
|
|
19
19
|
%w(
|
20
20
|
TEST_ADAPTER
|
21
21
|
TEST_DATABASE
|
22
|
+
TEST_DATABASE_HOST
|
22
23
|
TEST_OWNER
|
23
24
|
TEST_USERNAME
|
24
25
|
TEST_PASSWORD
|
@@ -33,10 +34,6 @@ begin
|
|
33
34
|
'sqlite3' => { 'TEST_DATABASE' => File.join(File.expand_path('.'), 'spec/internal/db/database.sqlite3') },
|
34
35
|
}
|
35
36
|
|
36
|
-
configs.merge!(
|
37
|
-
'mysql' => { 'TEST_ENCODING' => 'utf8', 'TEST_USERNAME' => 'root' }
|
38
|
-
) if RUBY_VERSION < '2.4'
|
39
|
-
|
40
37
|
configs.merge!(
|
41
38
|
'mysql2' => { 'TEST_ENCODING' => 'utf8', 'TEST_USERNAME' => 'root', 'TEST_DATABASE' => 'sequel_rails_test_mysql2' }
|
42
39
|
) unless SequelRails.jruby?
|
data/ci/rails-5.2.gemfile
CHANGED
@@ -10,12 +10,11 @@ gem 'sequel', "#{ENV['SEQUEL']}"
|
|
10
10
|
|
11
11
|
gem 'fakefs', '0.11.2', :require => 'fakefs/safe'
|
12
12
|
|
13
|
+
gem 'rspec-rails', '~> 5.0'
|
14
|
+
|
13
15
|
# MRI/Rubinius Adapter Dependencies
|
14
16
|
platform :ruby do
|
15
17
|
gem 'pg'
|
16
|
-
if RUBY_VERSION < '2.4'
|
17
|
-
gem 'mysql'
|
18
|
-
end
|
19
18
|
gem 'mysql2'
|
20
19
|
gem 'sqlite3'
|
21
20
|
end
|
data/ci/rails-6.0.gemfile
CHANGED
@@ -10,12 +10,11 @@ gem 'sequel', "#{ENV['SEQUEL']}"
|
|
10
10
|
|
11
11
|
gem 'fakefs', '0.11.2', :require => 'fakefs/safe'
|
12
12
|
|
13
|
+
gem 'rspec-rails', '~> 5.0'
|
14
|
+
|
13
15
|
# MRI/Rubinius Adapter Dependencies
|
14
16
|
platform :ruby do
|
15
17
|
gem 'pg'
|
16
|
-
if RUBY_VERSION < '2.4'
|
17
|
-
gem 'mysql'
|
18
|
-
end
|
19
18
|
gem 'mysql2'
|
20
19
|
gem 'sqlite3'
|
21
20
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'railties', '~>
|
4
|
-
gem 'activemodel', '~>
|
3
|
+
gem 'railties', '~> 6.1.0'
|
4
|
+
gem 'activemodel', '~> 6.1.0'
|
5
|
+
gem 'actionpack', '~> 6.1.0'
|
5
6
|
|
6
7
|
gemspec :path => '../'
|
7
8
|
|
@@ -9,12 +10,11 @@ gem 'sequel', "#{ENV['SEQUEL']}"
|
|
9
10
|
|
10
11
|
gem 'fakefs', '0.11.2', :require => 'fakefs/safe'
|
11
12
|
|
13
|
+
gem 'rspec-rails', '~> 5.0'
|
14
|
+
|
12
15
|
# MRI/Rubinius Adapter Dependencies
|
13
16
|
platform :ruby do
|
14
17
|
gem 'pg'
|
15
|
-
if RUBY_VERSION < '2.4'
|
16
|
-
gem 'mysql'
|
17
|
-
end
|
18
18
|
gem 'mysql2'
|
19
19
|
gem 'sqlite3'
|
20
20
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'railties', '~>
|
3
|
+
gem 'railties', '~> 7.0.0'
|
4
|
+
gem 'activemodel', '~> 7.0.0'
|
5
|
+
gem 'actionpack', '~> 7.0.0'
|
4
6
|
|
5
7
|
gemspec :path => '../'
|
6
8
|
|
@@ -8,12 +10,11 @@ gem 'sequel', "#{ENV['SEQUEL']}"
|
|
8
10
|
|
9
11
|
gem 'fakefs', '0.11.2', :require => 'fakefs/safe'
|
10
12
|
|
13
|
+
gem 'rspec-rails', '~> 5.0'
|
14
|
+
|
11
15
|
# MRI/Rubinius Adapter Dependencies
|
12
16
|
platform :ruby do
|
13
17
|
gem 'pg'
|
14
|
-
if RUBY_VERSION < '2.4'
|
15
|
-
gem 'mysql'
|
16
|
-
end
|
17
18
|
gem 'mysql2'
|
18
19
|
gem 'sqlite3'
|
19
20
|
end
|
@@ -27,6 +27,7 @@ module SequelRails
|
|
27
27
|
self.schema_dump = default_schema_dump
|
28
28
|
self.load_database_tasks = true
|
29
29
|
self.after_connect = nil
|
30
|
+
self.after_new_connection = nil
|
30
31
|
self.skip_connect = nil
|
31
32
|
self.test_connect = true
|
32
33
|
end
|
@@ -75,6 +76,7 @@ module SequelRails
|
|
75
76
|
config['search_path'] = search_path if search_path
|
76
77
|
config['servers'] = servers if servers
|
77
78
|
config['test'] = test_connect
|
79
|
+
config['after_connect'] = after_new_connection if after_new_connection
|
78
80
|
|
79
81
|
url = ENV['DATABASE_URL']
|
80
82
|
config['url'] ||= url if url
|
data/lib/sequel_rails/railtie.rb
CHANGED
@@ -15,7 +15,6 @@ require 'sequel_rails/configuration'
|
|
15
15
|
require 'sequel_rails/migrations'
|
16
16
|
require 'sequel_rails/railties/log_subscriber'
|
17
17
|
require 'sequel_rails/railties/i18n_support'
|
18
|
-
require 'sequel_rails/railties/spring_support'
|
19
18
|
require 'sequel_rails/railties/controller_runtime'
|
20
19
|
require 'sequel_rails/sequel/database/active_support_notification'
|
21
20
|
require 'action_dispatch/middleware/session/sequel_store'
|
@@ -76,19 +75,17 @@ module SequelRails
|
|
76
75
|
end
|
77
76
|
|
78
77
|
initializer 'sequel.spring' do |_app|
|
79
|
-
if defined?(
|
80
|
-
class ::Spring::Application # rubocop:disable Style/ClassAndModuleChildren
|
81
|
-
include ::SequelRails::SpringSupport
|
82
|
-
alias_method :disconnect_database_without_sequel, :disconnect_database
|
83
|
-
alias_method :disconnect_database, :disconnect_database_with_sequel
|
84
|
-
end
|
85
|
-
end
|
78
|
+
Spring.after_fork { Sequel::DATABASES.each(&:disconnect) } if defined?(Spring)
|
86
79
|
end
|
87
80
|
|
88
81
|
# Support overwriting crucial steps in subclasses
|
89
82
|
def configure_sequel(app)
|
90
83
|
rails_db_config = begin
|
91
84
|
app.config.database_configuration
|
85
|
+
rescue RuntimeError => e
|
86
|
+
raise unless e.message =~ /Cannot load database configuration/
|
87
|
+
|
88
|
+
{} # will try to use DATABASE_URL
|
92
89
|
rescue Errno::ENOENT
|
93
90
|
{} # will try to use DATABASE_URL
|
94
91
|
end
|
@@ -119,7 +116,7 @@ module SequelRails
|
|
119
116
|
end
|
120
117
|
|
121
118
|
def database_create_command?
|
122
|
-
[
|
119
|
+
['db:create', 'db:create:all'].any? { |c| ARGV.include?(c) }
|
123
120
|
end
|
124
121
|
end
|
125
122
|
end
|
data/lib/sequel_rails/version.rb
CHANGED
data/sequel-rails.gemspec
CHANGED
@@ -29,12 +29,13 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_dependency 'actionpack', '>= 4.0.0'
|
30
30
|
s.add_dependency 'sequel', ['>= 3.28', '< 6.0']
|
31
31
|
|
32
|
-
s.add_development_dependency 'combustion'
|
32
|
+
s.add_development_dependency 'combustion', '~> 1.3'
|
33
33
|
s.add_development_dependency 'generator_spec'
|
34
|
-
s.add_development_dependency 'rake'
|
35
|
-
s.add_development_dependency 'rspec'
|
36
|
-
s.add_development_dependency 'rspec-rails'
|
37
|
-
s.add_development_dependency 'rubocop', '
|
38
|
-
s.add_development_dependency 'ammeter', '1.1.
|
34
|
+
s.add_development_dependency 'rake'
|
35
|
+
s.add_development_dependency 'rspec'
|
36
|
+
s.add_development_dependency 'rspec-rails'
|
37
|
+
s.add_development_dependency 'rubocop', '1.27.0'
|
38
|
+
s.add_development_dependency 'ammeter', '1.1.5'
|
39
39
|
s.add_development_dependency 'test-unit'
|
40
|
+
s.add_development_dependency 'nokogiri', '>= 1.13.4'
|
40
41
|
end
|
data/spec/helpers/io.rb
CHANGED
@@ -4,5 +4,10 @@ module IOSpecHelper
|
|
4
4
|
# if this isn't a good use for case equality I don't know what is
|
5
5
|
pattern === a.first ? raise(Errno::ENOENT) : m.call(*a) # rubocop:disable CaseEquality
|
6
6
|
end
|
7
|
+
# Rails > 6.1 uses Pathname#exists? instead of rescuing read error
|
8
|
+
allow(Pathname).to receive(:new).and_call_original
|
9
|
+
allow(Pathname).to receive(:new).with(pattern).and_return(
|
10
|
+
instance_double(Pathname, :exist? => false)
|
11
|
+
)
|
7
12
|
end
|
8
13
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
test:
|
2
2
|
adapter: "<%= ENV["TEST_ADAPTER"] || "postgresql" %>"
|
3
3
|
database: "<%= ENV["TEST_DATABASE"] || "sequel_rails_test" %>"
|
4
|
+
host: "<%= ENV["TEST_DATABASE_HOST"] %>"
|
4
5
|
<% if ENV['TEST_ADAPTER'] != 'sqlite3' %>
|
5
6
|
owner: "<%= ENV["TEST_OWNER"] || ENV["USER"] %>"
|
6
7
|
user: "<%= ENV["TEST_USERNAME"] || ENV["USER"] %>"
|
@@ -8,6 +9,8 @@ test:
|
|
8
9
|
<% end %>
|
9
10
|
<% if ENV['TEST_ADAPTER'] =~ /mysql/ %>
|
10
11
|
encoding: "<%= ENV["TEST_ENCODING"] || "utf8" %>"
|
12
|
+
port: "<%= ENV["TEST_DATABASE_PORT"] || "3306" %>"
|
11
13
|
<% elsif ENV['TEST_ADAPTER'] =~ /postgres/ %>
|
12
14
|
encoding: "<%= ENV["TEST_ENCODING"] || "unicode" %>"
|
15
|
+
port: "<%= ENV["TEST_DATABASE_PORT"] || "5432" %>"
|
13
16
|
<% end %>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Sequel.migration do
|
2
2
|
change do
|
3
|
-
create_table :users do
|
3
|
+
create_table? :users do
|
4
4
|
primary_key :id
|
5
5
|
String :email
|
6
6
|
end
|
7
|
-
create_table :sessions do
|
7
|
+
create_table? :sessions do
|
8
8
|
primary_key :id
|
9
9
|
String :session_id, :null => false, :unique => true, :index => true
|
10
10
|
String :data, :text => true, :null => false
|
@@ -113,23 +113,33 @@ describe SequelRails::Configuration do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
describe '#connect' do
|
116
|
+
let(:adapter) { ENV['TEST_ADAPTER'] || 'postgres' }
|
116
117
|
let(:environments) do
|
117
118
|
{
|
118
119
|
'development' => {
|
119
|
-
'adapter' =>
|
120
|
+
'adapter' => adapter,
|
120
121
|
'owner' => (ENV['TEST_OWNER'] || ENV['USER']),
|
121
|
-
'username' => (ENV['TEST_OWNER'] || ENV['USER']),
|
122
|
+
'username' => (ENV['TEST_USERNAME'] || ENV['TEST_OWNER'] || ENV['USER']),
|
122
123
|
'database' => 'sequel_rails_test_storage_dev',
|
123
|
-
'
|
124
|
+
'password' => ENV['TEST_PASSWORD'],
|
125
|
+
'host' => ENV['TEST_DATABASE_HOST'],
|
126
|
+
'port' => ENV['TEST_DATABASE_PORT'],
|
124
127
|
},
|
125
128
|
'test' => {
|
126
|
-
'adapter' =>
|
129
|
+
'adapter' => adapter,
|
127
130
|
'owner' => (ENV['TEST_OWNER'] || ENV['USER']),
|
128
|
-
'username' => (ENV['TEST_OWNER'] || ENV['USER']),
|
131
|
+
'username' => (ENV['TEST_USERNAME'] || ENV['TEST_OWNER'] || ENV['USER']),
|
129
132
|
'database' => 'sequel_rails_test_storage_test',
|
130
|
-
'
|
133
|
+
'password' => ENV['TEST_PASSWORD'],
|
134
|
+
'host' => ENV['TEST_DATABASE_HOST'],
|
135
|
+
'port' => ENV['TEST_DATABASE_PORT'],
|
131
136
|
},
|
132
|
-
'
|
137
|
+
'remote_pg' => {
|
138
|
+
'adapter' => 'postgres',
|
139
|
+
'host' => '10.0.0.1',
|
140
|
+
'database' => 'sequel_rails_test_storage_dev',
|
141
|
+
},
|
142
|
+
'remote_mysql' => {
|
133
143
|
'adapter' => 'mysql',
|
134
144
|
'host' => '10.0.0.1',
|
135
145
|
'database' => 'sequel_rails_test_storage_remote',
|
@@ -315,7 +325,7 @@ describe SequelRails::Configuration do
|
|
315
325
|
end
|
316
326
|
end
|
317
327
|
|
318
|
-
let(:environment) { '
|
328
|
+
let(:environment) { 'remote_pg' }
|
319
329
|
|
320
330
|
context 'in C-Ruby' do
|
321
331
|
include_examples 'test_connect'
|
@@ -347,7 +357,7 @@ describe SequelRails::Configuration do
|
|
347
357
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
348
358
|
expect(url).to start_with('jdbc:postgresql://')
|
349
359
|
expect(hash[:adapter]).to eq('jdbc:postgresql')
|
350
|
-
expect(hash[:host]).to eq('
|
360
|
+
expect(hash[:host]).to eq('10.0.0.1')
|
351
361
|
end
|
352
362
|
subject.connect environment
|
353
363
|
end
|
@@ -367,7 +377,7 @@ describe SequelRails::Configuration do
|
|
367
377
|
end
|
368
378
|
|
369
379
|
context 'for a mysql connection' do
|
370
|
-
let(:environment) { '
|
380
|
+
let(:environment) { 'remote_mysql' }
|
371
381
|
|
372
382
|
context 'in C-Ruby' do
|
373
383
|
include_examples 'test_connect'
|
@@ -427,5 +437,16 @@ describe SequelRails::Configuration do
|
|
427
437
|
subject.connect environment
|
428
438
|
end
|
429
439
|
end
|
440
|
+
|
441
|
+
describe 'after each connection hook' do
|
442
|
+
let(:environment) { 'development' }
|
443
|
+
|
444
|
+
it 'runs hook if provided' do
|
445
|
+
called = 0
|
446
|
+
subject.after_new_connection = ->(_conn){ called += 1 }
|
447
|
+
subject.connect environment
|
448
|
+
expect(called).to eq(1)
|
449
|
+
end
|
450
|
+
end
|
430
451
|
end
|
431
452
|
end
|
@@ -10,7 +10,9 @@ describe SequelRails::Migrations do
|
|
10
10
|
context 'with no version specified' do
|
11
11
|
it 'runs migrations using Sequel::Migrator' do
|
12
12
|
expect(::Sequel::Migrator).to receive(:run).with(
|
13
|
-
db,
|
13
|
+
db,
|
14
|
+
Rails.root.join('db/migrate'),
|
15
|
+
{ :allow_missing_migration_files => false }
|
14
16
|
).and_return result
|
15
17
|
expect(described_class.send(migration_method)).to be(result)
|
16
18
|
end
|
@@ -18,7 +20,9 @@ describe SequelRails::Migrations do
|
|
18
20
|
context 'with version specified' do
|
19
21
|
it 'runs migrations using Sequel::Migrator' do
|
20
22
|
expect(::Sequel::Migrator).to receive(:run).with(
|
21
|
-
db,
|
23
|
+
db,
|
24
|
+
Rails.root.join('db/migrate'),
|
25
|
+
{ :allow_missing_migration_files => false, :target => 1 }
|
22
26
|
).and_return result
|
23
27
|
expect(described_class.send(migration_method, 1)).to be(result)
|
24
28
|
end
|
@@ -36,7 +40,9 @@ describe SequelRails::Migrations do
|
|
36
40
|
|
37
41
|
it 'runs migrations using Sequel::Migrator' do
|
38
42
|
expect(::Sequel::Migrator).to receive(:run).with(
|
39
|
-
db,
|
43
|
+
db,
|
44
|
+
Rails.root.join('db/migrate'),
|
45
|
+
{ :allow_missing_migration_files => true }
|
40
46
|
).and_return result
|
41
47
|
|
42
48
|
described_class.send(migration_method)
|
@@ -93,8 +93,12 @@ describe SequelRails::Railtie do
|
|
93
93
|
|
94
94
|
context 'and DATABASE_URL is defined' do
|
95
95
|
let :database_url do
|
96
|
-
|
97
|
-
|
96
|
+
if ENV['TEST_ADAPTER']=~/sqlite/
|
97
|
+
'sqlite:/' # in-memory db
|
98
|
+
else
|
99
|
+
cfg = Combustion::Application.config.database_configuration['test']
|
100
|
+
SequelRails::DbConfig.new(cfg).url
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
104
|
around do |ex|
|
@@ -83,6 +83,17 @@ describe SequelRails::Storage::Postgres, :postgres do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
describe '#drop' do
|
87
|
+
before do
|
88
|
+
stub_const('Sequel::DATABASES', [])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'properly executes without active sequel connections' do
|
92
|
+
expect(Sequel::Model).not_to receive(:db)
|
93
|
+
subject.drop
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
86
97
|
describe '#_dump' do
|
87
98
|
let(:dump_file_name) { 'dump.sql' }
|
88
99
|
it 'uses the pg_dump command' do
|
@@ -17,7 +17,10 @@ describe SequelRails::Storage::Sqlite, :sqlite do
|
|
17
17
|
it 'defer to Sequel' do
|
18
18
|
path = double(:path)
|
19
19
|
allow(subject).to receive(:path).and_return path
|
20
|
-
expect(::Sequel).to receive(:connect).with(
|
20
|
+
expect(::Sequel).to receive(:connect).with({
|
21
|
+
'adapter' => 'sqlite3',
|
22
|
+
'database' => path
|
23
|
+
})
|
21
24
|
subject._create
|
22
25
|
end
|
23
26
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,7 @@ require 'ammeter/init'
|
|
13
13
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
14
14
|
|
15
15
|
rspec_exclusions = {}
|
16
|
-
rspec_exclusions[:skip_jdbc] = SequelRails.jruby?
|
16
|
+
rspec_exclusions[:skip_jdbc] = !SequelRails.jruby?
|
17
17
|
rspec_exclusions[:postgres] = ENV['TEST_ADAPTER'] != 'postgresql'
|
18
18
|
rspec_exclusions[:mysql] = !%w(mysql mysql2).include?(ENV['TEST_ADAPTER'])
|
19
19
|
rspec_exclusions[:sqlite] = ENV['TEST_ADAPTER'] != 'sqlite3'
|