ardb 0.28.1 → 0.29.2
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 +7 -7
- data/.l.yml +8 -0
- data/.rubocop.yml +3 -0
- data/.t.yml +6 -0
- data/Gemfile +21 -8
- data/README.md +252 -3
- data/ardb.gemspec +14 -10
- data/bin/ardb +3 -1
- data/lib/ardb.rb +110 -80
- data/lib/ardb/adapter/base.rb +73 -47
- data/lib/ardb/adapter/mysql.rb +4 -17
- data/lib/ardb/adapter/postgresql.rb +51 -46
- data/lib/ardb/adapter/sqlite.rb +11 -15
- data/lib/ardb/adapter_spy.rb +18 -30
- data/lib/ardb/cli.rb +29 -24
- data/lib/ardb/cli/clirb.rb +19 -17
- data/lib/ardb/cli/commands.rb +308 -129
- data/lib/ardb/db_tests.rb +4 -4
- data/lib/ardb/default_order_by.rb +13 -21
- data/lib/ardb/migration.rb +15 -16
- data/lib/ardb/record_spy.rb +46 -61
- data/lib/ardb/relation_spy.rb +27 -31
- data/lib/ardb/require_autoloaded_active_record_files.rb +174 -58
- data/lib/ardb/test_helpers.rb +13 -14
- data/lib/ardb/use_db_default.rb +10 -19
- data/lib/ardb/version.rb +3 -1
- data/script/determine_autoloaded_active_record_files.rb +31 -24
- data/test/helper.rb +6 -13
- data/test/support/factory.rb +4 -3
- data/test/support/fake_schema.rb +3 -1
- data/test/support/postgresql/migrations/{.gitkeep → .keep} +0 -0
- data/test/support/postgresql/schema.rb +2 -1
- data/test/support/postgresql/setup_test_db.rb +17 -15
- data/test/support/relative_require_test_db_file.rb +1 -0
- data/test/support/require_test_db_file.rb +1 -0
- data/test/system/.keep +0 -0
- data/test/unit/adapter/base_tests.rb +83 -55
- data/test/unit/adapter/mysql_tests.rb +4 -19
- data/test/unit/adapter/postgresql_tests.rb +21 -30
- data/test/unit/adapter/sqlite_tests.rb +5 -11
- data/test/unit/adapter_spy_tests.rb +6 -17
- data/test/unit/ardb_tests.rb +81 -53
- data/test/unit/cli_tests.rb +232 -157
- data/test/unit/db_tests_tests.rb +7 -7
- data/test/unit/default_order_by_tests.rb +21 -20
- data/test/unit/migration_tests.rb +17 -18
- data/test/unit/record_spy_tests.rb +36 -34
- data/test/unit/relation_spy_tests.rb +40 -63
- data/test/unit/test_helpers_tests.rb +7 -15
- data/test/unit/use_db_default_tests.rb +22 -17
- metadata +117 -84
- data/lib/ardb/has_slug.rb +0 -107
- data/lib/ardb/migration_helpers.rb +0 -77
- data/lib/ardb/pg_json.rb +0 -90
- data/test/support/postgresql/pg_json_migrations/20160519133432_create_pg_json_migrate_test.rb +0 -13
- data/test/system/pg_json_tests.rb +0 -85
- data/test/unit/has_slug_tests.rb +0 -341
- data/test/unit/migration_helpers_tests.rb +0 -65
- data/test/unit/pg_json_tests.rb +0 -39
data/test/helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# this file is automatically required when you run `assert`
|
2
4
|
# put any test helpers here
|
3
5
|
|
@@ -7,19 +9,10 @@ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
|
7
9
|
TEST_SUPPORT_PATH = File.expand_path("../support", __FILE__)
|
8
10
|
TMP_PATH = File.expand_path("../../tmp", __FILE__)
|
9
11
|
|
10
|
-
require
|
12
|
+
require "logger"
|
11
13
|
log_path = File.expand_path("../../log/test.log", __FILE__)
|
12
|
-
TEST_LOGGER = Logger.new(File.open(log_path,
|
14
|
+
TEST_LOGGER = Logger.new(File.open(log_path, "w"))
|
13
15
|
|
14
16
|
# require pry for debugging (`binding.pry`)
|
15
|
-
require
|
16
|
-
require
|
17
|
-
|
18
|
-
# 1.8.7 backfills
|
19
|
-
|
20
|
-
# Array#sample
|
21
|
-
if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
|
22
|
-
class Array
|
23
|
-
alias_method :sample, :choice
|
24
|
-
end
|
25
|
-
end
|
17
|
+
require "pry"
|
18
|
+
require "test/support/factory"
|
data/test/support/factory.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "assert/factory"
|
2
4
|
|
3
5
|
module Factory
|
4
6
|
extend Assert::Factory
|
5
7
|
|
6
8
|
def self.migration_id
|
7
|
-
# identifiers need to be plural b/c af activesupport
|
9
|
+
# identifiers need to be plural b/c af activesupport"s pluralize
|
8
10
|
"#{Factory.string}_things"
|
9
11
|
end
|
10
12
|
|
@@ -22,5 +24,4 @@ module Factory
|
|
22
24
|
c.min_messages = Factory.string
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
27
|
end
|
data/test/support/fake_schema.rb
CHANGED
File without changes
|
@@ -1,24 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "assert"
|
4
|
+
require "ardb"
|
3
5
|
|
4
6
|
class PostgresqlDbTests < Assert::Context
|
5
7
|
setup do
|
6
|
-
@orig_env_ardb_db_file = ENV[
|
8
|
+
@orig_env_ardb_db_file = ENV["ARDB_DB_FILE"]
|
7
9
|
ActiveRecord::Base.logger = @orig_ar_loggerF
|
8
10
|
|
9
|
-
#
|
10
|
-
ENV[
|
11
|
+
# we"re manually configuring ardb so we don"t need this to do anything
|
12
|
+
ENV["ARDB_DB_FILE"] = File.join(TEST_SUPPORT_PATH, "require_test_db_file")
|
11
13
|
|
12
14
|
@ardb_config = Ardb::Config.new.tap do |c|
|
13
|
-
c.adapter =
|
14
|
-
c.database =
|
15
|
-
c.encoding =
|
16
|
-
c.min_messages =
|
15
|
+
c.adapter = "postgresql"
|
16
|
+
c.database = "redding_ardb_test"
|
17
|
+
c.encoding = "unicode"
|
18
|
+
c.min_messages = "WARNING"
|
17
19
|
|
18
20
|
c.logger = TEST_LOGGER
|
19
|
-
c.root_path = File.join(TEST_SUPPORT_PATH,
|
20
|
-
c.migrations_path =
|
21
|
-
c.schema_path =
|
21
|
+
c.root_path = File.join(TEST_SUPPORT_PATH, "postgresql")
|
22
|
+
c.migrations_path = "migrations"
|
23
|
+
c.schema_path = "schema"
|
22
24
|
c.schema_format = :ruby
|
23
25
|
end
|
24
26
|
Assert.stub(Ardb, :config){ @ardb_config }
|
@@ -31,8 +33,9 @@ class PostgresqlDbTests < Assert::Context
|
|
31
33
|
Ardb.adapter.connect_db
|
32
34
|
end
|
33
35
|
teardown do
|
36
|
+
Ardb.reset_adapter
|
34
37
|
ActiveRecord::Base.logger = @orig_ar_logger
|
35
|
-
ENV[
|
38
|
+
ENV["ARDB_DB_FILE"] = @orig_env_ardb_db_file
|
36
39
|
end
|
37
40
|
|
38
41
|
private
|
@@ -40,12 +43,11 @@ class PostgresqlDbTests < Assert::Context
|
|
40
43
|
# useful when testing creating/dropping/migrating DBs
|
41
44
|
def silence_stdout
|
42
45
|
current_stdout = $stdout.dup
|
43
|
-
$stdout = File.new(
|
46
|
+
$stdout = File.new("/dev/null", "w")
|
44
47
|
begin
|
45
48
|
yield
|
46
49
|
ensure
|
47
50
|
$stdout = current_stdout
|
48
51
|
end
|
49
52
|
end
|
50
|
-
|
51
53
|
end
|
data/test/system/.keep
ADDED
File without changes
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
require 'ardb/adapter/base'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
3
|
+
require "assert"
|
4
|
+
require "ardb/adapter/base"
|
5
|
+
|
6
|
+
require "active_record/migration"
|
7
|
+
require "ardb"
|
5
8
|
# This is needed by the schema dumper but it doesn't handle requiring it so we
|
6
9
|
# have to manually, otherwise this errors when you try to run the adapter base
|
7
10
|
# tests by themselves
|
8
|
-
require
|
11
|
+
require "active_support/core_ext/class/attribute_accessors"
|
9
12
|
|
10
13
|
class Ardb::Adapter::Base
|
11
|
-
|
12
14
|
class UnitTests < Assert::Context
|
13
15
|
desc "Ardb::Adapter::Base"
|
14
16
|
setup do
|
@@ -21,7 +23,6 @@ class Ardb::Adapter::Base
|
|
21
23
|
should have_imeths :connect_hash, :database, :migrations_path
|
22
24
|
should have_imeths :schema_format, :ruby_schema_path, :sql_schema_path
|
23
25
|
should have_imeths :escape_like_pattern
|
24
|
-
should have_imeths :foreign_key_add_sql, :foreign_key_drop_sql
|
25
26
|
should have_imeths :create_db, :drop_db, :drop_tables
|
26
27
|
should have_imeths :connect_db, :migrate_db
|
27
28
|
should have_imeths :load_schema, :load_ruby_schema, :load_sql_schema
|
@@ -49,12 +50,15 @@ class Ardb::Adapter::Base
|
|
49
50
|
"#{Factory.string}\\" \
|
50
51
|
"#{Factory.string} " \
|
51
52
|
"#{Factory.string}"
|
52
|
-
exp = pattern.gsub("\\"){ "\\\\" }.gsub(
|
53
|
+
exp = pattern.gsub("\\"){ "\\\\" }.gsub("%", "\\%").gsub("_", "\\_")
|
53
54
|
assert_equal exp, subject.escape_like_pattern(pattern)
|
55
|
+
|
56
|
+
pattern = Factory.string
|
57
|
+
assert_equal pattern, subject.escape_like_pattern(pattern)
|
54
58
|
end
|
55
59
|
|
56
60
|
should "allow using a custom escape char when escaping like patterns" do
|
57
|
-
escape_char =
|
61
|
+
escape_char = "#"
|
58
62
|
pattern = "#{Factory.string}%" \
|
59
63
|
"#{Factory.string}_" \
|
60
64
|
"#{Factory.string}\\" \
|
@@ -62,15 +66,10 @@ class Ardb::Adapter::Base
|
|
62
66
|
"#{Factory.string} " \
|
63
67
|
"#{Factory.string}"
|
64
68
|
exp = pattern.gsub(escape_char, "#{escape_char}#{escape_char}")
|
65
|
-
exp = exp.gsub(
|
69
|
+
exp = exp.gsub("%", "#{escape_char}%").gsub("_", "#{escape_char}_")
|
66
70
|
assert_equal exp, subject.escape_like_pattern(pattern, escape_char)
|
67
71
|
end
|
68
72
|
|
69
|
-
should "not implement the foreign key sql meths" do
|
70
|
-
assert_raises(NotImplementedError){ subject.foreign_key_add_sql }
|
71
|
-
assert_raises(NotImplementedError){ subject.foreign_key_drop_sql }
|
72
|
-
end
|
73
|
-
|
74
73
|
should "not implement the create and drop db methods" do
|
75
74
|
assert_raises(NotImplementedError){ subject.create_db }
|
76
75
|
assert_raises(NotImplementedError){ subject.drop_db }
|
@@ -92,7 +91,6 @@ class Ardb::Adapter::Base
|
|
92
91
|
non_matching_adapter = Ardb::Adapter::Base.new(Factory.ardb_config)
|
93
92
|
assert_not_equal non_matching_adapter, subject
|
94
93
|
end
|
95
|
-
|
96
94
|
end
|
97
95
|
|
98
96
|
class ConnectDbTests < UnitTests
|
@@ -111,58 +109,64 @@ class Ardb::Adapter::Base
|
|
111
109
|
@ar_with_connection_called = true
|
112
110
|
end
|
113
111
|
|
114
|
-
|
112
|
+
subject.connect_db
|
115
113
|
end
|
116
114
|
|
117
115
|
should "use activerecord to establish and then checkout a connection" do
|
118
116
|
assert_equal subject.connect_hash, @ar_establish_connection_called_with
|
119
117
|
assert_true @ar_with_connection_called
|
120
118
|
end
|
121
|
-
|
122
119
|
end
|
123
120
|
|
124
|
-
class
|
125
|
-
desc "`migrate_db`"
|
121
|
+
class MigrateTests < UnitTests
|
126
122
|
setup do
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
ENV["MIGRATE_VERSION"] = Factory.integer.to_s if Factory.boolean
|
131
|
-
ENV["MIGRATE_QUIET"] = Factory.boolean.to_s if Factory.boolean
|
132
|
-
|
133
|
-
@migrator_called_with = []
|
134
|
-
Assert.stub(ActiveRecord::Migrator, :migrate) do |*args|
|
135
|
-
@migrator_called_with = args
|
123
|
+
Assert.stub(ActiveRecord::MigrationContext, :new) do |*args|
|
124
|
+
@fake_migration_context ||= FakeMigrationContext.new(*args)
|
136
125
|
end
|
137
|
-
|
138
|
-
@adapter.migrate_db
|
139
|
-
end
|
140
|
-
teardown do
|
141
|
-
ENV['MIGRATE_VERSION'] = @orig_migrate_version_env_var
|
142
|
-
ENV['MIGRATE_QUIET'] = @orig_migrate_query_env_var
|
143
126
|
end
|
144
127
|
|
145
|
-
should "
|
146
|
-
|
147
|
-
|
128
|
+
should "migrate the db with `migrate_db`" do
|
129
|
+
subject.migrate_db
|
130
|
+
|
131
|
+
assert_equal [subject.migrations_path], @fake_migration_context.init_with
|
132
|
+
assert_equal [nil], @fake_migration_context.up_called_with
|
148
133
|
end
|
149
134
|
|
150
|
-
should "
|
151
|
-
|
152
|
-
assert_equal
|
135
|
+
should "migrate the db with `migrate_db_up`" do
|
136
|
+
subject.migrate_db_up
|
137
|
+
assert_equal [nil], @fake_migration_context.up_called_with
|
138
|
+
|
139
|
+
target = Factory.string
|
140
|
+
subject.migrate_db_up(target)
|
141
|
+
assert_equal [target], @fake_migration_context.up_called_with
|
153
142
|
end
|
154
143
|
|
155
|
-
should "
|
156
|
-
|
157
|
-
assert_equal
|
144
|
+
should "migrate the db with `migrate_db_down`" do
|
145
|
+
subject.migrate_db_down
|
146
|
+
assert_equal [nil], @fake_migration_context.down_called_with
|
147
|
+
|
148
|
+
target = Factory.string
|
149
|
+
subject.migrate_db_down(target)
|
150
|
+
assert_equal [target], @fake_migration_context.down_called_with
|
158
151
|
end
|
159
152
|
|
160
|
-
should "
|
161
|
-
|
162
|
-
|
163
|
-
|
153
|
+
should "migrate the db with `migrate_db_forward`" do
|
154
|
+
subject.migrate_db_forward
|
155
|
+
assert_equal [1], @fake_migration_context.forward_called_with
|
156
|
+
|
157
|
+
steps = Factory.integer(3)
|
158
|
+
subject.migrate_db_forward(steps)
|
159
|
+
assert_equal [steps], @fake_migration_context.forward_called_with
|
164
160
|
end
|
165
161
|
|
162
|
+
should "migrate the db with `migrate_db_backward`" do
|
163
|
+
subject.migrate_db_backward
|
164
|
+
assert_equal [1], @fake_migration_context.rollback_called_with
|
165
|
+
|
166
|
+
steps = Factory.integer(3)
|
167
|
+
subject.migrate_db_backward(steps)
|
168
|
+
assert_equal [steps], @fake_migration_context.rollback_called_with
|
169
|
+
end
|
166
170
|
end
|
167
171
|
|
168
172
|
class LoadAndDumpSchemaTests < UnitTests
|
@@ -235,12 +239,11 @@ class Ardb::Adapter::Base
|
|
235
239
|
subject.load_schema
|
236
240
|
assert_empty @captured_stdout
|
237
241
|
end
|
238
|
-
|
239
242
|
end
|
240
243
|
|
241
244
|
class LoadRubySchemaTests < UnitTests
|
242
245
|
setup do
|
243
|
-
@config.schema_path = File.join(TEST_SUPPORT_PATH,
|
246
|
+
@config.schema_path = File.join(TEST_SUPPORT_PATH, "fake_schema")
|
244
247
|
@adapter = Ardb::Adapter::Base.new(@config)
|
245
248
|
end
|
246
249
|
|
@@ -252,12 +255,12 @@ class Ardb::Adapter::Base
|
|
252
255
|
subject.load_ruby_schema
|
253
256
|
assert_equal 2, FAKE_SCHEMA.load_count
|
254
257
|
end
|
255
|
-
|
256
258
|
end
|
257
259
|
|
258
260
|
class DumpRubySchemaTests < UnitTests
|
259
261
|
setup do
|
260
|
-
@config.schema_path =
|
262
|
+
@config.schema_path =
|
263
|
+
File.join(TMP_PATH, "testdb", "test_dump_ruby_schema")
|
261
264
|
FileUtils.rm_rf(File.dirname(@config.schema_path))
|
262
265
|
|
263
266
|
@schema_dumper_connection, @schema_dumper_file = [nil, nil]
|
@@ -276,14 +279,13 @@ class Ardb::Adapter::Base
|
|
276
279
|
end
|
277
280
|
|
278
281
|
should "dump a ruby schema file using `dump_ruby_schema`" do
|
279
|
-
assert_false File.
|
282
|
+
assert_false File.exist?(subject.ruby_schema_path)
|
280
283
|
subject.dump_ruby_schema
|
281
|
-
assert_true File.
|
284
|
+
assert_true File.exist?(subject.ruby_schema_path)
|
282
285
|
assert_equal @fake_connection, @schema_dumper_connection
|
283
286
|
assert_instance_of File, @schema_dumper_file
|
284
287
|
assert_equal subject.ruby_schema_path, @schema_dumper_file.path
|
285
288
|
end
|
286
|
-
|
287
289
|
end
|
288
290
|
|
289
291
|
class FakeConnection; end
|
@@ -322,7 +324,33 @@ class Ardb::Adapter::Base
|
|
322
324
|
end
|
323
325
|
|
324
326
|
class FakeConnectionPool
|
325
|
-
def with_connection(&block)
|
327
|
+
def with_connection(&block)
|
328
|
+
end
|
326
329
|
end
|
327
330
|
|
331
|
+
class FakeMigrationContext
|
332
|
+
attr_reader :init_with
|
333
|
+
attr_reader :up_called_with, :down_called_with
|
334
|
+
attr_reader :forward_called_with, :rollback_called_with
|
335
|
+
|
336
|
+
def initialize(*args)
|
337
|
+
@init_with = args
|
338
|
+
end
|
339
|
+
|
340
|
+
def up(*args)
|
341
|
+
@up_called_with = args
|
342
|
+
end
|
343
|
+
|
344
|
+
def down(*args)
|
345
|
+
@down_called_with = args
|
346
|
+
end
|
347
|
+
|
348
|
+
def forward(*args)
|
349
|
+
@forward_called_with = args
|
350
|
+
end
|
351
|
+
|
352
|
+
def rollback(*args)
|
353
|
+
@rollback_called_with = args
|
354
|
+
end
|
355
|
+
end
|
328
356
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'ardb/adapter/mysql'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "assert"
|
4
|
+
require "ardb/adapter/mysql"
|
5
5
|
|
6
|
+
class Ardb::Adapter::Mysql
|
6
7
|
class UnitTests < Assert::Context
|
7
8
|
desc "Ardb::Adapter::Mysql"
|
8
9
|
setup do
|
@@ -11,20 +12,6 @@ class Ardb::Adapter::Mysql
|
|
11
12
|
end
|
12
13
|
subject{ @adapter }
|
13
14
|
|
14
|
-
should "know its foreign key add sql" do
|
15
|
-
exp_add_sql = "ALTER TABLE :from_table"\
|
16
|
-
" ADD CONSTRAINT :name"\
|
17
|
-
" FOREIGN KEY (:from_column)"\
|
18
|
-
" REFERENCES :to_table (:to_column)"
|
19
|
-
assert_equal exp_add_sql, subject.foreign_key_add_sql
|
20
|
-
end
|
21
|
-
|
22
|
-
should "know its foreign key drop sql" do
|
23
|
-
exp_drop_sql = "ALTER TABLE :from_table"\
|
24
|
-
" DROP FOREIGN KEY :name"
|
25
|
-
assert_equal exp_drop_sql, subject.foreign_key_drop_sql
|
26
|
-
end
|
27
|
-
|
28
15
|
# not currently implemented, see: https://github.com/redding/ardb/issues/13
|
29
16
|
should "not implement the create and drop db methods" do
|
30
17
|
assert_raises(NotImplementedError){ subject.create_db }
|
@@ -35,7 +22,5 @@ class Ardb::Adapter::Mysql
|
|
35
22
|
should "not implement the drop tables method" do
|
36
23
|
assert_raises(NotImplementedError){ subject.drop_tables }
|
37
24
|
end
|
38
|
-
|
39
25
|
end
|
40
|
-
|
41
26
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
require 'ardb/adapter/postgresql'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
3
|
+
require "assert"
|
4
|
+
require "ardb/adapter/postgresql"
|
5
5
|
|
6
|
-
|
6
|
+
require "scmd"
|
7
7
|
|
8
|
+
class Ardb::Adapter::Postgresql
|
8
9
|
class UnitTests < Assert::Context
|
9
10
|
desc "Ardb::Adapter::Postgresql"
|
10
11
|
setup do
|
@@ -17,52 +18,42 @@ class Ardb::Adapter::Postgresql
|
|
17
18
|
|
18
19
|
should "know its public connect hash" do
|
19
20
|
exp = subject.connect_hash.merge({
|
20
|
-
|
21
|
-
|
21
|
+
"database" => "postgres",
|
22
|
+
"schema_search_path" => "public",
|
22
23
|
})
|
23
24
|
assert_equal exp, subject.public_connect_hash
|
24
25
|
end
|
25
26
|
|
26
|
-
should "
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
assert_equal exp_add_sql, subject.foreign_key_add_sql
|
27
|
+
should "complain if given a database name with non-word characters" do
|
28
|
+
@config.database = "#{Factory.string}-#{Factory.string}"
|
29
|
+
assert_raises(Ardb::ConfigurationError) do
|
30
|
+
Ardb::Adapter::Postgresql.new(@config)
|
31
|
+
end
|
32
32
|
end
|
33
|
-
|
34
|
-
should "know its foreign key drop sql" do
|
35
|
-
exp_drop_sql = "ALTER TABLE :from_table"\
|
36
|
-
" DROP CONSTRAINT :name"
|
37
|
-
assert_equal exp_drop_sql, subject.foreign_key_drop_sql
|
38
|
-
end
|
39
|
-
|
40
33
|
end
|
41
34
|
|
42
35
|
class SQLSchemaTests < UnitTests
|
43
36
|
setup do
|
44
37
|
@env = {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
"PGHOST" => @adapter.connect_hash["host"],
|
39
|
+
"PGPORT" => @adapter.connect_hash["port"],
|
40
|
+
"PGUSER" => @adapter.connect_hash["username"],
|
41
|
+
"PGPASSWORD" => @adapter.connect_hash["password"],
|
49
42
|
}
|
50
43
|
end
|
51
|
-
|
52
44
|
end
|
53
45
|
|
54
46
|
class LoadSQLSchemaTests < SQLSchemaTests
|
55
47
|
setup do
|
56
48
|
cmd_str = "psql -f \"#{@adapter.sql_schema_path}\" #{@adapter.database}"
|
57
49
|
@cmd_spy = CmdSpy.new
|
58
|
-
Assert.stub(Scmd, :new).with(cmd_str, :
|
50
|
+
Assert.stub(Scmd, :new).with(cmd_str, env: @env){ @cmd_spy }
|
59
51
|
end
|
60
52
|
|
61
53
|
should "run a command for loading a SQL schema using `load_sql_schema`" do
|
62
54
|
subject.load_sql_schema
|
63
55
|
assert_true @cmd_spy.run_called
|
64
56
|
end
|
65
|
-
|
66
57
|
end
|
67
58
|
|
68
59
|
class DumpSQLSchemaTests < SQLSchemaTests
|
@@ -70,14 +61,13 @@ class Ardb::Adapter::Postgresql
|
|
70
61
|
cmd_str = "pg_dump -i -s -x -O -f " \
|
71
62
|
"\"#{@adapter.sql_schema_path}\" #{@adapter.database}"
|
72
63
|
@cmd_spy = CmdSpy.new
|
73
|
-
Assert.stub(Scmd, :new).with(cmd_str, :
|
64
|
+
Assert.stub(Scmd, :new).with(cmd_str, env: @env){ @cmd_spy }
|
74
65
|
end
|
75
66
|
|
76
67
|
should "run a command for dumping a SQL schema using `dump_sql_schema`" do
|
77
68
|
subject.dump_sql_schema
|
78
69
|
assert_true @cmd_spy.run_called
|
79
70
|
end
|
80
|
-
|
81
71
|
end
|
82
72
|
|
83
73
|
class CmdSpy
|
@@ -91,7 +81,8 @@ class Ardb::Adapter::Postgresql
|
|
91
81
|
@run_called = true
|
92
82
|
end
|
93
83
|
|
94
|
-
def success
|
84
|
+
def success?
|
85
|
+
true
|
86
|
+
end
|
95
87
|
end
|
96
|
-
|
97
88
|
end
|