From 9a217d1fa8386792c54d3417ae2e013a4e8bf25a Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 11:55:50 -0700 Subject: [PATCH] MS IZ request acceptance email --- app/mailers/notifier.rb | 13 +++- app/views/notifier/new_request.html.haml | 2 +- app/views/notifier/request_accepted.html.haml | 59 +++++++++++++++++++ app/views/notifier/request_accepted.text.haml | 9 +++ lib/diaspora/user/friending.rb | 5 +- spec/mailers/notifier_spec.rb | 22 +++++++ spec/models/user/user_friending_spec.rb | 41 ++++++++----- 7 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 app/views/notifier/request_accepted.html.haml create mode 100644 app/views/notifier/request_accepted.text.haml diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 40a94a1f3..f360f2a6f 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -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 diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml index 71932dc44..66bb56f1a 100644 --- a/app/views/notifier/new_request.html.haml +++ b/app/views/notifier/new_request.html.haml @@ -43,7 +43,7 @@ } %body %header - = image_tag '/images/diaspora_white.png' + = image_tag 'diaspora_white.png' #container %p Hello #{@receiver.profile.first_name}! diff --git a/app/views/notifier/request_accepted.html.haml b/app/views/notifier/request_accepted.html.haml new file mode 100644 index 000000000..191f8f42c --- /dev/null +++ b/app/views/notifier/request_accepted.html.haml @@ -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 diff --git a/app/views/notifier/request_accepted.text.haml b/app/views/notifier/request_accepted.text.haml new file mode 100644 index 000000000..e10623f16 --- /dev/null +++ b/app/views/notifier/request_accepted.text.haml @@ -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 diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index c7809b39d..3e0f6b3c5 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -63,14 +63,17 @@ 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 diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 394733cea..88550680f 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -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 diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 6bcdeb824..63a472031 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -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