From cfef9a747e83c4a89a8e37f8d680e63647bd1491 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi <ilya@joindiaspora.com> Date: Sun, 30 Jan 2011 20:10:34 -0800 Subject: [PATCH] all green --- app/controllers/notifications_controller.rb | 2 +- app/models/notification.rb | 4 +-- app/views/notifications/index.html.haml | 3 +-- spec/factories.rb | 5 ++-- spec/models/notification_spec.rb | 27 ++++++--------------- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 7856f6edfd..0f9b029897 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -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 diff --git a/app/models/notification.rb b/app/models/notification.rb index 1e887eb063..efca7def6d 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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 diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index c7163b6357..f709cb457e 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index cf3fd93c65..798077740e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index e6b44b516d..5ede818b4e 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -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 -- GitLab