migration_investigation 0.0.4 → 0.0.5

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: 698aa3dfb32aa648d5a042ce6f82180fa661658e
4
- data.tar.gz: be6eb8f95205d6268a85f7ea3079d392ba421b68
3
+ metadata.gz: db343e9aa4896c11604706e41c4edc07fafe6575
4
+ data.tar.gz: eaeb8cc77fed174079ed9f10c22f7b7344ae6d87
5
5
  SHA512:
6
- metadata.gz: 46bbd693ef9b2729cba74692597475368dd399c31e8a84380f1b7aaf2375a2cd998a032b314afec08c1d568dec2efb12582ca64e5aa770191f87b98118421f26
7
- data.tar.gz: d9ad4ea08aaf11ab13f864a90b70aa26de8600122559fa512b73ae4b95dbf28df995b5a219f87821254d7958d5a2c7929e25a39df512428bb641640282539f48
6
+ metadata.gz: 5be35dec195cdd849bb44b208ce33221de745226e64a0b9e3addb5cd7aa0725e66b736c20398f46324d2b8fd6ed18f74ce12239d03d9f9c8bcb4550f5f1390f0
7
+ data.tar.gz: fe69836f7d5ed7502ea801c8fa8a7e200ba3665619e9848b305fab9274e8bc5217d48b77a763042afefa8071d8721fb9338a176a2388f454df2259e410373f82
data/README.md CHANGED
@@ -32,6 +32,10 @@ parameter:
32
32
 
33
33
  $ MigrationInvestigation.pending_migrations? "staging", "abc123", additional_paths: ["db/seed.rb", "app/foo.txt"]
34
34
 
35
+ You can also add a pattern for migrations to ignore:
36
+
37
+ $ MigrationInvestigation.pending_migrations? "staging", "abc123", skip_filepath_pattern: /\d_online_/
38
+
35
39
  ## Contributing
36
40
 
37
41
  1. Fork it
@@ -6,7 +6,7 @@ module MigrationInvestigation
6
6
  old_sha = latest_stage_sha stage
7
7
  return true if old_sha.nil?
8
8
 
9
- change_count(old_sha, new_sha, build_interesting_paths(options)) != 0
9
+ change_count(old_sha, new_sha, build_interesting_paths(options.fetch(:additional_paths, [])), options[:skip_filepath_pattern]) != 0
10
10
  end
11
11
 
12
12
  private
@@ -16,14 +16,15 @@ module MigrationInvestigation
16
16
  latest_tag.sha if latest_tag
17
17
  end
18
18
 
19
- def change_count(old_sha, new_sha, interesting_paths)
20
- changes = `git diff --name-only #{old_sha} #{new_sha} #{interesting_paths.join(" ")} | wc -l`
21
- changes.to_i
19
+ def change_count(old_sha, new_sha, interesting_paths, skip_filepath_pattern)
20
+ cmd = "git diff --name-only #{old_sha} #{new_sha} #{interesting_paths.join(" ")}"
21
+ changes = `#{cmd}`
22
+ changes.split("\n").reject { |l| l.length == 0 }.reject { |l| skip_filepath_pattern && l =~ skip_filepath_pattern }.length
22
23
  end
23
24
 
24
- def build_interesting_paths(options)
25
+ def build_interesting_paths(additional_paths)
25
26
  interesting_paths = ["db/migrate/"]
26
- interesting_paths << options.fetch(:additional_paths, [])
27
+ interesting_paths << additional_paths
27
28
  interesting_paths.flatten
28
29
  end
29
30
  end
@@ -1,3 +1,3 @@
1
1
  module MigrationInvestigation
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -21,37 +21,78 @@ describe MigrationInvestigation do
21
21
  subject { MigrationInvestigation.pending_migrations? stage, new_sha }
22
22
 
23
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)
24
+ allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/").and_return(git_diff)
25
25
  end
26
26
 
27
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" }
28
+ let(:git_diff) do
29
+ <<~GITDIFF
30
+ db/migrate/121345_foo_migration.rb
31
+ db/migrate/121345_bar_migration.rb
32
+ db/migrate/121345_baz_migration.rb
33
+ GITDIFF
34
+ end
29
35
 
30
36
  it { is_expected.to be_truthy }
31
37
  end
32
38
 
33
39
  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" }
40
+ let(:git_diff) { "\n" }
35
41
 
36
42
  it { is_expected.to be_falsy }
37
43
  end
38
44
  end
39
45
 
46
+ context "when an uptime pattern is provided" do
47
+ subject { MigrationInvestigation.pending_migrations? stage, new_sha, skip_filepath_pattern: /\d_online_/}
48
+
49
+ before do
50
+ allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/").and_return(git_diff)
51
+ end
52
+
53
+ context "when only online migrations exist" do
54
+ let(:git_diff) do
55
+ <<~GITDIFF
56
+ db/migrate/121345_online_bar_migration.rb
57
+ db/migrate/121345_online_baz_migration.rb
58
+ GITDIFF
59
+ end
60
+
61
+ it { is_expected.to be_falsy }
62
+ end
63
+
64
+ context "when there are some offline migrations" do
65
+ let(:git_diff) do
66
+ <<~GITDIFF
67
+ db/migrate/121345_foo_migration.rb
68
+ db/migrate/121345_bar_migration.rb
69
+ db/migrate/121345_online_baz_migration.rb
70
+ GITDIFF
71
+ end
72
+
73
+ it { is_expected.to be_truthy }
74
+ end
75
+ end
76
+
40
77
  context "when additional paths are passed in" do
41
- subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
78
+ subject { MigrationInvestigation.pending_migrations? stage, new_sha, additional_paths: ["app/foo.rb"] }
42
79
 
43
80
  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)
81
+ allow(MigrationInvestigation).to receive(:`).with("git diff --name-only #{old_sha} #{new_sha} db/migrate/ app/foo.rb").and_return(git_diff)
45
82
  end
46
83
 
47
84
  context "when there are changes between the last tag for the given change, and the new SHA" do
48
- let(:git_diff) { " 3\n" }
85
+ let(:git_diff) do
86
+ <<~GITDIFF
87
+ app/foo.rb
88
+ GITDIFF
89
+ end
49
90
 
50
91
  it { is_expected.to be_truthy }
51
92
  end
52
93
 
53
94
  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" }
95
+ let(:git_diff) { "\n" }
55
96
 
56
97
  it { is_expected.to be_falsy }
57
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_investigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Wheeldon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: auto_tagger
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.4.6
80
+ rubygems_version: 2.5.1
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Checks whether migrations, or other parts of your repo, have any changes.