public
Rubygem
Description: Bang! You've deployed!
Homepage: http://opensource.thinkrelevance.com/
Clone URL: git://github.com/relevance/cap_gun.git
specing out things
rsanheim (author)
Fri Apr 04 08:51:34 -0700 2008
commit  6b81673475488f297919c43a3c0d7dbe4a1a3090
tree    d56987d9db38855a03ee1165d005be31685e1887
parent  9ca35810008e140b39e62cf340fe9987c4d9b1aa
...
29
30
31
 
32
33
34
35
36
37
38
39
40
41
42
43
44
 
45
46
 
 
 
 
 
47
48
49
50
51
 
 
 
52
53
54
55
56
57
58
 
59
60
61
...
71
72
73
74
 
 
 
 
 
75
76
77
...
90
91
92
93
94
95
96
97
98
...
29
30
31
32
33
 
 
34
35
36
37
 
 
 
 
 
 
38
39
 
40
41
42
43
44
45
46
47
 
 
48
49
50
51
52
53
54
55
56
 
57
58
59
60
...
70
71
72
 
73
74
75
76
77
78
79
80
...
93
94
95
 
96
 
97
98
99
0
@@ -29,33 +29,32 @@ module CapGun
0
 
0
   module Helper
0
     
0
+ # Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config"
0
     def load_mailer_config(cap)
0
- #mailer_config = File.open("#{rails_root}/config/cap_gun_config.yml")
0
- #mailer_options = YAML.load(mailer_config)
0
       raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
0
       ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
0
     end
0
   
0
- # Capistrano doesn't set this for some reason
0
- def rails_root
0
- Object.const_set("RAILS_ROOT", File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. ..]))) unless Object.const_defined?("RAILS_ROOT")
0
- RAILS_ROOT
0
- end
0
-
0
+ # Current user - unsupported on Windows
0
     def current_user
0
- `id -un`.strip
0
+ platform.include?('mswin') ? nil : `id -un`.strip
0
+ end
0
+
0
+ def platform
0
+ RUBY_PLATFORM
0
     end
0
   
0
     def time_from_release(path, timezone)
0
- timestamp = path[(path.rindex("/") + 1)..-1]
0
- datetime = DateTime.parse(timestamp)
0
+ match = path.match(/(\d+)$/)
0
+ return unless match
0
+ datetime = DateTime.parse(match[1])
0
       datetime.strftime("%B #{datetime.day.ordinalize}, %Y %l:%M %p #{timezone}").gsub(/\s+/, ' ').strip
0
     end
0
     
0
     extend self
0
   end
0
   
0
- class Mailer < ActionMailer::Base
0
+ class Mailer < ActionMailer::Base
0
       include CapGun::Helper
0
       DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>)
0
 
0
@@ -71,7 +70,11 @@ module CapGun
0
         recipients options[:recipients]
0
         from options[:sender_address] || DEFAULT_SENDER
0
 
0
- body <<-EOL
0
+ body create_body(capistrano)
0
+ end
0
+
0
+ def create_body(capistrano)
0
+<<-EOL
0
 #{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{time_from_release(capistrano[:current_release], capistrano[:timezone])}.
0
 
0
 Comment: #{capistrano[:comment] || "[none given]"}
0
@@ -90,9 +93,7 @@ Repository: #{capistrano[:repository]}
0
 Deploy path: #{capistrano[:deploy_to]}
0
 EOL
0
       end
0
-
0
     end
0
-
0
 
0
 end
0
 
...
13
14
15
16
 
 
 
 
 
 
 
 
17
18
19
20
 
 
 
 
 
21
22
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
30
 
 
 
 
 
 
 
 
 
 
 
31
 
32
33
34
...
13
14
15
 
16
17
18
19
20
21
22
23
24
 
 
 
25
26
27
28
29
30
31
 
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
0
@@ -13,22 +13,58 @@ describe "CapGun" do
0
 end
0
 
0
 describe "CapGun" do
0
- include CapGun::Helper
0
+
0
+ describe "mail settings" do
0
+ include CapGun::Helper
0
+
0
+ it "raises if we dont have settings" do
0
+ capistrano = stub_everything
0
+ lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
0
+ end
0
   
0
- it "raises if we dont have settings" do
0
- capistrano = stub_everything
0
- lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
0
+ it "gets action mailer config from capistrano" do
0
+ capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"})
0
+ CapGun::Helper.load_mailer_config(capistrano)
0
+ ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
0
+ end
0
   end
0
   
0
- it "gets action mailer config from capistrano" do
0
- capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"})
0
- CapGun::Helper.load_mailer_config(capistrano)
0
- ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
0
+ describe "misc helpers" do
0
+ include CapGun::Helper
0
+
0
+ it "returns nil for current user if platform is win32" do
0
+ expects(:platform).returns("mswin")
0
+ current_user.should.be nil
0
+ end
0
+
0
+ it "should get current user from *nix id command" do
0
+ expects(:"`").with('id -un').returns("joe")
0
+ current_user
0
+ end
0
+
0
+ it "returns nil for weird release path" do
0
+ time_from_release("/data/foo/my_release", "PDT").should == nil
0
+ end
0
+
0
+ it "parse datetime from release path" do
0
+ time_from_release("/data/foo/releases/20080402152141", "PDT").should == "April 2nd, 2008 3:21 PM PDT"
0
+ end
0
+
0
   end
0
   
0
- it "parses datetime from release path" do
0
- time_from_release("/data/foo/releases/20080402152141", "PDT").should == "April 2nd, 2008 3:21 PM PDT"
0
+ describe "Mailer" do
0
+ it "raises if we dont have at least one recipient" do
0
+ end
0
+
0
+ it "passes capistrano into create body" do
0
+ capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_options => {:recipients => "joe@example.com"} }
0
+ CapGun::Mailer.any_instance.expects(:create_body).with(capistrano).returns("foo")
0
+ CapGun::Mailer.create_deployment_notification capistrano
0
+
0
+ end
0
+
0
   end
0
+
0
 end
0
 
0
 

Comments

    No one has commented yet.