ridgepole 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae69c3f7da066d33e2e54bb5f8b6fcbfc5d42d36
4
- data.tar.gz: 354fed4e3f679ef14b5bd5d97523e58ee07d11bc
3
+ metadata.gz: 1450957da8f5ba966dfab934b036b4a93d972e99
4
+ data.tar.gz: 2d323098fd39e4e86dea90279e40dad90a4c09a8
5
5
  SHA512:
6
- metadata.gz: 3cd38079ebe1d5d1a112f4737c26579aa0bbce185e4e2159db12c2faa825a2f6db677a1086c77bffa93dc8af874bf9786d9608c93c2907b05c5aec487cc19b61
7
- data.tar.gz: 798ab1ed0a0dc0e8368781577713b57fd73eb3d5ecdc0a6594bf87c6937fbd14e586f1dd2f9eb52682cd0621a4f6ce1bcdcdfdbf8e1531fef8bd2b8ca4ca3f5d
6
+ metadata.gz: 07dacc0bce5cba26d9636bb5acbfb70a7db5bc6bcb5de2eaec9e4ad37ed84728891414d6c534560f1b59c3b3db16714141cdf03eb322274f563e3e682fd069b4
7
+ data.tar.gz: 3e064705391531a4918bfdf0c88ddcaa96ceab35d85b0e53a91966afd9fb3b0833365f2019098383407f441b51cd9b25d2a78f2a822ed46cfe0aeec0696ca61f
data/README.md CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
26
26
  ```
27
27
  Usage: ridgepole [options]
28
28
  -c, --config CONF_OR_FILE
29
+ -E, --env ENVIRONMENT
29
30
  -a, --apply
30
31
  -m, --merge
31
32
  -f, --file FILE
@@ -48,6 +49,7 @@ Usage: ridgepole [options]
48
49
  --log-file LOG_FILE
49
50
  --verbose
50
51
  --debug
52
+ -v, --version
51
53
  ```
52
54
 
53
55
  ## Usage
data/bin/ridgepole CHANGED
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  require 'optparse'
6
6
  require 'fileutils'
7
7
  require 'ridgepole'
8
+ require 'ridgepole/cli/config'
8
9
 
9
10
  $stdout.sync = true
10
11
  $stderr.sync = true
@@ -13,6 +14,7 @@ Version = Ridgepole::VERSION
13
14
  DEFAULT_FILENAME = 'Schemafile'
14
15
 
15
16
  config = nil
17
+ env = 'development'
16
18
  mode = nil
17
19
  file = DEFAULT_FILENAME
18
20
  output_file = '-'
@@ -42,6 +44,7 @@ end
42
44
  ARGV.options do |opt|
43
45
  begin
44
46
  opt.on('-c', '--config CONF_OR_FILE') {|v| config = v }
47
+ opt.on('-E', '--env ENVIRONMENT') {|v| env = v }
45
48
  opt.on('-a', '--apply') { set_mode[:apply] }
46
49
  opt.on('-m', '--merge') { set_mode[:apply]; options[:merge] = true }
47
50
  opt.on('-f', '--file FILE') {|v| file = v }
@@ -102,11 +105,7 @@ begin
102
105
  logger = Ridgepole::Logger.instance
103
106
  logger.set_debug(options[:debug])
104
107
 
105
- if config
106
- config = File.read(config) if File.exist?(config)
107
- config = YAML.load(config)
108
- client = Ridgepole::Client.new(config, options)
109
- end
108
+ client = Ridgepole::Client.new(Ridgepole::Config.load(config, env), options) if config
110
109
 
111
110
  ActiveRecord::Base.logger = logger
112
111
 
@@ -179,7 +178,12 @@ begin
179
178
  diff_files = diff_files.map do |file|
180
179
  if File.exist?(file)
181
180
  file_ext = File.extname(file)
