sequel-rails 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +24 -41
- data/History.md +8 -0
- data/README.md +38 -3
- data/ci/rails-3.2.gemfile +3 -0
- data/ci/rails-5.0.gemfile +25 -0
- data/lib/action_dispatch/middleware/session/sequel_store.rb +1 -1
- data/lib/generators/sequel/migration/migration_generator.rb +32 -16
- data/lib/sequel_rails.rb +23 -0
- data/lib/sequel_rails/configuration.rb +5 -4
- data/lib/sequel_rails/db_config.rb +19 -19
- data/lib/sequel_rails/railtie.rb +19 -9
- data/lib/sequel_rails/railties/controller_runtime.rb +2 -1
- data/lib/sequel_rails/railties/database.rake +30 -30
- data/lib/sequel_rails/railties/log_subscriber.rb +4 -2
- data/lib/sequel_rails/railties/spring_support.rb +13 -0
- data/lib/sequel_rails/sequel/database/active_support_notification.rb +2 -2
- data/lib/sequel_rails/shellwords.rb +1 -1
- data/lib/sequel_rails/storage.rb +1 -1
- data/lib/sequel_rails/storage/abstract.rb +3 -4
- data/lib/sequel_rails/storage/postgres.rb +0 -1
- data/lib/sequel_rails/version.rb +1 -1
- data/rubocop-todo.yml +9 -0
- data/sequel-rails.gemspec +3 -3
- data/spec/internal/config/database.yml +6 -0
- data/spec/internal/db/migrate/1273253849_add_twitter_handle_to_users.rb +0 -2
- data/spec/lib/generators/sequel/migration_spec.rb +0 -1
- data/spec/lib/generators/sequel/session_migration_spec.rb +0 -1
- data/spec/lib/sequel_rails/configuration_spec.rb +12 -27
- data/spec/lib/sequel_rails/db_config_spec.rb +26 -20
- data/spec/lib/sequel_rails/railtie_spec.rb +4 -4
- data/spec/lib/sequel_rails/railties/database_rake_spec.rb +18 -19
- data/spec/lib/sequel_rails/storage/postgres_spec.rb +1 -1
- metadata +15 -7
data/lib/sequel_rails/railtie.rb
CHANGED
@@ -15,6 +15,7 @@ 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'
|
18
19
|
require 'sequel_rails/railties/controller_runtime'
|
19
20
|
require 'sequel_rails/sequel/database/active_support_notification'
|
20
21
|
require 'action_dispatch/middleware/session/sequel_store'
|
@@ -36,10 +37,16 @@ module SequelRails
|
|
36
37
|
config.sequel = ::SequelRails::Configuration.new
|
37
38
|
|
38
39
|
rake_tasks do |app|
|
39
|
-
|
40
|
+
load_tasks_config = app.config.sequel.load_database_tasks
|
41
|
+
SequelRails::TASK_NAMESPACE =
|
42
|
+
case load_tasks_config
|
43
|
+
when Symbol, String then load_tasks_config.to_sym
|
44
|
+
else :db
|
45
|
+
end
|
46
|
+
load 'sequel_rails/railties/database.rake' if load_tasks_config
|
40
47
|
end
|
41
48
|
|
42
|
-
initializer 'sequel.load_hooks' do
|
49
|
+
initializer 'sequel.load_hooks' do
|
43
50
|
::ActiveSupport.run_load_hooks(:sequel, ::Sequel::Model)
|
44
51
|
end
|
45
52
|
|
@@ -48,7 +55,7 @@ module SequelRails
|
|
48
55
|
end
|
49
56
|
|
50
57
|
initializer 'sequel.logger' do |app|
|
51
|
-
|
58
|
+
app.config.sequel.logger ||= ::Rails.logger
|
52
59
|
end
|
53
60
|
|
54
61
|
initializer 'sequel.i18n_support' do |_app|
|
@@ -61,8 +68,15 @@ module SequelRails
|
|
61
68
|
end
|
62
69
|
|
63
70
|
initializer 'sequel.connect' do |app|
|
64
|
-
unless app.config.sequel[:skip_connect]
|
65
|
-
|
71
|
+
::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect]
|
72
|
+
end
|
73
|
+
|
74
|
+
initializer 'sequel.spring' do |app|
|
75
|
+
if defined?(::Spring::Application)
|
76
|
+
class ::Spring::Application
|
77
|
+
include ::SequelRails::SpringSupport
|
78
|
+
alias_method_chain :disconnect_database, :sequel
|
79
|
+
end
|
66
80
|
end
|
67
81
|
end
|
68
82
|
|
@@ -90,9 +104,5 @@ module SequelRails
|
|
90
104
|
require 'sequel_rails/railties/controller_runtime'
|
91
105
|
ActionController::Base.send :include, SequelRails::Railties::ControllerRuntime
|
92
106
|
end
|
93
|
-
|
94
|
-
def setup_logger(app, logger)
|
95
|
-
app.config.sequel.logger = logger
|
96
|
-
end
|
97
107
|
end
|
98
108
|
end
|
@@ -35,7 +35,8 @@ module SequelRails
|
|
35
35
|
|
36
36
|
module ClassMethods
|
37
37
|
def log_process_action(payload)
|
38
|
-
messages
|
38
|
+
messages = super
|
39
|
+
db_runtime = payload[:db_runtime]
|
39
40
|
messages << format('Models: %.1fms', db_runtime.to_f) if db_runtime
|
40
41
|
messages
|
41
42
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
require 'sequel_rails/storage'
|
2
2
|
|
3
|
+
sequel_rails_namespace = SequelRails::TASK_NAMESPACE
|
4
|
+
|
3
5
|
# TODO: DRY these up
|
4
|
-
namespace
|
6
|
+
namespace sequel_rails_namespace do
|
5
7
|
def db_for_current_env
|
6
8
|
@db_for_current_env ||= {}
|
7
9
|
@db_for_current_env[Rails.env] ||= ::SequelRails.setup(Rails.env)
|
8
10
|
end
|
9
11
|
|
10
12
|
# desc "Raises an error if there are pending migrations"
|
11
|
-
task :abort_if_pending_migrations => [:environment,
|
13
|
+
task :abort_if_pending_migrations => [:environment, "#{sequel_rails_namespace}:migrate:load"] do
|
12
14
|
if SequelRails::Migrations.pending_migrations?
|
13
15
|
warn 'You have pending migrations:'
|
14
|
-
abort
|
16
|
+
abort "Run `rake #{sequel_rails_namespace}:migrate` to update your database then try again."
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -24,7 +26,7 @@ namespace :db do
|
|
24
26
|
file << db_for_current_env.dump_schema_migration(:same_db => true)
|
25
27
|
file << SequelRails::Migrations.dump_schema_information(:sql => false)
|
26
28
|
end
|
27
|
-
Rake::Task[
|
29
|
+
Rake::Task["#{sequel_rails_namespace}:schema:dump"].reenable
|
28
30
|
end
|
29
31
|
|
30
32
|
desc 'Load a schema.rb file into the database'
|
@@ -35,7 +37,7 @@ namespace :db do
|
|
35
37
|
load(file)
|
36
38
|
::Sequel::Migration.descendants.each { |m| m.apply(db_for_current_env, :up) }
|
37
39
|
else
|
38
|
-
abort
|
40
|
+
abort '#{file} doesn\'t exist yet. Run \'rake #{sequel_rails_namespace}:migrate\' to create it, then try again.'
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -54,7 +56,7 @@ namespace :db do
|
|
54
56
|
abort "Could not dump structure for #{args.env}."
|
55
57
|
end
|
56
58
|
|
57
|
-
Rake::Task[
|
59
|
+
Rake::Task["#{sequel_rails_namespace}:structure:dump"].reenable
|
58
60
|
end
|
59
61
|
|
60
62
|
task :load, [:env] => :environment do |_t, args|
|
@@ -70,9 +72,9 @@ namespace :db do
|
|
70
72
|
task :dump => :environment do
|
71
73
|
case (SequelRails.configuration.schema_format ||= :ruby)
|
72
74
|
when :ruby
|
73
|
-
Rake::Task[
|
75
|
+
Rake::Task["#{sequel_rails_namespace}:schema:dump"].invoke
|
74
76
|
when :sql
|
75
|
-
Rake::Task[
|
77
|
+
Rake::Task["#{sequel_rails_namespace}:structure:dump"].invoke
|
76
78
|
else
|
77
79
|
abort "unknown schema format #{SequelRails.configuration.schema_format}"
|
78
80
|
end
|
@@ -81,9 +83,9 @@ namespace :db do
|
|
81
83
|
task :load => :environment do
|
82
84
|
case (SequelRails.configuration.schema_format ||= :ruby)
|
83
85
|
when :ruby
|
84
|
-
Rake::Task[
|
86
|
+
Rake::Task["#{sequel_rails_namespace}:schema:load"].invoke
|
85
87
|
when :sql
|
86
|
-
Rake::Task[
|
88
|
+
Rake::Task["#{sequel_rails_namespace}:structure:load"].invoke
|
87
89
|
else
|
88
90
|
abort "unknown schema format #{SequelRails.configuration.schema_format}"
|
89
91
|
end
|
@@ -129,23 +131,23 @@ namespace :db do
|
|
129
131
|
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
|
130
132
|
task :redo => :load do
|
131
133
|
if ENV['VERSION']
|
132
|
-
Rake::Task[
|
133
|
-
Rake::Task[
|
134
|
+
Rake::Task["#{sequel_rails_namespace}:migrate:down"].invoke
|
135
|
+
Rake::Task["#{sequel_rails_namespace}:migrate:up"].invoke
|
134
136
|
else
|
135
|
-
Rake::Task[
|
136
|
-
Rake::Task[
|
137
|
+
Rake::Task["#{sequel_rails_namespace}:rollback"].invoke
|
138
|
+
Rake::Task["#{sequel_rails_namespace}:migrate"].invoke
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
140
142
|
desc 'Resets your database using your migrations for the current environment'
|
141
|
-
task :reset => %
|
143
|
+
task :reset => %W(#{sequel_rails_namespace}:drop #{sequel_rails_namespace}:create #{sequel_rails_namespace}:migrate)
|
142
144
|
|
143
145
|
desc 'Runs the "up" for a given migration VERSION.'
|
144
146
|
task :up => :load do
|
145
147
|
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
146
148
|
fail 'VERSION is required' unless version
|
147
149
|
SequelRails::Migrations.migrate_up!(version)
|
148
|
-
Rake::Task[
|
150
|
+
Rake::Task["#{sequel_rails_namespace}:dump"].invoke if SequelRails.configuration.schema_dump
|
149
151
|
end
|
150
152
|
|
151
153
|
desc 'Runs the "down" for a given migration VERSION.'
|
@@ -153,14 +155,14 @@ namespace :db do
|
|
153
155
|
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
154
156
|
fail 'VERSION is required' unless version
|
155
157
|
SequelRails::Migrations.migrate_down!(version)
|
156
|
-
Rake::Task[
|
158
|
+
Rake::Task["#{sequel_rails_namespace}:dump"].invoke if SequelRails.configuration.schema_dump
|
157
159
|
end
|
158
160
|
end
|
159
161
|
|
160
162
|
desc 'Migrate the database to the latest version'
|
161
163
|
task :migrate => 'migrate:load' do
|
162
164
|
SequelRails::Migrations.migrate_up!(ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
|
163
|
-
Rake::Task[
|
165
|
+
Rake::Task["#{sequel_rails_namespace}:dump"].invoke if SequelRails.configuration.schema_dump
|
164
166
|
end
|
165
167
|
|
166
168
|
desc 'Rollback the latest migration file or down to specified VERSION=x'
|
@@ -171,7 +173,7 @@ namespace :db do
|
|
171
173
|
SequelRails::Migrations.previous_migration
|
172
174
|
end
|
173
175
|
SequelRails::Migrations.migrate_down! version
|
174
|
-
Rake::Task[
|
176
|
+
Rake::Task["#{sequel_rails_namespace}:dump"].invoke if SequelRails.configuration.schema_dump
|
175
177
|
end
|
176
178
|
|
177
179
|
desc 'Load the seed data from db/seeds.rb'
|
@@ -181,10 +183,10 @@ namespace :db do
|
|
181
183
|
end
|
182
184
|
|
183
185
|
desc 'Create the database, load the schema, and initialize with the seed data'
|
184
|
-
task :setup => %
|
186
|
+
task :setup => %W(#{sequel_rails_namespace}:create #{sequel_rails_namespace}:load #{sequel_rails_namespace}:seed)
|
185
187
|
|
186
188
|
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
187
|
-
task :reset => %
|
189
|
+
task :reset => %W(#{sequel_rails_namespace}:drop #{sequel_rails_namespace}:setup)
|
188
190
|
|
189
191
|
desc 'Forcibly close any open connections to the current env database (PostgreSQL specific)'
|
190
192
|
task :force_close_open_connections, [:env] => :environment do |_t, args|
|
@@ -193,18 +195,16 @@ namespace :db do
|
|
193
195
|
end
|
194
196
|
|
195
197
|
namespace :test do
|
196
|
-
desc
|
197
|
-
task :prepare =>
|
198
|
+
desc "Prepare test database (ensure all migrations ran, drop and re-create database then load schema). This task can be run in the same invocation as other task (eg: rake #{sequel_rails_namespace}:migrate #{sequel_rails_namespace}:test:prepare)."
|
199
|
+
task :prepare => "#{sequel_rails_namespace}:abort_if_pending_migrations" do
|
198
200
|
previous_env, Rails.env = Rails.env, 'test'
|
199
|
-
Rake::Task[
|
200
|
-
Rake::Task[
|
201
|
-
Rake::Task[
|
202
|
-
Sequel::DATABASES.each
|
203
|
-
db.disconnect
|
204
|
-
end
|
201
|
+
Rake::Task["#{sequel_rails_namespace}:drop"].execute
|
202
|
+
Rake::Task["#{sequel_rails_namespace}:create"].execute
|
203
|
+
Rake::Task["#{sequel_rails_namespace}:load"].execute
|
204
|
+
Sequel::DATABASES.each(&:disconnect)
|
205
205
|
Rails.env = previous_env
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
task 'test:prepare' =>
|
210
|
+
task 'test:prepare' => "#{sequel_rails_namespace}:test:prepare"
|
@@ -18,12 +18,14 @@ module SequelRails
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.reset_runtime
|
21
|
-
previous
|
21
|
+
previous = runtime
|
22
|
+
self.runtime = 0
|
22
23
|
previous
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.reset_count
|
26
|
-
previous
|
27
|
+
previous = count
|
28
|
+
self.count = 0
|
27
29
|
previous
|
28
30
|
end
|
29
31
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SequelRails
|
2
|
+
module SpringSupport
|
3
|
+
def disconnect_database_with_sequel
|
4
|
+
Sequel::DATABASES.each { |db| db.disconnect } if sequel_configured?
|
5
|
+
disconnect_database_without_sequel
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def sequel_configured?
|
10
|
+
defined?(Sequel::DATABASES)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -5,7 +5,7 @@ module Sequel
|
|
5
5
|
class Database
|
6
6
|
def log_yield(sql, args = nil)
|
7
7
|
sql_for_log = args ? "#{sql}; #{args.inspect}" : sql
|
8
|
-
start = Time.now
|
8
|
+
start = Time.now.to_f
|
9
9
|
begin
|
10
10
|
::ActiveSupport::Notifications.instrument(
|
11
11
|
'sql.sequel',
|
@@ -19,7 +19,7 @@ module Sequel
|
|
19
19
|
log_exception(e, sql_for_log) unless @loggers.empty?
|
20
20
|
raise
|
21
21
|
ensure
|
22
|
-
log_duration(Time.now - start, sql_for_log) unless e || @loggers.empty?
|
22
|
+
log_duration(Time.now.to_f - start, sql_for_log) unless e || @loggers.empty?
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -16,7 +16,7 @@ module SequelRails
|
|
16
16
|
# Treat multibyte characters as is. It is caller's responsibility
|
17
17
|
# to encode the string in the right encoding for the shell
|
18
18
|
# environment.
|
19
|
-
str.gsub!(
|
19
|
+
str.gsub!(%r{([^A-Za-z0-9_\-.,:/@\n])}, '\\\\\\1')
|
20
20
|
|
21
21
|
# A LF cannot be escaped with a backslash because a backslash + LF
|
22
22
|
# combo is regarded as line continuation and simply ignored.
|
data/lib/sequel_rails/storage.rb
CHANGED
@@ -94,10 +94,9 @@ module SequelRails
|
|
94
94
|
private
|
95
95
|
|
96
96
|
def add_option(commands, name, value)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
97
|
+
return unless value.present?
|
98
|
+
separator = name[0, 2] == '--' ? '=' : ' '
|
99
|
+
commands << "#{name}#{separator}#{value}"
|
101
100
|
end
|
102
101
|
|
103
102
|
def add_flag(commands, flag)
|
data/lib/sequel_rails/version.rb
CHANGED
data/rubocop-todo.yml
CHANGED
data/sequel-rails.gemspec
CHANGED
@@ -41,8 +41,8 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.add_development_dependency 'generator_spec'
|
42
42
|
s.add_development_dependency 'rake', '>= 0.8.7'
|
43
43
|
s.add_development_dependency 'rspec', '~> 3.1'
|
44
|
-
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
45
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
46
|
-
s.add_development_dependency 'ammeter', '1.1.
|
44
|
+
s.add_development_dependency 'rspec-rails', '~> 3.1', '< 3.3'
|
45
|
+
s.add_development_dependency 'rubocop', '~> 0.33.0' unless RUBY_VERSION < '1.9.2'
|
46
|
+
s.add_development_dependency 'ammeter', '1.1.3'
|
47
47
|
s.add_development_dependency 'test-unit' if RUBY_VERSION >= '2.2.0'
|
48
48
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
test:
|
2
2
|
adapter: "<%= ENV["TEST_ADAPTER"] || "postgresql" %>"
|
3
3
|
database: "<%= ENV["TEST_DATABASE"] || "sequel_rails_test" %>"
|
4
|
+
<% if ENV['TEST_ADAPTER'] != 'sqlite3' %>
|
4
5
|
owner: "<%= ENV["TEST_OWNER"] || ENV["USER"] %>"
|
5
6
|
user: "<%= ENV["TEST_USERNAME"] || ENV["USER"] %>"
|
6
7
|
password: "<%= ENV["TEST_PASSWORD"] %>"
|
8
|
+
<% end %>
|
9
|
+
<% if ENV['TEST_ADAPTER'] =~ /mysql/ %>
|
10
|
+
encoding: "<%= ENV["TEST_ENCODING"] || "utf8" %>"
|
11
|
+
<% elsif ENV['TEST_ADAPTER'] =~ /postgres/ %>
|
7
12
|
encoding: "<%= ENV["TEST_ENCODING"] || "unicode" %>"
|
13
|
+
<% end %>
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SequelRails do
|
4
|
-
|
5
4
|
describe '.setup' do
|
6
5
|
let(:environment) { 'development' }
|
7
6
|
let(:configuration) { SequelRails::Configuration.new }
|
@@ -12,11 +11,9 @@ describe SequelRails do
|
|
12
11
|
SequelRails.setup environment
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
describe SequelRails::Configuration do
|
19
|
-
|
20
17
|
describe '#schema_dump' do
|
21
18
|
before { allow(Rails).to receive(:env).and_return(environment) }
|
22
19
|
subject { described_class.new }
|
@@ -136,11 +133,10 @@ describe SequelRails::Configuration do
|
|
136
133
|
subject { described_class.new.tap { |config| config.raw = environments } }
|
137
134
|
|
138
135
|
context 'when stubbing SequelRails.jruby?' do
|
139
|
-
|
140
136
|
before { allow(SequelRails).to receive(:jruby?).and_return(is_jruby) }
|
141
137
|
|
142
138
|
shared_examples 'max_connections' do
|
143
|
-
context 'with max_connections config option' do
|
139
|
+
context 'with max_connections=7 config option' do
|
144
140
|
let(:max_connections) { 31_337 }
|
145
141
|
before do
|
146
142
|
environments[environment]['max_connections'] = 7
|
@@ -150,7 +146,7 @@ describe SequelRails::Configuration do
|
|
150
146
|
it 'overrides the option from the configuration' do
|
151
147
|
expect(::Sequel).to receive(:connect) do |hash_or_url, *_|
|
152
148
|
if hash_or_url.is_a? Hash
|
153
|
-
expect(hash_or_url[
|
149
|
+
expect(hash_or_url[:max_connections]).to eq(max_connections)
|
154
150
|
else
|
155
151
|
expect(hash_or_url).to include("max_connections=#{max_connections}")
|
156
152
|
end
|
@@ -166,7 +162,7 @@ describe SequelRails::Configuration do
|
|
166
162
|
it 'uses the value' do
|
167
163
|
expect(::Sequel).to receive(:connect) do |hash_or_url, *_|
|
168
164
|
if hash_or_url.is_a? Hash
|
169
|
-
expect(hash_or_url[
|
165
|
+
expect(hash_or_url[:max_connections]).to eq(7)
|
170
166
|
else
|
171
167
|
expect(hash_or_url).to include('max_connections=7')
|
172
168
|
end
|
@@ -228,7 +224,6 @@ describe SequelRails::Configuration do
|
|
228
224
|
end
|
229
225
|
|
230
226
|
context 'for a postgres connection' do
|
231
|
-
|
232
227
|
shared_examples 'search_path' do
|
233
228
|
context 'with search_path config option' do
|
234
229
|
let(:search_path) { %w(secret private public) }
|
@@ -240,7 +235,7 @@ describe SequelRails::Configuration do
|
|
240
235
|
it 'overrides the option from the configuration' do
|
241
236
|
expect(::Sequel).to receive(:connect) do |hash_or_url, *_|
|
242
237
|
if hash_or_url.is_a? Hash
|
243
|
-
expect(hash_or_url[
|
238
|
+
expect(hash_or_url[:search_path]).to eq(search_path)
|
244
239
|
else
|
245
240
|
expect(hash_or_url).to include('search_path=secret%2Cprivate%2Cpublic')
|
246
241
|
end
|
@@ -253,7 +248,6 @@ describe SequelRails::Configuration do
|
|
253
248
|
let(:environment) { 'development' }
|
254
249
|
|
255
250
|
context 'in C-Ruby' do
|
256
|
-
|
257
251
|
include_examples 'max_connections'
|
258
252
|
include_examples 'search_path'
|
259
253
|
include_examples 'with DATABASE_URL in ENV'
|
@@ -262,15 +256,13 @@ describe SequelRails::Configuration do
|
|
262
256
|
|
263
257
|
it 'produces a sane config without url' do
|
264
258
|
expect(::Sequel).to receive(:connect) do |hash|
|
265
|
-
expect(hash[
|
259
|
+
expect(hash[:adapter]).to eq('postgres')
|
266
260
|
end
|
267
261
|
subject.connect environment
|
268
262
|
end
|
269
|
-
|
270
263
|
end
|
271
264
|
|
272
265
|
context 'in JRuby' do
|
273
|
-
|
274
266
|
include_examples 'max_connections'
|
275
267
|
include_examples 'search_path'
|
276
268
|
include_examples 'with DATABASE_URL in ENV'
|
@@ -280,34 +272,30 @@ describe SequelRails::Configuration do
|
|
280
272
|
it 'produces an adapter config with a url' do
|
281
273
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
282
274
|
expect(url).to start_with('jdbc:postgresql://')
|
283
|
-
expect(hash[
|
284
|
-
expect(hash[
|
275
|
+
expect(hash[:adapter]).to eq('jdbc:postgresql')
|
276
|
+
expect(hash[:host]).to eq('127.0.0.1')
|
285
277
|
end
|
286
278
|
subject.connect environment
|
287
279
|
end
|
288
280
|
|
289
281
|
context 'when url is already given' do
|
290
|
-
|
291
282
|
let(:environment) { 'url_already_constructed' }
|
292
283
|
|
293
284
|
it 'does not change the url' do
|
294
285
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
295
286
|
expect(url).to eq('jdbc:adaptername://HOST/DB?user=U&password=P&ssl=true&sslfactory=sslFactoryOption')
|
296
|
-
expect(hash[
|
287
|
+
expect(hash[:adapter]).to eq('jdbc:adaptername')
|
297
288
|
end
|
298
289
|
subject.connect environment
|
299
290
|
end
|
300
|
-
|
301
291
|
end
|
302
292
|
end
|
303
293
|
end
|
304
294
|
|
305
295
|
context 'for a mysql connection' do
|
306
|
-
|
307
296
|
let(:environment) { 'remote' }
|
308
297
|
|
309
298
|
context 'in C-Ruby' do
|
310
|
-
|
311
299
|
include_examples 'max_connections'
|
312
300
|
include_examples 'with DATABASE_URL in ENV'
|
313
301
|
|
@@ -315,14 +303,13 @@ describe SequelRails::Configuration do
|
|
315
303
|
|
316
304
|
it 'produces a config without url' do
|
317
305
|
expect(::Sequel).to receive(:connect) do |hash|
|
318
|
-
expect(hash[
|
306
|
+
expect(hash[:adapter]).to eq('mysql')
|
319
307
|
end
|
320
308
|
subject.connect environment
|
321
309
|
end
|
322
310
|
end
|
323
311
|
|
324
312
|
context 'in JRuby' do
|
325
|
-
|
326
313
|
include_examples 'max_connections'
|
327
314
|
include_examples 'with DATABASE_URL in ENV'
|
328
315
|
|
@@ -331,20 +318,19 @@ describe SequelRails::Configuration do
|
|
331
318
|
it 'produces a jdbc mysql config' do
|
332
319
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
333
320
|
expect(url).to start_with('jdbc:mysql://')
|
334
|
-
expect(hash[
|
335
|
-
expect(hash[
|
321
|
+
expect(hash[:adapter]).to eq('jdbc:mysql')
|
322
|
+
expect(hash[:database]).to eq('sequel_rails_test_storage_remote')
|
336
323
|
end
|
337
324
|
subject.connect environment
|
338
325
|
end
|
339
326
|
|
340
327
|
context 'when url is already given' do
|
341
|
-
|
342
328
|
let(:environment) { 'url_already_constructed' }
|
343
329
|
|
344
330
|
it 'does not change the url' do
|
345
331
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
346
332
|
expect(url).to eq('jdbc:adaptername://HOST/DB?user=U&password=P&ssl=true&sslfactory=sslFactoryOption')
|
347
|
-
expect(hash[
|
333
|
+
expect(hash[:adapter]).to eq('jdbc:adaptername')
|
348
334
|
end
|
349
335
|
subject.connect environment
|
350
336
|
end
|
@@ -363,6 +349,5 @@ describe SequelRails::Configuration do
|
|
363
349
|
subject.connect environment
|
364
350
|
end
|
365
351
|
end
|
366
|
-
|
367
352
|
end
|
368
353
|
end
|