guard-migrate 1.2.0 → 1.2.1
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/lib/guard/migrate.rb +24 -27
- data/lib/guard/migrate/migration.rb +3 -5
- data/lib/guard/migrate/notify.rb +7 -7
- data/lib/guard/migrate/templates/Guardfile +0 -1
- data/lib/guard/migrate/version.rb +1 -1
- data/spec/guard/migrate/template_spec.rb +8 -44
- data/spec/guard/migrate_spec.rb +280 -143
- data/spec/spec_helper.rb +20 -12
- data/spec/support/migration_factory.rb +25 -27
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94e39e4669548c3a7a65480b567526254cf3dc56
|
4
|
+
data.tar.gz: 0d7f4d9854caed22c1ca0537ef79bed0ed37a026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe3e66b477a708630eb2c3e81f595fd0cbac696353c3dfdd6b657e03da28fa17f4b3a51841cee648d128d1b5a16cf5a1d17a97672d1b13d31f7353e1cf10ba4
|
7
|
+
data.tar.gz: b018ae5ef203ed064ca69d1a12b350e1918430c2b68f9a6efb5c94e768f8d9839427cfbaddd10714cb3d39ac5765fe05f867474533d9616374dfe98cb9a32fc4
|
data/lib/guard/migrate.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'guard/plugin'
|
1
|
+
require 'guard/compat/plugin'
|
2
2
|
|
3
3
|
module Guard
|
4
4
|
class Migrate < Plugin
|
@@ -6,7 +6,7 @@ module Guard
|
|
6
6
|
autoload :Migration, 'guard/migrate/migration'
|
7
7
|
attr_reader :seed, :rails_env
|
8
8
|
|
9
|
-
def initialize(options={})
|
9
|
+
def initialize(options = {})
|
10
10
|
super
|
11
11
|
|
12
12
|
@bundler = true unless options[:bundler] == false
|
@@ -70,10 +70,10 @@ module Guard
|
|
70
70
|
|
71
71
|
# Called on file(s) modifications
|
72
72
|
def run_on_changes(paths)
|
73
|
-
if paths.any?{|path| path.match(%r{^db/migrate/(\d+).+\.rb})} || reset?
|
74
|
-
migrations = paths.map {|path| Migration.new(path)}
|
73
|
+
if paths.any? { |path| path.match(%r{^db/migrate/(\d+).+\.rb}) } || reset?
|
74
|
+
migrations = paths.map { |path| Migration.new(path) }
|
75
75
|
migrate(migrations)
|
76
|
-
elsif paths.any?{|path| path.match(%r{^db/seeds\.rb$})}
|
76
|
+
elsif paths.any? { |path| path.match(%r{^db/seeds\.rb$}) }
|
77
77
|
seed_only
|
78
78
|
end
|
79
79
|
end
|
@@ -81,9 +81,9 @@ module Guard
|
|
81
81
|
def migrate(migrations = [])
|
82
82
|
return if !reset? && migrations.empty?
|
83
83
|
if reset?
|
84
|
-
UI.info "Running #{rake_string}"
|
84
|
+
Compat::UI.info "Running #{rake_string}"
|
85
85
|
result = system(rake_string)
|
86
|
-
result &&=
|
86
|
+
result &&= 'reset'
|
87
87
|
else
|
88
88
|
result = run_all_migrations(migrations)
|
89
89
|
end
|
@@ -92,9 +92,9 @@ module Guard
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def seed_only
|
95
|
-
UI.info "Running #{seed_only_string}"
|
95
|
+
Compat::UI.info "Running #{seed_only_string}"
|
96
96
|
result = system(seed_only_string)
|
97
|
-
result &&=
|
97
|
+
result &&= 'seed'
|
98
98
|
Notify.new(result).notify
|
99
99
|
end
|
100
100
|
|
@@ -111,7 +111,7 @@ module Guard
|
|
111
111
|
seed_string,
|
112
112
|
clone_string,
|
113
113
|
rails_env_string
|
114
|
-
].compact.join(
|
114
|
+
].compact.join(' ')
|
115
115
|
end
|
116
116
|
|
117
117
|
def seed_only_string
|
@@ -122,7 +122,7 @@ module Guard
|
|
122
122
|
seed_string,
|
123
123
|
clone_string,
|
124
124
|
rails_env_string
|
125
|
-
].compact.join(
|
125
|
+
].compact.join(' ')
|
126
126
|
end
|
127
127
|
|
128
128
|
private
|
@@ -131,11 +131,11 @@ module Guard
|
|
131
131
|
result = nil
|
132
132
|
migrations.each do |migration|
|
133
133
|
if migration.valid?
|
134
|
-
UI.info "Running #{rake_string(migration.version)}"
|
134
|
+
Compat::UI.info "Running #{rake_string(migration.version)}"
|
135
135
|
result = system rake_string(migration.version)
|
136
136
|
break unless result
|
137
137
|
else
|
138
|
-
UI.info "Skip empty migration - #{migration.version}"
|
138
|
+
Compat::UI.info "Skip empty migration - #{migration.version}"
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -143,11 +143,11 @@ module Guard
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def rake_command
|
146
|
-
|
146
|
+
'rake' unless custom_command.to_s.match(/rake/)
|
147
147
|
end
|
148
148
|
|
149
149
|
def bundler_command
|
150
|
-
|
150
|
+
'bundle exec' if bundler?
|
151
151
|
end
|
152
152
|
|
153
153
|
def custom_command
|
@@ -159,24 +159,21 @@ module Guard
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def clone_string
|
162
|
-
if test_clone?
|
163
|
-
|
164
|
-
end
|
162
|
+
return if !test_clone? || custom_command.to_s.match(/db:test:clone/)
|
163
|
+
'db:test:clone'
|
165
164
|
end
|
166
165
|
|
167
166
|
def seed_string
|
168
|
-
|
167
|
+
'db:seed' if @seed
|
169
168
|
end
|
170
169
|
|
171
170
|
def migrate_string(version)
|
172
|
-
if
|
173
|
-
string = "db:migrate"
|
174
|
-
string += ":reset" if reset?
|
175
|
-
string += ":redo VERSION=#{version}" if run_redo?(version)
|
176
|
-
string
|
177
|
-
end
|
178
|
-
end
|
171
|
+
return if custom_command.to_s.match(/db:migrate/)
|
179
172
|
|
173
|
+
string = 'db:migrate'
|
174
|
+
string += ':reset' if reset?
|
175
|
+
string += ":redo VERSION=#{version}" if run_redo?(version)
|
176
|
+
string
|
177
|
+
end
|
180
178
|
end
|
181
179
|
end
|
182
|
-
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Guard
|
2
2
|
class Migrate
|
3
3
|
class Migration
|
4
|
-
|
5
4
|
attr_accessor :path
|
6
5
|
|
7
6
|
def initialize(_path)
|
@@ -19,9 +18,8 @@ module Guard
|
|
19
18
|
rescue Errno::ENOENT
|
20
19
|
false
|
21
20
|
ensure
|
22
|
-
begin; file.close; rescue; end
|
23
|
-
end
|
24
|
-
|
21
|
+
begin; file.close; rescue; end
|
22
|
+
end
|
25
23
|
end
|
26
24
|
end
|
27
|
-
end
|
25
|
+
end
|
data/lib/guard/migrate/notify.rb
CHANGED
@@ -6,10 +6,10 @@ module Guard
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def notify
|
9
|
-
|
9
|
+
Guard::Compat::UI.notify(
|
10
10
|
message,
|
11
|
-
:
|
12
|
-
:
|
11
|
+
title: 'Database Migrations',
|
12
|
+
image: image
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -17,10 +17,10 @@ module Guard
|
|
17
17
|
|
18
18
|
def message
|
19
19
|
case @result
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
when 'reset' then 'The database has been reset'
|
21
|
+
when 'seed' then 'The database has been seeded'
|
22
|
+
when true then 'Migrations have been applied successfully'
|
23
|
+
else 'There was an error running migrations'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -1,50 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require 'guard/guardfile'
|
3
|
-
require 'files'
|
1
|
+
require 'guard/compat/test/template'
|
4
2
|
|
5
|
-
|
6
|
-
GUARDFILE_TEMPLATE = "#{File.dirname(__FILE__)}/../../../Guardfile"
|
7
|
-
GUARD_MIGRATE_GUARDFILE_TEMPLATE =
|
8
|
-
"#{File.dirname(__FILE__)}/../../../lib/guard/migrate/templates/Guardfile"
|
3
|
+
require 'guard/migrate'
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
working = dir 'working'
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'templates' do
|
17
|
-
|
18
|
-
before(:each) do
|
19
|
-
FileUtils.cd(working)
|
20
|
-
end
|
5
|
+
RSpec.describe Guard::Migrate do
|
6
|
+
describe 'template' do
|
7
|
+
subject { Guard::Compat::Test::Template.new(described_class) }
|
21
8
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it 'is a sample Guardfile' do
|
27
|
-
expect { Guard::Guardfile.create_guardfile }.to_not raise_error
|
28
|
-
guardfile_contents = IO.read('Guardfile')
|
29
|
-
guardfile_contents.should include('sample Guardfile')
|
30
|
-
guardfile_contents.should_not include('db/migrate')
|
9
|
+
it 'works' do
|
10
|
+
expect(subject.changed('db/seeds.rb')).to eq(%w(db/seeds.rb))
|
11
|
+
expect(subject.changed('db/migrate/12345_add_some_field.rb')).to eq(%w(db/migrate/12345_add_some_field.rb))
|
31
12
|
end
|
32
|
-
|
33
13
|
end
|
34
|
-
|
35
|
-
describe 'Guard::Migrate guardfile template' do
|
36
|
-
|
37
|
-
specify { File.exists?(GUARD_MIGRATE_GUARDFILE_TEMPLATE).should be_true }
|
38
|
-
|
39
|
-
it 'successfully initializes a Guard::Migrate guard' do
|
40
|
-
expect { Guard::Guardfile.initialize_template('migrate') }.to_not raise_error
|
41
|
-
guardfile_contents = IO.read('Guardfile')
|
42
|
-
guardfile_contents.should include('sample Guardfile')
|
43
|
-
guardfile_contents.should include('db/migrate')
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
14
|
end
|
49
|
-
|
50
|
-
FileUtils.cd(@current_dir)
|
data/spec/guard/migrate_spec.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'tempfile'
|
3
2
|
|
4
|
-
|
5
|
-
let(:options){ {watchers: paths}}
|
6
|
-
let(:paths){{}}
|
3
|
+
require 'guard/compat/test/helper'
|
7
4
|
|
8
|
-
|
5
|
+
require 'guard/migrate'
|
6
|
+
|
7
|
+
RSpec.describe Guard::Migrate do
|
8
|
+
let(:options) { { watchers: paths } }
|
9
|
+
let(:paths) { {} }
|
10
|
+
|
11
|
+
subject { Guard::Migrate.new(options) }
|
9
12
|
|
10
13
|
before(:all) do
|
11
14
|
FileUtils.mkdir_p('db/migrate')
|
@@ -15,70 +18,107 @@ describe Guard::Migrate do
|
|
15
18
|
FileUtils.rm_rf('db')
|
16
19
|
end
|
17
20
|
|
18
|
-
describe
|
19
|
-
context
|
20
|
-
context
|
21
|
-
before{File.
|
22
|
-
its(:bundler?){should be_true}
|
23
|
-
its(:rake_string){should match(/^bundle exec rake/)}
|
21
|
+
describe 'options' do
|
22
|
+
context 'bundler' do
|
23
|
+
context 'with a gemfile found' do
|
24
|
+
before { allow(File).to receive(:exist?).and_return(true) }
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
describe '#bundler?' do
|
27
|
+
subject { super().bundler? }
|
28
|
+
it { is_expected.to be_truthy }
|
29
|
+
end
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
describe '#rake_string' do
|
32
|
+
subject { super().rake_string }
|
33
|
+
it { is_expected.to match(/^bundle exec rake/) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with bunder set to false' do
|
37
|
+
let(:options) { { bundler: false } }
|
38
|
+
|
39
|
+
describe '#bundler?' do
|
40
|
+
subject { super().bundler? }
|
41
|
+
it { is_expected.to be_falsey }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#rake_string' do
|
45
|
+
subject { super().rake_string }
|
46
|
+
it { is_expected.to match(/^rake/) }
|
47
|
+
end
|
30
48
|
end
|
31
49
|
end
|
32
|
-
context
|
33
|
-
before{File.
|
34
|
-
|
35
|
-
|
50
|
+
context 'with no gemfile found' do
|
51
|
+
before { allow(File).to receive(:exist?).and_return(false) }
|
52
|
+
|
53
|
+
describe '#bundler?' do
|
54
|
+
subject { super().bundler? }
|
55
|
+
it { is_expected.not_to be_truthy }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#rake_string' do
|
59
|
+
subject { super().rake_string }
|
60
|
+
it { is_expected.to match(/^rake/) }
|
61
|
+
end
|
36
62
|
end
|
37
63
|
end
|
38
64
|
|
39
|
-
context
|
40
|
-
context
|
41
|
-
|
65
|
+
context 'cmd' do
|
66
|
+
context 'without command customization' do
|
67
|
+
describe '#cmd?' do
|
68
|
+
subject { super().cmd? }
|
69
|
+
it { is_expected.not_to be_truthy }
|
70
|
+
end
|
42
71
|
end
|
43
72
|
|
44
|
-
context
|
45
|
-
before{File.
|
46
|
-
let(:options){ { :
|
73
|
+
context 'with command customization' do
|
74
|
+
before { allow(File).to receive(:exist?).and_return(false) }
|
75
|
+
let(:options) { { cmd: 'custom command rake' } }
|
76
|
+
|
77
|
+
describe '#cmd?' do
|
78
|
+
subject { super().cmd? }
|
79
|
+
it { is_expected.to be_truthy }
|
80
|
+
end
|
47
81
|
|
48
|
-
|
49
|
-
|
82
|
+
describe '#rake_string' do
|
83
|
+
subject { super().rake_string }
|
84
|
+
it { is_expected.to match(/^custom command rake/) }
|
85
|
+
end
|
50
86
|
|
51
87
|
context "without presence of 'rake' keyword" do
|
52
|
-
let(:options){ { :
|
88
|
+
let(:options) { { cmd: 'custom command' } }
|
53
89
|
|
54
|
-
it
|
90
|
+
it 'should raise and error' do
|
55
91
|
pending
|
92
|
+
fail 'pending'
|
56
93
|
end
|
57
94
|
end
|
58
95
|
|
59
|
-
context
|
60
|
-
before{File.
|
96
|
+
context 'with Bundler' do
|
97
|
+
before { allow(File).to receive(:exist?).and_return(true) }
|
61
98
|
|
62
|
-
|
99
|
+
describe '#rake_string' do
|
100
|
+
subject { super().rake_string }
|
101
|
+
it { is_expected.to match(/^bundle exec custom command rake/) }
|
102
|
+
end
|
63
103
|
end
|
64
104
|
|
65
|
-
context
|
66
|
-
context
|
67
|
-
let(:options){ { :
|
105
|
+
context 'with custom rake task specified' do
|
106
|
+
context 'with duplication of db:migrate' do
|
107
|
+
let(:options) { { cmd: 'custom command rake db:migrate' } }
|
68
108
|
|
69
|
-
context
|
109
|
+
context 'rake_string' do
|
70
110
|
it "should contains 'db:migrate' once" do
|
71
|
-
subject.rake_string.scan(
|
111
|
+
expect(subject.rake_string.scan('db:migrate').size).to eq(1)
|
72
112
|
end
|
73
113
|
end
|
74
114
|
end
|
75
115
|
|
76
|
-
context
|
77
|
-
let(:options){ { :
|
116
|
+
context 'with duplication of db:test:clone' do
|
117
|
+
let(:options) { { cmd: 'custom command rake db:test:clone' } }
|
78
118
|
|
79
|
-
context
|
119
|
+
context 'rake_string' do
|
80
120
|
it "should contains 'db:test:clone' once" do
|
81
|
-
subject.rake_string.scan(
|
121
|
+
expect(subject.rake_string.scan('db:test:clone').size).to eq(1)
|
82
122
|
end
|
83
123
|
end
|
84
124
|
end
|
@@ -86,202 +126,299 @@ describe Guard::Migrate do
|
|
86
126
|
end
|
87
127
|
end
|
88
128
|
|
89
|
-
context
|
90
|
-
context
|
91
|
-
|
92
|
-
|
93
|
-
|
129
|
+
context 'test clone' do
|
130
|
+
context 'with no options passed' do
|
131
|
+
describe '#test_clone?' do
|
132
|
+
subject { super().test_clone? }
|
133
|
+
it { is_expected.to be_falsey }
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#rake_string' do
|
137
|
+
subject { super().rake_string }
|
138
|
+
it { is_expected.to match(/rake db:migrate/) }
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#rake_string' do
|
142
|
+
subject { super().rake_string }
|
143
|
+
it { is_expected.not_to match(/db:test:clone/) }
|
144
|
+
end
|
94
145
|
end
|
95
146
|
|
96
|
-
context
|
97
|
-
let(:options){ {:
|
98
|
-
|
99
|
-
|
100
|
-
|
147
|
+
context 'when passed false' do
|
148
|
+
let(:options) { { test_clone: false } }
|
149
|
+
|
150
|
+
describe '#test_clone?' do
|
151
|
+
subject { super().test_clone? }
|
152
|
+
it { is_expected.to be_falsey }
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#rake_string' do
|
156
|
+
subject { super().rake_string }
|
157
|
+
it { is_expected.to match(/rake db:migrate/) }
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#rake_string' do
|
161
|
+
subject { super().rake_string }
|
162
|
+
it { is_expected.not_to match(/db:test:clone/) }
|
163
|
+
end
|
101
164
|
end
|
102
165
|
|
103
|
-
context
|
104
|
-
let(:options){ {:
|
105
|
-
|
106
|
-
|
107
|
-
|
166
|
+
context 'when passed true' do
|
167
|
+
let(:options) { { test_clone: true } }
|
168
|
+
|
169
|
+
describe '#test_clone?' do
|
170
|
+
subject { super().test_clone? }
|
171
|
+
it { is_expected.to be_truthy }
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#rake_string' do
|
175
|
+
subject { super().rake_string }
|
176
|
+
it { is_expected.to match(/rake db:migrate/) }
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#rake_string' do
|
180
|
+
subject { super().rake_string }
|
181
|
+
it { is_expected.to match(/db:test:clone/) }
|
182
|
+
end
|
108
183
|
end
|
109
184
|
end
|
110
185
|
|
111
|
-
context
|
112
|
-
context
|
113
|
-
|
186
|
+
context 'reset' do
|
187
|
+
context 'with no options passed' do
|
188
|
+
describe '#reset?' do
|
189
|
+
subject { super().reset? }
|
190
|
+
it { is_expected.not_to be_truthy }
|
191
|
+
end
|
114
192
|
|
115
|
-
context
|
116
|
-
let(:paths){ ['1234'] }
|
117
|
-
it
|
118
|
-
subject.rake_string(paths.first).
|
193
|
+
context 'with paths' do
|
194
|
+
let(:paths) { ['1234'] }
|
195
|
+
it 'rake string should attempt redo of changed migration' do
|
196
|
+
expect(subject.rake_string(paths.first)).to match(/rake db:migrate:redo VERSION\=1234/)
|
119
197
|
end
|
120
198
|
end
|
121
199
|
end
|
122
200
|
|
123
|
-
context
|
124
|
-
let(:options){ {:
|
125
|
-
|
126
|
-
|
201
|
+
context 'when passed true' do
|
202
|
+
let(:options) { { reset: true } }
|
203
|
+
|
204
|
+
describe '#reset?' do
|
205
|
+
subject { super().reset? }
|
206
|
+
it { is_expected.to be_truthy }
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#rake_string' do
|
210
|
+
subject { super().rake_string }
|
211
|
+
it { is_expected.to match(/rake db:migrate:reset/) }
|
212
|
+
end
|
127
213
|
end
|
128
214
|
end
|
129
215
|
|
130
|
-
context
|
131
|
-
context
|
132
|
-
|
216
|
+
context 'run on start' do
|
217
|
+
context 'with no options set' do
|
218
|
+
describe '#run_on_start?' do
|
219
|
+
subject { super().run_on_start? }
|
220
|
+
it { is_expected.not_to be_truthy }
|
221
|
+
end
|
133
222
|
|
134
|
-
it
|
135
|
-
subject.
|
223
|
+
it 'should not run on start' do
|
224
|
+
expect(subject).to receive(:migrate).never
|
136
225
|
subject.start
|
137
226
|
end
|
138
227
|
|
139
|
-
it
|
140
|
-
subject.
|
228
|
+
it 'should not run migrate on the reload command' do
|
229
|
+
expect(subject).to receive(:migrate).never
|
141
230
|
subject.reload
|
142
231
|
end
|
143
232
|
|
144
|
-
it
|
145
|
-
subject.
|
233
|
+
it 'should not run migrate on the run all command' do
|
234
|
+
expect(subject).to receive(:migrate).never
|
146
235
|
subject.run_all
|
147
236
|
end
|
148
237
|
end
|
149
238
|
|
150
|
-
context
|
151
|
-
let(:options){ {:
|
152
|
-
its(:run_on_start?){should be_true}
|
239
|
+
context 'when passed true' do
|
240
|
+
let(:options) { { run_on_start: true } }
|
153
241
|
|
154
|
-
|
155
|
-
subject
|
242
|
+
describe '#run_on_start?' do
|
243
|
+
subject { super().run_on_start? }
|
244
|
+
it { is_expected.to be_truthy }
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should run migrate on the start' do
|
248
|
+
expect(subject).to receive(:migrate)
|
156
249
|
subject.start
|
157
250
|
end
|
158
251
|
|
159
|
-
it
|
160
|
-
subject.
|
252
|
+
it 'should run migrate on the reload command' do
|
253
|
+
expect(subject).to receive(:migrate)
|
161
254
|
subject.reload
|
162
255
|
end
|
163
256
|
|
164
|
-
it
|
165
|
-
subject.
|
257
|
+
it 'should run migrate on the run all command' do
|
258
|
+
expect(subject).to receive(:migrate)
|
166
259
|
subject.run_all
|
167
260
|
end
|
168
261
|
|
169
|
-
context
|
170
|
-
let(:options){ {:
|
171
|
-
it
|
172
|
-
subject.rake_string.
|
262
|
+
context 'with reset set to true' do
|
263
|
+
let(:options) { { run_on_start: true, reset: true } }
|
264
|
+
it 'should run a migrate reset on start' do
|
265
|
+
expect(subject.rake_string).to match(/db:migrate:reset/)
|
173
266
|
end
|
174
267
|
end
|
175
268
|
|
176
|
-
context
|
177
|
-
let(:options){ {:
|
178
|
-
it
|
179
|
-
subject.rake_string.
|
180
|
-
subject.rake_string.
|
181
|
-
subject.rake_string.
|
269
|
+
context 'with reset set to false' do
|
270
|
+
let(:options) { { run_on_start: true, reset: false } }
|
271
|
+
it 'should run a regular migrate on start' do
|
272
|
+
expect(subject.rake_string).to match(/db:migrate/)
|
273
|
+
expect(subject.rake_string).not_to match(/db:migrate:reset/)
|
274
|
+
expect(subject.rake_string).not_to match(/db:migrate:redo/)
|
182
275
|
end
|
183
276
|
end
|
184
277
|
end
|
185
278
|
end
|
186
279
|
|
187
280
|
context 'Rails Environment' do
|
188
|
-
context
|
189
|
-
|
281
|
+
context 'when no option is passed' do
|
282
|
+
describe '#rails_env' do
|
283
|
+
subject { super().rails_env }
|
284
|
+
it { is_expected.to be_nil }
|
285
|
+
end
|
190
286
|
end
|
191
287
|
|
192
|
-
context
|
193
|
-
let(:options){ {:
|
194
|
-
its(:rails_env){ should == 'development'}
|
288
|
+
context 'when a rails environment is passed' do
|
289
|
+
let(:options) { { rails_env: 'development' } }
|
195
290
|
|
196
|
-
|
291
|
+
describe '#rails_env' do
|
292
|
+
subject { super().rails_env }
|
293
|
+
it { is_expected.to eq('development') }
|
294
|
+
end
|
295
|
+
|
296
|
+
describe '#rake_string' do
|
297
|
+
subject { super().rake_string }
|
298
|
+
it { is_expected.to match(/RAILS_ENV=development/) }
|
299
|
+
end
|
197
300
|
end
|
198
301
|
end
|
199
302
|
|
200
|
-
context
|
201
|
-
context
|
202
|
-
|
303
|
+
context 'Seed the database' do
|
304
|
+
context 'when no option is passed' do
|
305
|
+
describe '#seed' do
|
306
|
+
subject { super().seed }
|
307
|
+
it { is_expected.to be_nil }
|
308
|
+
end
|
203
309
|
end
|
204
310
|
|
205
|
-
context
|
206
|
-
let(:options){ {:
|
207
|
-
|
208
|
-
|
311
|
+
context 'when set to true' do
|
312
|
+
let(:options) { { seed: true } }
|
313
|
+
|
314
|
+
describe '#seed' do
|
315
|
+
subject { super().seed }
|
316
|
+
it { is_expected.to be_truthy }
|
317
|
+
end
|
318
|
+
|
319
|
+
describe '#rake_string' do
|
320
|
+
subject { super().rake_string }
|
321
|
+
it { is_expected.to match(/db:seed/) }
|
322
|
+
end
|
209
323
|
end
|
210
324
|
|
211
|
-
context
|
212
|
-
let(:options){ {:
|
213
|
-
it
|
214
|
-
subject.rake_string.
|
325
|
+
context 'when seed is set to true and clone is set to true' do
|
326
|
+
let(:options) { { seed: true, test_clone: true } }
|
327
|
+
it 'runs the seed option before the clone option' do
|
328
|
+
expect(subject.rake_string).to match(/db:seed.*db:test:clone/)
|
215
329
|
end
|
216
330
|
end
|
217
331
|
end
|
218
332
|
|
219
|
-
context
|
220
|
-
let(:paths){ ['db/seeds.rb'] }
|
221
|
-
let(:options){ {:
|
222
|
-
its(:seed_only_string){ should match(/db:seed db:test:clone/) }
|
333
|
+
context 'when the seeds file is passed as the paths' do
|
334
|
+
let(:paths) { ['db/seeds.rb'] }
|
335
|
+
let(:options) { { seed: true, test_clone: true } }
|
223
336
|
|
224
|
-
|
225
|
-
subject
|
337
|
+
describe '#seed_only_string' do
|
338
|
+
subject { super().seed_only_string }
|
339
|
+
it { is_expected.to match(/db:seed db:test:clone/) }
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'runs the rake command with seed only' do
|
343
|
+
allow(Guard::Compat::UI).to receive(:info)
|
344
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
345
|
+
expect(subject).to receive(:system).with(subject.seed_only_string)
|
226
346
|
subject.run_on_changes paths
|
227
347
|
end
|
228
348
|
|
229
|
-
context
|
230
|
-
let(:options){ {:
|
349
|
+
context 'When reset is set to true' do
|
350
|
+
let(:options) { { seed: true, reset: true } }
|
351
|
+
|
352
|
+
describe '#rake_string' do
|
353
|
+
subject { super().rake_string }
|
354
|
+
it { is_expected.to match(/db:seed/) }
|
355
|
+
end
|
231
356
|
|
232
|
-
|
233
|
-
|
357
|
+
describe '#rake_string' do
|
358
|
+
subject { super().rake_string }
|
359
|
+
it { is_expected.to match(/db:migrate:reset/) }
|
360
|
+
end
|
234
361
|
end
|
235
362
|
end
|
236
363
|
end
|
237
364
|
|
238
|
-
context
|
239
|
-
|
240
|
-
let(:paths){ [create_valid_up_and_down_migration('1234_i_like_cheese').path] }
|
241
|
-
it
|
242
|
-
|
365
|
+
context 'run on change should fixup the path to only the version' do
|
366
|
+
# #I don't like this test much - consider refactoring
|
367
|
+
let(:paths) { [create_valid_up_and_down_migration('1234_i_like_cheese').path] }
|
368
|
+
it 'should run the rake command' do
|
369
|
+
allow(Guard::Compat::UI).to receive(:info)
|
370
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
371
|
+
expect(subject).to receive(:system).with(subject.rake_string('1234'))
|
243
372
|
subject.run_on_changes paths
|
244
373
|
end
|
245
374
|
end
|
246
375
|
|
247
|
-
context
|
248
|
-
let(:paths){ [create_valid_up_and_down_migration('1234_i_like_cheese').path, create_valid_change_migration('1235_i_like_cheese').path] }
|
249
|
-
let(:options){ {:
|
250
|
-
it
|
251
|
-
subject.
|
376
|
+
context 'run on change when set to reset should only run migrations one time' do
|
377
|
+
let(:paths) { [create_valid_up_and_down_migration('1234_i_like_cheese').path, create_valid_change_migration('1235_i_like_cheese').path] }
|
378
|
+
let(:options) { { reset: true, test_clone: true } }
|
379
|
+
it 'should run the rake command' do
|
380
|
+
expect(subject).to receive(:system).with(subject.rake_string('1234'))
|
381
|
+
allow(Guard::Compat::UI).to receive(:info)
|
382
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
252
383
|
subject.run_on_changes paths
|
253
384
|
end
|
254
385
|
end
|
255
386
|
|
256
|
-
context
|
257
|
-
|
258
|
-
it "should keep valid up/down migrations" do
|
387
|
+
context 'valid/invalid migrations' do
|
388
|
+
it 'should keep valid up/down migrations' do
|
259
389
|
migration = create_valid_up_and_down_migration('1234_i_like_cheese')
|
260
390
|
|
261
|
-
|
391
|
+
allow(Guard::Compat::UI).to receive(:info)
|
392
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
393
|
+
expect(subject).to receive(:system).with(subject.rake_string('1234'))
|
262
394
|
subject.run_on_changes [migration.path]
|
263
395
|
end
|
264
396
|
|
265
|
-
it
|
397
|
+
it 'should keep valid change migrations' do
|
266
398
|
migration = create_valid_change_migration('1234_i_like_cheese')
|
267
399
|
|
268
|
-
|
400
|
+
allow(Guard::Compat::UI).to receive(:info)
|
401
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
402
|
+
expect(subject).to receive(:system).with(subject.rake_string('1234'))
|
269
403
|
subject.run_on_changes [migration.path]
|
270
404
|
end
|
271
405
|
|
272
|
-
it
|
406
|
+
it 'should remove empty up/down migrations' do
|
273
407
|
migration = create_invalid_up_and_down_migration('1234_i_like_cheese')
|
274
408
|
|
275
|
-
|
409
|
+
allow(Guard::Compat::UI).to receive(:info)
|
410
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
411
|
+
expect(subject).not_to receive(:system).with(subject.rake_string('1234'))
|
276
412
|
subject.run_on_changes [migration.path]
|
277
413
|
end
|
278
414
|
|
279
|
-
it
|
415
|
+
it 'should remove empty change migrations' do
|
280
416
|
migration = create_invalid_change_migration('1234_i_like_cheese')
|
281
417
|
|
282
|
-
|
418
|
+
allow(Guard::Compat::UI).to receive(:info)
|
419
|
+
allow(Guard::Compat::UI).to receive(:notify)
|
420
|
+
expect(subject).not_to receive(:system).with(subject.rake_string('1234'))
|
283
421
|
subject.run_on_changes [migration.path]
|
284
422
|
end
|
285
423
|
end
|
286
|
-
|
287
424
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,25 +7,33 @@ if RUBY_VERSION.to_f == 1.9
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
require 'rspec'
|
11
|
-
require 'guard/migrate'
|
12
|
-
|
13
10
|
# Requires supporting files with custom matchers and macros, etc,
|
14
11
|
# in ./support/ and its subdirectories.
|
15
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
16
13
|
|
17
14
|
RSpec.configure do |config|
|
18
|
-
config.
|
19
|
-
|
20
|
-
config.run_all_when_everything_filtered = true
|
21
|
-
|
22
|
-
config.before(:each) do
|
23
|
-
ENV["GUARD_ENV"] = 'test'
|
15
|
+
config.expect_with :rspec do |expectations|
|
16
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
24
17
|
end
|
25
18
|
|
26
|
-
config.
|
27
|
-
|
19
|
+
config.mock_with :rspec do |mocks|
|
20
|
+
mocks.verify_partial_doubles = true
|
28
21
|
end
|
29
22
|
|
23
|
+
config.filter_run focus: (ENV['CI'] != 'true')
|
24
|
+
config.run_all_when_everything_filtered = true
|
25
|
+
|
26
|
+
config.disable_monkey_patching!
|
27
|
+
|
28
|
+
# config.warnings = true
|
29
|
+
|
30
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
31
|
+
|
32
|
+
# config.profile_examples = 10
|
33
|
+
|
34
|
+
config.order = :random
|
35
|
+
|
36
|
+
Kernel.srand config.seed
|
37
|
+
|
30
38
|
config.include MigrationFactory
|
31
39
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module MigrationFactory
|
2
|
-
|
3
2
|
def create_valid_up_and_down_migration(name)
|
4
3
|
create_migration(name, valid_up_and_down_migration)
|
5
4
|
end
|
6
5
|
|
7
6
|
def create_valid_change_migration(name)
|
8
7
|
create_migration(name, valid_change_migration)
|
9
|
-
end
|
8
|
+
end
|
10
9
|
|
11
10
|
def create_invalid_up_and_down_migration(name)
|
12
11
|
create_migration(name, invalid_up_and_down_migration)
|
@@ -14,19 +13,19 @@ module MigrationFactory
|
|
14
13
|
|
15
14
|
def create_invalid_change_migration(name)
|
16
15
|
create_migration(name, invalid_change_migration)
|
17
|
-
end
|
16
|
+
end
|
18
17
|
|
19
18
|
private
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def create_migration(name, content)
|
21
|
+
migration = File.new("db/migrate/#{name}.rb", 'w')
|
22
|
+
migration.write(content)
|
23
|
+
migration.close
|
24
|
+
migration
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
def valid_up_and_down_migration
|
28
|
+
<<-EOS
|
30
29
|
class ILikeCheese < ActiveRecord::Migration
|
31
30
|
def up
|
32
31
|
add_column :my_table, :my_column, :string
|
@@ -36,23 +35,23 @@ module MigrationFactory
|
|
36
35
|
remove_column :my_table, :my_column
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
EOS
|
41
|
-
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
42
|
+
def valid_change_migration
|
43
|
+
<<-EOS
|
45
44
|
class ILikeCheese < ActiveRecord::Migration
|
46
45
|
def change
|
47
46
|
add_column :my_table, :my_column, :string
|
48
47
|
end
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
EOS
|
52
|
-
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
def invalid_up_and_down_migration
|
54
|
+
<<-EOS
|
56
55
|
class ILikeCheese < ActiveRecord::Migration
|
57
56
|
def up
|
58
57
|
end
|
@@ -60,18 +59,17 @@ module MigrationFactory
|
|
60
59
|
def down
|
61
60
|
end
|
62
61
|
end
|
63
|
-
|
62
|
+
|
64
63
|
EOS
|
65
|
-
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
66
|
+
def invalid_change_migration
|
67
|
+
<<-EOS
|
69
68
|
class ILikeCheese < ActiveRecord::Migration
|
70
69
|
def change
|
71
70
|
end
|
72
71
|
end
|
73
|
-
|
74
|
-
EOS
|
75
|
-
end
|
76
72
|
|
77
|
-
|
73
|
+
EOS
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Lanotte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.3
|
19
|
+
version: '2.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-compat
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
40
|
+
version: '1.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: activerecord
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|