notification now only created when message is received, not when message is first saved
This commit is contained in:
parent
0416fa14b2
commit
8c5621158d
3 changed files with 34 additions and 18 deletions
|
|
@ -8,7 +8,6 @@ class Mention < ActiveRecord::Base
|
||||||
validates_presence_of :post
|
validates_presence_of :post
|
||||||
validates_presence_of :person
|
validates_presence_of :person
|
||||||
|
|
||||||
after_create :notify_recipient
|
|
||||||
after_destroy :delete_notification
|
after_destroy :delete_notification
|
||||||
|
|
||||||
def notify_recipient
|
def notify_recipient
|
||||||
|
|
|
||||||
|
|
@ -5,30 +5,18 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Mention do
|
describe Mention do
|
||||||
describe 'before create' do
|
describe "#notify_recipient" do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect1 = @user.aspects.create(:name => 'second_aspect')
|
|
||||||
@mentioned_user = bob
|
|
||||||
@non_friend = eve
|
|
||||||
|
|
||||||
@sm = Factory(:status_message)
|
@sm = Factory(:status_message)
|
||||||
@m = Mention.new(:person => @user.person, :post=> @sm)
|
@m = Mention.create(:person => @user.person, :post=> @sm)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'notifies the person being mentioned' do
|
it 'notifies the person being mentioned' do
|
||||||
Notification.should_receive(:notify).with(@user, anything(), @sm.author)
|
Notification.should_receive(:notify).with(@user, anything(), @sm.author)
|
||||||
@m.save
|
@m.notify_recipient
|
||||||
end
|
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)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#notification_type' do
|
describe '#notification_type' do
|
||||||
|
|
@ -41,7 +29,8 @@ describe Mention do
|
||||||
it 'destroys a notification' do
|
it 'destroys a notification' do
|
||||||
@user = alice
|
@user = alice
|
||||||
@sm = Factory(:status_message)
|
@sm = Factory(:status_message)
|
||||||
@m = Mention.create(:person => @user.person, :post=> @sm)
|
@m = Mention.create(:person => @user.person, :post => @sm)
|
||||||
|
@m.notify_recipient
|
||||||
|
|
||||||
lambda{
|
lambda{
|
||||||
@m.destroy
|
@m.destroy
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,34 @@ describe User do
|
||||||
end
|
end
|
||||||
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
|
describe 'account removal' do
|
||||||
it 'should disconnect everyone' do
|
it 'should disconnect everyone' do
|
||||||
alice.should_receive(:disconnect_everyone)
|
alice.should_receive(:disconnect_everyone)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue