Skip to content
Extraits de code Groupes Projets
Valider 8c562115 rédigé par Michael Nutt's avatar Michael Nutt
Parcourir les fichiers

notification now only created when message is received, not when message is first saved

parent 0416fa14
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -8,7 +8,6 @@ class Mention < ActiveRecord::Base
validates_presence_of :post
validates_presence_of :person
after_create :notify_recipient
after_destroy :delete_notification
def notify_recipient
......
......@@ -5,30 +5,18 @@
require 'spec_helper'
describe Mention do
describe 'before create' do
describe "#notify_recipient" do
before do
@user = alice
@aspect1 = @user.aspects.create(:name => 'second_aspect')
@mentioned_user = bob
@non_friend = eve
@sm = Factory(:status_message)
@m = Mention.new(:person => @user.person, :post=> @sm)
@m = Mention.create(:person => @user.person, :post=> @sm)
end
it 'notifies the person being mentioned' do
Notification.should_receive(:notify).with(@user, anything(), @sm.author)
@m.save
end
it 'should not notify a user if they do not see the message' do
connect_users(@user, @aspect1, @non_friend, @non_friend.aspects.first)
Notification.should_not_receive(:notify).with(@mentioned_user, anything(), @user.person)
sm2 = @user.post(:status_message, :message => "stuff @{#{@non_friend.name}; #{@non_friend.diaspora_handle}}", :to => @user.aspects.first)
sm2.receive(@non_friend, @non_friend.person)
@m.notify_recipient
end
end
describe '#notification_type' do
......@@ -41,7 +29,8 @@ describe Mention do
it 'destroys a notification' do
@user = alice
@sm = Factory(:status_message)
@m = Mention.create(:person => @user.person, :post=> @sm)
@m = Mention.create(:person => @user.person, :post => @sm)
@m.notify_recipient
lambda{
@m.destroy
......
......@@ -317,6 +317,34 @@ describe User do
end
end
describe '#notify_if_mentioned' do
before do
@post = Factory.create(:status_message, :author => bob.person)
end
it 'notifies the user if the incoming post mentions them' do
@post.should_receive(:mentions?).with(alice.person).and_return(true)
@post.should_receive(:notify_person).with(alice.person)
alice.notify_if_mentioned(@post)
end
it 'does not notify the user if the incoming post does not mention them' do
@post.should_receive(:mentions?).with(alice.person).and_return(false)
@post.should_not_receive(:notify_person)
alice.notify_if_mentioned(@post)
end
it 'does not notify the user if the post author is not a contact' do
@post = Factory.create(:status_message, :author => eve.person)
@post.stub(:mentions?).and_return(true)
@post.should_not_receive(:notify_person)
alice.notify_if_mentioned(@post)
end
end
describe 'account removal' do
it 'should disconnect everyone' do
alice.should_receive(:disconnect_everyone)
......
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