all green
This commit is contained in:
parent
a4988a28b4
commit
cfef9a747e
5 changed files with 14 additions and 27 deletions
|
|
@ -19,7 +19,7 @@ class NotificationsController < ApplicationController
|
|||
|
||||
def index
|
||||
@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") }
|
||||
respond_with @notifications
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base
|
|||
include Diaspora::Socketable
|
||||
|
||||
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
|
||||
belongs_to :target, :polymorphic => true
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ private
|
|||
if n = Notification.where(:target_id => target.id,
|
||||
:action => action,
|
||||
:recipient_id => recipient.id).first
|
||||
n.actors << actor
|
||||
n.actors << actor unless n.actors.include?(actor)
|
||||
n.save!
|
||||
n
|
||||
else
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@
|
|||
%h2
|
||||
= t('.notifications')
|
||||
.span-13.last.left
|
||||
.button.mark_all_read
|
||||
= link_to t('.mark_all_as_read'), "#"
|
||||
= link_to t('.mark_all_as_read'), "#", :class => "button mark_all_read"
|
||||
|
||||
.span-24.last
|
||||
%ul.stream.notifications
|
||||
|
|
|
|||
|
|
@ -91,10 +91,11 @@ end
|
|||
|
||||
Factory.define(:notification) do |n|
|
||||
n.association :recipient, :factory => :user
|
||||
n.association :actors, :factory => :person
|
||||
n.association :target, :factory => :comment
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -20,22 +20,9 @@ describe Notification do
|
|||
@note.actors =[ @person]
|
||||
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
|
||||
@note.save
|
||||
lambda{@note.destroy}.should change(NotificationActors, :count).by(-1)
|
||||
lambda{@note.destroy}.should change(NotificationActor, :count).by(-1)
|
||||
end
|
||||
|
||||
describe '.for' do
|
||||
|
|
@ -70,11 +57,11 @@ describe Notification do
|
|||
opts = {:target_id => @request.id,
|
||||
:target_type => "Request",
|
||||
:action => @request.notification_type(@user, @person),
|
||||
:actor_id => @person.id,
|
||||
:actors => [@person],
|
||||
:recipient_id => @user.id}
|
||||
|
||||
n = Notification.create(opts)
|
||||
Notification.stub!(:create).and_return n
|
||||
Notification.stub!(:make_notification).and_return n
|
||||
|
||||
n.should_receive(:socket_to_user).once
|
||||
Notification.notify(@user, @request, @person)
|
||||
|
|
@ -84,7 +71,7 @@ describe Notification do
|
|||
it 'calls mail' do
|
||||
opts = {
|
||||
:action => "new_request",
|
||||
:actor_id => @person.id,
|
||||
:actors => [@person],
|
||||
:recipient_id => @user.id}
|
||||
|
||||
n = Notification.new(opts)
|
||||
|
|
@ -98,9 +85,9 @@ describe Notification do
|
|||
it "updates the notification with a more people if one already exists" do
|
||||
@user3 = bob
|
||||
sm = @user3.post(:status_message, :message => "comment!", :to => :all)
|
||||
@user3.receive_object(@user2.reload.comment("hey", :on => sm), @user2.person)
|
||||
@user3.receive_object(@user.reload.comment("way", :on => sm), @user.person)
|
||||
Notification.where(:user_id => @user.id,:target_id => sm.id).first.people.count.should == 2
|
||||
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => sm)).receive_object
|
||||
Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :on => sm)).receive_object
|
||||
Notification.where(:recipient_id => @user3.id,:target_id => sm.id).first.actors.count.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue