migration_investigation 0.0.3 → 0.0.4

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: 91513fab4ee07b15ace6022637aac1c4a6b0d63c
4
- data.tar.gz: 678ac5207077c480991cbf8434c782dad0723d51
3
+ metadata.gz: 698aa3dfb32aa648d5a042ce6f82180fa661658e
4
+ data.tar.gz: be6eb8f95205d6268a85f7ea3079d392ba421b68
5
5
  SHA512:
6
- metadata.gz: 8e932ec123891349b920a8bd9b6d0f7c54eea89e0fd5bc39900635bb7beda5bac25f0bede1f84524e00bed31e51c38f446b60c740ad77f0c706c3f2b4822cc2f
7
- data.tar.gz: ab1cc4ed15336aae4d5ef5a5409f5f873690db37e5e9b6467272867d691c8da11889ff8786099eae9ca639779c9280dc159445faacb4e5624caa40553d932d5f
6
+ metadata.gz: 46bbd693ef9b2729cba74692597475368dd399c31e8a84380f1b7aaf2375a2cd998a032b314afec08c1d568dec2efb12582ca64e5aa770191f87b98118421f26
7
+ data.tar.gz: d9ad4ea08aaf11ab13f864a90b70aa26de8600122559fa512b73ae4b95dbf28df995b5a219f87821254d7958d5a2c7929e25a39df512428bb641640282539f48
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  The gem is very simple:
24
24
 
25
- $ MigrationInvestigation.pending_migrations? "staging", "abc123"
25
+ $ MigrationInvestigation.pending_migrations? "staging", "abc123"
26
26
 
27
27
  Where `staging` is the name of the tag, and `abc123` is the SHA you're about to deploy.
28
28
  You can also pass nil for the SHA you're about to deploy and it will assume you're deloying `HEAD`.
@@ -30,7 +30,7 @@ You can also pass nil for the SHA you're about to deploy and it will assume you'
30
30
  If you'd also like to check additional files or directories, say seed data, you can pass in a third
31
31
  parameter:
32
32
 
33
- $ MigrationInvestigation.pending_migrations? "staging", "abc123", additional_paths: ["db/seed.rb", "app/foo.txt"]
33
+ $ MigrationInvestigation.pending_migrations? "staging", "abc123", additional_paths: ["db/seed.rb", "app/foo.txt"]
34
34
 
35
35
  ## Contributing
36
36
 
@@ -1,3 +1,3 @@
1
1
  module MigrationInvestigation
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,23 +3,28 @@ require "migration_investigation/version"
3
3
  module MigrationInvestigation
4
4
  class << self
5
5
  def pending_migrations?(stage, new_sha, options={})
6
- interesting_paths = options.fetch(:additional_paths, [])
7
- interesting_paths = [interesting_paths] unless interesting_paths.is_a?(Array)
8
- interesting_paths << "db/migrate/"
9
- old_sha = get_latest_sha stage
10
- change_count = get_change_count old_sha, new_sha, interesting_paths
11
- change_count != 0
6
+ old_sha = latest_stage_sha stage
7
+ return true if old_sha.nil?
8
+
9
+ change_count(old_sha, new_sha, build_interesting_paths(options)) != 0
12
10
  end
13
11
 
14
12
  private
15
13
 
16
- def get_latest_sha(stage)
17
- AutoTagger::Base.new({}).refs_for_stage(stage).last.sha
14
+ def latest_stage_sha(stage)
15
+ latest_tag = AutoTagger::Base.new({}).refs_for_stage(stage).last
16
+ latest_tag.sha if latest_tag
18
17
  end
19
18
 
20
- def get_change_count(old_sha, new_sha, interesting_paths)
19
+ def change_count(old_sha, new_sha, interesting_paths)
21
20
  changes = `git diff --name-only #{old_sha} #{new_sha} #{interesting_paths.join(" ")} | wc -l`
22
21
  changes.to_i
23
22
  end
23
+
24
+ def build_interesting_paths(options)
25
+ interesting_paths = ["db/migrate/"]
26
+ interesting_paths << options.fetch(:additional_paths, [])
27
+ interesting_paths.flatten
28
+ end
24
29
  end
25
30
  end
@@ -5,55 +5,65 @@ describe MigrationInvestigation do
5
5
  let(:stage) { "stage" }
6
6
  let(:new_sha) { "abc123" }
7
7
 
8
- let(:refs) { [ref1, ref2] }
9
- let(:ref1) { double(:ref1) }
10
- let(:ref2) { double(:ref2, sha: old_sha) }
11
- let(:old_sha) { "cba321" }
12
-
13
8
  before do
14
9
  auto_tagger = double(:auto_tagger)
15
10
  allow(AutoTagger::Base).to receive(:new).with({}).and_return(auto_tagger)
16
11
  allow(auto_tagger).to receive(:refs_for_stage).with(stage).and_return(refs)
17
12
  end
18
13
 
19
- context "when no additional paths are passed in" do
20
- subject { MigrationInvestigation.pending_migrations? stage, new_sha }
14
+ context "when there are refs for the given stage" do
15
+ let(:refs) { [ref1, ref2] }
16
+ let(:ref1) { double(:ref1) }
17
+ let(:ref2) { double(:ref2, sha: old_sha) }
18
+ let(:old_sha) { "cba321" }
21
19
 
22
- before do
23
- allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l").and_return(git_diff)
24
- end
20
+ context "when no additional paths are passed in" do
21
+ subject { MigrationInvestigation.pending_migrations? stage, new_sha }
25
22
 
26
- context "when there are migrations changed between the last tag for the given change, and the new SHA" do
27
- let(:git_diff) { " 3\n" }
23
+ before do
24
+ allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ | wc -l").and_return(git_diff)
25
+ end
28
26
 
29
- it { is_expected.to be_truthy }
30
- end
27
+ context "when there are migrations changed between the last tag for the given change, and the new SHA" do
28
+ let(:git_diff) { " 3\n" }
31
29
 
32
- context "when there are no migrations changes between the last tag for the given change, and the new SHA" do
33
- let(:git_diff) { " 0\n" }
30
+ it { is_expected.to be_truthy }
31
+ end
34
32
 
35
- it { is_expected.to be_falsy }
33
+ context "when there are no migrations changes between the last tag for the given change, and the new SHA" do
34
+ let(:git_diff) { " 0\n" }
35
+
36
+ it { is_expected.to be_falsy }
37
+ end
36
38
  end
37
- end
38
39
 
39
- context "when additional paths are passed in" do
40
- subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
40
+ context "when additional paths are passed in" do
41
+ subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
41
42
 
42
- before do
43
- allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} app/foo.rb db/migrate/ | wc -l").and_return(git_diff)
44
- end
43
+ before do
44
+ allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ app/foo.rb | wc -l").and_return(git_diff)
45
+ end
45
46
 
46
- context "when there are changes between the last tag for the given change, and the new SHA" do
47
- let(:git_diff) { " 3\n" }
47
+ context "when there are changes between the last tag for the given change, and the new SHA" do
48
+ let(:git_diff) { " 3\n" }
48
49
 
49
- it { is_expected.to be_truthy }
50
- end
50
+ it { is_expected.to be_truthy }
51
+ end
51
52
 
52
- context "when there are no changes between the last tag for the given change, and the new SHA" do
53
- let(:git_diff) { " 0\n" }
53
+ context "when there are no changes between the last tag for the given change, and the new SHA" do
54
+ let(:git_diff) { " 0\n" }
54
55
 
55
- it { is_expected.to be_falsy }
56
+ it { is_expected.to be_falsy }
57
+ end
56
58
  end
57
59
  end
60
+
61
+ context "when there are no refs for the given stage" do
62
+ subject { MigrationInvestigation.pending_migrations? stage, new_sha }
63
+
64
+ let(:refs) { [] }
65
+
66
+ it { is_expected.to be_truthy }
67
+ end
58
68
  end
59
69
  end
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Wheeldon