182
- %w(.yml .yaml).include?(file_ext) ? YAML.load_file(file) : File.read(file)
181
+
182
+ if %w(.yml .yaml).include?(file_ext)
183
+ Ridgepole::Config.load(file, env)
184
+ else
185
+ File.read(file)
186
+ end
183
187
  else
184
188
  YAML.load(file)
185
189
  end
@@ -0,0 +1,19 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+
4
+ class Ridgepole::Config
5
+ def self.load(config, env = 'development')
6
+ config = if File.exist?(config)
7
+ yaml = ERB.new(File.read(config)).result
8
+ YAML.load(yaml)
9
+ else
10
+ YAML.load(ERB.new(config).result)
11
+ end
12
+
13
+ if config.has_key?(env.to_s)
14
+ config.fetch(env.to_s)
15
+ else
16
+ config
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.4.6'
2
+ VERSION = '0.4.7'
3
3
  end
@@ -0,0 +1,73 @@
1
+ describe Ridgepole::Config do
2
+ subject { Ridgepole::Config.load(config, env) }
3
+
4
+ context 'when passed toplevel yaml' do
5
+ let(:config) {
6
+ <<-YAML.strip_heredoc
7
+ adapter: mysql2
8
+ encoding: utf8
9
+ database: blog
10
+ username: root
11
+ YAML
12
+ }
13
+ let(:env) { 'development' }
14
+ it {
15
+ expect(subject['adapter']).to eq "mysql2"
16
+ expect(subject['encoding']).to eq "utf8"
17
+ expect(subject['database']).to eq "blog"
18
+ expect(subject['username']).to eq "root"
19
+ }
20
+ end
21
+
22
+ context 'when passed dynamic yaml' do
23
+ let(:config) {
24
+ <<-YAML.strip_heredoc
25
+ adapter: mysql2
26
+ encoding: utf8
27
+ database: blog_<%= 1 + 2 %>
28
+ username: user_<%= 3 * 4 %>
29
+ YAML
30
+ }
31
+ let(:env) { 'development' }
32
+ it {
33
+ expect(subject['adapter']).to eq "mysql2"
34
+ expect(subject['encoding']).to eq "utf8"
35
+ expect(subject['database']).to eq "blog_3"
36
+ expect(subject['username']).to eq "user_12"
37
+ }
38
+ end
39
+
40
+ context 'when passed rails database.yml style yaml' do
41
+ let(:config) {
42
+ <<-YAML.strip_heredoc
43
+ development:
44
+ adapter: sqlite
45
+ database: db/sample.db
46
+ production:
47
+ adapter: mysql2
48
+ encoding: utf8
49
+ database: blog
50
+ username: root
51
+ YAML
52
+ }
53
+
54
+ context 'in development env' do
55
+ let(:env) { 'development' }
56
+ it {
57
+ expect(subject['adapter']).to eq "sqlite"
58
+ expect(subject['database']).to eq "db/sample.db"
59
+ expect(subject['username']).to be_nil
60
+ }
61
+ end
62
+
63
+ context 'in production env' do
64
+ let(:env) { 'production' }
65
+ it {
66
+ expect(subject['adapter']).to eq "mysql2"
67
+ expect(subject['encoding']).to eq "utf8"
68
+ expect(subject['database']).to eq "blog"
69
+ expect(subject['username']).to eq "root"
70
+ }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,388 @@
1
+ describe 'ridgepole' do
2
+ let(:differ) { false }
3
+ let(:conf) { "'" + JSON.dump(conn_spec) + "'" }
4
+
5
+ context 'when help' do
6
+ it do
7
+ out, status = run_cli(:args => ['-h'])
8
+ out = out.gsub(/Usage: .*\n/, '').strip_heredoc
9
+
10
+ expect(status.success?).to be_truthy
11
+ expect(out).to eq <<-EOS.strip_heredoc
12
+ -c, --config CONF_OR_FILE
13
+ -E, --env ENVIRONMENT
14
+ -a, --apply
15
+ -m, --merge
16
+ -f, --file FILE
17
+ --dry-run
18
+ --table-options OPTIONS
19
+ --bulk-change
20
+ --default-int-limit LIMIT
21
+ --pre-query QUERY
22
+ --post-query QUERY
23
+ -e, --export
24
+ --split
25
+ --split-with-dir
26
+ -d, --diff DSL1 DSL2
27
+ --reverse
28
+ --with-apply
29
+ -o, --output FILE
30
+ -t, --tables TABLES
31
+ --ignore-tables TABLES
32
+ --disable-mysql-unsigned
33
+ --log-file LOG_FILE
34
+ --verbose
35
+ --debug
36
+ -v, --version
37
+ EOS
38
+ end
39
+ end
40
+
41
+ context 'when export' do
42
+ it 'not split' do
43
+ out, status = run_cli(:args => ['-c', conf, '-e', conf, conf])
44
+
45
+ expect(status.success?).to be_truthy
46
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
47
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
48
+ # Export Schema
49
+ Ridgepole::Client#dump
50
+ EOS
51
+ end
52
+
53
+ it 'not split with outfile' do
54
+ Tempfile.open("#{File.basename __FILE__}.#{$$}") do |f|
55
+ out, status = run_cli(:args => ['-c', conf, '-e', '-o', f.path])
56
+
57
+ expect(status.success?).to be_truthy
58
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
59
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
60
+ Export Schema to `#{f.path}`
61
+ Ridgepole::Client#dump
62
+ EOS
63
+ end
64
+ end
65
+
66
+ it 'not split with output stdout' do
67
+ out, status = run_cli(:args => ['-c', conf, '-e', '-o', '-'])
68
+
69
+ expect(status.success?).to be_truthy
70
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
71
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
72
+ # Export Schema
73
+ Ridgepole::Client#dump
74
+ EOS
75
+ end
76
+
77
+ it 'split' do
78
+ out, status = run_cli(:args => ['-c', conf, '-e', '--split'])
79
+
80
+ expect(status.success?).to be_truthy
81
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
82
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
83
+ Export Schema
84
+ Ridgepole::Client#dump
85
+ write `Schemafile`
86
+ EOS
87
+ end
88
+
89
+ it 'split with outdir' do
90
+ Tempfile.open("#{File.basename __FILE__}.#{$$}") do |f|
91
+ out, status = run_cli(:args => ['-c', conf, '-e', '--split', '-o', f.path, conf, conf])
92
+
93
+ expect(status.success?).to be_truthy
94
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
95
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
96
+ Export Schema
97
+ Ridgepole::Client#dump
98
+ write `#{f.path}`
99
+ EOS
100
+ end
101
+ end
102
+ end
103
+
104
+ context 'when apply' do
105
+ it 'apply' do
106
+ out, status = run_cli(:args => ['-c', conf, '-a'])
107
+
108
+ expect(status.success?).to be_truthy
109
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
110
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
111
+ Apply `Schemafile`
112
+ Ridgepole::Client#diff
113
+ Ridgepole::Delta#migrate
114
+ Ridgepole::Delta#differ?
115
+ No change
116
+ EOS
117
+ end
118
+
119
+ it 'apply with conf file' do
120
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
121
+ conf_file.puts <<-EOS.strip_heredoc
122
+ adapter: mysql2
123
+ database: ridgepole_test_for_conf_file
124
+ EOS
125
+ conf_file.flush
126
+
127
+ out, status = run_cli(:args => ['-c', conf_file.path, '-a', '--debug'])
128
+
129
+ expect(status.success?).to be_truthy
130
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
131
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test_for_conf_file"}, {:dry_run=>false, :debug=>true}])
132
+ Apply `Schemafile`
133
+ Ridgepole::Client#diff
134
+ Ridgepole::Delta#migrate
135
+ Ridgepole::Delta#differ?
136
+ No change
137
+ EOS
138
+ end
139
+ end
140
+
141
+ it 'apply with conf file (production)' do
142
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
143
+ conf_file.puts <<-EOS.strip_heredoc
144
+ development:
145
+ adapter: mysql2
146
+ database: ridgepole_development
147
+ production:
148
+ adapter: mysql2
149
+ database: ridgepole_production
150
+ EOS
151
+ conf_file.flush
152
+
153
+ out, status = run_cli(:args => ['-c', conf_file.path, '-a', '--debug'])
154
+
155
+ expect(status.success?).to be_truthy
156
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
157
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_development"}, {:dry_run=>false, :debug=>true}])
158
+ Apply `Schemafile`
159
+ Ridgepole::Client#diff
160
+ Ridgepole::Delta#migrate
161
+ Ridgepole::Delta#differ?
162
+ No change
163
+ EOS
164
+ end
165
+ end
166
+
167
+ it 'dry-run' do
168
+ out, status = run_cli(:args => ['-c', conf, '-a', '--dry-run'])
169
+
170
+ expect(status.success?).to be_truthy
171
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
172
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>true, :debug=>false}])
173
+ Apply `Schemafile` (dry-run)
174
+ Ridgepole::Client#diff
175
+ Ridgepole::Delta#differ?
176
+ Ridgepole::Delta#differ?
177
+ No change
178
+ EOS
179
+ end
180
+
181
+ context 'when differ true' do
182
+ let(:differ) { true }
183
+
184
+ it 'apply' do
185
+ out, status = run_cli(:args => ['-c', conf, '-a'])
186
+
187
+ expect(status.success?).to be_truthy
188
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
189
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
190
+ Apply `Schemafile`
191
+ Ridgepole::Client#diff
192
+ Ridgepole::Delta#migrate
193
+ Ridgepole::Delta#differ?
194
+ EOS
195
+ end
196
+
197
+ it 'dry-run' do
198
+ out, status = run_cli(:args => ['-c', conf, '-a', '--dry-run'])
199
+
200
+ expect(status.success?).to be_truthy
201
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
202
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>true, :debug=>false}])
203
+ Apply `Schemafile` (dry-run)
204
+ Ridgepole::Client#diff
205
+ Ridgepole::Delta#differ?
206
+ Ridgepole::Delta#script
207
+ create_table :table do
208
+ end
209
+
210
+ Ridgepole::Delta#migrate
211
+ # create_table :table do
212
+
213
+ # end
214
+
215
+ Ridgepole::Delta#differ?
216
+ EOS
217
+ end
218
+ end
219
+ end
220
+
221
+ context 'when diff' do
222
+ it do
223
+ out, status = run_cli(:args => ['-c', conf, '-d', conf, conf])
224
+
225
+ expect(status.success?).to be_truthy
226
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
227
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
228
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
229
+ Ridgepole::Delta#differ?
230
+ EOS
231
+ end
232
+
233
+ context 'when differ true' do
234
+ let(:differ) { true }
235
+
236
+ it do
237
+ out, status = run_cli(:args => ['-c', conf, '-d', conf, conf])
238
+
239
+ # Exit code 1 if there is a difference
240
+ expect(status.success?).to be_falsey
241
+
242
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
243
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
244
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
245
+ Ridgepole::Delta#differ?
246
+ Ridgepole::Delta#script
247
+ create_table :table do
248
+ end
249
+
250
+ Ridgepole::Delta#migrate
251
+ # create_table :table do
252
+
253
+ # end
254
+ EOS
255
+ end
256
+ end
257
+
258
+ context 'when config file' do
259
+ it '.yml' do
260
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
261
+ conf_file.puts <<-EOS.strip_heredoc
262
+ adapter: mysql2
263
+ database: ridgepole_test_for_conf_file
264
+ EOS
265
+ conf_file.flush
266
+
267
+ out, status = run_cli(:args => ['-c', conf, '-d', conf_file.path, conf])
268
+
269
+ expect(status.success?).to be_truthy
270
+
271
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
272
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
273
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_test_for_conf_file"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
274
+ Ridgepole::Delta#differ?
275
+ EOS
276
+ end
277
+ end
278
+
279
+ it '.yml (file2)' do
280
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
281
+ conf_file.puts <<-EOS.strip_heredoc
282
+ adapter: mysql2
283
+ database: ridgepole_test_for_conf_file
284
+ EOS
285
+ conf_file.flush
286
+
287
+ out, status = run_cli(:args => ['-c', conf, '-d', conf, conf_file.path])
288
+
289
+ expect(status.success?).to be_truthy
290
+
291
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
292
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
293
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test_for_conf_file"}, {:dry_run=>false, :debug=>false}])
294
+ Ridgepole::Delta#differ?
295
+ EOS
296
+ end
297
+ end
298
+
299
+ it '.yml (development)' do
300
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
301
+ conf_file.puts <<-EOS.strip_heredoc
302
+ development:
303
+ adapter: mysql2
304
+ database: ridgepole_development
305
+ production:
306
+ adapter: mysql2
307
+ database: ridgepole_production
308
+ EOS
309
+ conf_file.flush
310
+
311
+ out, status = run_cli(:args => ['-c', conf, '-d', conf_file.path, conf])
312
+
313
+ expect(status.success?).to be_truthy
314
+
315
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
316
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
317
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_development"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
318
+ Ridgepole::Delta#differ?
319
+ EOS
320
+ end
321
+ end
322
+
323
+ it '.yml (production)' do
324
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yml']) do |conf_file|
325
+ conf_file.puts <<-EOS.strip_heredoc
326
+ development:
327
+ adapter: mysql2
328
+ database: ridgepole_development
329
+ production:
330
+ adapter: mysql2
331
+ database: ridgepole_production
332
+ EOS
333
+ conf_file.flush
334
+
335
+ out, status = run_cli(:args => ['-c', conf, '-d', conf_file.path, conf, '-E', :production])
336
+
337
+ expect(status.success?).to be_truthy
338
+
339
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
340
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
341
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_production"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
342
+ Ridgepole::Delta#differ?
343
+ EOS
344
+ end
345
+ end
346
+
347
+ it '.yaml' do
348
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.yaml']) do |conf_file|
349
+ conf_file.puts <<-EOS.strip_heredoc
350
+ adapter: mysql2
351
+ database: ridgepole_test_for_conf_file
352
+ EOS
353
+ conf_file.flush
354
+
355
+ out, status = run_cli(:args => ['-c', conf, '-d', conf_file.path, conf])
356
+
357
+ expect(status.success?).to be_truthy
358
+
359
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
360
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
361
+ Ridgepole::Client.diff([{"adapter"=>"mysql2", "database"=>"ridgepole_test_for_conf_file"}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
362
+ Ridgepole::Delta#differ?
363
+ EOS
364
+ end
365
+ end
366
+
367
+ it '.rb' do
368
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.rb']) do |conf_file|
369
+ conf_file.puts <<-EOS.strip_heredoc
370
+ create_table :table do
371
+ end
372
+ EOS
373
+ conf_file.flush
374
+
375
+ out, status = run_cli(:args => ['-c', conf, '-d', conf_file.path, conf])
376
+
377
+ expect(status.success?).to be_truthy
378
+
379
+ expect(out.strip).to eq <<-'EOS'.strip_heredoc.strip
380
+ Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
381
+ Ridgepole::Client.diff(["create_table :table do\nend\n", {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
382
+ Ridgepole::Delta#differ?
383
+ EOS
384
+ end
385
+ end
386
+ end
387
+ end
388
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  $: << File.expand_path('..', __FILE__)
2
2
  require 'ridgepole'
3
+ require 'ridgepole/cli/config'
3
4
  require 'active_support/core_ext/string/strip'
4
5
  require 'string_ext'
6
+ require 'open3'
7
+ require 'tempfile'
8
+ require 'json'
5
9
 
6
10
  ActiveRecord::Migration.verbose = false
7
11
  Ridgepole::Logger.instance.level = ::Logger::ERROR
@@ -37,3 +41,64 @@ def conn_spec(config = {})
37
41
  database: 'ridgepole_test',
38
42
  }.merge(config)
39
43
  end
44
+
45
+ def default_cli_hook
46
+ <<-RUBY.strip_heredoc
47
+ require 'ridgepole'
48
+
49
+ class Ridgepole::Delta
50
+ def initialize(*args);
51
+ end
52
+ def migrate(*args)
53
+ puts "Ridgepole::Delta#migrate"
54
+ "create_table :table do\\nend"
55
+ end
56
+ def script
57
+ puts "Ridgepole::Delta#script"
58
+
59
+ "create_table :table do\\nend"
60
+ end
61
+ def differ?
62
+ puts "Ridgepole::Delta#differ?"
63
+ #{differ}
64
+ end
65
+ end
66
+
67
+ class Ridgepole::Client
68
+ def initialize(*args)
69
+ puts "Ridgepole::Client#initialize(\#{args.inspect})"
70
+ end
71
+ def dump
72
+ puts "Ridgepole::Client#dump"
73
+ end
74
+ def diff(*args)
75
+ puts "Ridgepole::Client#diff"
76
+ Ridgepole::Delta.new
77
+ end
78
+ class << self
79
+ def diff(*args)
80
+ puts "Ridgepole::Client.diff(\#{args.inspect})"
81
+ Ridgepole::Delta.new
82
+ end
83
+ def dump(args)
84
+ puts "Ridgepole::Client.dump"
85
+ end
86
+ end
87
+ end
88
+ RUBY
89
+ end
90
+
91
+ def run_cli(options = {})
92
+ args = options[:args] || []
93
+ hook = options[:hook] || default_cli_hook
94
+ path = File.expand_path('../../bin/ridgepole', __FILE__)
95
+
96
+ Tempfile.open(["#{File.basename __FILE__}.#{$$}", '.rb']) do |f|
97
+ f.puts(hook)
98
+ f.puts(File.read(path))
99
+ f.flush
100
+
101
+ cmd = ([:ruby, f.path] + args).join(' ')
102
+ Open3.capture2e(cmd)
103
+ end
104
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -112,6 +112,7 @@ files:
112
112
  - Rakefile
113
113
  - bin/ridgepole
114
114
  - lib/ridgepole.rb
115
+ - lib/ridgepole/cli/config.rb
115
116
  - lib/ridgepole/client.rb
116
117
  - lib/ridgepole/delta.rb
117
118
  - lib/ridgepole/diff.rb
@@ -124,6 +125,8 @@ files:
124
125
  - lib/ridgepole/version.rb
125
126
  - ridgepole.gemspec
126
127
  - spec/0_diff/dump_disable_unsigned_spec.rb
128
+ - spec/cli/config_spec.rb
129
+ - spec/cli/ridgepole_spec.rb
127
130
  - spec/diff/diff_spec.rb
128
131
  - spec/dump/dump_class_method_spec.rb
129
132
  - spec/dump/dump_some_tables_spec.rb
@@ -187,12 +190,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
190
  version: '0'
188
191
  requirements: []
189
192
  rubyforge_project:
190
- rubygems_version: 2.0.14
193
+ rubygems_version: 2.4.1
191
194
  signing_key:
192
195
  specification_version: 4
193
196
  summary: Ridgepole is a tool to manage DB schema.
194
197
  test_files:
195
198
  - spec/0_diff/dump_disable_unsigned_spec.rb
199
+ - spec/cli/config_spec.rb
200
+ - spec/cli/ridgepole_spec.rb
196
201
  - spec/diff/diff_spec.rb
197
202
  - spec/dump/dump_class_method_spec.rb
198
203
  - spec/dump/dump_some_tables_spec.rb