From 4fec1bf71797e76282ab71073daed7f3ccf22f64 Mon Sep 17 00:00:00 2001
From: Raphael <raphael@joindiaspora.com>
Date: Tue, 28 Dec 2010 11:38:26 -0800
Subject: [PATCH] 1 failure left in mysql specs

---
 app/helpers/notifications_helper.rb |  6 +++---
 app/helpers/sockets_helper.rb       |  5 +++--
 app/models/notification.rb          |  5 ++++-
 spec/models/notification_spec.rb    | 16 +++++++++-------
 4 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb
index 7b0ef659f4..7c60ec5776 100644
--- a/app/helpers/notifications_helper.rb
+++ b/app/helpers/notifications_helper.rb
@@ -1,8 +1,8 @@
 module NotificationsHelper
   def object_link(note)
-    kind = note.kind
-    translation = t("notifications.#{kind}")
-    case kind
+    target_type = note.target_type
+    translation = t("notifications.#{target_type}")
+    case target_type
     when 'request_accepted'
       translation
     when 'new_request'
diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb
index 43aa91b702..856a6351ca 100644
--- a/app/helpers/sockets_helper.rb
+++ b/app/helpers/sockets_helper.rb
@@ -51,14 +51,15 @@ module SocketsHelper
         v = render_to_string(:partial => 'comments/comment', :locals => {:hash => {:comment => object, :person => object.person}})
 
       elsif object.is_a? Notification
-        v = render_to_string(:partial => 'notifications/popup', :locals => {:note => object, :person => object.person})
+        v = render_to_string(:partial => 'notifications/popup', :locals => {:note => object, :person => object.actor})
 
       else
         v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
       end
     rescue Exception => e
       Rails.logger.error("event=socket_render status=fail user=#{user.diaspora_handle} object=#{object.id.to_s}")
-      raise e.original_exception
+      raise e.original_exception if e.respond_to?(:original_exception)
+      raise e
     end
     action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
     action_hash.merge! opts
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 625ba1197a..14480536a1 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -3,6 +3,7 @@
 #   the COPYRIGHT file.
 #
 class Notification < ActiveRecord::Base
+  include Diaspora::Socketable
 
   belongs_to :recipient, :class_name => 'User'
   belongs_to :actor, :class_name => 'Person'
@@ -15,10 +16,12 @@ class Notification < ActiveRecord::Base
   def self.notify(recipient, target, actor)
     if target.respond_to? :notification_type
       if action = target.notification_type(recipient, actor)
-        create(:target => target,
+        n = create(:target => target,
                :action => action,
                :actor => actor,
                :recipient => recipient)
+        n.socket_to_uid(recipient.id) if n
+        n
        end
     end
   end
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
index b8dffc9c17..02a65e50c2 100644
--- a/spec/models/notification_spec.rb
+++ b/spec/models/notification_spec.rb
@@ -50,17 +50,18 @@ describe Notification do
       Notification.should_not_receive(:create)
       Notification.notify(@user, @sm, @person)
     end
-
+   context 'with a request' do
+     before do
+      @request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
+     end
    it 'calls Notification.create if the object has a notification_type' do
-      request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
       Notification.should_receive(:create).once
-      Notification.notify(@user, request, @person)
+      Notification.notify(@user, @request, @person)
     end
 
     it 'sockets to the recipient' do
-      request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
-      opts = {:target_id => request.id,
-              :target_type => request.notification_type(@user, @person),
+      opts = {:target_id => @request.id,
+              :target_type => @request.notification_type(@user, @person),
               :actor_id => @person.id,
               :recipient_id => @user.id}
 
@@ -68,8 +69,9 @@ describe Notification do
       Notification.stub!(:create).and_return n
 
       n.should_receive(:socket_to_uid).once
-      Notification.notify(@user, request, @person)
+      Notification.notify(@user, @request, @person)
     end
+   end
   end
 end
 
-- 
GitLab