sequel-rails 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +15 -43
- data/Gemfile +10 -10
- data/History.md +8 -0
- data/README.md +36 -0
- data/Rakefile +70 -2
- data/ci/rails-3.2.gemfile +15 -12
- data/ci/rails-4.0.gemfile +12 -12
- data/config.ru +1 -1
- data/lib/generators/sequel/migration/migration_generator.rb +10 -13
- data/lib/generators/sequel/model/model_generator.rb +11 -9
- data/lib/generators/sequel/observer/observer_generator.rb +6 -7
- data/lib/generators/sequel/session_migration/session_migration_generator.rb +30 -0
- data/lib/generators/sequel/session_migration/templates/migration.rb.erb +10 -0
- data/lib/generators/sequel.rb +9 -13
- data/lib/sequel-rails.rb +1 -1
- data/lib/sequel_rails/configuration.rb +29 -35
- data/lib/sequel_rails/migrations.rb +4 -4
- data/lib/sequel_rails/railtie.rb +16 -20
- data/lib/sequel_rails/railties/controller_runtime.rb +2 -8
- data/lib/sequel_rails/railties/database.rake +42 -46
- data/lib/sequel_rails/railties/i18n_support.rb +0 -2
- data/lib/sequel_rails/railties/legacy_model_config.rb +1 -1
- data/lib/sequel_rails/railties/log_subscriber.rb +5 -9
- data/lib/sequel_rails/sequel/database/active_support_notification.rb +4 -6
- data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +2 -3
- data/lib/sequel_rails/session_store.rb +6 -42
- data/lib/sequel_rails/shellwords.rb +3 -3
- data/lib/sequel_rails/storage/abstract.rb +14 -16
- data/lib/sequel_rails/storage/jdbc.rb +8 -10
- data/lib/sequel_rails/storage/mysql.rb +13 -15
- data/lib/sequel_rails/storage/postgres.rb +42 -45
- data/lib/sequel_rails/storage/sqlite.rb +0 -1
- data/lib/sequel_rails/storage.rb +10 -10
- data/lib/sequel_rails/version.rb +1 -1
- data/lib/sequel_rails.rb +3 -3
- data/rubocop-todo.yml +24 -0
- data/sequel-rails.gemspec +21 -19
- data/spec/internal/Rakefile +2 -2
- data/spec/internal/config/initializers/session.rb +1 -1
- data/spec/internal/db/schema.rb.init +6 -0
- data/spec/lib/generators/sequel/migration_spec.rb +77 -77
- data/spec/lib/generators/sequel/session_migration_spec.rb +41 -0
- data/spec/lib/sequel_rails/configuration_spec.rb +161 -161
- data/spec/lib/sequel_rails/jdbc_spec.rb +4 -4
- data/spec/lib/sequel_rails/migrations_spec.rb +29 -29
- data/spec/lib/sequel_rails/railtie_spec.rb +31 -29
- data/spec/lib/sequel_rails/railties/database_rake_spec.rb +16 -15
- data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +6 -6
- data/spec/lib/sequel_rails/storage/mysql_spec.rb +31 -31
- data/spec/lib/sequel_rails/storage/postgres_spec.rb +67 -67
- data/spec/lib/sequel_rails/storage/sqlite_spec.rb +40 -40
- data/spec/lib/sequel_rails/storage_spec.rb +77 -89
- data/spec/spec_helper.rb +16 -10
- metadata +61 -28
- data/tasks/spec.rake +0 -81
@@ -1,26 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SequelRails::Railtie do
|
4
4
|
let(:app) { Combustion::Application }
|
5
5
|
|
6
|
-
it
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
it 'registers ::Sequel::Railtie::LogSubscriber to receive :sequel notification' do
|
7
|
+
expect(
|
8
|
+
ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
|
9
|
+
subscriber.is_a?(SequelRails::Railties::LogSubscriber)
|
10
|
+
end
|
11
|
+
).to have(1).item
|
10
12
|
end
|
11
13
|
|
12
|
-
context
|
13
|
-
it
|
14
|
-
app.config.generators.options[:rails][:orm].
|
14
|
+
context 'configures generator to use Sequel' do
|
15
|
+
it 'as orm' do
|
16
|
+
expect(app.config.generators.options[:rails][:orm]).to be(:sequel)
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
18
|
-
app.config.generators.options[:sequel][:migration].
|
19
|
+
it 'for migrations' do
|
20
|
+
expect(app.config.generators.options[:sequel][:migration]).to be_true
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
23
|
-
app.config.rails_fancy_pants_logging.
|
24
|
+
it 'configures rails to use fancy pants logging' do
|
25
|
+
expect(app.config.rails_fancy_pants_logging).to be_true
|
24
26
|
end
|
25
27
|
|
26
28
|
context "configures action dispatch's rescue responses" do
|
@@ -28,44 +30,44 @@ describe SequelRails::Railtie do
|
|
28
30
|
app.config.action_dispatch.rescue_responses
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
32
|
-
rescue_responses[
|
33
|
+
it 'to handle Sequel::Plugins::RailsExtensions::ModelNotFound with :not_found' do
|
34
|
+
expect(rescue_responses['Sequel::Plugins::RailsExtensions::ModelNotFound']).to be(:not_found)
|
33
35
|
end
|
34
36
|
|
35
|
-
it
|
36
|
-
rescue_responses[
|
37
|
+
it 'to handle Sequel::NoMatchingRow with :not_found' do
|
38
|
+
expect(rescue_responses['Sequel::NoMatchingRow']).to be(:not_found)
|
37
39
|
end
|
38
40
|
|
39
|
-
it
|
40
|
-
rescue_responses[
|
41
|
+
it 'to handle Sequel::ValidationFailed with :unprocessable_entity' do
|
42
|
+
expect(rescue_responses['Sequel::ValidationFailed']).to be(:unprocessable_entity)
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
44
|
-
rescue_responses[
|
45
|
+
it 'to handle Sequel::NoExistingObject with :unprocessable_entity' do
|
46
|
+
expect(rescue_responses['Sequel::NoExistingObject']).to be(:unprocessable_entity)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
it "stores it's own config in app.config.sequel" do
|
49
|
-
app.config.sequel.
|
51
|
+
expect(app.config.sequel).to be_instance_of SequelRails::Configuration
|
50
52
|
end
|
51
53
|
|
52
|
-
it
|
53
|
-
app.config.sequel.logger.
|
54
|
+
it 'sets Rails.logger as default logger for its configuration' do
|
55
|
+
expect(app.config.sequel.logger).to be Rails.logger
|
54
56
|
end
|
55
57
|
|
56
|
-
it
|
57
|
-
User.new.i18n_scope.
|
58
|
+
it 'configures Sequel::Model instances for i18n' do
|
59
|
+
expect(User.new.i18n_scope).to be(:sequel)
|
58
60
|
end
|
59
61
|
|
60
|
-
it
|
61
|
-
ActionController::Base.included_modules.
|
62
|
+
it 'adds Sequel runtime to controller for logging' do
|
63
|
+
expect(ActionController::Base.included_modules).to include(
|
62
64
|
SequelRails::Railties::ControllerRuntime
|
63
65
|
)
|
64
66
|
end
|
65
67
|
|
66
|
-
it
|
68
|
+
it 'configures database in Sequel' do
|
67
69
|
expect do
|
68
70
|
Sequel::Model.db.test_connection
|
69
|
-
end.to_not raise_error
|
71
|
+
end.to_not raise_error
|
70
72
|
end
|
71
73
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Database rake tasks' do
|
4
4
|
|
5
5
|
let(:app) { Combustion::Application }
|
6
6
|
let(:app_root) { app.root }
|
@@ -14,22 +14,23 @@ describe "Database rake tasks" do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
17
|
+
describe 'db:schema:dump' do
|
18
18
|
let(:schema) { "#{app_root}/db/schema.rb" }
|
19
19
|
|
20
20
|
it "dumps the schema in 'db/schema.rb'" do
|
21
21
|
Dir.chdir app_root do
|
22
22
|
`rake db:schema:dump`
|
23
|
-
File.exists?(schema).
|
23
|
+
expect(File.exists?(schema)).to be_true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'append the migration schema information if any' do
|
28
28
|
Dir.chdir app_root do
|
29
29
|
`rake db:migrate db:schema:dump`
|
30
|
-
sql = Sequel::Model.db.from(
|
31
|
-
|
32
|
-
|
30
|
+
sql = Sequel::Model.db.from(
|
31
|
+
:schema_migrations
|
32
|
+
).insert_sql(:filename => '1273253849_add_twitter_handle_to_users.rb')
|
33
|
+
expect(File.read(schema)).to include <<-EOS
|
33
34
|
Sequel.migration do
|
34
35
|
change do
|
35
36
|
self << #{sql.inspect}
|
@@ -40,25 +41,25 @@ EOS
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
describe
|
44
|
+
describe 'db:structure:dump', :skip_jdbc do
|
44
45
|
let(:schema) { "#{app_root}/db/structure.sql" }
|
45
46
|
|
46
47
|
it "dumps the schema in 'db/structure.sql'" do
|
47
48
|
Dir.chdir app_root do
|
48
49
|
`rake db:structure:dump`
|
49
|
-
File.exists?(schema).
|
50
|
+
expect(File.exists?(schema)).to be_true
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
it
|
54
|
+
it 'append the migration schema information if any' do
|
54
55
|
Dir.chdir app_root do
|
55
56
|
`rake db:migrate db:structure:dump`
|
56
57
|
|
57
|
-
sql = Sequel::Model.db.from(
|
58
|
-
|
59
|
-
|
58
|
+
sql = Sequel::Model.db.from(
|
59
|
+
:schema_migrations
|
60
|
+
).insert_sql(:filename => '1273253849_add_twitter_handle_to_users.rb')
|
61
|
+
expect(File.read(schema)).to include sql
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
63
|
-
|
64
65
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/log_subscriber/test_helper'
|
3
3
|
|
4
4
|
describe SequelRails::Railties::LogSubscriber do
|
5
5
|
include ActiveSupport::LogSubscriber::TestHelper
|
@@ -13,16 +13,16 @@ describe SequelRails::Railties::LogSubscriber do
|
|
13
13
|
end
|
14
14
|
after { teardown }
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'logs queries' do
|
17
17
|
User.all
|
18
18
|
wait
|
19
|
-
@logger.logged(:debug).last.
|
19
|
+
expect(@logger.logged(:debug).last).to match(/SELECT \* FROM ("|`)users("|`)/)
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'does not log query when logger level is not debug' do
|
23
23
|
@logger.level = :info
|
24
24
|
User.all
|
25
25
|
wait
|
26
|
-
@logger.logged(:debug).
|
26
|
+
expect(@logger.logged(:debug)).to have(:no).line
|
27
27
|
end
|
28
28
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SequelRails::Storage::Mysql, :mysql do
|
4
|
-
let(:username) {
|
5
|
-
let(:host) {
|
4
|
+
let(:username) { 'username' }
|
5
|
+
let(:host) { 'host' }
|
6
6
|
let(:port) { 1234 }
|
7
|
-
let(:password) {
|
8
|
-
let(:charset) {
|
9
|
-
let(:collation) {
|
10
|
-
let(:database) {
|
7
|
+
let(:password) { 'password' }
|
8
|
+
let(:charset) { 'charset' }
|
9
|
+
let(:collation) { 'collation' }
|
10
|
+
let(:database) { 'database' }
|
11
11
|
let(:config) do
|
12
12
|
{
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
'adapter' => 'postgres',
|
14
|
+
'username' => username,
|
15
|
+
'password' => password,
|
16
|
+
'host' => host,
|
17
|
+
'port' => port,
|
18
|
+
'database' => database,
|
19
|
+
'charset' => charset,
|
20
|
+
'collation' => collation,
|
21
21
|
}
|
22
22
|
end
|
23
23
|
subject { described_class.new config }
|
24
24
|
|
25
|
-
describe
|
26
|
-
context
|
27
|
-
it
|
28
|
-
subject.
|
25
|
+
describe '#_create' do
|
26
|
+
context 'with all possible options' do
|
27
|
+
it 'uses the mysql command' do
|
28
|
+
expect(subject).to receive(:`).with(
|
29
29
|
"mysql --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --execute\\=CREATE\\ DATABASE\\ IF\\ NOT\\ EXISTS\\ \\`#{database}\\`\\ DEFAULT\\ CHARACTER\\ SET\\ #{charset}\\ DEFAULT\\ COLLATE\\ #{collation}"
|
30
30
|
)
|
31
31
|
subject._create
|
@@ -33,30 +33,30 @@ describe SequelRails::Storage::Mysql, :mysql do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
37
|
-
it
|
38
|
-
subject.
|
36
|
+
describe '#_drop' do
|
37
|
+
it 'uses the mysql command' do
|
38
|
+
expect(subject).to receive(:`).with(
|
39
39
|
"mysql --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --execute\\=DROP\\ DATABASE\\ IF\\ EXISTS\\ \\`#{database}\\`"
|
40
40
|
)
|
41
41
|
subject._drop
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
let(:dump_file_name) {
|
47
|
-
it
|
48
|
-
subject.
|
45
|
+
describe '#_dump' do
|
46
|
+
let(:dump_file_name) { 'dump.sql' }
|
47
|
+
it 'uses the mysqldump command' do
|
48
|
+
expect(subject).to receive(:`).with(
|
49
49
|
"mysqldump --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --no-data --result-file\\=#{dump_file_name} #{database}"
|
50
50
|
)
|
51
51
|
subject._dump dump_file_name
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
56
|
-
let(:dump_file_name) {
|
57
|
-
it
|
58
|
-
subject.
|
59
|
-
|
55
|
+
describe '#_load' do
|
56
|
+
let(:dump_file_name) { 'dump.sql' }
|
57
|
+
it 'uses the mysql command' do
|
58
|
+
expect(subject).to receive(:`).with(
|
59
|
+
'mysql --user\\=username --password\\=password --host\\=host --port\\=1234 --database\\=database --execute\\=SET\\ FOREIGN_KEY_CHECKS\\ \\=\\ 0\\;\\ SOURCE\\ dump.sql\\;\\ SET\\ FOREIGN_KEY_CHECKS\\ \\=\\ 1'
|
60
60
|
)
|
61
61
|
subject._load dump_file_name
|
62
62
|
end
|
@@ -1,121 +1,121 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SequelRails::Storage::Postgres, :postgres do
|
4
|
-
let(:username) {
|
5
|
-
let(:host) {
|
4
|
+
let(:username) { 'username' }
|
5
|
+
let(:host) { 'host' }
|
6
6
|
let(:port) { 1234 }
|
7
|
-
let(:password) {
|
8
|
-
let(:maintenance_db){
|
9
|
-
let(:encoding) {
|
10
|
-
let(:locale) {
|
11
|
-
let(:collation) {
|
12
|
-
let(:ctype) {
|
13
|
-
let(:template) {
|
14
|
-
let(:tablespace) {
|
15
|
-
let(:owner) {
|
16
|
-
let(:database) {
|
7
|
+
let(:password) { 'password' }
|
8
|
+
let(:maintenance_db) { 'maintenance_db' }
|
9
|
+
let(:encoding) { 'encoding' }
|
10
|
+
let(:locale) { 'locale' }
|
11
|
+
let(:collation) { 'collation' }
|
12
|
+
let(:ctype) { 'ctype' }
|
13
|
+
let(:template) { 'template' }
|
14
|
+
let(:tablespace) { 'tablespace' }
|
15
|
+
let(:owner) { 'owner' }
|
16
|
+
let(:database) { 'database' }
|
17
17
|
let(:config) do
|
18
18
|
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
'adapter' => 'postgres',
|
20
|
+
'username' => username,
|
21
|
+
'password' => password,
|
22
|
+
'host' => host,
|
23
|
+
'port' => port,
|
24
|
+
'maintenance_db' => maintenance_db,
|
25
|
+
'encoding' => encoding,
|
26
|
+
'locale' => locale,
|
27
|
+
'collation' => collation,
|
28
|
+
'ctype' => ctype,
|
29
|
+
'template' => template,
|
30
|
+
'tablespace' => tablespace,
|
31
|
+
'owner' => owner,
|
32
|
+
'database' => database,
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
36
|
subject { described_class.new config }
|
37
37
|
|
38
|
-
describe
|
39
|
-
context
|
40
|
-
it
|
41
|
-
subject.
|
38
|
+
describe '#_create' do
|
39
|
+
context 'with all possible options' do
|
40
|
+
it 'uses the createdb command' do
|
41
|
+
expect(subject).to receive(:`).with(
|
42
42
|
"createdb --username\\=#{username} --host\\=#{host} --port\\=#{port} --maintenance-db\\=#{maintenance_db} --encoding\\=#{encoding} --locale\\=#{locale} --lc-collate\\=#{collation} --lc-ctype\\=#{ctype} --template\\=#{template} --tablespace\\=#{tablespace} --owner\\=#{owner} #{database}"
|
43
43
|
)
|
44
44
|
subject._create
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
context
|
49
|
-
let(:maintenance_db) {
|
50
|
-
let(:locale) {
|
51
|
-
it
|
52
|
-
subject.
|
48
|
+
context 'with only a subset of possible options' do
|
49
|
+
let(:maintenance_db) { '' }
|
50
|
+
let(:locale) { '' }
|
51
|
+
it 'uses the createdb command' do
|
52
|
+
expect(subject).to receive(:`).with(
|
53
53
|
"createdb --username\\=#{username} --host\\=#{host} --port\\=#{port} --encoding\\=#{encoding} --lc-collate\\=#{collation} --lc-ctype\\=#{ctype} --template\\=#{template} --tablespace\\=#{tablespace} --owner\\=#{owner} #{database}"
|
54
54
|
)
|
55
55
|
subject._create
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
ENV[
|
61
|
-
subject.
|
62
|
-
ENV[
|
59
|
+
it 'sets and remove the password in environment variable PGPASSWORD' do
|
60
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
61
|
+
expect(subject).to receive(:`) do |_|
|
62
|
+
expect(ENV['PGPASSWORD']).to eq(password)
|
63
63
|
end
|
64
64
|
subject._create
|
65
|
-
ENV[
|
65
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
it
|
71
|
-
subject.
|
69
|
+
describe '#_drop' do
|
70
|
+
it 'uses the dropdb command' do
|
71
|
+
expect(subject).to receive(:`).with(
|
72
72
|
"dropdb --username\\=#{username} --host\\=#{host} --port\\=#{port} #{database}"
|
73
73
|
)
|
74
74
|
subject._drop
|
75
75
|
end
|
76
|
-
it
|
77
|
-
ENV[
|
78
|
-
subject.
|
79
|
-
ENV[
|
76
|
+
it 'sets and remove the password in environment variable PGPASSWORD' do
|
77
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
78
|
+
expect(subject).to receive(:`) do |_|
|
79
|
+
expect(ENV['PGPASSWORD']).to eq(password)
|
80
80
|
end
|
81
81
|
subject._drop
|
82
|
-
ENV[
|
82
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe
|
87
|
-
let(:dump_file_name) {
|
88
|
-
it
|
89
|
-
subject.
|
86
|
+
describe '#_dump' do
|
87
|
+
let(:dump_file_name) { 'dump.sql' }
|
88
|
+
it 'uses the pg_dump command' do
|
89
|
+
expect(subject).to receive(:`).with(
|
90
90
|
"pg_dump --username\\=#{username} --host\\=#{host} --port\\=#{port} -i -s -x -O --file\\=#{dump_file_name} #{database}"
|
91
91
|
)
|
92
92
|
subject._dump dump_file_name
|
93
93
|
end
|
94
|
-
it
|
95
|
-
ENV[
|
96
|
-
subject.
|
97
|
-
ENV[
|
94
|
+
it 'sets and remove the password in environment variable PGPASSWORD' do
|
95
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
96
|
+
expect(subject).to receive(:`) do |_|
|
97
|
+
expect(ENV['PGPASSWORD']).to eq(password)
|
98
98
|
end
|
99
99
|
subject._dump dump_file_name
|
100
|
-
ENV[
|
100
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe
|
105
|
-
let(:dump_file_name) {
|
106
|
-
it
|
107
|
-
subject.
|
104
|
+
describe '#_load' do
|
105
|
+
let(:dump_file_name) { 'dump.sql' }
|
106
|
+
it 'uses the psql command' do
|
107
|
+
expect(subject).to receive(:`).with(
|
108
108
|
"psql --username\\=#{username} --host\\=#{host} --port\\=#{port} --file\\=#{dump_file_name} #{database}"
|
109
109
|
)
|
110
110
|
subject._load dump_file_name
|
111
111
|
end
|
112
|
-
it
|
113
|
-
ENV[
|
114
|
-
subject.
|
115
|
-
ENV[
|
112
|
+
it 'sets and remove the password in environment variable PGPASSWORD' do
|
113
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
114
|
+
expect(subject).to receive(:`) do |_|
|
115
|
+
expect(ENV['PGPASSWORD']).to eq(password)
|
116
116
|
end
|
117
117
|
subject._load dump_file_name
|
118
|
-
ENV[
|
118
|
+
expect(ENV['PGPASSWORD']).to be_nil
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SequelRails::Storage::Sqlite, :sqlite do
|
4
4
|
let(:config) do
|
5
5
|
{
|
6
|
-
|
7
|
-
|
6
|
+
'adapter' => 'sqlite3',
|
7
|
+
'database' => database,
|
8
8
|
}
|
9
9
|
end
|
10
10
|
subject { described_class.new config }
|
11
11
|
|
12
|
-
context
|
13
|
-
let(:database) {
|
12
|
+
context 'when database is not in memory' do
|
13
|
+
let(:database) { 'test_database.sqlite' }
|
14
14
|
let(:database_path) { "#{Combustion::Application.root}/#{database}" }
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
18
|
-
path =
|
19
|
-
subject.
|
20
|
-
::Sequel.
|
16
|
+
describe '#_create' do
|
17
|
+
it 'defer to Sequel' do
|
18
|
+
path = double(:path)
|
19
|
+
allow(subject).to receive(:path).and_return path
|
20
|
+
expect(::Sequel).to receive(:connect).with('adapter' => 'sqlite3', 'database' => path)
|
21
21
|
subject._create
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
27
|
-
path =
|
28
|
-
subject.
|
29
|
-
path.
|
25
|
+
describe '#_drop' do
|
26
|
+
it 'delete the database file' do
|
27
|
+
path = double(:path, :file? => true)
|
28
|
+
allow(subject).to receive(:path).and_return path
|
29
|
+
expect(path).to receive :unlink
|
30
30
|
subject._drop
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
let(:dump_file_name) {
|
36
|
-
it
|
37
|
-
subject.
|
34
|
+
describe '#_dump' do
|
35
|
+
let(:dump_file_name) { 'dump.sql' }
|
36
|
+
it 'uses the sqlite3 command' do
|
37
|
+
expect(subject).to receive(:`).with(
|
38
38
|
"sqlite3 #{database_path} .schema > #{dump_file_name}"
|
39
39
|
)
|
40
40
|
subject._dump dump_file_name
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
45
|
-
let(:dump_file_name) {
|
46
|
-
it
|
47
|
-
subject.
|
44
|
+
describe '#_load' do
|
45
|
+
let(:dump_file_name) { 'dump.sql' }
|
46
|
+
it 'uses the sqlite3 command' do
|
47
|
+
expect(subject).to receive(:`).with(
|
48
48
|
"sqlite3 #{database_path} < #{dump_file_name}"
|
49
49
|
)
|
50
50
|
subject._load dump_file_name
|
@@ -52,36 +52,36 @@ describe SequelRails::Storage::Sqlite, :sqlite do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
56
|
-
let(:database) {
|
55
|
+
context 'when database is in memory' do
|
56
|
+
let(:database) { ':memory:' }
|
57
57
|
|
58
|
-
describe
|
58
|
+
describe '#_create' do
|
59
59
|
it "don't do anything" do
|
60
|
-
::Sequel.
|
60
|
+
expect(::Sequel).to_not receive(:connect)
|
61
61
|
subject._create
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
66
|
-
it
|
67
|
-
path =
|
68
|
-
subject.
|
69
|
-
path.
|
65
|
+
describe '#_drop' do
|
66
|
+
it 'do not try to delete the database file' do
|
67
|
+
path = double(:path, :file? => true)
|
68
|
+
allow(subject).to receive(:path).and_return path
|
69
|
+
expect(path).to_not receive :unlink
|
70
70
|
subject._drop
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
describe
|
75
|
-
it
|
76
|
-
subject.
|
77
|
-
subject._dump
|
74
|
+
describe '#_dump' do
|
75
|
+
it 'do not dump anything' do
|
76
|
+
expect(subject).to_not receive(:`)
|
77
|
+
subject._dump 'dump.sql'
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
describe
|
82
|
-
it
|
83
|
-
subject.
|
84
|
-
subject._load
|
81
|
+
describe '#_load' do
|
82
|
+
it 'do not load anything' do
|
83
|
+
expect(subject).to_not receive(:`)
|
84
|
+
subject._load 'dump.sql'
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|