capistrano_mailer 3.2.7 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :show do
4
+ task :me do
5
+ set :task_name, task_call_frames.first.task.fully_qualified_name
6
+ end
7
+ end
8
+
9
+ namespace :deploy do
10
+ desc "Send email notification of deployment"
11
+ task :notify, :roles => :app do
12
+ show.me # this sets the task_name variable
13
+
14
+ # Set the release notes
15
+ git_commits_range = "#{previous_revision.strip}..#{current_revision.strip}"
16
+ git_log = `git log --pretty=oneline --abbrev-commit #{git_commits_range}` # executes in local shell
17
+ set :release_notes, git_log.blank? ? "No Changes since last deploy." : "from git:\n" + git_log
18
+
19
+ # These are overridden by the configuration in the block:
20
+ # CapMailer.configure do |config|
21
+ # config[:attach_log_on] = [:failure]
22
+ # end
23
+ mailer.send_notification_email(self, {
24
+ #:attach_log_on => [:success, :failure],
25
+ :release_notes => release_notes
26
+ })
27
+ end
28
+
29
+ # This is to test hte cap mailer notification system.
30
+ # Execute:
31
+ # bundle exec cap staging deploy:nothing
32
+ task :nothing, :roles => :app do
33
+ puts "DOING NOTHING!"
34
+ set :release_notes, "No Changes since last deploy."
35
+ end
36
+
37
+ end
38
+
39
+ after "deploy", "deploy:notify"
40
+
41
+ after "deploy:nothing", "deploy:notify"
42
+
43
+ end
@@ -0,0 +1,2 @@
1
+ # Just a shim
2
+ require 'capistrano/mailer'
@@ -0,0 +1,3 @@
1
+ module CapistranoMailer
2
+ VERSION = "3.3.0"
3
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe "rvm:create_gemset task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @gemset = 'mygemset'
8
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
9
+ @task = @configuration.find_task 'rvm:create_gemset'
10
+ }
11
+
12
+ it "should create a gemset in $HOME" do
13
+ @configuration.trigger :load
14
+ expected = "$HOME/.rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}"
15
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
16
+ @configuration.execute_task @task
17
+ end
18
+
19
+ it "should create a system-wide gemset" do
20
+ @configuration.set :rvm_type, :system
21
+ @configuration.trigger :load
22
+ expected = <<-EOSHELL.gsub(/^ /, '')
23
+ if id | grep ' groups=.*(rvm)' >/dev/null ;
24
+ then /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset} ;
25
+ else sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}' ;
26
+ fi
27
+ EOSHELL
28
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
29
+ @configuration.execute_task @task
30
+ end
31
+
32
+ it "should create a gemset in $HOME in mixed mode" do
33
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
34
+ @configuration.set :rvm_type, :mixed
35
+ @configuration.set :rvm_user, [ :gemsets ]
36
+ @configuration.trigger :load
37
+ task = @configuration.find_task 'rvm:create_gemset'
38
+ expected = \
39
+ "/usr/local/rvm/bin/rvm 2.0.0 do rvm user gemsets ; " +
40
+ "/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create #{@gemset}"
41
+ task.namespace.should_receive(:run_without_rvm).with(expected)
42
+ @configuration.execute_task task
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm:create_gemset task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @configuration.require 'rvm/capistrano/empty_gemset'
8
+ @gemset = 'mygemset'
9
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
10
+ @task = @configuration.find_task 'rvm:empty_gemset'
11
+ }
12
+
13
+ it "should empty a gemset in $HOME" do
14
+ @configuration.trigger :load
15
+ expected = "$HOME/.rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset}"
16
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
17
+ @configuration.execute_task @task
18
+ end
19
+
20
+ it "should empty a system-wide gemset" do
21
+ @configuration.set :rvm_type, :system
22
+ @configuration.trigger :load
23
+ expected = <<-EOSHELL.gsub(/^ /, '')
24
+ if id | grep ' groups=.*(rvm)' >/dev/null ;
25
+ then /usr/local/rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset} ;
26
+ else sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm --force gemset empty #{@gemset}' ;
27
+ fi
28
+ EOSHELL
29
+ @task.namespace.should_receive(:run_without_rvm).with(expected)
30
+ @configuration.execute_task @task
31
+ end
32
+ end
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm:install_ruby task" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ before {
7
+ @gemset = 'mygemset'
8
+ @configuration.set :rvm_ruby_string, '2.0.0@' + @gemset
9
+ @task = @configuration.find_task 'rvm:install_ruby'
10
+ }
11
+
12
+ it "should install a ruby in $HOME" do
13
+ @configuration.trigger :load
14
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
15
+ __LAST_STATUS=0;
16
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
17
+ mkdir ${CURL_HOME}/;
18
+ {
19
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
20
+ echo \"silent\";
21
+ echo \"show-error\";
22
+ } > $CURL_HOME/.curlrc;
23
+ $HOME/.rvm/bin/rvm --autolibs=2 install 2.0.0 ;
24
+ $HOME/.rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
25
+ rm -rf $CURL_HOME;
26
+ exit ${__LAST_STATUS}
27
+ EOSHELL
28
+ @configuration.should_receive(:run_without_rvm).with(expected)
29
+ @configuration.execute_task @task
30
+ end
31
+
32
+ it "should install a ruby system-wide" do
33
+ @configuration.set :rvm_type, :system
34
+ @configuration.trigger :load
35
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
36
+ __LAST_STATUS=0;
37
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
38
+ mkdir ${CURL_HOME}/;
39
+ {
40
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
41
+ echo \"silent\";
42
+ echo \"show-error\";
43
+ } > $CURL_HOME/.curlrc;
44
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
45
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
46
+ else
47
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ' ;
48
+ fi ;
49
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
50
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset ;
51
+ else
52
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset' ;
53
+ fi || __LAST_STATUS=$?;
54
+ rm -rf $CURL_HOME;
55
+ exit ${__LAST_STATUS}
56
+ EOSHELL
57
+ @configuration.should_receive(:run_without_rvm).with(expected)
58
+ @configuration.execute_task @task
59
+ end
60
+
61
+ context "in mixed mode with user gemsets" do
62
+ before do
63
+ @configuration.set :rvm_type, :mixed
64
+ @configuration.set :rvm_user, [ :gemsets ]
65
+ @configuration.trigger :load
66
+ end
67
+
68
+ it "should install a ruby system-wide and create a user gemset" do
69
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
70
+ __LAST_STATUS=0;
71
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
72
+ mkdir ${CURL_HOME}/;
73
+ {
74
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
75
+ echo \"silent\";
76
+ echo \"show-error\";
77
+ } > $CURL_HOME/.curlrc;
78
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm user gemsets ;
79
+ if id | grep ' groups=.*(rvm)' >/dev/null ; then
80
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
81
+ else
82
+ sudo -p 'sudo password: ' sg rvm -c '/usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ' ;
83
+ fi ;
84
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
85
+ rm -rf $CURL_HOME;
86
+ exit ${__LAST_STATUS}
87
+ EOSHELL
88
+ @configuration.should_receive(:run_without_rvm).with(expected)
89
+ @configuration.execute_task @task
90
+ end
91
+ end
92
+
93
+ context "in mixed mode with user rubies and gemsets" do
94
+ before do
95
+ @configuration.set :rvm_type, :mixed
96
+ @configuration.set :rvm_user, [ :rubies, :gemsets ]
97
+ @configuration.trigger :load
98
+ end
99
+
100
+ it "should install a ruby and create a gemset in $HOME" do
101
+ expected = ' ' + <<-EOSHELL.gsub(/^\s+/, '').gsub("\n", ' ')
102
+ __LAST_STATUS=0;
103
+ export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\";
104
+ mkdir ${CURL_HOME}/;
105
+ {
106
+ [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
107
+ echo \"silent\";
108
+ echo \"show-error\";
109
+ } > $CURL_HOME/.curlrc;
110
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm user rubies gemsets ;
111
+ /usr/local/rvm/bin/rvm --autolibs=2 install 2.0.0 ;
112
+ /usr/local/rvm/bin/rvm 2.0.0 do rvm gemset create mygemset || __LAST_STATUS=$?;
113
+ rm -rf $CURL_HOME;
114
+ exit ${__LAST_STATUS}
115
+ EOSHELL
116
+ @configuration.should_receive(:run_without_rvm).with(expected)
117
+ @configuration.execute_task @task
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "rvm paths" do
4
+ include_context "Capistrano::Configuration"
5
+
6
+ describe "default values" do
7
+ before { @configuration.trigger(:load) }
8
+
9
+ it "should return default system path" do
10
+ @configuration.fetch(:rvm_system_path).should == '/usr/local/rvm'
11
+ end
12
+
13
+ it "should return default user path" do
14
+ @configuration.fetch(:rvm_user_path).should == '$HOME/.rvm'
15
+ end
16
+
17
+ it "should return default installation mode" do
18
+ @configuration.fetch(:rvm_type).should == :user
19
+ end
20
+
21
+ it "should return default path" do
22
+ @configuration.fetch(:rvm_path).should == '$HOME/.rvm'
23
+ end
24
+
25
+ it "should return default bin path" do
26
+ @configuration.fetch(:rvm_bin_path).should == '$HOME/.rvm/bin'
27
+ end
28
+
29
+ it "should return default gemset path" do
30
+ @configuration.fetch(:rvm_gemset_path).should == '$HOME/.rvm/gemsets'
31
+ end
32
+ end
33
+
34
+ describe "system mode" do
35
+ before do
36
+ @configuration.set(:rvm_type, :system)
37
+ @configuration.trigger(:load)
38
+ end
39
+
40
+ it "should return default path" do
41
+ @configuration.fetch(:rvm_path).should == '/usr/local/rvm'
42
+ end
43
+
44
+ it "should return system bin path" do
45
+ @configuration.fetch(:rvm_bin_path).should == '/usr/local/rvm/bin'
46
+ end
47
+
48
+ it "should return system gemset path" do
49
+ @configuration.fetch(:rvm_gemset_path).should == '/usr/local/rvm/gemsets'
50
+ end
51
+ end
52
+
53
+ describe "invalid configuration values" do
54
+ context "in :mixed mode" do
55
+ before { @configuration.set(:rvm_type, :mixed) }
56
+
57
+ it "should abort if rvm_type is :mixed and rvm_user empty" do
58
+ expect { @configuration.trigger(:load) }.to \
59
+ abort_with_error(/When rvm_type is :mixed, you must also set rvm_user/)
60
+ end
61
+
62
+ it "should abort if rvm_user isn't an Array" do
63
+ @configuration.set(:rvm_user, "a string")
64
+ expect { @configuration.trigger(:load) }.to \
65
+ abort_with_error(/rvm_user must be an Array/)
66
+ end
67
+
68
+ it "should abort if rvm_user contains an invalid value" do
69
+ @configuration.set(:rvm_user, [ :invalid_value ])
70
+ expect { @configuration.trigger(:load) }.to \
71
+ abort_with_error(/Invalid value\(s\) in rvm_user: invalid_value/)
72
+ end
73
+
74
+ it "should abort if rvm_user mixes :none with other values" do
75
+ @configuration.set(:rvm_user, [ :none, :gemsets ])
76
+ expect { @configuration.trigger(:load) }.to \
77
+ abort_with_error(/rvm_user cannot mix :none with other values/)
78
+ end
79
+
80
+ it "should abort if rvm_user mixes :all with other values" do
81
+ @configuration.set(:rvm_user, [ :gemsets, :all ])
82
+ expect { @configuration.trigger(:load) }.to \
83
+ abort_with_error(/rvm_user cannot mix :all with other values/)
84
+ end
85
+ end
86
+
87
+ it "should abort if rvm_user is set and rvm_type isn't :mixed" do
88
+ @configuration.set(:rvm_user, [ :gemsets ])
89
+ expect { @configuration.trigger(:load) }.to \
90
+ abort_with_error(/rvm_user must not be set unless rvm_type is :mixed/)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ # Requires supporting files with custom matchers and macros, etc,
2
+ # in ./support/ and its subdirectories.
3
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,42 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :abort_with_error do |message|
4
+ match do |block|
5
+ @block = block
6
+ with_fake_stderr do
7
+ @got_system_exit = false
8
+ begin
9
+ block.call
10
+ rescue SystemExit
11
+ @got_system_exit = true
12
+ @stderr = $stderr.string
13
+ message ? message === @stderr : true
14
+ else
15
+ false
16
+ end
17
+ end
18
+ end
19
+
20
+ description do
21
+ "blahhh"
22
+ end
23
+
24
+ failure_message_for_should do |actual|
25
+ if @got_system_exit
26
+ "expected STDERR to match " + \
27
+ ((message.is_a?(Regexp) ? "/%s/" : "'%s'") % message) + \
28
+ " but got:\n#{@stderr}"
29
+ else
30
+ "expected #{@block} to raise SystemExit"
31
+ end
32
+ end
33
+
34
+ # Fake STDERR and return a string written to it.
35
+ def with_fake_stderr
36
+ original_stderr = $stderr
37
+ $stderr = StringIO.new
38
+ yield
39
+ ensure
40
+ $stderr = original_stderr
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'capistrano-spec'
2
+ require 'capistrano'
3
+
4
+ RSpec.configure do |config|
5
+ config.include Capistrano::Spec::Matchers
6
+ config.include Capistrano::Spec::Helpers
7
+ end
8
+
9
+ shared_context "Capistrano::Configuration" do
10
+ before do
11
+ @configuration = Capistrano::Configuration.new
12
+ $:.unshift File.dirname(__FILE__) + '/../../lib'
13
+ # @configuration.load_paths.unshift File.dirname(__FILE__) + '/../../lib'
14
+ Capistrano::Configuration.instance = @configuration
15
+
16
+ # define _cset etc. from capistrano
17
+ @configuration.load 'deploy'
18
+
19
+ # load rvm/capistrano/base etc.
20
+ @configuration.require 'rvm/capistrano'
21
+
22
+ @configuration.extend(Capistrano::Spec::ConfigurationExtension)
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'yaml'
3
+ require 'rubygems/specification'
4
+
5
+ class BuildGemTest < Test::Unit::TestCase
6
+ def test_build_gem
7
+ data = File.read(File.join(File.dirname(__FILE__), '..', 'capistrano_mailer.gemspec'))
8
+ spec = nil
9
+
10
+ if data !~ %r{!ruby/object:Gem::Specification}
11
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
12
+ else
13
+ spec = YAML.load(data)
14
+ end
15
+
16
+ assert spec.validate
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5
+ <title><%= @site_name %> Notification </title>
6
+ </head>
7
+ <body style="font: 14px normal Helvetica, Arial, Sans; background: #999;">
8
+
9
+ <div style="width:800px; margin: 10px auto; background: #fff; border: 10px solid #aaa;">
10
+
11
+ <h1 style="clear: both; margin: 0; padding: 5px 20px 5px 20px; border-bottom: 1px dotted; background: #ccc;">
12
+ <%= @site_name %> <%=@task_name.titleize unless @task_name.nil? %>
13
+ </h1>
14
+
15
+ <% unless @site_url.nil? %>
16
+ <p style="margin: 8px 0 20px 20px; padding: 0px; font-style: italic;" >
17
+ View site: <a href="<%= @site_url -%>"><%= @site_url -%></a>
18
+ </p>
19
+ <% end %>
20
+
21
+ <p style="margin: 10px 20px; font-weight: bold;">Released: <%= @date %> at <%= @time %></p>
22
+
23
+ <%= @sections.map { |section|
24
+ data = @section_data[section.to_sym]
25
+ if !data.empty?
26
+ if %w(extra_information release_data).include?(section)
27
+ render :partial => 'section_custom.html.erb', :locals => {:section_title => section, :data => data}
28
+ else
29
+ render :partial => 'section.html.erb', :locals => {:section_title => section, :data => data}
30
+ end
31
+ end
32
+ }.join unless @sections.nil? %>
33
+ </div>
34
+
35
+ <p style="margin: 8px 0 20px 20px; padding: 0px; font-style: italic;" >
36
+ Brought to you by: <a href="http://github.com/textgoeshere/capistrano_mailer">Capistrano Mailer</a>
37
+ </p>
38
+ </body>
39
+ </html>