Skip to content
Extraits de code Groupes Projets
Valider 7b1abacf rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

wip

parent f1fe9135
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -7,4 +7,15 @@ class Mention < ActiveRecord::Base ...@@ -7,4 +7,15 @@ class Mention < ActiveRecord::Base
belongs_to :person belongs_to :person
validates_presence_of :post validates_presence_of :post
validates_presence_of :person 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 end
...@@ -30,16 +30,18 @@ class Notification < ActiveRecord::Base ...@@ -30,16 +30,18 @@ class Notification < ActiveRecord::Base
end end
end end
def email_the_user(comment, actor) def email_the_user(target, actor)
case self.action case self.action
when "new_request" when "new_request"
self.recipient.mail(Job::MailRequestReceived, self.recipient_id, actor.id) self.recipient.mail(Job::MailRequestReceived, self.recipient_id, actor.id)
when "request_accepted" when "request_accepted"
self.recipient.mail(Job::MailRequestAcceptance, self.recipient_id, actor.id) self.recipient.mail(Job::MailRequestAcceptance, self.recipient_id, actor.id)
when "comment_on_post" 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" 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
end end
......
...@@ -404,7 +404,7 @@ ActiveRecord::Schema.define(:version => 20110209204702) do ...@@ -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", ["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", ["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", ["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| create_table "requests", :force => true do |t|
t.integer "sender_id", :null => false t.integer "sender_id", :null => false
...@@ -466,8 +466,8 @@ ActiveRecord::Schema.define(:version => 20110209204702) do ...@@ -466,8 +466,8 @@ ActiveRecord::Schema.define(:version => 20110209204702) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "mongo_id" t.string "mongo_id"
t.string "invitation_service" t.string "invitation_service", :limit => 127
t.string "invitation_identifier" t.string "invitation_identifier", :limit => 127
end end
add_index "users", ["email"], :name => "index_users_on_email" add_index "users", ["email"], :name => "index_users_on_email"
......
# 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
# 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 ...@@ -12,6 +12,14 @@ describe StatusMessage do
@aspect = @user.aspects.first @aspect = @user.aspects.first
end 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 describe '#diaspora_handle=' do
it 'sets #person' do it 'sets #person' do
person = Factory.create(:person) person = Factory.create(:person)
...@@ -108,6 +116,7 @@ STR ...@@ -108,6 +116,7 @@ STR
end end
end end
describe '#create_mentions' do describe '#create_mentions' do
it 'creates a mention for everyone mentioned in the message' do it 'creates a mention for everyone mentioned in the message' do
@sm.should_receive(:mentioned_people_from_string).and_return(@people) @sm.should_receive(:mentioned_people_from_string).and_return(@people)
@sm.mentions.delete_all @sm.mentions.delete_all
......
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