1 failure left in mysql specs

This commit is contained in:
Raphael 2010-12-28 11:38:26 -08:00
parent be9101b51f
commit 4fec1bf717
4 changed files with 19 additions and 13 deletions

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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