Skip to content

Commit

Permalink
don't try to display rails env if its not set
Browse files Browse the repository at this point in the history
  • Loading branch information
rsanheim committed May 27, 2008
1 parent 06a864c commit aebcb4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 9 additions & 2 deletions lib/cap_gun.rb
Expand Up @@ -53,6 +53,7 @@ def platform
# This assumes Capistrano uses UTC for its date/timestamped directories, and converts to the local
# machine timezone.
def humanize_release_time(path)
return unless path
match = path.match(/(\d+)$/)
return unless match
local = convert_from_utc(match[1])
Expand Down Expand Up @@ -86,8 +87,9 @@ class Mailer < ActionMailer::Base
DEFAULT_EMAIL_PREFIX = "[DEPLOY] "

adv_attr_accessor :email_prefix
attr_accessor :summary

# Grab the options for emaililng from cap_gun_email_envelope (should be set in your deploy file)
# Grab the options for emailing from cap_gun_email_envelope (should be set in your deploy file)
#
# Valid options:
# :recipients (required) an array or string of email address(es) that should get notifications
Expand All @@ -102,16 +104,21 @@ def init(envelope = {})
# Do the actual email
def deployment_notification(capistrano)
init(capistrano[:cap_gun_email_envelope])
self.summary = create_summary(capistrano)

content_type "text/plain"
subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}"
body create_body(capistrano)
end

def create_summary(capistrano)
%[#{capistrano[:application]} was deployed#{" to " << capistrano[:rails_env] if capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.]
end

# Create the body of the message using a bunch of values from Capistrano
def create_body(capistrano)
<<-EOL
#{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.
#{summary}
Comment: #{capistrano[:comment] || "[none given]"}
Expand Down
16 changes: 13 additions & 3 deletions spec/cap_gun_spec.rb
Expand Up @@ -110,10 +110,20 @@
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.from.should == ["booyakka!@example.com"]
end

xit "has a friendly summary line"
end

describe "creating body" do
it "has a friendly summary line" do
capistrano = { :application => "my app", :rails_env => "staging", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.body.split("\n").first.should == "my app was deployed to staging by rsanheim at February 27th, 2008 8:00 AM EDT."
end

xit "does not include rails env in summary if not defined"
it "does not include rails env in summary if not defined" do
capistrano = { :application => "my app", :current_release => "/data/foo/releases/20080227120000", :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.body.split("\n").first.should == "my app was deployed by rsanheim at February 27th, 2008 8:00 AM EDT."
end

end

Expand Down

0 comments on commit aebcb4f

Please sign in to comment.