Skip to content
Extraits de code Groupes Projets
Valider 4fec1bf7 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

1 failure left in mysql specs

parent be9101b5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
module NotificationsHelper module NotificationsHelper
def object_link(note) def object_link(note)
kind = note.kind target_type = note.target_type
translation = t("notifications.#{kind}") translation = t("notifications.#{target_type}")
case kind case target_type
when 'request_accepted' when 'request_accepted'
translation translation
when 'new_request' when 'new_request'
......
...@@ -51,14 +51,15 @@ module SocketsHelper ...@@ -51,14 +51,15 @@ module SocketsHelper
v = render_to_string(:partial => 'comments/comment', :locals => {:hash => {:comment => object, :person => object.person}}) v = render_to_string(:partial => 'comments/comment', :locals => {:hash => {:comment => object, :person => object.person}})
elsif object.is_a? Notification 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 else
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
end end
rescue Exception => e rescue Exception => e
Rails.logger.error("event=socket_render status=fail user=#{user.diaspora_handle} object=#{object.id.to_s}") 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 end
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)} action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
action_hash.merge! opts action_hash.merge! opts
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# the COPYRIGHT file. # the COPYRIGHT file.
# #
class Notification < ActiveRecord::Base class Notification < ActiveRecord::Base
include Diaspora::Socketable
belongs_to :recipient, :class_name => 'User' belongs_to :recipient, :class_name => 'User'
belongs_to :actor, :class_name => 'Person' belongs_to :actor, :class_name => 'Person'
...@@ -15,10 +16,12 @@ class Notification < ActiveRecord::Base ...@@ -15,10 +16,12 @@ class Notification < ActiveRecord::Base
def self.notify(recipient, target, actor) def self.notify(recipient, target, actor)
if target.respond_to? :notification_type if target.respond_to? :notification_type
if action = target.notification_type(recipient, actor) if action = target.notification_type(recipient, actor)
create(:target => target, n = create(:target => target,
:action => action, :action => action,
:actor => actor, :actor => actor,
:recipient => recipient) :recipient => recipient)
n.socket_to_uid(recipient.id) if n
n
end end
end end
end end
......
...@@ -50,17 +50,18 @@ describe Notification do ...@@ -50,17 +50,18 @@ describe Notification do
Notification.should_not_receive(:create) Notification.should_not_receive(:create)
Notification.notify(@user, @sm, @person) Notification.notify(@user, @sm, @person)
end 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 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.should_receive(:create).once
Notification.notify(@user, request, @person) Notification.notify(@user, @request, @person)
end end
it 'sockets to the recipient' do it 'sockets to the recipient' do
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect) opts = {:target_id => @request.id,
opts = {:target_id => request.id, :target_type => @request.notification_type(@user, @person),
:target_type => request.notification_type(@user, @person),
:actor_id => @person.id, :actor_id => @person.id,
:recipient_id => @user.id} :recipient_id => @user.id}
...@@ -68,8 +69,9 @@ describe Notification do ...@@ -68,8 +69,9 @@ describe Notification do
Notification.stub!(:create).and_return n Notification.stub!(:create).and_return n
n.should_receive(:socket_to_uid).once n.should_receive(:socket_to_uid).once
Notification.notify(@user, request, @person) Notification.notify(@user, @request, @person)
end end
end
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter