gitpusshuten 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/.bundle/config +2 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +53 -0
  5. data/README.md +7 -0
  6. data/bin/gitpusshuten +4 -0
  7. data/bin/heavenly +4 -0
  8. data/bin/ten +4 -0
  9. data/gitpusshuten.gemspec +26 -0
  10. data/lib/gitpusshuten/cli.rb +78 -0
  11. data/lib/gitpusshuten/command.rb +147 -0
  12. data/lib/gitpusshuten/commands/base.rb +246 -0
  13. data/lib/gitpusshuten/commands/delete.rb +27 -0
  14. data/lib/gitpusshuten/commands/help.rb +36 -0
  15. data/lib/gitpusshuten/commands/initialize.rb +61 -0
  16. data/lib/gitpusshuten/commands/push.rb +54 -0
  17. data/lib/gitpusshuten/commands/remote.rb +29 -0
  18. data/lib/gitpusshuten/commands/user.rb +252 -0
  19. data/lib/gitpusshuten/commands/version.rb +21 -0
  20. data/lib/gitpusshuten/configuration.rb +122 -0
  21. data/lib/gitpusshuten/environment.rb +70 -0
  22. data/lib/gitpusshuten/gem.rb +33 -0
  23. data/lib/gitpusshuten/git.rb +111 -0
  24. data/lib/gitpusshuten/helpers/environment/installers.rb +59 -0
  25. data/lib/gitpusshuten/helpers/environment/packages.rb +21 -0
  26. data/lib/gitpusshuten/helpers/environment/scp.rb +57 -0
  27. data/lib/gitpusshuten/helpers/environment/ssh.rb +77 -0
  28. data/lib/gitpusshuten/helpers/environment/ssh_key.rb +79 -0
  29. data/lib/gitpusshuten/helpers/environment/user.rb +70 -0
  30. data/lib/gitpusshuten/helpers/spinner.rb +98 -0
  31. data/lib/gitpusshuten/hook.rb +26 -0
  32. data/lib/gitpusshuten/hooks.rb +147 -0
  33. data/lib/gitpusshuten/initializer.rb +95 -0
  34. data/lib/gitpusshuten/local.rb +35 -0
  35. data/lib/gitpusshuten/log.rb +83 -0
  36. data/lib/gitpusshuten/modules/active_record/hooks.rb +19 -0
  37. data/lib/gitpusshuten/modules/apache/command.rb +354 -0
  38. data/lib/gitpusshuten/modules/bundler/command.rb +43 -0
  39. data/lib/gitpusshuten/modules/bundler/hooks.rb +8 -0
  40. data/lib/gitpusshuten/modules/mysql/command.rb +192 -0
  41. data/lib/gitpusshuten/modules/nanoc/hooks.rb +9 -0
  42. data/lib/gitpusshuten/modules/nginx/command.rb +447 -0
  43. data/lib/gitpusshuten/modules/passenger/command.rb +310 -0
  44. data/lib/gitpusshuten/modules/passenger/hooks.rb +4 -0
  45. data/lib/gitpusshuten/modules/rvm/command.rb +277 -0
  46. data/lib/gitpusshuten.rb +21 -0
  47. data/lib/templates/config.rb +37 -0
  48. data/lib/templates/hooks.rb +40 -0
  49. data/spec/cli_spec.rb +83 -0
  50. data/spec/command_spec.rb +76 -0
  51. data/spec/configuration_spec.rb +45 -0
  52. data/spec/environment_spec.rb +64 -0
  53. data/spec/fixtures/combined_hooks.rb +23 -0
  54. data/spec/fixtures/config.rb +23 -0
  55. data/spec/fixtures/hooks.rb +37 -0
  56. data/spec/fixtures/passenger.json +1 -0
  57. data/spec/gem_spec.rb +28 -0
  58. data/spec/git_spec.rb +59 -0
  59. data/spec/gitpusshuten_spec.rb +9 -0
  60. data/spec/hook_spec.rb +48 -0
  61. data/spec/hooks_spec.rb +150 -0
  62. data/spec/initializer_spec.rb +26 -0
  63. data/spec/log_spec.rb +20 -0
  64. data/spec/spec_helper.rb +43 -0
  65. metadata +220 -0
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::CLI do
4
+
5
+ let(:cli) { GitPusshuTen::CLI.new }
6
+
7
+ it "should flatten the arguments" do
8
+ cli = GitPusshuTen::CLI.new(['tag', [['1.4.2', 'to'], 'staging']])
9
+ cli.arguments.should == ['1.4.2']
10
+ end
11
+
12
+ describe "extracting the environment" do
13
+ it "should return the environment" do
14
+ cli = GitPusshuTen::CLI.new(%w[tag 1.4.2 to staging])
15
+ cli.environment.should == :staging
16
+ end
17
+
18
+ it "should return the environment" do
19
+ cli = GitPusshuTen::CLI.new(%w[delete development environment])
20
+ cli.environment.should == :development
21
+ end
22
+
23
+ it "should return the environment" do
24
+ cli = GitPusshuTen::CLI.new(%w[maintenance enable for production environment])
25
+ cli.environment.should == :production
26
+ end
27
+
28
+ it "should return the environment" do
29
+ cli = GitPusshuTen::CLI.new(%w[maintenance enable production environment])
30
+ cli.environment.should == :production
31
+ end
32
+
33
+ it "should return the environment" do
34
+ cli = GitPusshuTen::CLI.new(%w[maintenance enable for production])
35
+ cli.environment.should == :production
36
+ end
37
+
38
+ it "should return the environment" do
39
+ cli = GitPusshuTen::CLI.new(%w[maintenance enable for pr0duct10n])
40
+ cli.environment.should == :pr0duct10n
41
+ end
42
+
43
+ it "should return the environment" do
44
+ cli = GitPusshuTen::CLI.new(%w[nginx upload-vhost to production])
45
+ cli.environment.should == :production
46
+ end
47
+
48
+ it "should return the environment" do
49
+ cli = GitPusshuTen::CLI.new(%w[nginx download-vhost from production])
50
+ cli.environment.should == :production
51
+ end
52
+
53
+ it "should return the environment" do
54
+ cli = GitPusshuTen::CLI.new(%w[user install-ssh-key on staging])
55
+ cli.environment.should == :staging
56
+ end
57
+ end
58
+
59
+ describe '#command' do
60
+ it "should extract the command from the cli" do
61
+ cli = GitPusshuTen::CLI.new(%w[maintenance on for pr0duct10n])
62
+ cli.command.should == 'maintenance'
63
+ end
64
+
65
+ it "should make underscores from dashes for commands" do
66
+ cli = GitPusshuTen::CLI.new(%w[remote command on pr0duct10n ls -la])
67
+ cli.command.should == 'remote'
68
+ end
69
+ end
70
+
71
+ describe '#arguments' do
72
+ it do
73
+ cli = GitPusshuTen::CLI.new(%w[nginx upload-vhost to production])
74
+ cli.arguments.should == ['upload-vhost']
75
+ end
76
+
77
+ it do
78
+ cli = GitPusshuTen::CLI.new(%w[remote command on staging ls -la])
79
+ cli.arguments.should == ['command', 'ls', '-la']
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Command do
4
+
5
+ let(:cli) { mock('cli') }
6
+ let(:configuration) { mock('configuration') }
7
+ let(:hooks) { mock('hooks') }
8
+ let(:environment) { mock('environment') }
9
+
10
+ before do
11
+ cli.stubs(:command).returns('non_existing_command')
12
+ configuration.stubs(:additional_modules).returns([])
13
+ end
14
+
15
+ it "should error out if the command was not found" do
16
+ GitPusshuTen::Log.expects(:error).with('Command <non_existing_command> not found.')
17
+ GitPusshuTen::Command.any_instance.expects(:exit)
18
+
19
+ GitPusshuTen::Command.new(cli, configuration, hooks, environment)
20
+ end
21
+
22
+ describe '#available_commands' do
23
+ it "should display available commands without the .rb extension" do
24
+ GitPusshuTen::Command.any_instance.stubs(:exit)
25
+ GitPusshuTen::Log.stubs(:error)
26
+
27
+ command = GitPusshuTen::Command.new(cli, configuration, hooks, environment)
28
+ command.expects(:commands_directory).returns([Dir.pwd + '/commands/mock_tag.rb'])
29
+ command.available_commands.should include('mock_tag')
30
+ end
31
+
32
+ it "should not include the base command" do
33
+ GitPusshuTen::Command.any_instance.stubs(:exit)
34
+ GitPusshuTen::Log.stubs(:error)
35
+
36
+ command = GitPusshuTen::Command.new(cli, configuration, hooks, environment)
37
+ command.expects(:commands_directory).returns(Dir[File.expand_path(File.dirname(__FILE__) + '/../lib/gitpusshuten/commands/*.rb')])
38
+ command.available_commands.should_not include('base')
39
+ end
40
+ end
41
+
42
+ it "should initialize the specified command" do
43
+ GitPusshuTen::Command.any_instance.stubs(:exit)
44
+ GitPusshuTen::Log.stubs(:error)
45
+
46
+ GitPusshuTen::Commands::NonExistingCommand.expects(:new).with(cli, configuration, hooks, environment)
47
+
48
+ command = GitPusshuTen::Command.new(cli, configuration, hooks, environment)
49
+ command.stubs(:commands_directory).returns([Dir.pwd + '/commands/mock_tag.rb'])
50
+ command.command
51
+ end
52
+
53
+ describe "perform hooks" do
54
+ let(:command_initializer) { GitPusshuTen::Command.new(cli, configuration, hooks, environment) }
55
+ let(:command) { command_initializer.command }
56
+
57
+ before do
58
+ GitPusshuTen::Command.any_instance.stubs(:exit)
59
+ GitPusshuTen::Log.stubs(:error)
60
+ command.stubs(:validate!)
61
+ end
62
+
63
+ it "should invoke a pre-perform hook" do
64
+ command.expects(:pre_perform!).once
65
+ command.stubs(:post_perform!)
66
+ command_initializer.perform!
67
+ end
68
+
69
+ it "should invoke a post-perform hook" do
70
+ command.expects(:post_perform!).once
71
+ command.stubs(:pre_perform!)
72
+ command_initializer.perform!
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Configuration do
4
+
5
+ let(:configuration) { GitPusshuTen::Configuration.new(:staging) }
6
+
7
+ describe 'the environment name' do
8
+ it "should contain the remote environment" do
9
+ configuration.environment.should == :staging
10
+ end
11
+
12
+ it "should be a symbol object" do
13
+ GitPusshuTen::Log.expects(:error).with('Please use symbols as environment name.')
14
+ configuration.expects(:exit)
15
+ configuration.pusshuten('notasymbol', 'RSpec Production Example Application')
16
+ end
17
+ end
18
+
19
+ describe '#parse!' do
20
+ before do
21
+ configuration.parse!(File.dirname(__FILE__) + '/fixtures/config.rb')
22
+ end
23
+
24
+ it "should extract the application and remote branch names from the staging branch" do
25
+ configuration.application.should == 'RSpec Staging Example Application'
26
+ end
27
+
28
+ it "should parse the authorization details" do
29
+ configuration.user.should == 'git'
30
+ configuration.password.should == 'testtest'
31
+ configuration.passphrase.should == 'myphrase'
32
+ configuration.ip.should == '123.45.678.910'
33
+ configuration.port.should == '20'
34
+
35
+ configuration.path.should == '/var/apps/'
36
+
37
+ configuration.additional_modules.should == [:nginx, :passenger, :active_record]
38
+ end
39
+
40
+ it "should return self" do
41
+ configuration.should == configuration.parse!(File.dirname(__FILE__) + '/fixtures/config.rb')
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Environment do
4
+
5
+ let(:cli) { GitPusshuTen::CLI.new(%w[tag 1.4.2 to staging]) }
6
+ let(:configuration_file) { File.expand_path(File.dirname(__FILE__) + '/fixtures/config.rb') }
7
+ let(:configuration) { GitPusshuTen::Configuration.new(cli.environment).parse!(configuration_file) }
8
+ let(:environment) { GitPusshuTen::Environment.new(configuration) }
9
+
10
+ it "should initialize based on the provided configuration" do
11
+ environment.configuration.should be_an_instance_of(GitPusshuTen::Configuration)
12
+ end
13
+
14
+ describe '#app_dir' do
15
+ it "should be the <path>/<application>.<environment>" do
16
+ environment.app_dir.should == '/var/apps/rspec_staging_example_application.staging'
17
+ end
18
+ end
19
+
20
+ describe '#name' do
21
+ it "should return the name of the environment we're working in" do
22
+ environment.name.should == :staging
23
+ end
24
+ end
25
+
26
+ describe '#delete!' do
27
+ it "should delete the application root" do
28
+ environment.expects(:execute_as_user).with('rm -rf /var/apps/rspec_staging_example_application.staging')
29
+ environment.delete!
30
+ end
31
+ end
32
+
33
+ describe 'the ssh methods' do
34
+ describe '#authorized_ssh_keys' do
35
+ it do
36
+ environment.expects(:execute_as_root).with("cat '/var/apps/.ssh/authorized_keys'")
37
+ environment.authorized_ssh_keys
38
+ end
39
+ end
40
+
41
+ describe '#install_ssh_key!' do
42
+ it do
43
+ environment.expects(:ssh_key).returns('mysshkey')
44
+ environment.expects(:execute_as_root).with("mkdir -p '/var/apps/.ssh';echo 'mysshkey' >> '/var/apps/.ssh/authorized_keys';chown -R git:git '/var/apps/.ssh';chmod 700 '/var/apps/.ssh'; chmod 600 '/var/apps/.ssh/authorized_keys'")
45
+ environment.install_ssh_key!
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#download_packages!' do
51
+ it "should download the gitpusshuten packages" do
52
+ environment.expects(:execute_as_user).with("cd /var/apps/; git clone git://github.com/meskyanichi/gitpusshuten-packages.git")
53
+ environment.download_packages!('/var/apps/')
54
+ end
55
+ end
56
+
57
+ describe '#clean_up_packages!' do
58
+ it "should delete them as root" do
59
+ environment.expects(:execute_as_user).with("cd /var/apps; rm -rf gitpusshuten-packages")
60
+ environment.clean_up_packages!('/var/apps')
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,23 @@
1
+ perform_on :staging, :production do
2
+ pre :remove_output do
3
+ run 'rm -rf output'
4
+ end
5
+
6
+ post :render_output do
7
+ run 'rake render:output'
8
+ end
9
+ end
10
+
11
+ perform_on :staging do
12
+ post :clear_whitespace do
13
+ run 'rake clear:whitespace'
14
+ run 'rake flush'
15
+ end
16
+ end
17
+
18
+ perform_on :production do
19
+ pre :update_vhost do
20
+ run 'webserver update vhost'
21
+ run 'webserver restart'
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ pusshuten 'RSpec Staging Example Application', :staging do
2
+
3
+ configure do |c|
4
+ c.user = 'git'
5
+ c.password = 'testtest'
6
+ c.passphrase = 'myphrase'
7
+ c.ip = '123.45.678.910'
8
+ c.port = '20'
9
+
10
+ c.path = '/var/apps/'
11
+ end
12
+
13
+ modules do |m|
14
+ m.add :nginx
15
+ m.add :passenger
16
+ m.add :active_record
17
+ end
18
+
19
+ end
20
+
21
+ pusshuten 'RSpec Production Example Application', :production do
22
+
23
+ end
@@ -0,0 +1,37 @@
1
+ perform_on :staging do
2
+ pre :remove_output do
3
+ run 'rm -rf output'
4
+ end
5
+
6
+ post :render_output do
7
+ run 'rake render:output'
8
+ end
9
+
10
+ post :restart_nginx_and_passenger do
11
+ run '/etc/init.d/nginx stop'
12
+ run 'sleep 1'
13
+ run '/etc/init.d/nginx start'
14
+ run 'mkdir tmp'
15
+ run 'touch tmp/restart.txt'
16
+ end
17
+
18
+ post :ensure_correct_branch do
19
+ run 'git commit -am "Commit and Ensuring"'
20
+ run 'git checkout master'
21
+ end
22
+ end
23
+
24
+ perform_on :production do
25
+ pre :maintenance_on do
26
+ run 'mv public/maintenance_off.html public/maintenance.html'
27
+ end
28
+
29
+ pre :clean_up_local do
30
+ run 'rake remove:trash'
31
+ end
32
+
33
+ post :update_vhost do
34
+ run 'webserver update vhost'
35
+ run 'webserver restart'
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ {"dependencies":{"runtime":[{"name":"rack","requirements":">= 0"},{"name":"file-tail","requirements":">= 0"},{"name":"daemon_controller","requirements":">= 0.2.5"},{"name":"fastthread","requirements":">= 1.0.1"},{"name":"rake","requirements":">= 0.8.1"}],"development":[]},"name":"passenger","downloads":333050,"info":"Easy and robust Ruby web application deployment.","version_downloads":25851,"version":"3.0.0","homepage_uri":"http://www.modrails.com/","bug_tracker_uri":"http://code.google.com/p/phusion-passenger/issues/list","source_code_uri":"http://github.com/FooBarWidget/passenger","gem_uri":"http://rubygems.org/gems/passenger-3.0.0.gem","project_uri":"http://rubygems.org/gems/passenger","authors":"Phusion - http://www.phusion.nl/","mailing_list_uri":"http://groups.google.com/group/phusion-passenger","documentation_uri":"http://www.modrails.com/documentation.html","wiki_uri":""}
data/spec/gem_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Gem do
4
+
5
+ before do
6
+ GitPusshuTen::Gem.any_instance.stubs(:base_url).returns(File.dirname(__FILE__) + '/fixtures')
7
+ end
8
+
9
+ it "should return the latest version of the Passenger gem" do
10
+ GitPusshuTen::Gem.new(:passenger).latest_version.should match /\d+\.\d+\..+/
11
+ end
12
+
13
+ describe "#outdated" do
14
+ it "should be outdated" do
15
+ gem = GitPusshuTen::Gem.new(:passenger)
16
+ gem.stubs(:latest_version).returns('3.0.0')
17
+ gem.outdated?('2.9.3').should be_true
18
+ end
19
+
20
+ it "should not be outdated" do
21
+ gem = GitPusshuTen::Gem.new(:passenger)
22
+ gem.stubs(:latest_version).returns('3.0.0')
23
+ gem.outdated?('3.0.0').should be_false
24
+ gem.outdated?('3.0.1').should be_false
25
+ end
26
+ end
27
+
28
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Git do
4
+
5
+ let(:git) { GitPusshuTen::Git.new }
6
+
7
+ before do
8
+ %x(git remote rm rspec_staging) if %x(git remote) =~ /rspec_staging/
9
+ end
10
+
11
+ describe '#has_remote?' do
12
+ it 'should be able to see if a remote already exists' do
13
+ git.has_remote?(:rspec_staging).should be_false
14
+ end
15
+
16
+ it 'should have a remote called staging' do
17
+ git.expects(:git).with('remote').returns('origin production rspec_staging')
18
+ git.has_remote?(:rspec_staging).should be_true
19
+ end
20
+ end
21
+
22
+ describe '#add_remote' do
23
+ it 'should add a remote with the specified url' do
24
+ git.expects(:git).with('remote add rspec_staging someurl')
25
+ git.add_remote(:rspec_staging, 'someurl')
26
+ end
27
+ end
28
+
29
+ describe '#remove_remote' do
30
+ it 'should remove a remote' do
31
+ git.expects(:git).with('remote rm rspec_staging')
32
+ git.remove_remote(:rspec_staging)
33
+ end
34
+ end
35
+
36
+ describe '#pushing to a remote' do
37
+ context 'when pushing a tag' do
38
+ it 'should push a tag to the remote' do
39
+ git.expects(:git).with('push rspec_staging 1.4.2~0:refs/heads/master --force')
40
+ git.push(:tag, '1.4.2').to(:rspec_staging)
41
+ end
42
+ end
43
+
44
+ context 'when pushing a branch' do
45
+ it 'should push a branch to the remote' do
46
+ git.expects(:git).with('push rspec_staging development:refs/heads/master --force')
47
+ git.push(:branch, :development).to(:rspec_staging)
48
+ end
49
+ end
50
+
51
+ context 'when pushing a ref' do
52
+ it 'should push a ref to the remote' do
53
+ git.expects(:git).with('push rspec_staging ad36b4c018f7580db48c20fa4ed7911ea50a5684:refs/heads/master --force')
54
+ git.push(:ref, 'ad36b4c018f7580db48c20fa4ed7911ea50a5684').to(:rspec_staging)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen do
4
+
5
+ it "should return the version" do
6
+ GitPusshuTen::VERSION.should be_a(String)
7
+ end
8
+
9
+ end
data/spec/hook_spec.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Hook do
4
+
5
+ describe 'assigning a name' do
6
+ it "should assign a name" do
7
+ GitPusshuTen::Hook.new({
8
+ :name => :restart_webserver
9
+ }).name.should eql :restart_webserver
10
+ end
11
+ end
12
+
13
+ describe 'assigning a type' do
14
+ it "should set up a new pre hook" do
15
+ GitPusshuTen::Hook.new({
16
+ :type => :pre
17
+ }).type.should eql :pre
18
+ end
19
+
20
+ it "should set up a new post hook" do
21
+ GitPusshuTen::Hook.new({
22
+ :type => :post
23
+ }).type.should eql :post
24
+ end
25
+ end
26
+
27
+ describe 'assigning commands' do
28
+ it "should be nil if no commands are specified" do
29
+ hook = GitPusshuTen::Hook.new({
30
+ :commands => []
31
+ })
32
+
33
+ hook.commands.count.should == 0
34
+ end
35
+
36
+ it "should have an array of commands to run" do
37
+ hook = GitPusshuTen::Hook.new({
38
+ :commands => ['rm -rf *', 'killall', '/etc/init.d/nginx stop']
39
+ })
40
+
41
+ hook.commands.count.should == 3
42
+ hook.commands[0].should == 'rm -rf *'
43
+ hook.commands[1].should == 'killall'
44
+ hook.commands[2].should == '/etc/init.d/nginx stop'
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPusshuTen::Hooks do
4
+
5
+ let(:cli) { GitPusshuTen::CLI.new(%w[tag 1.4.2 to staging]) }
6
+ let(:configuration_file) { File.expand_path(File.dirname(__FILE__) + '/fixtures/config.rb') }
7
+ let(:configuration) { GitPusshuTen::Configuration.new(cli.environment).parse!(configuration_file) }
8
+ let(:hooks_staging) { GitPusshuTen::Hooks.new(:staging, configuration) }
9
+ let(:hooks_production) { GitPusshuTen::Hooks.new(:production, configuration) }
10
+
11
+ describe '#new' do
12
+ it "should intialize a new hooks object that takes a path to the hooks file as argument" do
13
+ hooks_staging
14
+ end
15
+
16
+ it "should set the environment" do
17
+ hooks_staging.environment.should == :staging
18
+ hooks_production.environment.should == :production
19
+ end
20
+ end
21
+
22
+ describe '#parse!' do
23
+ it "return the object instance itself" do
24
+ hooks_staging.should == hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb'))
25
+ hooks_production.should == hooks_production.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb'))
26
+ end
27
+
28
+ context "when the hooks file does not exist" do
29
+ it "should issue a warning" do
30
+ GitPusshuTen::Log.expects(:warning).with("Could not locate the hooks.rb file in /Users/Michael/Desktop/GitPusshuTen/spec/fixtures/hooks_not_exist.rb")
31
+ hooks_staging.should == hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks_not_exist.rb'))
32
+ end
33
+
34
+ it "should not attempt to parse it" do
35
+ GitPusshuTen::Log.stubs(:warning)
36
+ hooks_staging.expects(:instance_eval).never
37
+ hooks_staging.should == hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks_not_exist.rb'))
38
+ end
39
+ end
40
+
41
+ it "should parse if the hooks file eixsts" do
42
+ hooks_staging.expects(:instance_eval).once
43
+ hooks_staging.should == hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb'))
44
+ end
45
+
46
+ describe 'storing parsed information' do
47
+ before do
48
+ hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb'))
49
+ hooks_production.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb'))
50
+ end
51
+
52
+ it "should load the hooks.rb file and parse it, setting values to the instance" do
53
+ hooks_staging.to_perform.size.should == 4
54
+ hooks_production.to_perform.size.should == 3
55
+ end
56
+
57
+ it "should have 1 pre hook and 3 post hooks" do
58
+ hooks_staging.pre_hooks.count.should == 1
59
+ hooks_staging.post_hooks.count.should == 3
60
+ end
61
+
62
+ it "should have 2 pre hook and 1 post hooks" do
63
+ hooks_production.pre_hooks.count.should == 2
64
+ hooks_production.post_hooks.count.should == 1
65
+ end
66
+
67
+ it "should extract the commands that must be run and add them as an array to the hook" do
68
+ hook_file_commands = ['rm -rf output', 'rake render:output', '/etc/init.d/nginx stop']
69
+ hook_file_commands += ['sleep 1', '/etc/init.d/nginx start', 'mkdir tmp', 'touch tmp/restart.txt']
70
+ hook_file_commands += ['git commit -am "Commit and Ensuring"', 'git checkout master']
71
+ hook_file_commands += ['mv public/maintenance_off.html public/maintenance.html', 'rake remove:trash']
72
+ hook_file_commands += ['webserver update vhost', 'webserver restart']
73
+
74
+ hooks_staging.to_perform.each do |hook|
75
+ hook.commands.each do |command|
76
+ hook_file_commands.should include(command)
77
+ end
78
+ end
79
+
80
+ hooks_production.to_perform.each do |hook|
81
+ hook.commands.each do |command|
82
+ hook_file_commands.should include(command)
83
+ end
84
+ end
85
+
86
+ hooks_staging.pre_hooks[0].commands.first.should == 'rm -rf output'
87
+ hooks_staging.post_hooks[1].commands.last.should == 'touch tmp/restart.txt'
88
+ hooks_production.post_hooks[0].commands.first.should == 'webserver update vhost'
89
+ hooks_production.post_hooks[0].commands.last.should == 'webserver restart'
90
+ end
91
+ end
92
+
93
+ describe 'storing parsed information from a combined config' do
94
+ before do
95
+ hooks_staging.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/combined_hooks.rb'))
96
+ hooks_production.parse!(File.expand_path(File.dirname(__FILE__) + '/fixtures/combined_hooks.rb'))
97
+ end
98
+
99
+ it "should load the hooks.rb file and parse it, setting values to the instance" do
100
+ hooks_staging.to_perform.size.should == 3
101
+ hooks_production.to_perform.size.should == 3
102
+ end
103
+
104
+ it "should have 1 pre hook and 3 post hooks" do
105
+ hooks_staging.pre_hooks.count.should == 1
106
+ hooks_staging.post_hooks.count.should == 2
107
+ end
108
+
109
+ it "should have 2 pre hook and 1 post hooks" do
110
+ hooks_production.pre_hooks.count.should == 2
111
+ hooks_production.post_hooks.count.should == 1
112
+ end
113
+
114
+ it "should extract the commands that must be run and add them as an array to the hook" do
115
+ hooks_staging.pre_hooks[0].commands[0].should == 'rm -rf output'
116
+ hooks_staging.post_hooks[0].commands[0].should == 'rake render:output'
117
+ hooks_staging.post_hooks[1].commands[0].should == 'rake clear:whitespace'
118
+ hooks_staging.post_hooks[1].commands[1].should == 'rake flush'
119
+
120
+ hooks_production.pre_hooks[0].commands[0].should == 'rm -rf output'
121
+ hooks_production.pre_hooks[1].commands[0].should == 'webserver update vhost'
122
+ hooks_production.pre_hooks[1].commands[1].should == 'webserver restart'
123
+ hooks_production.post_hooks[0].commands[0].should == 'rake render:output'
124
+ end
125
+ end
126
+ end
127
+
128
+ describe 'the hooks' do
129
+
130
+ let(:cli) { GitPusshuTen::CLI.new(%w[tag 1.4.2 to staging]) }
131
+ let(:configuration_file) { File.expand_path(File.dirname(__FILE__) + '/fixtures/config.rb') }
132
+ let(:configuration) { GitPusshuTen::Configuration.new(cli.environment).parse!(configuration_file) }
133
+ let(:hooks_file) { File.expand_path(File.dirname(__FILE__) + '/fixtures/hooks.rb') }
134
+ let(:hooks) { GitPusshuTen::Hooks.new(cli.environment, configuration).parse!(hooks_file) }
135
+ let(:environment) { GitPusshuTen::Environment.new(configuration) }
136
+ let(:command) { GitPusshuTen::Commands::NonExistingCommand.new(cli, configuration, hooks, environment) }
137
+
138
+ describe '#render_commands_as_string' do
139
+ it do
140
+ hooks.render_commands(hooks.post_hooks).should == {
141
+ :render_output => 'rake render:output;',
142
+ :restart_nginx_and_passenger => '/etc/init.d/nginx stop;sleep 1;/etc/init.d/nginx start;mkdir tmp;touch tmp/restart.txt;',
143
+ :ensure_correct_branch => 'git commit -am "Commit and Ensuring";git checkout master;'
144
+ }
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ end