diff --git a/app/models/mention.rb b/app/models/mention.rb index fcf2bbaef..bc253fe89 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -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 diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index 77428a541..4b2c6cdd2 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -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 + @m.notify_recipient 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 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 41008ef54..3b974a026 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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)