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 ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -1,5 +1,22 @@
1
1
  require "migration_investigation/version"
2
2
 
3
3
  module MigrationInvestigation
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module MigrationInvestigation
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency 'auto_tagger'
22
+ gem.add_development_dependency 'rspec'
22
23
  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
@@ -0,0 +1,9 @@
1
+ require 'migration_investigation'
2
+ require 'auto_tagger'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ config.order = 'random'
9
+ 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.1
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