guard-migrate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Geoff Lanotte
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = guard-migrate
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to guard-migrate
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Geoff Lanotte. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,81 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Migrate < Guard
6
+ def initialize(watchers=[], options={})
7
+ super
8
+
9
+ @reset = true unless options[:reset] == false
10
+ @test_clone = true unless options[:test_clone] == false
11
+ @run_on_start = true if options[:run_on_start] == true
12
+ @rails_env = options[:rails_env]
13
+ end
14
+
15
+ def run_on_start?
16
+ !!@run_on_start
17
+ end
18
+
19
+ def test_clone?
20
+ !!@test_clone
21
+ end
22
+
23
+ def reset?
24
+ !!@reset
25
+ end
26
+
27
+ def rails_env
28
+ @rails_env
29
+ end
30
+
31
+ # =================
32
+ # = Guard methods =
33
+ # =================
34
+
35
+ # If one of those methods raise an exception, the Guard::GuardName instance
36
+ # will be removed from the active guards.
37
+
38
+ # Called once when Guard starts
39
+ # Please override initialize method to init stuff
40
+ def start
41
+ self.migrate if self.run_on_start?
42
+ end
43
+
44
+ # Called on Ctrl-C signal (when Guard quits)
45
+ def stop
46
+ true
47
+ end
48
+
49
+ # Called on Ctrl-Z signal
50
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
51
+ def reload
52
+ self.migrate if self.run_on_start?
53
+ end
54
+
55
+ # Called on Ctrl-/ signal
56
+ # This method should be principally used for long action like running all specs/tests/...
57
+ def run_all
58
+ self.migrate if self.run_on_start?
59
+ end
60
+
61
+ # Called on file(s) modifications
62
+ def run_on_change(paths)
63
+ self.migrate
64
+ end
65
+
66
+ def migrate
67
+ system self.rake_string
68
+ end
69
+
70
+ def rake_string
71
+ @rake_string = 'rake'
72
+ @rake_string += ' db:migrate'
73
+ @rake_string += ':reset' if self.reset?
74
+ @rake_string += ' db:test:clone' if self.test_clone?
75
+ @rake_string += " RAILS_ENV=#{self.rails_env}" if self.rails_env
76
+ @rake_string
77
+ end
78
+
79
+ end
80
+ end
81
+
@@ -0,0 +1,4 @@
1
+ guard 'migrate' do
2
+ watch('db/migrate/*.rb')
3
+ end
4
+
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module MigrateVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
File without changes
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Migrate do
4
+ let(:options){ {}}
5
+ subject{ Guard::Migrate.new([], options) }
6
+
7
+ describe "options" do
8
+ context "test clone" do
9
+ context "with no optios passed" do
10
+ its(:test_clone?){should be_true}
11
+ its(:rake_string){should match(/db:test:clone/)}
12
+ end
13
+
14
+ context "when passed false" do
15
+ let(:options){ {:test_clone => false} }
16
+ its(:test_clone?){should_not be_true}
17
+ its(:rake_string){should match(/rake db:migrate/)}
18
+ its(:rake_string){should_not match(/db:test:clone/)}
19
+ end
20
+ end
21
+
22
+ context "reset" do
23
+ context "with no options passed" do
24
+ its(:reset?){should be_true}
25
+ its(:rake_string){should match(/rake db:migrate:reset/)}
26
+ end
27
+
28
+ context "when passed false" do
29
+ let(:options){ {:reset => false} }
30
+ its(:reset?){should_not be_true}
31
+ its(:rake_string){should match(/rake db:migrate/)}
32
+ its(:rake_string){should_not match(/rake db:migrate:reset/)}
33
+ end
34
+ end
35
+
36
+ context "run on start" do
37
+ context "with no options set" do
38
+ its(:run_on_start?){should_not be_true}
39
+
40
+ it "should not run on start" do
41
+ subject.should_receive(:migrate).never
42
+ subject.start
43
+ end
44
+
45
+ it "should not run migrate on the reload command" do
46
+ subject.should_receive(:migrate).never
47
+ subject.reload
48
+ end
49
+
50
+ it "should not run migrate on the run all command" do
51
+ subject.should_receive(:migrate).never
52
+ subject.run_all
53
+ end
54
+ end
55
+
56
+ context "when passed true" do
57
+ let(:options){ {:run_on_start => true} }
58
+ its(:run_on_start?){should be_true}
59
+
60
+ it "should run migrate on the start" do
61
+ subject.should_receive(:migrate)
62
+ subject.start
63
+ end
64
+
65
+ it "should run migrate on the reload command" do
66
+ subject.should_receive(:migrate)
67
+ subject.reload
68
+ end
69
+
70
+ it "should run migrate on the run all command" do
71
+ subject.should_receive(:migrate)
72
+ subject.run_all
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'Rails Environment' do
78
+ context "when no option is passed" do
79
+ its(:rails_env){should be_nil}
80
+ end
81
+
82
+ context "when a rails environment is passed" do
83
+ let(:options){ {:rails_env => 'development'}}
84
+ its(:rails_env){ should == 'development'}
85
+
86
+ its(:rake_string){ should match(/RAILS_ENV=development/)}
87
+ end
88
+ end
89
+ end
90
+
91
+ context "migrate" do
92
+ it "should run the rake command" do
93
+ subject.should_receive(:system).with(subject.rake_string)
94
+ subject.run_on_change []
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec'
2
+ require 'guard/migrate'
3
+
4
+ # Requires supporting files with custom matchers and macros, etc,
5
+ # in ./support/ and its subdirectories.
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.filter_run :focus => true
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ config.before(:each) do
14
+ ENV["GUARD_ENV"] = 'test'
15
+ end
16
+
17
+ config.after(:each) do
18
+ ENV["GUARD_ENV"] = nil
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-migrate
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Geoff Lanotte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-15 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.6.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: guard-rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.1
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: Guard::Migrate automatically runs your database migrations when needed
49
+ email:
50
+ - geofflanotte@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - lib/guard/migrate/templates/Guardfile
59
+ - lib/guard/migrate/version.rb
60
+ - lib/guard/migrate.rb
61
+ - LICENSE.txt
62
+ - README.rdoc
63
+ - spec/guard/migrate/notifier_spec.rb
64
+ - spec/guard/migrate_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: http://rubygems.org/gems/guard-migrate
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ - --main=README.rdoc
73
+ - --exclude='(lib|test|spec)|(Gem|Guard|Rake)file'
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.6
88
+ requirements: []
89
+
90
+ rubyforge_project: guard-migrate
91
+ rubygems_version: 1.8.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Guard gem for rails migrations
95
+ test_files:
96
+ - spec/guard/migrate/notifier_spec.rb
97
+ - spec/guard/migrate_spec.rb
98
+ - spec/spec_helper.rb