diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb
new file mode 100644
index 000000000..56f0f3555
--- /dev/null
+++ b/app/mailers/notifier.rb
@@ -0,0 +1,14 @@
+class Notifier < ActionMailer::Base
+ default :from => "no-reply@joindiaspora.com"
+
+ def new_request(recipient, sender)
+ @receiver = recipient
+ @sender = sender
+ mail(:to => recipient.email) do |format|
+ format.text { render :text => "This is text!" }
+ format.html { render :text => "
#{@receiver.person.profile.first_name}This is HTML
" }
+ end
+ end
+
+
+end
diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml
new file mode 100644
index 000000000..daa54c0eb
--- /dev/null
+++ b/app/views/notifier/new_request.html.haml
@@ -0,0 +1,61 @@
+!!!
+%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 '/images/diaspora_white.png'
+ #container
+ %p
+ Hello #{@receiver.first_name}!
+ %p
+ #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below.
+ - @resource.inviters.each do |inv|
+ - if @resource.invite_messages[inv.id.to_s]
+ = "#{inv.real_name}:"
+ = @resource.invite_messages[inv.id.to_s]
+ %p
+ %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text"
+ %p.small
+ If you don't want to accept the invitation, please ignore this email.
+ %br/
+ Your account won't be created until you access the link above and sign up.
diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb
index 6946910f2..570ce3544 100644
--- a/lib/diaspora/user/friending.rb
+++ b/lib/diaspora/user/friending.rb
@@ -74,6 +74,7 @@ module Diaspora
else
self.pending_requests << friend_request
self.save
+ Notifier.new_request(self, friend_request.person)
Rails.logger.info("#{self.real_name} has received a friend request")
friend_request.save
end
diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb
new file mode 100644
index 000000000..97316890d
--- /dev/null
+++ b/spec/mailers/notifier_spec.rb
@@ -0,0 +1,19 @@
+
+require 'spec_helper'
+
+describe Notifier do
+
+ let(:user) {Factory.create :user}
+ let(:person) {Factory.create :person}
+ let(:request_mail) {Notifier.new_request(user, person)}
+
+ describe "#new_request" do
+ it 'goes to the right person' do
+ request_mail.to.should == [user.email]
+ end
+
+ it 'has the receivers name in the body' do
+ request_mail.body.encoded.includes?(user.first_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 2fde487b3..83c1f456a 100644
--- a/spec/models/user/user_friending_spec.rb
+++ b/spec/models/user/user_friending_spec.rb
@@ -93,6 +93,16 @@ describe User do
}.should_not change(Person, :count)
user2.friends.include?(user.person).should be false
end
+
+ it 'sends an email to the receiving user' do
+ Notifier.should_receive(:new_request)
+ 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
@@ -107,7 +117,7 @@ describe User do
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
@@ -124,6 +134,8 @@ describe User do
user2.friends.include?(person_one).should be false
end
end
+
+
end
describe 'a user accepting rejecting multiple people' do