MS IZ request acceptance email

This commit is contained in:
ilya 2010-10-22 11:55:50 -07:00
parent 47b03c45b2
commit 9a217d1fa8
7 changed files with 132 additions and 19 deletions

View file

@ -4,7 +4,18 @@ class Notifier < ActionMailer::Base
def new_request(recipient, sender)
@receiver = recipient
@sender = sender
attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png")
mail(:to => "#{recipient.real_name} <#{recipient.email}>",
:subject => "new Diaspora* friend request from #{@sender.real_name}")
:subject => "new Diaspora* friend request from #{@sender.real_name}", :host => APP_CONFIG[:terse_pod_url])
end
def request_accepted(recipient, sender, aspect)
@receiver = recipient
@sender = sender
@aspect = aspect
attachments["diaspora_white.png"] = File.read("#{Rails.root}/public/images/diaspora_white.png")
mail(:to => "#{recipient.real_name} <#{recipient.email}>",
:subject => "#{@sender.real_name} has accepted your friend request on Diaspora*", :host => APP_CONFIG[:terse_pod_url])
end
end

View file

@ -43,7 +43,7 @@
}
%body
%header
= image_tag '/images/diaspora_white.png'
= image_tag 'diaspora_white.png'
#container
%p
Hello #{@receiver.profile.first_name}!

View file

@ -0,0 +1,59 @@
!!!
%html
%head
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
:css
body{
width:600px;
font-family:'Arial','Helvetica',sans-serif;
font-size:14px;
color:#333;
}
#container{
margin-bottom:25px
min-height:400px;
padding-left:15px;
}
header{
background-color:#333;
padding: 15px;
margin-bottom: 25px;
}
p{
padding:5px;
}
p.small{
font-size:smaller;
color:#999;
font-style:italic;
}
a{
color:#107FC9;
font-weight:bold;
}
a:hover{
color: #22AAE0;
}
a:active{
color: #005D9C;
}
.large_text{
font-size:21px;
font-family:"Helvetica Neue",Arial,Helvetica,sans-serif;
}
%body
%header
= image_tag 'diaspora_white.png'
#container
%p
Hello #{@receiver.profile.first_name}!
%p
= "#{@sender.real_name} (#{@sender.diaspora_handle})"
has accepted your friend request. They are now in your
= link_to @aspect.name, aspect_url(@aspect)
aspect.
%br
love,
%br
the diaspora email robot

View file

@ -0,0 +1,9 @@
= "hey #{@receiver.profile.first_name},"
= "#{@sender.real_name} (#{@sender.diaspora_handle})"
has accepted your friend request. They are now in your
= "#{@aspect.name} asepct.\n"
= "#{aspect_url(@aspect)}"
love, \n
the diaspora email robot

View file

@ -64,13 +64,16 @@ module Diaspora
def receive_friend_request(friend_request)
Rails.logger.info("receiving friend request #{friend_request.to_json}")
#response from a friend request you sent
if request_from_me?(friend_request) && self.aspect_by_id(friend_request.aspect_id)
aspect = self.aspect_by_id(friend_request.aspect_id)
activate_friend(friend_request.person, aspect)
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
Notifier.request_accepted(self, friend_request.person, aspect).deliver
friend_request.destroy
#this is a new friend request
else
self.pending_requests << friend_request
self.save

View file

@ -4,8 +4,11 @@ require 'spec_helper'
describe Notifier do
let!(:user) {Factory.create :user}
let!(:aspect) {user.aspect(:name => "science")}
let!(:person) {Factory.create :person}
let!(:request_mail) {Notifier.new_request(user, person)}
let!(:request_accepted_mail) {Notifier.request_accepted(user, person, aspect)}
describe "#new_request" do
it 'goes to the right person' do
@ -21,4 +24,23 @@ describe Notifier do
request_mail.body.encoded.include?(person.real_name).should be true
end
end
describe "#request_accpeted" do
it 'goes to the right person' do
request_accepted_mail.to.should == [user.email]
end
it 'has the receivers name in the body' do
request_accepted_mail.body.encoded.include?(user.person.profile.first_name).should be true
end
it 'has the name of person sending the request' do
request_accepted_mail.body.encoded.include?(person.real_name).should be true
end
it 'has the name of the aspect in the body' do
request_accepted_mail.body.encoded.include?(aspect.name).should be true
end
end
end

View file

@ -5,7 +5,7 @@
require 'spec_helper'
describe User do
describe Diaspora::UserModules::Friending do
let(:user) { Factory.create :user }
let(:aspect) { user.aspect(:name => 'heroes') }
let(:aspect1) { user.aspect(:name => 'other') }
@ -21,6 +21,7 @@ describe User do
deliverable = Object.new
deliverable.stub!(:deliver)
Notifier.stub!(:new_request).and_return(deliverable)
Notifier.stub!(:request_accepted).and_return(deliverable)
end
context 'friend requesting' do
@ -61,6 +62,13 @@ describe User do
proc { user.send_friend_request_to(nil, aspect) }.should raise_error(RuntimeError, /befriend yourself/)
end
it 'should send an email on acceptance if a friend request' do
Notifier.should_receive(:request_accepted)
request = user.send_friend_request_to(user2.person, aspect)
request.reverse_for(user2)
user.receive_friend_request(request)
end
describe 'multiple users accepting/rejecting the same person' do
@ -108,9 +116,7 @@ describe User do
user.receive @req_xml, person_one
end
it 'should send a an email saying your friend request was confirmed' do
pending
end
end
context 'Two users receiving requests from one person' do
before do
@ -118,21 +124,24 @@ describe User do
user2.receive @req_two_xml, person_one
end
it 'should both users should befriend the same person' do
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
describe '#accept_friend_request' do
it 'should both users should befriend the same person' do
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
user2.accept_friend_request @request_two.id, aspect2.id
user2.friends.include?(person_one).should be true
user2.accept_friend_request @request_two.id, aspect2.id
user2.friends.include?(person_one).should be true
end
it 'should keep the person around if one of the users rejects him' do
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
user2.ignore_friend_request @request_two.id
user2.friends.include?(person_one).should be false
end
end
it 'should keep the person around if one of the users rejects him' do
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
user2.ignore_friend_request @request_two.id
user2.friends.include?(person_one).should be false
end
it 'should keep the person around if the users ignores them' do
user.ignore_friend_request user.pending_requests.first.id