diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 2070b5427..7b1ee2a3e 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -68,9 +68,8 @@ describe 'a user receives a post' do alice.visible_posts.count.should == 1 end - context 'mentions' do - it 'adds the notifications for the mentioned users reguardless of the order they are received' do - pending 'this is for mnutt' + context 'mentions' do + it 'adds the notifications for the mentioned users regardless of the order they are received' do Notification.should_receive(:notify).with(@user1, anything(), @user2.person) Notification.should_receive(:notify).with(@user3, anything(), @user2.person) @@ -85,6 +84,32 @@ describe 'a user receives a post' do zord = Postzord::Receiver.new(@user3, :object => @sm, :person => @user2.person) zord.receive_object end + + it 'notifies users when receiving a mention in a post from a remote user' do + @remote_person = Factory.create(:person, :diaspora_handle => "foobar@foobar.com") + Contact.create!(:user => @user1, :person => @remote_person, :aspects => [@aspect], :pending => false) + + Notification.should_receive(:notify).with(@user1, anything(), @remote_person) + + @sm = Factory.build(:status_message, :message => "hello @{#{@user1.name}; #{@user1.diaspora_handle}}", :diaspora_handle => @remote_person.diaspora_handle, :person => @remote_person) + @sm.stub!(:socket_to_user) + @sm.save + + zord = Postzord::Receiver.new(@user1, :object => @sm, :person => @user2.person) + zord.receive_object + end + + it 'does not notify the mentioned user if the mentioned user is not friends with the post author' do + Notification.should_not_receive(:notify).with(@user1, anything(), @user3.person) + + @sm = @user3.build_post(:status_message, :message => "should not notify @{#{@user1.name}; #{@user1.diaspora_handle}}") + @sm.stub!(:socket_to_user) + @user3.add_to_streams(@sm, [@user3.aspects.first]) + @sm.save + + zord = Postzord::Receiver.new(@user1, :object => @sm, :person => @user2.person) + zord.receive_object + end end context 'update posts' do diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index 4b2c6cdd2..d4ac9e9f7 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -8,14 +8,24 @@ describe Mention do describe "#notify_recipient" do before do @user = alice - @sm = Factory(:status_message) - @m = Mention.create(:person => @user.person, :post=> @sm) + @aspect1 = @user.aspects.create(:name => 'second_aspect') + @mentioned_user = bob + @non_friend = eve + @sm = @user.build_post(:status_message, :message => "hi @{#{@mentioned_user.name}; #{@mentioned_user.diaspora_handle}}", :to => @user.aspects.first) end it 'notifies the person being mentioned' do - Notification.should_receive(:notify).with(@user, anything(), @sm.author) - @m.notify_recipient + Notification.should_receive(:notify).with(@mentioned_user, anything(), @sm.person) + @sm.receive(@mentioned_user, @mentioned_user.person) + 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 @@ -28,8 +38,10 @@ describe Mention do describe 'after destroy' do it 'destroys a notification' do @user = alice - @sm = Factory(:status_message) - @m = Mention.create(:person => @user.person, :post => @sm) + @mentioned_user = bob + + @sm = @user.post(:status_message, :message => "hi", :to => @user.aspects.first) + @m = Mention.create!(:person => @mentioned_user.person, :post => @sm) @m.notify_recipient lambda{