sequel-rails 0.9.7 → 0.9.8
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 +4 -4
- data/.travis.yml +7 -0
- data/Gemfile +9 -1
- data/History.md +6 -0
- data/Rakefile +1 -1
- data/ci/rails-3.2.gemfile +9 -1
- data/ci/rails-4.2.gemfile +1 -2
- data/lib/sequel_rails/configuration.rb +10 -52
- data/lib/sequel_rails/db_config.rb +122 -0
- data/lib/sequel_rails/railtie.rb +7 -1
- data/lib/sequel_rails/version.rb +1 -1
- data/sequel-rails.gemspec +12 -1
- data/spec/helpers/io.rb +12 -0
- data/spec/lib/sequel_rails/configuration_spec.rb +7 -7
- data/spec/lib/sequel_rails/db_config_spec.rb +105 -0
- data/spec/lib/sequel_rails/railtie_spec.rb +55 -0
- metadata +32 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d771ec2940ad6044fb503e9df3eb2c332c9f75
|
4
|
+
data.tar.gz: b0eb4385f8183c19dd36e9fb8820e9503ea337fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d6792f857e88538475a854dd8c44ffd7ebc6e7d29bfb113d7ddbb8714d49c56833249e9223e0f9738ba097f4c62e2b4e8da4128c7af591280e23a00168ce831
|
7
|
+
data.tar.gz: 51d72c173fa2ab5f5772f86bd33e6e15efe076be3c7a96692f6fe8b8e0a4146525e63541429383478a724547bacd96a8ca9b9230791f0cf3830283785fee90be
|
data/.travis.yml
CHANGED
@@ -7,6 +7,7 @@ rvm:
|
|
7
7
|
- 1.9.3
|
8
8
|
- 2.0.0
|
9
9
|
- 2.1
|
10
|
+
- 2.2
|
10
11
|
- jruby-18mode
|
11
12
|
- jruby-19mode
|
12
13
|
env:
|
@@ -19,6 +20,12 @@ gemfile:
|
|
19
20
|
- ci/rails-4.2.gemfile
|
20
21
|
matrix:
|
21
22
|
exclude:
|
23
|
+
- rvm: 2.2
|
24
|
+
gemfile: ci/rails-3.2.gemfile
|
25
|
+
env: SEQUEL='~> 3.0'
|
26
|
+
- rvm: 2.2
|
27
|
+
gemfile: ci/rails-3.2.gemfile
|
28
|
+
env: SEQUEL='~> 4.0'
|
22
29
|
- rvm: ree
|
23
30
|
gemfile: ci/rails-4.0.gemfile
|
24
31
|
env: SEQUEL='~> 3.0'
|
data/Gemfile
CHANGED
@@ -4,7 +4,15 @@ gemspec
|
|
4
4
|
|
5
5
|
gem 'actionpack'
|
6
6
|
gem 'fakefs', '0.5.3', :require => 'fakefs/safe'
|
7
|
-
|
7
|
+
|
8
|
+
if RUBY_VERSION < '1.9'
|
9
|
+
# why do we even care, it's deprecated
|
10
|
+
gem 'activesupport', '< 4'
|
11
|
+
gem 'pry', '< 0.10'
|
12
|
+
gem 'tzinfo'
|
13
|
+
else
|
14
|
+
gem 'pry'
|
15
|
+
end
|
8
16
|
|
9
17
|
# MRI/Rubinius Adapter Dependencies
|
10
18
|
platform :ruby do
|
data/History.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.9.8 (2015-01-04)
|
2
|
+
==================
|
3
|
+
|
4
|
+
* Add Ruby < 1.9.3 deprecation notice via Gem's `post_install_message` [#80](https://github.com/TalentBox/sequel-rails/pull/78)
|
5
|
+
* Support running without database.yml, for 12 factor compliance (Rafał Rzepecki) [#78](https://github.com/TalentBox/sequel-rails/pull/78)
|
6
|
+
|
1
7
|
0.9.7 (2014-12-18)
|
2
8
|
==================
|
3
9
|
|
data/Rakefile
CHANGED
data/ci/rails-3.2.gemfile
CHANGED
@@ -11,9 +11,17 @@ gem 'fakefs', '0.5.3', :require => 'fakefs/safe'
|
|
11
11
|
# activesupport has an undeclared dependency on tzinfo prior to 4.0.0
|
12
12
|
gem 'tzinfo'
|
13
13
|
|
14
|
+
if RUBY_VERSION < '1.9'
|
15
|
+
gem 'i18n', '< 0.7.0'
|
16
|
+
end
|
17
|
+
|
14
18
|
# MRI/Rubinius Adapter Dependencies
|
15
19
|
platform :ruby do
|
16
|
-
|
20
|
+
if RUBY_VERSION < '1.9'
|
21
|
+
gem 'pg', '~> 0.17.1'
|
22
|
+
else
|
23
|
+
gem 'pg'
|
24
|
+
end
|
17
25
|
gem 'mysql'
|
18
26
|
gem 'mysql2'
|
19
27
|
gem 'sqlite3'
|
data/ci/rails-4.2.gemfile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute_accessors'
|
2
|
+
require 'sequel_rails/db_config'
|
2
3
|
|
3
4
|
module SequelRails
|
4
5
|
mattr_accessor :configuration
|
@@ -45,6 +46,12 @@ module SequelRails
|
|
45
46
|
|
46
47
|
def connect(environment)
|
47
48
|
normalized_config = environment_for environment
|
49
|
+
|
50
|
+
unless (normalized_config.keys & %w(adapter url)).any?
|
51
|
+
fail "Database not configured.\n" \
|
52
|
+
'Please create config/database.yml or set DATABASE_URL in environment.'
|
53
|
+
end
|
54
|
+
|
48
55
|
if normalized_config['url']
|
49
56
|
::Sequel.connect normalized_config['url'], normalized_config
|
50
57
|
else
|
@@ -59,65 +66,16 @@ module SequelRails
|
|
59
66
|
end
|
60
67
|
|
61
68
|
def normalize_repository_config(hash)
|
62
|
-
config =
|
63
|
-
hash.each do |key, value|
|
64
|
-
config[key.to_s] =
|
65
|
-
if key.to_s == 'port'
|
66
|
-
value.to_i
|
67
|
-
elsif key.to_s == 'adapter' && value == 'sqlite3'
|
68
|
-
'sqlite'
|
69
|
-
elsif key.to_s == 'database' && (hash['adapter'] == 'sqlite3' ||
|
70
|
-
hash['adapter'] == 'sqlite' ||
|
71
|
-
hash[:adapter] == 'sqlite3' ||
|
72
|
-
hash[:adapter] == 'sqlite')
|
73
|
-
value == ':memory:' ? value : File.expand_path((hash['database'] || hash[:database]), root)
|
74
|
-
elsif key.to_s == 'adapter' && value == 'postgresql'
|
75
|
-
'postgres'
|
76
|
-
else
|
77
|
-
value
|
78
|
-
end
|
79
|
-
end
|
69
|
+
config = DbConfig.new hash, :root => root
|
80
70
|
|
81
|
-
# always use jdbc when running jruby
|
82
|
-
if SequelRails.jruby?
|
83
|
-
if config['adapter']
|
84
|
-
case config['adapter'].to_sym
|
85
|
-
when :postgres
|
86
|
-
config['adapter'] = :postgresql
|
87
|
-
end
|
88
|
-
config['adapter'] = "jdbc:#{config['adapter']}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# override max connections if requested in app configuration
|
93
|
-
config['max_connections'] ||= config['pool']
|
94
71
|
config['max_connections'] = max_connections if max_connections
|
95
72
|
config['search_path'] = search_path if search_path
|
96
73
|
|
97
|
-
# Allow to set the URL from environment directly
|
98
74
|
url = ENV['DATABASE_URL']
|
99
75
|
config['url'] ||= url if url
|
100
76
|
|
101
|
-
#
|
102
|
-
|
103
|
-
params = {}
|
104
|
-
config.each do |k, v|
|
105
|
-
next if %w(adapter host port database).include?(k)
|
106
|
-
if k == 'search_path'
|
107
|
-
v = v.split(',').map(&:strip) unless v.is_a? Array
|
108
|
-
v = URI.escape(v.join(','))
|
109
|
-
end
|
110
|
-
params[k] = v
|
111
|
-
end
|
112
|
-
params_str = params.map { |k, v| "#{k}=#{v}" }.join('&')
|
113
|
-
port = config['port'] ? ":#{config['port']}" : ''
|
114
|
-
config['url'] ||=
|
115
|
-
if config['adapter'].include?('sqlite')
|
116
|
-
format('%s:%s', config['adapter'], config['database'])
|
117
|
-
else
|
118
|
-
format('%s://%s%s/%s?%s', config['adapter'], config['host'], port, config['database'], params_str)
|
119
|
-
end
|
120
|
-
end
|
77
|
+
# create the url if neccessary
|
78
|
+
config['url'] ||= config.url if config['adapter'] =~ /^(jdbc|do):/
|
121
79
|
|
122
80
|
config
|
123
81
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'active_support/hash_with_indifferent_access.rb'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module SequelRails
|
5
|
+
class DbConfig < ActiveSupport::HashWithIndifferentAccess
|
6
|
+
def initialize(raw, opts = {})
|
7
|
+
merge! raw
|
8
|
+
self[:port] = port.to_i if include? :port
|
9
|
+
normalize_adapter if include? :adapter
|
10
|
+
normalize_db opts[:root] if include? :database
|
11
|
+
self[:max_connections] = pool if include? :pool
|
12
|
+
end
|
13
|
+
|
14
|
+
# allow easier access
|
15
|
+
def method_missing(key, *a)
|
16
|
+
return self[key] if a.empty? && include?(key)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to_missing?(key, include_private = false)
|
21
|
+
include?(key) || super
|
22
|
+
end
|
23
|
+
|
24
|
+
def url
|
25
|
+
# the gsub transforms foo:/bar
|
26
|
+
# (which jdbc doesn't like)
|
27
|
+
# into foo:///bar
|
28
|
+
self[:url] || make_url.to_s.gsub(/:\/(?=\w)/, ':///')
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
ADAPTER_MAPPING = {
|
34
|
+
'sqlite3' => 'sqlite',
|
35
|
+
'postgresql' => 'postgres'
|
36
|
+
}
|
37
|
+
|
38
|
+
def normalize_adapter
|
39
|
+
self[:adapter] = ADAPTER_MAPPING[adapter.to_s] || adapter.to_s
|
40
|
+
jdbcify_adapter if SequelRails.jruby?
|
41
|
+
end
|
42
|
+
|
43
|
+
def jdbcify_adapter
|
44
|
+
return if adapter =~ /^jdbc:/
|
45
|
+
self[:adapter] = 'postgresql' if adapter == 'postgres'
|
46
|
+
self[:adapter] = 'jdbc:' + adapter
|
47
|
+
end
|
48
|
+
|
49
|
+
def normalize_db(root)
|
50
|
+
return unless include? :adapter
|
51
|
+
if root && adapter.include?('sqlite') && database != ':memory:'
|
52
|
+
# sqlite expects path as the database name
|
53
|
+
self[:database] = File.expand_path database.to_s, root
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_url
|
58
|
+
if adapter =~ /^(jdbc|do):/
|
59
|
+
scheme, subadapter = adapter.split ':'
|
60
|
+
return URI::Generic.build \
|
61
|
+
:scheme => scheme,
|
62
|
+
:opaque => build_url(to_hash.merge 'adapter' => subadapter).to_s
|
63
|
+
else
|
64
|
+
build_url to_hash
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_url(cfg)
|
69
|
+
if (adapter = cfg['adapter']) =~ /sqlite/ &&
|
70
|
+
(database = cfg['database']) =~ /^:/
|
71
|
+
# magic sqlite databases
|
72
|
+
return URI::Generic.build \
|
73
|
+
:scheme => adapter,
|
74
|
+
:opaque => database
|
75
|
+
end
|
76
|
+
|
77
|
+
# these four are handled separately
|
78
|
+
params = cfg.reject { |k, _| %w(adapter host port database).include? k }
|
79
|
+
|
80
|
+
if (v = params['search_path'])
|
81
|
+
# make sure there's no whitespace
|
82
|
+
v = v.split(',').map(&:strip) unless v.respond_to? :join
|
83
|
+
params['search_path'] = v.join(',')
|
84
|
+
end
|
85
|
+
|
86
|
+
path = cfg['database'].to_s
|
87
|
+
path = "/#{path}" if path =~ /^(?!\/)/
|
88
|
+
|
89
|
+
q = URI.encode_www_form(params)
|
90
|
+
q = nil if q.empty?
|
91
|
+
|
92
|
+
URI::Generic.build \
|
93
|
+
:scheme => cfg['adapter'],
|
94
|
+
:host => cfg['host'],
|
95
|
+
:port => cfg['port'],
|
96
|
+
:path => path,
|
97
|
+
:query => q
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
unless URI.respond_to? :encode_www_form
|
103
|
+
def URI.encode_www_form(enum)
|
104
|
+
enum.map do |k, v|
|
105
|
+
if v.nil?
|
106
|
+
encode_www_form_component(k)
|
107
|
+
elsif v.respond_to?(:to_ary)
|
108
|
+
v.to_ary.map do |w|
|
109
|
+
str = encode_www_form_component(k)
|
110
|
+
unless w.nil?
|
111
|
+
str << '='
|
112
|
+
str << encode_www_form_component(w)
|
113
|
+
end
|
114
|
+
end.join('&')
|
115
|
+
else
|
116
|
+
str = encode_www_form_component(k)
|
117
|
+
str << '='
|
118
|
+
str << encode_www_form_component(v)
|
119
|
+
end
|
120
|
+
end.join('&')
|
121
|
+
end
|
122
|
+
end
|
data/lib/sequel_rails/railtie.rb
CHANGED
@@ -62,9 +62,15 @@ module SequelRails
|
|
62
62
|
|
63
63
|
# Support overwriting crucial steps in subclasses
|
64
64
|
def configure_sequel(app)
|
65
|
+
rails_db_config = begin
|
66
|
+
app.config.database_configuration
|
67
|
+
rescue Errno::ENOENT
|
68
|
+
{} # will try to use DATABASE_URL
|
69
|
+
end
|
70
|
+
|
65
71
|
app.config.sequel.merge!(
|
66
72
|
:root => ::Rails.root,
|
67
|
-
:raw =>
|
73
|
+
:raw => rails_db_config
|
68
74
|
)
|
69
75
|
::SequelRails.configuration = app.config.sequel
|
70
76
|
end
|
data/lib/sequel_rails/version.rb
CHANGED
data/sequel-rails.gemspec
CHANGED
@@ -20,6 +20,16 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.rdoc_options = ['--charset=UTF-8']
|
21
21
|
s.license = 'MIT'
|
22
22
|
|
23
|
+
s.post_install_message = <<-NOTE
|
24
|
+
|
25
|
+
!!! sequel-rails
|
26
|
+
NOTE: Support for Ruby < 1.9.3 (this is 1.8.x, 1.9.0, 1.9.2) in sequel-rails
|
27
|
+
is deprecated and will be dropped in the next major release. If you really
|
28
|
+
rely on it please complain at http://git.io/WgfgZQ to delay the inevitable.
|
29
|
+
!!!
|
30
|
+
|
31
|
+
NOTE
|
32
|
+
|
23
33
|
s.add_dependency 'activemodel'
|
24
34
|
s.add_dependency 'railties', '>= 3.2.0'
|
25
35
|
s.add_dependency 'actionpack', '>= 3.2.0'
|
@@ -30,6 +40,7 @@ Gem::Specification.new do |s|
|
|
30
40
|
s.add_development_dependency 'rake', '>= 0.8.7'
|
31
41
|
s.add_development_dependency 'rspec', '~> 3.1'
|
32
42
|
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
33
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
43
|
+
s.add_development_dependency 'rubocop', '~> 0.28.0' unless RUBY_VERSION < '1.9.2'
|
34
44
|
s.add_development_dependency 'ammeter', '1.1.2'
|
45
|
+
s.add_development_dependency 'test-unit' if RUBY_VERSION >= '2.2.0'
|
35
46
|
end
|
data/spec/helpers/io.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module IOSpecHelper
|
2
|
+
def pretend_file_not_exists(pattern)
|
3
|
+
allow(IO).to receive(:read).and_wrap_original do |m, *a|
|
4
|
+
# if this isn't a good use for case equality I don't know what is
|
5
|
+
if pattern === a.first # rubocop:disable CaseEquality
|
6
|
+
fail Errno::ENOENT
|
7
|
+
else
|
8
|
+
m.call(*a)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -110,8 +110,8 @@ describe SequelRails::Configuration do
|
|
110
110
|
'database' => 'sequel_rails_test_storage_production',
|
111
111
|
},
|
112
112
|
'url_already_constructed' => {
|
113
|
-
'adapter' => '
|
114
|
-
'url' => 'jdbc:
|
113
|
+
'adapter' => 'adaptername',
|
114
|
+
'url' => 'jdbc:adaptername://HOST/DB?user=U&password=P&ssl=true&sslfactory=sslFactoryOption'
|
115
115
|
},
|
116
116
|
'bogus' => {},
|
117
117
|
}
|
@@ -226,7 +226,7 @@ describe SequelRails::Configuration do
|
|
226
226
|
if hash_or_url.is_a? Hash
|
227
227
|
expect(hash_or_url['search_path']).to eq(search_path)
|
228
228
|
else
|
229
|
-
expect(hash_or_url).to include('search_path=secret
|
229
|
+
expect(hash_or_url).to include('search_path=secret%2Cprivate%2Cpublic')
|
230
230
|
end
|
231
231
|
end
|
232
232
|
subject.connect environment
|
@@ -276,8 +276,8 @@ describe SequelRails::Configuration do
|
|
276
276
|
|
277
277
|
it 'does not change the url' do
|
278
278
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
279
|
-
expect(url).to eq('jdbc:
|
280
|
-
expect(hash['adapter']).to eq('jdbc:
|
279
|
+
expect(url).to eq('jdbc:adaptername://HOST/DB?user=U&password=P&ssl=true&sslfactory=sslFactoryOption')
|
280
|
+
expect(hash['adapter']).to eq('jdbc:adaptername')
|
281
281
|
end
|
282
282
|
subject.connect environment
|
283
283
|
end
|
@@ -327,8 +327,8 @@ describe SequelRails::Configuration do
|
|
327
327
|
|
328
328
|
it 'does not change the url' do
|
329
329
|
expect(::Sequel).to receive(:connect) do |url, hash|
|
330
|
-
expect(url).to eq('jdbc:
|
331
|
-
expect(hash['adapter']).to eq('jdbc:
|
330
|
+
expect(url).to eq('jdbc:adaptername://HOST/DB?user=U&password=P&ssl=true&sslfactory=sslFactoryOption')
|
331
|
+
expect(hash['adapter']).to eq('jdbc:adaptername')
|
332
332
|
end
|
333
333
|
subject.connect environment
|
334
334
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sequel_rails/db_config'
|
3
|
+
|
4
|
+
describe SequelRails::DbConfig do
|
5
|
+
let(:root) { '/dummy/project/root' }
|
6
|
+
|
7
|
+
# running under JRuby mangles adapters: tested separately
|
8
|
+
context 'when running jruby' do
|
9
|
+
before { allow(SequelRails).to receive(:jruby?).and_return true }
|
10
|
+
it 'always uses jdbc adapter' do
|
11
|
+
expect(from(:adapter => :sqlite)[:adapter]).to eq 'jdbc:sqlite'
|
12
|
+
end
|
13
|
+
it 'changes postgres adapter to jdbc:postgresql' do
|
14
|
+
expect(from(:adapter => :postgres)[:adapter]).to eq 'jdbc:postgresql'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# and generic handling:
|
19
|
+
before { allow(SequelRails).to receive(:jruby?).and_return false }
|
20
|
+
|
21
|
+
def from(definition)
|
22
|
+
SequelRails::DbConfig.new definition, :root => root
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'normalizes port to an integer' do
|
26
|
+
expect(from(:port => '33')[:port]).to eq 33
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'normalizes adapter to a string' do
|
30
|
+
expect(from(:adapter => :some)[:adapter]).to eq 'some'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'normalizes sqlite3 adapter to sqlite' do
|
34
|
+
expect(from(:adapter => :sqlite3)[:adapter]).to eq 'sqlite'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'expands path of an sqlite database' do
|
38
|
+
expect(from(:adapter => :sqlite, :database => :some)[:database]).to eq "#{root}/some"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "leaves sqlite's :memory: as is" do
|
42
|
+
expect(from(:adapter => :sqlite, :database => ':memory:')[:database]).to eq ':memory:'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'normalizes postgresql adapter to postgres' do
|
46
|
+
expect(from(:adapter => :postgresql)[:adapter]).to eq 'postgres'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'copies pool to max_connections' do
|
50
|
+
expect(from(:pool => 42)[:max_connections]).to eq 42
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'works with empty initialization' do
|
54
|
+
expect { from({}) }.to_not raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'works when initialized without adapter' do
|
58
|
+
expect { from(:database => 'foo') }.to_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not change the url' do
|
62
|
+
url = 'foo://bar/baz'
|
63
|
+
expect(from(:adapter => 'jdbc:some', 'url' => url).url).to eq url
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#url' do
|
67
|
+
it 'creates plain sqlite URLs' do
|
68
|
+
expect(from(:adapter => :sqlite, :database => :some).url).to\
|
69
|
+
eq "sqlite://#{root}/some"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'creates opaque sqlite URL for memory' do
|
73
|
+
expect(from(:adapter => :sqlite, :database => ':memory:').url).to\
|
74
|
+
eq 'sqlite::memory:'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'creates nice URLs' do
|
78
|
+
expect(%w(postgres://bar:42/foo?something=hi%21&user=linus
|
79
|
+
postgres://bar:42/foo?user=linus&something=hi%21)).to \
|
80
|
+
include from(:adapter => :postgresql,
|
81
|
+
:database => :foo, :host => 'bar', :port => 42,
|
82
|
+
:something => 'hi!', :user => 'linus'
|
83
|
+
).url
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'creates triple slash urls when without host' do
|
87
|
+
expect(from(:adapter => :foo, :database => :bar).url).to\
|
88
|
+
eq 'foo:///bar'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'creates proper JDBC URLs' do
|
92
|
+
expect(%w(jdbc:postgresql://bar:42/foo?something=hi%21&user=linus
|
93
|
+
jdbc:postgresql://bar:42/foo?user=linus&something=hi%21)).to \
|
94
|
+
include from(:adapter => 'jdbc:postgresql',
|
95
|
+
:database => :foo, :host => 'bar', :port => 42,
|
96
|
+
:something => 'hi!', :user => 'linus'
|
97
|
+
).url
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'creates proper magic Sqlite JDBC URLs' do
|
101
|
+
expect(from(:adapter => 'jdbc:sqlite', :database => ':memory:').url).to\
|
102
|
+
eq 'jdbc:sqlite::memory:'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'helpers/io'
|
2
3
|
|
3
4
|
describe SequelRails::Railtie do
|
4
5
|
let(:app) { Combustion::Application }
|
@@ -72,4 +73,58 @@ describe SequelRails::Railtie do
|
|
72
73
|
Sequel::Model.db.test_connection
|
73
74
|
end.to_not raise_error
|
74
75
|
end
|
76
|
+
|
77
|
+
context 'when database.yml does not exist' do
|
78
|
+
before do
|
79
|
+
app.config.sequel = ::SequelRails::Configuration.new
|
80
|
+
end
|
81
|
+
|
82
|
+
let :configure_sequel! do
|
83
|
+
app.configure_for_combustion
|
84
|
+
app.config.eager_load = false # to supress a warning
|
85
|
+
SequelRails::Railtie.configure_sequel app
|
86
|
+
::SequelRails.setup ::Rails.env
|
87
|
+
end
|
88
|
+
|
89
|
+
include IOSpecHelper
|
90
|
+
before do
|
91
|
+
pretend_file_not_exists(/\/database.yml$/)
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'and DATABASE_URL is defined' do
|
95
|
+
let :database_url do
|
96
|
+
cfg = Combustion::Application.config.database_configuration['test']
|
97
|
+
SequelRails::DbConfig.new(cfg).url
|
98
|
+
end
|
99
|
+
|
100
|
+
around do |ex|
|
101
|
+
orig = ENV['DATABASE_URL']
|
102
|
+
ENV['DATABASE_URL'] = database_url
|
103
|
+
ex.run
|
104
|
+
ENV['DATABASE_URL'] = orig
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'initializing the application uses it' do
|
108
|
+
expect do
|
109
|
+
configure_sequel!
|
110
|
+
Sequel::Model.db.test_connection
|
111
|
+
end.to_not raise_error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'and DATABASE_URL is not defined' do
|
116
|
+
around do |ex|
|
117
|
+
orig = ENV['DATABASE_URL']
|
118
|
+
ENV.delete 'DATABASE_URL'
|
119
|
+
ex.run
|
120
|
+
ENV['DATABASE_URL'] = orig
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'initializing the application fails' do
|
124
|
+
expect do
|
125
|
+
configure_sequel!
|
126
|
+
end.to raise_error
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
75
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brasten Sager (brasten)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -149,14 +149,14 @@ dependencies:
|
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.28.0
|
153
153
|
type: :development
|
154
154
|
prerelease: false
|
155
155
|
version_requirements: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.28.0
|
160
160
|
- !ruby/object:Gem::Dependency
|
161
161
|
name: ammeter
|
162
162
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +171,20 @@ dependencies:
|
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: 1.1.2
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: test-unit
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
type: :development
|
182
|
+
prerelease: false
|
183
|
+
version_requirements: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
174
188
|
description: Integrate Sequel with Rails (3.x and 4.x)
|
175
189
|
email:
|
176
190
|
- brasten@gmail.com
|
@@ -209,6 +223,7 @@ files:
|
|
209
223
|
- lib/sequel-rails.rb
|
210
224
|
- lib/sequel_rails.rb
|
211
225
|
- lib/sequel_rails/configuration.rb
|
226
|
+
- lib/sequel_rails/db_config.rb
|
212
227
|
- lib/sequel_rails/migrations.rb
|
213
228
|
- lib/sequel_rails/railtie.rb
|
214
229
|
- lib/sequel_rails/railties/controller_runtime.rb
|
@@ -229,6 +244,7 @@ files:
|
|
229
244
|
- lib/sequel_rails/version.rb
|
230
245
|
- rubocop-todo.yml
|
231
246
|
- sequel-rails.gemspec
|
247
|
+
- spec/helpers/io.rb
|
232
248
|
- spec/integration/sessions_controller_spec.rb
|
233
249
|
- spec/internal/Rakefile
|
234
250
|
- spec/internal/app/controllers/application_controller.rb
|
@@ -243,6 +259,7 @@ files:
|
|
243
259
|
- spec/lib/generators/sequel/migration_spec.rb
|
244
260
|
- spec/lib/generators/sequel/session_migration_spec.rb
|
245
261
|
- spec/lib/sequel_rails/configuration_spec.rb
|
262
|
+
- spec/lib/sequel_rails/db_config_spec.rb
|
246
263
|
- spec/lib/sequel_rails/jdbc_spec.rb
|
247
264
|
- spec/lib/sequel_rails/migrations_spec.rb
|
248
265
|
- spec/lib/sequel_rails/railtie_spec.rb
|
@@ -257,7 +274,14 @@ homepage: http://talentbox.github.io/sequel-rails/
|
|
257
274
|
licenses:
|
258
275
|
- MIT
|
259
276
|
metadata: {}
|
260
|
-
post_install_message:
|
277
|
+
post_install_message: |2+
|
278
|
+
|
279
|
+
!!! sequel-rails
|
280
|
+
NOTE: Support for Ruby < 1.9.3 (this is 1.8.x, 1.9.0, 1.9.2) in sequel-rails
|
281
|
+
is deprecated and will be dropped in the next major release. If you really
|
282
|
+
rely on it please complain at http://git.io/WgfgZQ to delay the inevitable.
|
283
|
+
!!!
|
284
|
+
|
261
285
|
rdoc_options:
|
262
286
|
- "--charset=UTF-8"
|
263
287
|
require_paths:
|
@@ -274,11 +298,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
298
|
version: '0'
|
275
299
|
requirements: []
|
276
300
|
rubyforge_project:
|
277
|
-
rubygems_version: 2.
|
301
|
+
rubygems_version: 2.4.5
|
278
302
|
signing_key:
|
279
303
|
specification_version: 4
|
280
304
|
summary: Use Sequel with Rails (3.x and 4.x)
|
281
305
|
test_files:
|
306
|
+
- spec/helpers/io.rb
|
282
307
|
- spec/integration/sessions_controller_spec.rb
|
283
308
|
- spec/internal/Rakefile
|
284
309
|
- spec/internal/app/controllers/application_controller.rb
|
@@ -293,6 +318,7 @@ test_files:
|
|
293
318
|
- spec/lib/generators/sequel/migration_spec.rb
|
294
319
|
- spec/lib/generators/sequel/session_migration_spec.rb
|
295
320
|
- spec/lib/sequel_rails/configuration_spec.rb
|
321
|
+
- spec/lib/sequel_rails/db_config_spec.rb
|
296
322
|
- spec/lib/sequel_rails/jdbc_spec.rb
|
297
323
|
- spec/lib/sequel_rails/migrations_spec.rb
|
298
324
|
- spec/lib/sequel_rails/railtie_spec.rb
|