migration_bundler 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +122 -0
- data/Guardfile +8 -0
- data/LICENSE +202 -0
- data/README.md +219 -0
- data/Rakefile +16 -0
- data/bin/mb +6 -0
- data/lib/migration_bundler/actions.rb +38 -0
- data/lib/migration_bundler/cli.rb +355 -0
- data/lib/migration_bundler/databases/abstract_database.rb +54 -0
- data/lib/migration_bundler/databases/cassandra_database.rb +88 -0
- data/lib/migration_bundler/databases/sqlite_database.rb +116 -0
- data/lib/migration_bundler/migrations.rb +52 -0
- data/lib/migration_bundler/project.rb +90 -0
- data/lib/migration_bundler/targets/base.rb +85 -0
- data/lib/migration_bundler/targets/cassandra/cassandra_target.rb +73 -0
- data/lib/migration_bundler/targets/cassandra/create_schema_migrations.cql.erb +16 -0
- data/lib/migration_bundler/targets/cassandra/migration.cql.erb +0 -0
- data/lib/migration_bundler/targets/cocoapods/cocoapods_target.rb +43 -0
- data/lib/migration_bundler/targets/cocoapods/podspec.erb +12 -0
- data/lib/migration_bundler/targets/maven/maven_target.rb +62 -0
- data/lib/migration_bundler/targets/maven/project/.gitignore +6 -0
- data/lib/migration_bundler/targets/maven/project/MonkeyButler.iml +19 -0
- data/lib/migration_bundler/targets/maven/project/build.gradle +54 -0
- data/lib/migration_bundler/targets/sqlite/create_migration_bundler_tables.sql.erb +15 -0
- data/lib/migration_bundler/targets/sqlite/migration.sql.erb +11 -0
- data/lib/migration_bundler/targets/sqlite/sqlite_target.rb +92 -0
- data/lib/migration_bundler/templates/Gemfile.erb +4 -0
- data/lib/migration_bundler/templates/gitignore.erb +1 -0
- data/lib/migration_bundler/util.rb +71 -0
- data/lib/migration_bundler/version.rb +3 -0
- data/lib/migration_bundler.rb +1 -0
- data/migration_bundler.gemspec +33 -0
- data/spec/cli_spec.rb +700 -0
- data/spec/databases/cassandra_database_spec.rb +260 -0
- data/spec/databases/sqlite_database_spec.rb +198 -0
- data/spec/migrations_spec.rb +4 -0
- data/spec/project_spec.rb +128 -0
- data/spec/sandbox/cassandra/.gitignore +2 -0
- data/spec/sandbox/cassandra/.migration_bundler.yml +9 -0
- data/spec/sandbox/cassandra/migrations/20140523123443021_create_sandbox.cql.sql +14 -0
- data/spec/sandbox/cassandra/sandbox.cql +0 -0
- data/spec/sandbox/sqlite/.gitignore +2 -0
- data/spec/sandbox/sqlite/.migration_bundler.yml +9 -0
- data/spec/sandbox/sqlite/migrations/20140523123443021_create_sandbox.sql +14 -0
- data/spec/sandbox/sqlite/sandbox.sql +0 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/targets/cassandra_target_spec.rb +191 -0
- data/spec/targets/cocoapods_target_spec.rb +197 -0
- data/spec/targets/maven_target_spec.rb +156 -0
- data/spec/targets/sqlite_target_spec.rb +103 -0
- data/spec/util_spec.rb +13 -0
- metadata +260 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'migration_bundler/databases/cassandra_database'
|
3
|
+
|
4
|
+
describe MigrationBundler::Databases::CassandraDatabase do
|
5
|
+
let(:db) { MigrationBundler::Databases::CassandraDatabase.new(cassandra_url) }
|
6
|
+
let(:cassandra_url) { URI("cassandra://localhost:9042/migration_bundler") }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
db.drop
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".migration_ext" do
|
13
|
+
MigrationBundler::Databases::CassandraDatabase.migration_ext.should == '.cql'
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#keyspace' do
|
17
|
+
it "extracts keyspace from path" do
|
18
|
+
db.keyspace.should == 'migration_bundler'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#migrations_table?" do
|
23
|
+
context "when the migrations table exists" do
|
24
|
+
before(:each) do
|
25
|
+
db.create_migrations_table
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is true" do
|
29
|
+
expect(db.migrations_table?).to be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the migrations table does not exist" do
|
34
|
+
before(:each) do
|
35
|
+
db.drop
|
36
|
+
end
|
37
|
+
|
38
|
+
it "is true" do
|
39
|
+
expect(db.migrations_table?).to be_false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#origin_version" do
|
45
|
+
context "when the schema_migrations table does not exist" do
|
46
|
+
before(:each) do
|
47
|
+
db.drop
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raises an error" do
|
51
|
+
expect { db.origin_version }.to raise_error(Cql::QueryError, "Keyspace 'migration_bundler' does not exist")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the schema_migrations table is empty" do
|
56
|
+
before(:each) do
|
57
|
+
db.create_migrations_table
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns nil" do
|
61
|
+
db.origin_version.should be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when the database has one version row" do
|
66
|
+
before(:each) do
|
67
|
+
db.create_migrations_table
|
68
|
+
db.insert_version(20140101023213)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns that row" do
|
72
|
+
db.origin_version.should == 20140101023213
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the database has three version rows" do
|
77
|
+
before(:each) do
|
78
|
+
db.create_migrations_table
|
79
|
+
db.insert_version(1)
|
80
|
+
db.insert_version(2)
|
81
|
+
db.insert_version(3)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns the lowest value" do
|
85
|
+
db.origin_version.should == 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#current_version" do
|
91
|
+
context "when the schema_migrations table does not exist" do
|
92
|
+
before(:each) do
|
93
|
+
db.drop
|
94
|
+
end
|
95
|
+
|
96
|
+
it "raises an error" do
|
97
|
+
expect { db.current_version }.to raise_error(Cql::QueryError, "Keyspace 'migration_bundler' does not exist")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when the schema_migrations table is empty" do
|
102
|
+
before(:each) do
|
103
|
+
db.create_migrations_table
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns nil" do
|
107
|
+
db.current_version.should be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when the database has one version row" do
|
112
|
+
before(:each) do
|
113
|
+
db.create_migrations_table
|
114
|
+
db.insert_version(20140101023213)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns that row" do
|
118
|
+
db.current_version.should == 20140101023213
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when the database has three version rows" do
|
123
|
+
before(:each) do
|
124
|
+
db.create_migrations_table
|
125
|
+
db.insert_version(1)
|
126
|
+
db.insert_version(2)
|
127
|
+
db.insert_version(3)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns the highest value" do
|
131
|
+
db.current_version.should == 3
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#all_versions" do
|
137
|
+
context "when the schema_migrations table does not exist" do
|
138
|
+
before(:each) do
|
139
|
+
db.drop
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises an error" do
|
143
|
+
expect { db.current_version }.to raise_error(Cql::QueryError, "Keyspace 'migration_bundler' does not exist")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when the schema_migrations table is empty" do
|
148
|
+
before(:each) do
|
149
|
+
db.create_migrations_table
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns an empty array" do
|
153
|
+
db.all_versions.should be_empty
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when the database has one version row" do
|
158
|
+
before(:each) do
|
159
|
+
db.create_migrations_table
|
160
|
+
db.insert_version(20140101023213)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "returns that row" do
|
164
|
+
db.all_versions.should == [20140101023213]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when the database has three version rows" do
|
169
|
+
before(:each) do
|
170
|
+
db.create_migrations_table
|
171
|
+
db.insert_version(1)
|
172
|
+
db.insert_version(2)
|
173
|
+
db.insert_version(3)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns the highest value" do
|
177
|
+
db.all_versions.should == [1,2,3]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#insert_version" do
|
183
|
+
context "when the schema_migrations table does not exist" do
|
184
|
+
before(:each) do
|
185
|
+
db.drop
|
186
|
+
end
|
187
|
+
|
188
|
+
it "raises an error" do
|
189
|
+
expect { db.insert_version(1234) }.to raise_error(Cql::QueryError, "Keyspace 'migration_bundler' does not exist")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "when the schema_migrations table exists" do
|
194
|
+
before(:each) do
|
195
|
+
db.create_migrations_table
|
196
|
+
end
|
197
|
+
|
198
|
+
it "inserts successfully" do
|
199
|
+
db.insert_version(1234)
|
200
|
+
db.all_versions.should == [1234]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "#execute_migration" do
|
206
|
+
context "when the schema_migrations table does not exist" do
|
207
|
+
before(:each) do
|
208
|
+
db.drop
|
209
|
+
end
|
210
|
+
|
211
|
+
it "raises an error" do
|
212
|
+
expect { db.insert_version(1234) }.to raise_error(Cql::QueryError, "Keyspace 'migration_bundler' does not exist")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "when the schema_migrations table exists" do
|
217
|
+
before(:each) do
|
218
|
+
db.create_migrations_table
|
219
|
+
end
|
220
|
+
|
221
|
+
it "inserts successfully" do
|
222
|
+
db.insert_version(1234)
|
223
|
+
db.all_versions.should == [1234]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "#truncate" do
|
229
|
+
context "when the keyspace has tables" do
|
230
|
+
before(:each) do
|
231
|
+
db.create_migrations_table
|
232
|
+
end
|
233
|
+
|
234
|
+
it "destroys the tables" do
|
235
|
+
expect(db.migrations_table?).to be_true
|
236
|
+
db.drop
|
237
|
+
expect(db.migrations_table?).to be_false
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#dump_rows" do
|
243
|
+
before(:each) do
|
244
|
+
db.create_migrations_table
|
245
|
+
1.upto(5) { |version| db.insert_version(version) }
|
246
|
+
end
|
247
|
+
|
248
|
+
it "dumps the rows as statements" do
|
249
|
+
statements = db.dump_rows('schema_migrations')
|
250
|
+
expected_statements = [
|
251
|
+
"INSERT INTO schema_migrations (partition_key, version) VALUES (0, 1);",
|
252
|
+
"INSERT INTO schema_migrations (partition_key, version) VALUES (0, 2);",
|
253
|
+
"INSERT INTO schema_migrations (partition_key, version) VALUES (0, 3);",
|
254
|
+
"INSERT INTO schema_migrations (partition_key, version) VALUES (0, 4);",
|
255
|
+
"INSERT INTO schema_migrations (partition_key, version) VALUES (0, 5);"
|
256
|
+
]
|
257
|
+
expect(statements).to eq(expected_statements)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'migration_bundler/databases/sqlite_database'
|
3
|
+
|
4
|
+
describe MigrationBundler::Databases::SqliteDatabase do
|
5
|
+
it "has a SQL file extension" do
|
6
|
+
MigrationBundler::Databases::SqliteDatabase.migration_ext.should == '.sql'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "initializes with a URL" do
|
10
|
+
path = Dir.mktmpdir + '/sandbox.sqlite'
|
11
|
+
database = MigrationBundler::Databases::SqliteDatabase.new(URI("sqlite://#{path}"))
|
12
|
+
database.path.should == path
|
13
|
+
end
|
14
|
+
|
15
|
+
it "stores url" do
|
16
|
+
url = URI("sqlite://#{Dir.mktmpdir}/sandbox.sqlite")
|
17
|
+
database = MigrationBundler::Databases::SqliteDatabase.new(url)
|
18
|
+
database.url.should == url
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses path for to_s" do
|
22
|
+
url = URI("sqlite://#{Dir.mktmpdir}/sandbox.sqlite")
|
23
|
+
database = MigrationBundler::Databases::SqliteDatabase.new(url)
|
24
|
+
database.to_s.should == url.path
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when initialized with a relative path" do
|
28
|
+
it "loads the relative path" do
|
29
|
+
path = Dir.mktmpdir
|
30
|
+
Dir.chdir(path) do
|
31
|
+
database = MigrationBundler::Databases::SqliteDatabase.new(URI("sqlite:test.sqlite"))
|
32
|
+
database.path.should == 'test.sqlite'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:db_path) { Tempfile.new('migration_bundler').path }
|
38
|
+
let(:db) { MigrationBundler::Databases::SqliteDatabase.create(URI(db_path)) }
|
39
|
+
|
40
|
+
describe '#origin_version' do
|
41
|
+
context "when the schema_migrations table is empty" do
|
42
|
+
it "returns nil" do
|
43
|
+
db.origin_version.should be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the schema_migrations table has a single row" do
|
48
|
+
before(:each) do
|
49
|
+
@version = MigrationBundler::Util.migration_timestamp
|
50
|
+
db.insert_version(@version)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns the value of the version column" do
|
54
|
+
db.origin_version.should == @version
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the schema_migrations table has many rows" do
|
59
|
+
before(:each) do
|
60
|
+
# Inject to guarantee mutation of the timestamp
|
61
|
+
@versions = (1..5).inject([]) do |versions, i|
|
62
|
+
version = MigrationBundler::Util.migration_timestamp + i
|
63
|
+
db.insert_version(version)
|
64
|
+
versions << version
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns the lowest value" do
|
69
|
+
db.origin_version.should == @versions.first
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#current_version' do
|
75
|
+
context "when the schema_migrations table is empty" do
|
76
|
+
it "returns nil" do
|
77
|
+
db.current_version.should be_nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when the schema_migrations table has a single row" do
|
82
|
+
before(:each) do
|
83
|
+
@version = MigrationBundler::Util.migration_timestamp
|
84
|
+
db.insert_version(@version)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns the value of the version column" do
|
88
|
+
db.current_version.should == @version
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when the schema_migrations table has many rows" do
|
93
|
+
before(:each) do
|
94
|
+
# Inject to guarantee mutation of the timestamp
|
95
|
+
@versions = (1..5).inject([]) do |versions, i|
|
96
|
+
version = MigrationBundler::Util.migration_timestamp + i
|
97
|
+
db.insert_version(version)
|
98
|
+
versions << version
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns the highest value" do
|
103
|
+
db.current_version.should == @versions.last
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#all_versions' do
|
109
|
+
context "when the database is empty" do
|
110
|
+
it "raises a SQL exception" do
|
111
|
+
db = MigrationBundler::Databases::SqliteDatabase.new(URI(db_path))
|
112
|
+
expect { db.all_versions }.to raise_error(SQLite3::SQLException)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when the schema_migrations table is empty" do
|
117
|
+
it "returns an empty array" do
|
118
|
+
db.all_versions.should == []
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when the schema_migrations table has a single row" do
|
123
|
+
before(:each) do
|
124
|
+
@version = MigrationBundler::Util.migration_timestamp
|
125
|
+
db.insert_version(@version)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "returns the only value" do
|
129
|
+
db.all_versions.should == [@version]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when the schema_migrations table has many rows" do
|
134
|
+
before(:each) do
|
135
|
+
# Inject to guarantee mutation of the timestamp
|
136
|
+
@versions = (1..5).inject([]) do |versions, i|
|
137
|
+
version = MigrationBundler::Util.migration_timestamp + i
|
138
|
+
db.insert_version(version)
|
139
|
+
versions << version
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "returns all values in ascending order" do
|
144
|
+
db.all_versions.should == @versions
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#execute_migration' do
|
150
|
+
context "when given valid SQL" do
|
151
|
+
it "executes without error" do
|
152
|
+
expect { db.execute_migration("CREATE TABLE new_table(version INTEGER UNIQUE NOT NULL)") }.not_to raise_error
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when given invalid SQL" do
|
157
|
+
it "raises an error" do
|
158
|
+
expect do
|
159
|
+
db.execute_migration MigrationBundler::Util.strip_leading_whitespace(
|
160
|
+
<<-SQL
|
161
|
+
CREATE TABLE new_table(version INTEGER UNIQUE NOT NULL);
|
162
|
+
DELETE FROM invalid_table;
|
163
|
+
SQL
|
164
|
+
)
|
165
|
+
end.to raise_error(SQLite3::SQLException)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "rolls back transaction" do
|
169
|
+
db.execute_migration("CREATE TABLE new_table(version INTEGER UNIQUE NOT NULL)")
|
170
|
+
db.execute_migration MigrationBundler::Util.strip_leading_whitespace(
|
171
|
+
<<-SQL
|
172
|
+
DROP TABLE new_table;
|
173
|
+
DELETE FROM invalid_table;
|
174
|
+
SQL
|
175
|
+
) rescue nil
|
176
|
+
expect(db.db.get_first_value('SELECT MIN(version) FROM new_table')).to be_nil
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#dump_rows" do
|
182
|
+
before(:each) do
|
183
|
+
1.upto(5) { |version| db.insert_version(version) }
|
184
|
+
end
|
185
|
+
|
186
|
+
it "dumps the rows to SQL" do
|
187
|
+
statements = db.dump_rows('schema_migrations')
|
188
|
+
expected_statements = [
|
189
|
+
"INSERT INTO schema_migrations (version) VALUES (1);",
|
190
|
+
"INSERT INTO schema_migrations (version) VALUES (2);",
|
191
|
+
"INSERT INTO schema_migrations (version) VALUES (3);",
|
192
|
+
"INSERT INTO schema_migrations (version) VALUES (4);",
|
193
|
+
"INSERT INTO schema_migrations (version) VALUES (5);"
|
194
|
+
]
|
195
|
+
expect(statements).to eq(expected_statements)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MigrationBundler::Project do
|
4
|
+
let!(:project_root) { clone_temp_sandbox }
|
5
|
+
let(:project) { MigrationBundler::Project.load(project_root) }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
Dir.chdir(project_root)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#database" do
|
12
|
+
context "when given a URL without a scheme" do
|
13
|
+
it "assumes SQLite" do
|
14
|
+
project = MigrationBundler::Project.new(database_url: 'sandbox.sqlite')
|
15
|
+
project.database.should == 'sqlite'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "given a SQLite URL" do
|
20
|
+
it "returns sqlite" do
|
21
|
+
project = MigrationBundler::Project.new(database_url: 'sqlite:///sandbox.sqlite')
|
22
|
+
project.database.should == 'sqlite'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "given a Cassandra URL" do
|
27
|
+
it "returns cassandra" do
|
28
|
+
project = MigrationBundler::Project.new(database_url: 'cassandra://localhost:9170')
|
29
|
+
project.database.should == 'cassandra'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#git_url' do
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#git_latest_tag' do
|
38
|
+
context "when there are no tags" do
|
39
|
+
it "returns nil" do
|
40
|
+
project.git_latest_tag.should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when there is one tag" do
|
45
|
+
before(:each) do
|
46
|
+
tag_versions(%w{1.0.0})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns that tag" do
|
50
|
+
project.git_latest_tag.should == '1.0.0'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when there are 4 tags" do
|
55
|
+
before(:each) do
|
56
|
+
tag_versions(%w{1.0.0 0.9.8 2.2.3 1.9.5})
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns the highest version number" do
|
60
|
+
project.git_latest_tag.should == '2.2.3'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#git_tag_for_version' do
|
66
|
+
context "when there are no tags" do
|
67
|
+
it "returns nil" do
|
68
|
+
project.git_tag_for_version('v1.0.0').should be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when there is one tag" do
|
73
|
+
before(:each) do
|
74
|
+
tag_versions(%w{1.0.0})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns that tag" do
|
78
|
+
project.git_tag_for_version('1.0.0').should == '1.0.0'
|
79
|
+
end
|
80
|
+
|
81
|
+
context "but it doesn't match the query" do
|
82
|
+
it "returns nil" do
|
83
|
+
project.git_tag_for_version('0.9.6').should be_nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when there are 4 tags" do
|
89
|
+
before(:each) do
|
90
|
+
tag_versions(%w{1.0.0 0.9.8 2.2.3 1.9.5})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns the matching tag" do
|
94
|
+
project.git_tag_for_version('0.9.8').should == '0.9.8'
|
95
|
+
end
|
96
|
+
|
97
|
+
context "but none match the query" do
|
98
|
+
it "returns nil" do
|
99
|
+
project.git_tag_for_version('0.5.12').should be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "and there are point releases" do
|
104
|
+
before(:each) do
|
105
|
+
tag_versions(%w{0.9.8.1 0.9.8.5000 0.9.8.2 0.9.8.3})
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns the highest matching tag" do
|
109
|
+
project.git_tag_for_version('0.9.8').should == '0.9.8.5000'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def tag_versions(*versions)
|
116
|
+
Dir.chdir(project_root) do
|
117
|
+
versions.flatten.each do |version|
|
118
|
+
filename = random_migration_name
|
119
|
+
`echo '' > #{filename}`
|
120
|
+
raise "Failed touching file" unless $?.exitstatus.zero?
|
121
|
+
`git add #{filename} && git commit -m 'commiting #{random_migration_name}' .`
|
122
|
+
raise "Failed commiting" unless $?.exitstatus.zero?
|
123
|
+
`git tag #{version}`
|
124
|
+
raise "Failed tagging version" unless $?.exitstatus.zero?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/* Create Monkey Butler Tables */
|
2
|
+
|
3
|
+
-- Maintains list of applied migrations
|
4
|
+
CREATE TABLE schema_migrations(
|
5
|
+
version INTEGER UNIQUE NOT NULL
|
6
|
+
);
|
7
|
+
|
8
|
+
/* Create application tables */
|
9
|
+
/*
|
10
|
+
CREATE TABLE table_name (
|
11
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
12
|
+
...
|
13
|
+
);
|
14
|
+
*/
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/* Create Monkey Butler Tables */
|
2
|
+
|
3
|
+
-- Maintains list of applied migrations
|
4
|
+
CREATE TABLE schema_migrations(
|
5
|
+
version INTEGER UNIQUE NOT NULL
|
6
|
+
);
|
7
|
+
|
8
|
+
/* Create application tables */
|
9
|
+
/*
|
10
|
+
CREATE TABLE table_name (
|
11
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
12
|
+
...
|
13
|
+
);
|
14
|
+
*/
|
File without changes
|