Commit 13a85a2127d0a9c74f4e5cc5904f5c49ba4b008e

Authored by Jared Pace
1 parent cccdfbdc
Exists in master and in 1 other branch production

Add a watcher address that will be the user's email or the email listed on the w…

…atcher. Send to this address.
app/mailers/mailer.rb
@@ -6,7 +6,7 @@ class Mailer < ActionMailer::Base @@ -6,7 +6,7 @@ class Mailer < ActionMailer::Base
6 @app = notice.err.app 6 @app = notice.err.app
7 7
8 mail({ 8 mail({
9 - :to => @app.watchers.map(&:email), 9 + :to => @app.watchers.map(&:address),
10 :subject => "[#{@app.name}] #{@notice.err.message}" 10 :subject => "[#{@app.name}] #{@notice.err.message}"
11 }) 11 })
12 end 12 end
@@ -16,7 +16,7 @@ class Mailer < ActionMailer::Base @@ -16,7 +16,7 @@ class Mailer < ActionMailer::Base
16 @app = deploy.app 16 @app = deploy.app
17 17
18 mail({ 18 mail({
19 - :to => @app.watchers.map(&:email), 19 + :to => @app.watchers.map(&:address),
20 :subject => "[#{@app.name}] Deployed to #{@deploy.environment} by #{@deploy.username}" 20 :subject => "[#{@app.name}] Deployed to #{@deploy.environment} by #{@deploy.username}"
21 }) 21 })
22 end 22 end
app/models/watcher.rb
@@ -13,6 +13,10 @@ class Watcher @@ -13,6 +13,10 @@ class Watcher
13 user ? user.name : email 13 user ? user.name : email
14 end 14 end
15 15
  16 + def address
  17 + user.try(:email) || email
  18 + end
  19 +
16 protected 20 protected
17 21
18 def ensure_user_or_email 22 def ensure_user_or_email
spec/models/watcher_spec.rb
@@ -17,8 +17,19 @@ describe Watcher do @@ -17,8 +17,19 @@ describe Watcher do
17 watcher.user = Factory(:user) 17 watcher.user = Factory(:user)
18 watcher.should be_valid 18 watcher.should be_valid
19 end 19 end
  20 + end
  21 +
  22 + context 'address' do
  23 + it "returns the user's email address if there is a user" do
  24 + user = Factory(:user, :email => 'foo@bar.com')
  25 + watcher = Factory(:watcher, :user => user)
  26 + watcher.address.should == 'foo@bar.com'
  27 + end
20 28
21 - 29 + it "returns the email if there is no user" do
  30 + watcher = Factory(:watcher, :email => 'widgets@acme.com', :user => nil)
  31 + watcher.address.should == 'widgets@acme.com'
  32 + end
22 end 33 end
23 34
24 end 35 end