Skip to content
Extraits de code Groupes Projets
Valider cfef9a74 rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

all green

parent a4988a28
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -19,7 +19,7 @@ class NotificationsController < ApplicationController ...@@ -19,7 +19,7 @@ class NotificationsController < ApplicationController
def index def index
@notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id}, @notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id},
:order => 'created_at desc', :include => [:target]).paginate :page => params[:page], :per_page => 25 :order => 'created_at desc', :include => [:target, {:actors => :profile}]).paginate :page => params[:page], :per_page => 25
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } @group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
respond_with @notifications respond_with @notifications
end end
......
...@@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base ...@@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base
include Diaspora::Socketable include Diaspora::Socketable
belongs_to :recipient, :class_name => 'User' belongs_to :recipient, :class_name => 'User'
has_many :notification_actors has_many :notification_actors, :dependent => :destroy
has_many :actors, :class_name => 'Person', :through => :notification_actors, :source => :person has_many :actors, :class_name => 'Person', :through => :notification_actors, :source => :person
belongs_to :target, :polymorphic => true belongs_to :target, :polymorphic => true
...@@ -48,7 +48,7 @@ private ...@@ -48,7 +48,7 @@ private
if n = Notification.where(:target_id => target.id, if n = Notification.where(:target_id => target.id,
:action => action, :action => action,
:recipient_id => recipient.id).first :recipient_id => recipient.id).first
n.actors << actor n.actors << actor unless n.actors.include?(actor)
n.save! n.save!
n n
else else
......
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
%h2 %h2
= t('.notifications') = t('.notifications')
.span-13.last.left .span-13.last.left
.button.mark_all_read = link_to t('.mark_all_as_read'), "#", :class => "button mark_all_read"
= link_to t('.mark_all_as_read'), "#"
.span-24.last .span-24.last
%ul.stream.notifications %ul.stream.notifications
......
...@@ -91,10 +91,11 @@ end ...@@ -91,10 +91,11 @@ end
Factory.define(:notification) do |n| Factory.define(:notification) do |n|
n.association :recipient, :factory => :user n.association :recipient, :factory => :user
n.association :actors, :factory => :person
n.association :target, :factory => :comment n.association :target, :factory => :comment
n.after_build do |note| n.after_build do |note|
note.action = note.target.notification_type(note.recipient, note.actor) note.actors << Factory.build( :person )
note.action = note.target.notification_type(note.recipient, note.actors.first)
end end
end end
...@@ -20,22 +20,9 @@ describe Notification do ...@@ -20,22 +20,9 @@ describe Notification do
@note.actors =[ @person] @note.actors =[ @person]
end end
it 'contains a type' do
@note.target_type.should == StatusMessage.name
end
it 'contains a target_id' do
@note.target_id.should == @sm.id
end
it 'has many people' do
@note.associations[:people].type.should == :many
end
it 'destoys the associated notification_actor' do it 'destoys the associated notification_actor' do
@note.save @note.save
lambda{@note.destroy}.should change(NotificationActors, :count).by(-1) lambda{@note.destroy}.should change(NotificationActor, :count).by(-1)
end end
describe '.for' do describe '.for' do
...@@ -70,11 +57,11 @@ describe Notification do ...@@ -70,11 +57,11 @@ describe Notification do
opts = {:target_id => @request.id, opts = {:target_id => @request.id,
:target_type => "Request", :target_type => "Request",
:action => @request.notification_type(@user, @person), :action => @request.notification_type(@user, @person),
:actor_id => @person.id, :actors => [@person],
:recipient_id => @user.id} :recipient_id => @user.id}
n = Notification.create(opts) n = Notification.create(opts)
Notification.stub!(:create).and_return n Notification.stub!(:make_notification).and_return n
n.should_receive(:socket_to_user).once n.should_receive(:socket_to_user).once
Notification.notify(@user, @request, @person) Notification.notify(@user, @request, @person)
...@@ -84,7 +71,7 @@ describe Notification do ...@@ -84,7 +71,7 @@ describe Notification do
it 'calls mail' do it 'calls mail' do
opts = { opts = {
:action => "new_request", :action => "new_request",
:actor_id => @person.id, :actors => [@person],
:recipient_id => @user.id} :recipient_id => @user.id}
n = Notification.new(opts) n = Notification.new(opts)
...@@ -98,9 +85,9 @@ describe Notification do ...@@ -98,9 +85,9 @@ describe Notification do
it "updates the notification with a more people if one already exists" do it "updates the notification with a more people if one already exists" do
@user3 = bob @user3 = bob
sm = @user3.post(:status_message, :message => "comment!", :to => :all) sm = @user3.post(:status_message, :message => "comment!", :to => :all)
@user3.receive_object(@user2.reload.comment("hey", :on => sm), @user2.person) Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => sm)).receive_object
@user3.receive_object(@user.reload.comment("way", :on => sm), @user.person) Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :on => sm)).receive_object
Notification.where(:user_id => @user.id,:target_id => sm.id).first.people.count.should == 2 Notification.where(:recipient_id => @user3.id,:target_id => sm.id).first.actors.count.should == 2
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