ardb 0.28.3 → 0.30.0
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 +9 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/.t.yml +6 -0
- data/Gemfile +24 -8
- data/README.md +252 -3
- data/ardb.gemspec +14 -10
- data/bin/ardb +3 -1
- data/lib/ardb/adapter/base.rb +72 -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/clirb.rb +16 -18
- data/lib/ardb/cli/commands.rb +308 -129
- data/lib/ardb/cli.rb +29 -24
- 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 +28 -32
- data/lib/ardb/require_autoloaded_active_record_files.rb +258 -57
- data/lib/ardb/test_helpers.rb +33 -29
- data/lib/ardb/use_db_default.rb +13 -21
- data/lib/ardb/version.rb +3 -1
- data/lib/ardb.rb +105 -86
- 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 +23 -21
- 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 +80 -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 +75 -53
- data/test/unit/cli_tests.rb +234 -158
- data/test/unit/db_tests_tests.rb +7 -7
- data/test/unit/default_order_by_tests.rb +26 -24
- data/test/unit/migration_tests.rb +17 -18
- data/test/unit/record_spy_tests.rb +45 -41
- 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 +35 -27
- metadata +109 -87
- 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/unit/cli_tests.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
require 'ardb/cli'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require 'ardb/migration'
|
3
|
+
require "assert"
|
4
|
+
require "ardb/cli"
|
7
5
|
|
8
|
-
|
6
|
+
require "ardb"
|
7
|
+
require "ardb/adapter_spy"
|
8
|
+
require "ardb/migration"
|
9
9
|
|
10
|
+
class Ardb::CLI
|
10
11
|
class UnitTests < Assert::Context
|
11
12
|
desc "Ardb::CLI"
|
12
13
|
setup do
|
@@ -26,16 +27,22 @@ class Ardb::CLI
|
|
26
27
|
end
|
27
28
|
|
28
29
|
should "know its commands" do
|
29
|
-
assert_equal
|
30
|
+
assert_equal 9, COMMANDS.size
|
30
31
|
|
31
32
|
assert_instance_of InvalidCommand, COMMANDS[Factory.string]
|
32
|
-
assert_instance_of ConnectCommand,
|
33
|
-
assert_instance_of CreateCommand,
|
34
|
-
assert_instance_of DropCommand,
|
35
|
-
assert_instance_of
|
36
|
-
|
33
|
+
assert_instance_of ConnectCommand, COMMANDS["connect"]
|
34
|
+
assert_instance_of CreateCommand, COMMANDS["create"]
|
35
|
+
assert_instance_of DropCommand, COMMANDS["drop"]
|
36
|
+
assert_instance_of(
|
37
|
+
GenerateMigrationCommand,
|
38
|
+
COMMANDS["generate-migration"],
|
39
|
+
)
|
40
|
+
assert_instance_of MigrateCommand, COMMANDS["migrate"]
|
41
|
+
assert_instance_of MigrateUpCommand, COMMANDS["migrate-up"]
|
42
|
+
assert_instance_of MigrateDownCommand, COMMANDS["migrate-down"]
|
43
|
+
assert_instance_of MigrateForwardCommand, COMMANDS["migrate-forward"]
|
44
|
+
assert_instance_of MigrateBackwardCommand, COMMANDS["migrate-backward"]
|
37
45
|
end
|
38
|
-
|
39
46
|
end
|
40
47
|
|
41
48
|
class InitTests < UnitTests
|
@@ -50,25 +57,25 @@ class Ardb::CLI
|
|
50
57
|
subject{ @cli }
|
51
58
|
|
52
59
|
should have_imeths :run
|
53
|
-
|
54
60
|
end
|
55
61
|
|
56
62
|
class RunSetupTests < InitTests
|
57
63
|
setup do
|
58
64
|
@command_name = Factory.string
|
59
|
-
@
|
65
|
+
@command_class = Class.new{ include ValidCommand }
|
66
|
+
Assert.stub(@command_class, :command_name){ @command_name }
|
60
67
|
|
61
|
-
@
|
62
|
-
@command_spy = CommandSpy.new
|
68
|
+
@command_spy = CommandSpy.new(@command_name)
|
63
69
|
Assert.stub(@command_class, :new){ @command_spy }
|
64
|
-
COMMANDS.add(@command_class
|
70
|
+
COMMANDS.add(@command_class)
|
65
71
|
|
66
72
|
@invalid_command = InvalidCommand.new(@command_name)
|
73
|
+
|
74
|
+
@argv = [@command_name, Factory.string]
|
67
75
|
end
|
68
76
|
teardown do
|
69
|
-
COMMANDS.remove(@
|
77
|
+
COMMANDS.remove(@command_class)
|
70
78
|
end
|
71
|
-
|
72
79
|
end
|
73
80
|
|
74
81
|
class RunTests < RunSetupTests
|
@@ -88,7 +95,6 @@ class Ardb::CLI
|
|
88
95
|
should "have successfully exited" do
|
89
96
|
assert_equal 0, @kernel_spy.exit_status
|
90
97
|
end
|
91
|
-
|
92
98
|
end
|
93
99
|
|
94
100
|
class RunWithNoArgsTests < RunSetupTests
|
@@ -98,14 +104,13 @@ class Ardb::CLI
|
|
98
104
|
end
|
99
105
|
|
100
106
|
should "output the invalid command's help" do
|
101
|
-
assert_equal @invalid_command.
|
107
|
+
assert_equal @invalid_command.command_help, @stdout.read
|
102
108
|
assert_empty @stderr.read
|
103
109
|
end
|
104
110
|
|
105
111
|
should "have successfully exited" do
|
106
112
|
assert_equal 0, @kernel_spy.exit_status
|
107
113
|
end
|
108
|
-
|
109
114
|
end
|
110
115
|
|
111
116
|
class RunWithInvalidCommandTests < RunSetupTests
|
@@ -117,15 +122,14 @@ class Ardb::CLI
|
|
117
122
|
end
|
118
123
|
|
119
124
|
should "output that it is invalid and output the invalid command's help" do
|
120
|
-
exp = "
|
125
|
+
exp = "\"#{@name}\" is not a command.\n\n"
|
121
126
|
assert_equal exp, @stderr.read
|
122
|
-
assert_equal @invalid_command.
|
127
|
+
assert_equal @invalid_command.command_help, @stdout.read
|
123
128
|
end
|
124
129
|
|
125
130
|
should "have unsuccessfully exited" do
|
126
131
|
assert_equal 1, @kernel_spy.exit_status
|
127
132
|
end
|
128
|
-
|
129
133
|
end
|
130
134
|
|
131
135
|
class RunWithCommandExitErrorTests < RunSetupTests
|
@@ -139,30 +143,28 @@ class Ardb::CLI
|
|
139
143
|
assert_equal 1, @kernel_spy.exit_status
|
140
144
|
assert_empty @stderr.read
|
141
145
|
end
|
142
|
-
|
143
146
|
end
|
144
147
|
|
145
148
|
class RunWithHelpTests < RunSetupTests
|
146
149
|
desc "and run with the help switch"
|
147
150
|
setup do
|
148
|
-
@cli.run([
|
151
|
+
@cli.run(["--help"])
|
149
152
|
end
|
150
153
|
|
151
154
|
should "output the invalid command's help" do
|
152
|
-
assert_equal @invalid_command.
|
155
|
+
assert_equal @invalid_command.command_help, @stdout.read
|
153
156
|
assert_empty @stderr.read
|
154
157
|
end
|
155
158
|
|
156
159
|
should "have successfully exited" do
|
157
160
|
assert_equal 0, @kernel_spy.exit_status
|
158
161
|
end
|
159
|
-
|
160
162
|
end
|
161
163
|
|
162
164
|
class RunWithVersionTests < RunSetupTests
|
163
165
|
desc "and run with the version switch"
|
164
166
|
setup do
|
165
|
-
@cli.run([
|
167
|
+
@cli.run(["--version"])
|
166
168
|
end
|
167
169
|
|
168
170
|
should "output its version" do
|
@@ -173,7 +175,6 @@ class Ardb::CLI
|
|
173
175
|
should "have successfully exited" do
|
174
176
|
assert_equal 0, @kernel_spy.exit_status
|
175
177
|
end
|
176
|
-
|
177
178
|
end
|
178
179
|
|
179
180
|
class RunWithErrorTests < RunSetupTests
|
@@ -193,7 +194,6 @@ class Ardb::CLI
|
|
193
194
|
should "have unsuccessfully exited" do
|
194
195
|
assert_equal 1, @kernel_spy.exit_status
|
195
196
|
end
|
196
|
-
|
197
197
|
end
|
198
198
|
|
199
199
|
class InvalidCommandTests < UnitTests
|
@@ -206,7 +206,7 @@ class Ardb::CLI
|
|
206
206
|
subject{ @cmd }
|
207
207
|
|
208
208
|
should have_readers :name, :clirb
|
209
|
-
should have_imeths :new, :run, :
|
209
|
+
should have_imeths :new, :run, :command_help
|
210
210
|
|
211
211
|
should "know its attrs" do
|
212
212
|
assert_equal @name, subject.name
|
@@ -218,12 +218,12 @@ class Ardb::CLI
|
|
218
218
|
end
|
219
219
|
|
220
220
|
should "parse its argv on run" do
|
221
|
-
assert_raises(CLIRB::HelpExit){ subject.new.run([
|
222
|
-
assert_raises(CLIRB::VersionExit){ subject.new.run([
|
221
|
+
assert_raises(CLIRB::HelpExit){ subject.new.run(["--help"]) }
|
222
|
+
assert_raises(CLIRB::VersionExit){ subject.new.run(["--version"]) }
|
223
223
|
end
|
224
224
|
|
225
225
|
should "raise a help exit if its name is empty" do
|
226
|
-
cmd = @command_class.new([nil,
|
226
|
+
cmd = @command_class.new([nil, ""].sample)
|
227
227
|
argv = [Factory.string, Factory.string]
|
228
228
|
assert_raises(CLIRB::HelpExit){ cmd.new.run(argv) }
|
229
229
|
end
|
@@ -237,9 +237,8 @@ class Ardb::CLI
|
|
237
237
|
"Options: #{subject.clirb}\n" \
|
238
238
|
"Commands:\n" \
|
239
239
|
"#{COMMANDS.to_s.split("\n").map{ |l| " #{l}" }.join("\n")}\n"
|
240
|
-
assert_equal exp, subject.
|
240
|
+
assert_equal exp, subject.command_help
|
241
241
|
end
|
242
|
-
|
243
242
|
end
|
244
243
|
|
245
244
|
class CommandSetupTests < UnitTests
|
@@ -253,7 +252,6 @@ class Ardb::CLI
|
|
253
252
|
Assert.stub(Ardb, :adapter){ @adapter_spy }
|
254
253
|
end
|
255
254
|
subject{ @cmd }
|
256
|
-
|
257
255
|
end
|
258
256
|
|
259
257
|
class ValidCommandTests < CommandSetupTests
|
@@ -263,7 +261,10 @@ class Ardb::CLI
|
|
263
261
|
@cmd = @command_class.new
|
264
262
|
end
|
265
263
|
|
266
|
-
should
|
264
|
+
should have_cmeths :command_name, :command_summary
|
265
|
+
|
266
|
+
should have_imeths :clirb, :run
|
267
|
+
should have_imeths :command_name, :command_summary, :command_help
|
267
268
|
|
268
269
|
should "know its CLI.RB" do
|
269
270
|
assert_instance_of CLIRB, subject.clirb
|
@@ -276,17 +277,34 @@ class Ardb::CLI
|
|
276
277
|
end
|
277
278
|
|
278
279
|
should "take custom CLIRB build procs" do
|
279
|
-
cmd =
|
280
|
-
|
280
|
+
cmd =
|
281
|
+
@command_class.new do
|
282
|
+
option "test", "testing", abbrev: "t"
|
283
|
+
end
|
284
|
+
cmd.run(["-t"], @stdout, @stderr)
|
285
|
+
assert_true cmd.clirb.opts["test"]
|
286
|
+
end
|
287
|
+
|
288
|
+
should "not implement its command name" do
|
289
|
+
assert_raises NotImplementedError do
|
290
|
+
subject.command_name
|
281
291
|
end
|
282
|
-
cmd.run(['-t'], @stdout, @stderr)
|
283
|
-
assert_true cmd.clirb.opts['test']
|
284
292
|
end
|
285
293
|
|
286
|
-
should "default its summary" do
|
287
|
-
assert_equal
|
294
|
+
should "default its command summary" do
|
295
|
+
assert_equal "", subject.command_summary
|
288
296
|
end
|
289
297
|
|
298
|
+
should "know its command help" do
|
299
|
+
Assert.stub(subject, :command_name){ "some-command" }
|
300
|
+
Assert.stub(subject, :command_summary){ "some-summary" }
|
301
|
+
|
302
|
+
exp = "Usage: ardb #{subject.command_name} [options]\n\n" \
|
303
|
+
"Options: #{subject.clirb}\n" \
|
304
|
+
"Description:\n" \
|
305
|
+
" #{subject.command_summary}"
|
306
|
+
assert_equal exp, subject.command_help
|
307
|
+
end
|
290
308
|
end
|
291
309
|
|
292
310
|
class ConnectCommandTests < CommandSetupTests
|
@@ -300,17 +318,12 @@ class Ardb::CLI
|
|
300
318
|
assert_kind_of ValidCommand, subject
|
301
319
|
end
|
302
320
|
|
303
|
-
should "know its summary" do
|
304
|
-
exp = "
|
305
|
-
assert_equal exp, subject.
|
306
|
-
end
|
321
|
+
should "know its command name and summary" do
|
322
|
+
exp = "connect"
|
323
|
+
assert_equal exp, subject.command_name
|
307
324
|
|
308
|
-
|
309
|
-
exp
|
310
|
-
"Options: #{subject.clirb}\n" \
|
311
|
-
"Description:\n" \
|
312
|
-
" #{subject.summary}"
|
313
|
-
assert_equal exp, subject.help
|
325
|
+
exp = "Connect to the configured DB"
|
326
|
+
assert_equal exp, subject.command_summary
|
314
327
|
end
|
315
328
|
|
316
329
|
should "init ardb and connect to the db when run" do
|
@@ -319,7 +332,9 @@ class Ardb::CLI
|
|
319
332
|
assert_equal [false], @ardb_init_called_with
|
320
333
|
assert_true @adapter_spy.connect_db_called?
|
321
334
|
|
322
|
-
exp =
|
335
|
+
exp =
|
336
|
+
"connected to #{Ardb.config.adapter} "\
|
337
|
+
"db #{Ardb.config.database.inspect}\n"
|
323
338
|
assert_equal exp, @stdout.read
|
324
339
|
end
|
325
340
|
|
@@ -338,7 +353,6 @@ class Ardb::CLI
|
|
338
353
|
"with #{Ardb.config.activerecord_connect_hash.inspect}"
|
339
354
|
assert_includes exp, err_output
|
340
355
|
end
|
341
|
-
|
342
356
|
end
|
343
357
|
|
344
358
|
class CreateCommandTests < CommandSetupTests
|
@@ -352,17 +366,12 @@ class Ardb::CLI
|
|
352
366
|
assert_kind_of ValidCommand, subject
|
353
367
|
end
|
354
368
|
|
355
|
-
should "know its summary" do
|
356
|
-
exp = "
|
357
|
-
assert_equal exp, subject.
|
358
|
-
end
|
369
|
+
should "know its command name and summary" do
|
370
|
+
exp = "create"
|
371
|
+
assert_equal exp, subject.command_name
|
359
372
|
|
360
|
-
|
361
|
-
exp
|
362
|
-
"Options: #{subject.clirb}\n" \
|
363
|
-
"Description:\n" \
|
364
|
-
" #{subject.summary}"
|
365
|
-
assert_equal exp, subject.help
|
373
|
+
exp = "Create the configured DB"
|
374
|
+
assert_equal exp, subject.command_summary
|
366
375
|
end
|
367
376
|
|
368
377
|
should "init ardb and create the db when run" do
|
@@ -371,7 +380,8 @@ class Ardb::CLI
|
|
371
380
|
assert_equal [false], @ardb_init_called_with
|
372
381
|
assert_true @adapter_spy.create_db_called?
|
373
382
|
|
374
|
-
exp =
|
383
|
+
exp =
|
384
|
+
"created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
|
375
385
|
assert_equal exp, @stdout.read
|
376
386
|
end
|
377
387
|
|
@@ -386,7 +396,6 @@ class Ardb::CLI
|
|
386
396
|
exp = "error creating #{Ardb.config.database.inspect} database"
|
387
397
|
assert_includes exp, err_output
|
388
398
|
end
|
389
|
-
|
390
399
|
end
|
391
400
|
|
392
401
|
class DropCommandTests < CommandSetupTests
|
@@ -400,17 +409,12 @@ class Ardb::CLI
|
|
400
409
|
assert_kind_of ValidCommand, subject
|
401
410
|
end
|
402
411
|
|
403
|
-
should "know its summary" do
|
404
|
-
exp = "
|
405
|
-
assert_equal exp, subject.
|
406
|
-
end
|
412
|
+
should "know its command name and summary" do
|
413
|
+
exp = "drop"
|
414
|
+
assert_equal exp, subject.command_name
|
407
415
|
|
408
|
-
|
409
|
-
exp
|
410
|
-
"Options: #{subject.clirb}\n" \
|
411
|
-
"Description:\n" \
|
412
|
-
" #{subject.summary}"
|
413
|
-
assert_equal exp, subject.help
|
416
|
+
exp = "Drop the configured DB"
|
417
|
+
assert_equal exp, subject.command_summary
|
414
418
|
end
|
415
419
|
|
416
420
|
should "init ardb and drop the db when run" do
|
@@ -419,7 +423,8 @@ class Ardb::CLI
|
|
419
423
|
assert_equal [true], @ardb_init_called_with
|
420
424
|
assert_true @adapter_spy.drop_db_called?
|
421
425
|
|
422
|
-
exp =
|
426
|
+
exp =
|
427
|
+
"dropped #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
|
423
428
|
assert_equal exp, @stdout.read
|
424
429
|
end
|
425
430
|
|
@@ -434,35 +439,102 @@ class Ardb::CLI
|
|
434
439
|
exp = "error dropping #{Ardb.config.database.inspect} database"
|
435
440
|
assert_includes exp, err_output
|
436
441
|
end
|
442
|
+
end
|
443
|
+
|
444
|
+
class GenerateMigrationCommandTests < CommandSetupTests
|
445
|
+
desc "GenerateMigrationCommand"
|
446
|
+
setup do
|
447
|
+
@identifier = Factory.migration_id
|
448
|
+
|
449
|
+
@migration_spy = nil
|
450
|
+
@migration_class = Ardb::Migration
|
451
|
+
Assert.stub(@migration_class, :new) do |*args|
|
452
|
+
@migration_spy = MigrationSpy.new(*args)
|
453
|
+
end
|
454
|
+
|
455
|
+
@command_class = GenerateMigrationCommand
|
456
|
+
@cmd = @command_class.new
|
457
|
+
end
|
437
458
|
|
459
|
+
should "be a valid command" do
|
460
|
+
assert_kind_of ValidCommand, subject
|
461
|
+
end
|
462
|
+
|
463
|
+
should "know its command name and summary" do
|
464
|
+
exp = "generate-migration"
|
465
|
+
assert_equal exp, subject.command_name
|
466
|
+
|
467
|
+
exp = "Generate a MIGRATION-NAME migration file"
|
468
|
+
assert_equal exp, subject.command_summary
|
469
|
+
end
|
470
|
+
|
471
|
+
should "init ardb and save a migration for the identifier when run" do
|
472
|
+
subject.run([@identifier], @stdout, @stderr)
|
473
|
+
|
474
|
+
assert_equal [false], @ardb_init_called_with
|
475
|
+
assert_equal Ardb.config, @migration_spy.ardb_config
|
476
|
+
assert_equal @identifier, @migration_spy.identifier
|
477
|
+
assert_true @migration_spy.save_called
|
478
|
+
|
479
|
+
exp = "generated #{@migration_spy.file_path}\n"
|
480
|
+
assert_equal exp, @stdout.read
|
481
|
+
end
|
482
|
+
|
483
|
+
should "re-raise a specific argument error on "\
|
484
|
+
"migration \"no identifer\" errors" do
|
485
|
+
Assert.stub(@migration_class, :new) do
|
486
|
+
raise Ardb::Migration::NoIdentifierError
|
487
|
+
end
|
488
|
+
|
489
|
+
ex =
|
490
|
+
assert_that{
|
491
|
+
cmd = @command_class.new
|
492
|
+
cmd.run([])
|
493
|
+
}.raises(ArgumentError)
|
494
|
+
exp = "MIGRATION-NAME must be provided"
|
495
|
+
assert_equal exp, ex.message
|
496
|
+
assert_not_empty ex.backtrace
|
497
|
+
end
|
498
|
+
|
499
|
+
should "output any errors and raise an exit error when run" do
|
500
|
+
err = StandardError.new(Factory.string)
|
501
|
+
err.set_backtrace(Factory.integer(3).times.map{ Factory.path })
|
502
|
+
Assert.stub(@migration_class, :new){ raise err }
|
503
|
+
|
504
|
+
assert_raises(CommandExitError) do
|
505
|
+
subject.run([@identifier], @stdout, @stderr)
|
506
|
+
end
|
507
|
+
err_output = @stderr.read
|
508
|
+
|
509
|
+
assert_includes err.to_s, err_output
|
510
|
+
assert_includes err.backtrace.join("\n"), err_output
|
511
|
+
|
512
|
+
exp = "error generating migration"
|
513
|
+
assert_includes exp, err_output
|
514
|
+
end
|
438
515
|
end
|
439
516
|
|
440
517
|
class MigrateCommandTests < CommandSetupTests
|
441
518
|
desc "MigrateCommand"
|
442
519
|
setup do
|
443
|
-
@orig_env_var_migrate_no_schema = ENV[
|
520
|
+
@orig_env_var_migrate_no_schema = ENV["ARDB_MIGRATE_NO_SCHEMA"]
|
444
521
|
@command_class = MigrateCommand
|
445
522
|
@cmd = @command_class.new
|
446
523
|
end
|
447
524
|
teardown do
|
448
|
-
ENV[
|
525
|
+
ENV["ARDB_MIGRATE_NO_SCHEMA"] = @orig_env_var_migrate_no_schema
|
449
526
|
end
|
450
527
|
|
451
|
-
should "be a
|
452
|
-
assert_kind_of
|
528
|
+
should "be a migrate command" do
|
529
|
+
assert_kind_of MigrateCommandBehaviors, subject
|
453
530
|
end
|
454
531
|
|
455
|
-
should "know its summary" do
|
456
|
-
exp = "
|
457
|
-
assert_equal exp, subject.
|
458
|
-
end
|
532
|
+
should "know its command name and summary" do
|
533
|
+
exp = "migrate"
|
534
|
+
assert_equal exp, subject.command_name
|
459
535
|
|
460
|
-
|
461
|
-
exp
|
462
|
-
"Options: #{subject.clirb}\n" \
|
463
|
-
"Description:\n" \
|
464
|
-
" #{subject.summary}"
|
465
|
-
assert_equal exp, subject.help
|
536
|
+
exp = "Migrate the configured DB"
|
537
|
+
assert_equal exp, subject.command_summary
|
466
538
|
end
|
467
539
|
|
468
540
|
should "init ardb, migrate the db and dump the schema when run" do
|
@@ -473,8 +545,9 @@ class Ardb::CLI
|
|
473
545
|
assert_true @adapter_spy.dump_schema_called?
|
474
546
|
end
|
475
547
|
|
476
|
-
should "only init ardb and migrate when run with no schema dump
|
477
|
-
|
548
|
+
should "only init ardb and migrate when run with no schema dump "\
|
549
|
+
"env var set" do
|
550
|
+
ENV["ARDB_MIGRATE_NO_SCHEMA"] = "yes"
|
478
551
|
subject.run([], @stdout, @stderr)
|
479
552
|
|
480
553
|
assert_equal [true], @ardb_init_called_with
|
@@ -496,83 +569,86 @@ class Ardb::CLI
|
|
496
569
|
exp = "error migrating #{Ardb.config.database.inspect} database"
|
497
570
|
assert_includes exp, err_output
|
498
571
|
end
|
499
|
-
|
500
572
|
end
|
501
573
|
|
502
|
-
class
|
503
|
-
desc "
|
574
|
+
class MigrateUpCommandTests < CommandSetupTests
|
575
|
+
desc "MigrateUpCommand"
|
504
576
|
setup do
|
505
|
-
@
|
506
|
-
|
507
|
-
@migration_spy = nil
|
508
|
-
@migration_class = Ardb::Migration
|
509
|
-
Assert.stub(@migration_class, :new) do |*args|
|
510
|
-
@migration_spy = MigrationSpy.new(*args)
|
511
|
-
end
|
512
|
-
|
513
|
-
@command_class = GenerateMigrationCommand
|
577
|
+
@command_class = MigrateUpCommand
|
514
578
|
@cmd = @command_class.new
|
515
579
|
end
|
516
580
|
|
517
|
-
should "be a
|
518
|
-
assert_kind_of
|
581
|
+
should "be a migrate command" do
|
582
|
+
assert_kind_of MigrateCommandBehaviors, subject
|
519
583
|
end
|
520
584
|
|
521
|
-
should "know its summary" do
|
522
|
-
exp = "
|
523
|
-
assert_equal exp, subject.
|
585
|
+
should "know its command name and summary" do
|
586
|
+
exp = "migrate-up"
|
587
|
+
assert_equal exp, subject.command_name
|
588
|
+
|
589
|
+
exp = "Migrate the configured DB up"
|
590
|
+
assert_equal exp, subject.command_summary
|
524
591
|
end
|
592
|
+
end
|
525
593
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
assert_equal exp, subject.help
|
594
|
+
class MigrateDownCommandTests < CommandSetupTests
|
595
|
+
desc "MigrateDownCommand"
|
596
|
+
setup do
|
597
|
+
@command_class = MigrateDownCommand
|
598
|
+
@cmd = @command_class.new
|
532
599
|
end
|
533
600
|
|
534
|
-
should "
|
535
|
-
|
601
|
+
should "be a migrate command" do
|
602
|
+
assert_kind_of MigrateCommandBehaviors, subject
|
603
|
+
end
|
536
604
|
|
537
|
-
|
538
|
-
|
539
|
-
assert_equal
|
540
|
-
assert_true @migration_spy.save_called
|
605
|
+
should "know its command name and summary" do
|
606
|
+
exp = "migrate-down"
|
607
|
+
assert_equal exp, subject.command_name
|
541
608
|
|
542
|
-
exp = "
|
543
|
-
assert_equal exp,
|
609
|
+
exp = "Migrate the configured DB down"
|
610
|
+
assert_equal exp, subject.command_summary
|
544
611
|
end
|
612
|
+
end
|
545
613
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
rescue ArgumentError => err
|
553
|
-
end
|
614
|
+
class MigrateForwardCommandTests < CommandSetupTests
|
615
|
+
desc "MigrateForwardCommand"
|
616
|
+
setup do
|
617
|
+
@command_class = MigrateForwardCommand
|
618
|
+
@cmd = @command_class.new
|
619
|
+
end
|
554
620
|
|
555
|
-
|
556
|
-
|
557
|
-
assert_equal exp, err.message
|
558
|
-
assert_not_empty err.backtrace
|
621
|
+
should "be a migrate command" do
|
622
|
+
assert_kind_of MigrateCommandBehaviors, subject
|
559
623
|
end
|
560
624
|
|
561
|
-
should "
|
562
|
-
|
563
|
-
|
564
|
-
Assert.stub(@migration_class, :new){ raise err }
|
625
|
+
should "know its command name and summary" do
|
626
|
+
exp = "migrate-forward"
|
627
|
+
assert_equal exp, subject.command_name
|
565
628
|
|
566
|
-
|
567
|
-
|
629
|
+
exp = "Migrate the configured DB forward"
|
630
|
+
assert_equal exp, subject.command_summary
|
631
|
+
end
|
632
|
+
end
|
568
633
|
|
569
|
-
|
570
|
-
|
634
|
+
class MigrateBackwardCommandTests < CommandSetupTests
|
635
|
+
desc "MigrateBackwardCommand"
|
636
|
+
setup do
|
637
|
+
@command_class = MigrateBackwardCommand
|
638
|
+
@cmd = @command_class.new
|
639
|
+
end
|
571
640
|
|
572
|
-
|
573
|
-
|
641
|
+
should "be a migrate command" do
|
642
|
+
assert_kind_of MigrateCommandBehaviors, subject
|
574
643
|
end
|
575
644
|
|
645
|
+
should "know its command name and summary" do
|
646
|
+
exp = "migrate-backward"
|
647
|
+
assert_equal exp, subject.command_name
|
648
|
+
|
649
|
+
exp = "Migrate the configured DB backward"
|
650
|
+
assert_equal exp, subject.command_summary
|
651
|
+
end
|
576
652
|
end
|
577
653
|
|
578
654
|
class CLISpy
|
@@ -588,9 +664,10 @@ class Ardb::CLI
|
|
588
664
|
end
|
589
665
|
|
590
666
|
class CommandSpy
|
591
|
-
attr_reader :argv, :stdout, :stderr, :run_called
|
667
|
+
attr_reader :command_name, :argv, :stdout, :stderr, :run_called
|
592
668
|
|
593
|
-
def initialize
|
669
|
+
def initialize(command_name)
|
670
|
+
@command_name = command_name
|
594
671
|
@argv = nil
|
595
672
|
@stdout, @stderr = nil, nil
|
596
673
|
@run_called = false
|
@@ -602,12 +679,12 @@ class Ardb::CLI
|
|
602
679
|
@run_called = true
|
603
680
|
end
|
604
681
|
|
605
|
-
def
|
606
|
-
@
|
682
|
+
def command_summary
|
683
|
+
@command_summary ||= Factory.string
|
607
684
|
end
|
608
685
|
|
609
|
-
def
|
610
|
-
@
|
686
|
+
def command_help
|
687
|
+
@command_help ||= Factory.text
|
611
688
|
end
|
612
689
|
end
|
613
690
|
|
@@ -653,5 +730,4 @@ class Ardb::CLI
|
|
653
730
|
self
|
654
731
|
end
|
655
732
|
end
|
656
|
-
|
657
733
|
end
|