wip
This commit is contained in:
parent
f1fe913527
commit
7b1abacfe6
6 changed files with 78 additions and 6 deletions
|
|
@ -7,4 +7,15 @@ class Mention < ActiveRecord::Base
|
|||
belongs_to :person
|
||||
validates_presence_of :post
|
||||
validates_presence_of :person
|
||||
|
||||
after_create :notify_recipient
|
||||
|
||||
def notify_recipient
|
||||
Notification.notify(person.owner, self, post.person) unless person.remote?
|
||||
end
|
||||
|
||||
|
||||
def notification_type
|
||||
'mentioned'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,16 +30,18 @@ class Notification < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def email_the_user(comment, actor)
|
||||
def email_the_user(target, actor)
|
||||
case self.action
|
||||
when "new_request"
|
||||
self.recipient.mail(Job::MailRequestReceived, self.recipient_id, actor.id)
|
||||
when "request_accepted"
|
||||
self.recipient.mail(Job::MailRequestAcceptance, self.recipient_id, actor.id)
|
||||
when "comment_on_post"
|
||||
self.recipient.mail(Job::MailCommentOnPost, self.recipient_id, actor.id, comment.id)
|
||||
self.recipient.mail(Job::MailCommentOnPost, self.recipient_id, actor.id, target.id)
|
||||
when "also_commented"
|
||||
self.recipient.mail(Job::MailAlsoCommented, self.recipient_id, actor.id, comment.id)
|
||||
self.recipient.mail(Job::MailAlsoCommented, self.recipient_id, actor.id, target.id)
|
||||
when "mentioned"
|
||||
self.recipient.mail(Job::MailMentioned, self.recipient_id, actor.id, target.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ ActiveRecord::Schema.define(:version => 20110209204702) do
|
|||
add_index "profiles", ["first_name", "searchable"], :name => "index_profiles_on_first_name_and_searchable"
|
||||
add_index "profiles", ["last_name", "searchable"], :name => "index_profiles_on_last_name_and_searchable"
|
||||
add_index "profiles", ["mongo_id"], :name => "index_profiles_on_mongo_id"
|
||||
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id", :unique => true
|
||||
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id"
|
||||
|
||||
create_table "requests", :force => true do |t|
|
||||
t.integer "sender_id", :null => false
|
||||
|
|
@ -466,8 +466,8 @@ ActiveRecord::Schema.define(:version => 20110209204702) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "mongo_id"
|
||||
t.string "invitation_service"
|
||||
t.string "invitation_identifier"
|
||||
t.string "invitation_service", :limit => 127
|
||||
t.string "invitation_identifier", :limit => 127
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email"
|
||||
|
|
|
|||
17
spec/models/jobs/mail_mentioned_spec.rb
Normal file
17
spec/models/jobs/mail_mentioned_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Job::MailMentioned do
|
||||
describe '#perfom_delegate' do
|
||||
it 'should call .deliver on the notifier object' do
|
||||
user = alice
|
||||
sm = Factory(:status_message)
|
||||
m = Mention.new(:person => user.person, :post=> sm)
|
||||
|
||||
Notification.notify(user, m, sm.person)
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/models/mention_spec.rb
Normal file
33
spec/models/mention_spec.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Mention do
|
||||
describe 'before create' do
|
||||
before do
|
||||
@user = alice
|
||||
@sm = Factory(:status_message)
|
||||
@m = Mention.new(:person => @user.person, :post=> @sm)
|
||||
|
||||
end
|
||||
it 'notifies the person being mention' do
|
||||
Notification.should_receive(:notify).with(@user, @m, @sm.person)
|
||||
@m.save
|
||||
end
|
||||
|
||||
it 'should only notify if the person is local' do
|
||||
m = Mention.new(:person => Factory(:person), :post => @sm)
|
||||
Notification.should_not_receive(:notify)
|
||||
m.save
|
||||
end
|
||||
end
|
||||
|
||||
describe '#notification_type' do
|
||||
it "returns 'mentioned'" do
|
||||
Mention.new.notification_type.should == 'mentioned'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -12,6 +12,14 @@ describe StatusMessage do
|
|||
@aspect = @user.aspects.first
|
||||
end
|
||||
|
||||
describe '.before_create' do
|
||||
it 'calls create_mentions' do
|
||||
status = Factory.build(:status_message)
|
||||
status.should_receive(:create_mentions)
|
||||
status.save
|
||||
end
|
||||
end
|
||||
|
||||
describe '#diaspora_handle=' do
|
||||
it 'sets #person' do
|
||||
person = Factory.create(:person)
|
||||
|
|
@ -108,6 +116,7 @@ STR
|
|||
end
|
||||
end
|
||||
describe '#create_mentions' do
|
||||
|
||||
it 'creates a mention for everyone mentioned in the message' do
|
||||
@sm.should_receive(:mentioned_people_from_string).and_return(@people)
|
||||
@sm.mentions.delete_all
|
||||
|
|
|
|||
Loading…
Reference in a new issue