migration_investigation 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/lib/migration_investigation.rb +18 -1
- data/lib/migration_investigation/version.rb +1 -1
- data/migration_investigation.gemspec +1 -0
- data/spec/migration_investigation_spec.rb +34 -0
- data/spec/spec_helper.rb +9 -0
- metadata +23 -2
data/.rspec
ADDED
@@ -1,5 +1,22 @@
|
|
1
1
|
require "migration_investigation/version"
|
2
2
|
|
3
3
|
module MigrationInvestigation
|
4
|
-
|
4
|
+
class << self
|
5
|
+
def pending_migrations? stage, new_sha
|
6
|
+
old_sha = get_latest_sha stage
|
7
|
+
change_count = get_change_count old_sha, new_sha
|
8
|
+
change_count != 0
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get_latest_sha stage
|
14
|
+
AutoTagger::Base.new({}).refs_for_stage(stage).last.sha
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_change_count old_sha, new_sha
|
18
|
+
changes = `git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l`
|
19
|
+
changes.to_i
|
20
|
+
end
|
21
|
+
end
|
5
22
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MigrationInvestigation do
|
4
|
+
describe ".pending_migrations?" do
|
5
|
+
subject { MigrationInvestigation.pending_migrations? stage, new_sha }
|
6
|
+
|
7
|
+
let(:stage) { "stage" }
|
8
|
+
let(:new_sha) { "abc123" }
|
9
|
+
|
10
|
+
let(:refs) { [ref1, ref2] }
|
11
|
+
let(:ref1) { stub(:ref1) }
|
12
|
+
let(:ref2) { stub(:ref2, sha: old_sha) }
|
13
|
+
let(:old_sha) { "cba321" }
|
14
|
+
|
15
|
+
before do
|
16
|
+
auto_tagger = stub(:auto_tagger)
|
17
|
+
AutoTagger::Base.stub(:new).with({}) { auto_tagger }
|
18
|
+
auto_tagger.stub(:refs_for_stage).with(stage) { refs }
|
19
|
+
MigrationInvestigation.stub(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l") { git_diff }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when there are migrations changed between the last tag for the given change, and the new SHA" do
|
23
|
+
let(:git_diff) { " 3\n" }
|
24
|
+
|
25
|
+
it { should be_true }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when there are no migrations changes between the last tag for the given change, and the new SHA" do
|
29
|
+
let(:git_diff) { " 0\n" }
|
30
|
+
|
31
|
+
it { should be_false }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migration_investigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Checks whether migrations need to be run, without loading your environment
|
31
47
|
email:
|
32
48
|
- brent.wheeldon@gmail.com
|
@@ -35,6 +51,7 @@ extensions: []
|
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
37
53
|
- .gitignore
|
54
|
+
- .rspec
|
38
55
|
- Gemfile
|
39
56
|
- LICENSE.txt
|
40
57
|
- README.md
|
@@ -42,6 +59,8 @@ files:
|
|
42
59
|
- lib/migration_investigation.rb
|
43
60
|
- lib/migration_investigation/version.rb
|
44
61
|
- migration_investigation.gemspec
|
62
|
+
- spec/migration_investigation_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
45
64
|
homepage: https://github.com/BrentWheeldon/migration_investigation
|
46
65
|
licenses:
|
47
66
|
- MIT
|
@@ -67,4 +86,6 @@ rubygems_version: 1.8.24
|
|
67
86
|
signing_key:
|
68
87
|
specification_version: 3
|
69
88
|
summary: Checks whether migrations need to be run, without loading your environment
|
70
|
-
test_files:
|
89
|
+
test_files:
|
90
|
+
- spec/migration_investigation_spec.rb
|
91
|
+
- spec/spec_helper.rb
|