-
Notifications
You must be signed in to change notification settings - Fork 27
/
cap_gun_spec.rb
120 lines (91 loc) · 4.32 KB
/
cap_gun_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
ENV["RAILS_ENV"] = "test"
require 'rubygems'
require 'test/unit'
require 'test/spec'
require 'mocha'
require 'net/smtp'
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun])
describe "CapGun" do
it "uses action mailer hack" do
Net::SMTP.new('').respond_to?(:starttls, true).should == true
end
end
describe "CapGun" do
describe "mail settings" do
include CapGun::Helper
it "raises if we don't have settings" do
capistrano = stub_everything
lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
end
it "gets action mailer config from capistrano" do
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
capistrano.stubs(:[]).returns({:recipients => 'foo'})
CapGun::Helper.load_mailer_config(capistrano)
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
end
it "raises if we have no cap gun email envelope" do
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
end
it "raises if we don't have at least one recipient" do
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
end
end
describe "misc helpers" do
include CapGun::Helper
it "returns nil for current user if platform is win32" do
expects(:platform).returns("mswin")
current_user.should.be nil
end
it "should get current user from *nix id command" do
expects(:"`").with('id -un').returns("joe")
current_user
end
end
describe "handling release time" do
include CapGun::Helper
before do # make DateTime act as if local timezone is EDT
stubs(:local_timezone).returns("EDT")
stubs(:local_datetime_zone_offset).returns(Rational(-1,6))
end
it "returns nil for weird release path" do
humanize_release_time("/data/foo/my_release").should == nil
end
it "parse datetime from release path" do
humanize_release_time("/data/foo/releases/20080227120000").should == "February 27th, 2008 8:00 AM EDT"
end
it "converts time from release into localtime" do
humanize_release_time("/data/foo/releases/20080410040000").should == "April 10th, 2008 12:00 AM EDT"
end
end
describe "Mailer" do
it "passes capistrano into create body" do
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
CapGun::Mailer.any_instance.expects(:create_body).with(capistrano).returns("foo")
CapGun::Mailer.create_deployment_notification capistrano
end
end
describe "Mail envelope" do
before { CapGun::Mailer.any_instance.stubs(:create_body).returns("email body!") }
it "gets recipients from email envelope" do
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.to.should == ["foo@here.com", "bar@here.com"]
end
it "should have a default sender" do
capistrano = { :cap_gun_email_envelope => { :recipients => "foo@here.com" } }
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.from.should == ["cap_gun@example.com"]
end
it "should override sender from email envelope" do
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
mail = CapGun::Mailer.create_deployment_notification capistrano
mail.from.should == ["booyakka!@example.com"]
end
xit "has a friendly summary line"
xit "does not include rails env in summary if not defined"
end
end