fixed the problem where notifications are not keeping track of the target id as well as making notifications for a mention be destroyed when a post is
This commit is contained in:
parent
057dcc218d
commit
36d7973005
4 changed files with 25 additions and 2 deletions
|
|
@ -10,6 +10,8 @@ class Mention < ActiveRecord::Base
|
||||||
|
|
||||||
after_create :notify_recipient
|
after_create :notify_recipient
|
||||||
|
|
||||||
|
after_destroy :delete_notification
|
||||||
|
|
||||||
def notify_recipient
|
def notify_recipient
|
||||||
Notification.notify(person.owner, self, post.person) unless person.remote?
|
Notification.notify(person.owner, self, post.person) unless person.remote?
|
||||||
end
|
end
|
||||||
|
|
@ -18,4 +20,8 @@ class Mention < ActiveRecord::Base
|
||||||
def notification_type(*args)
|
def notification_type(*args)
|
||||||
'mentioned'
|
'mentioned'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_notification
|
||||||
|
Notification.where(:target_type => self.class, :target_id => self.id).delete_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,13 @@ class Notification < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
def self.concatenate_or_create(recipient, target, actor, action)
|
def self.concatenate_or_create(recipient, target, actor, action)
|
||||||
if n = Notification.where(:target_id => target.id,
|
if n = Notification.where(:target_id => target.id,
|
||||||
|
:target_type => target.type,
|
||||||
:action => action,
|
:action => action,
|
||||||
:recipient_id => recipient.id).first
|
:recipient_id => recipient.id).first
|
||||||
unless n.actors.include?(actor)
|
unless n.actors.include?(actor)
|
||||||
n.actors << actor
|
n.actors << actor
|
||||||
end
|
end
|
||||||
|
|
||||||
n.unread = true
|
n.unread = true
|
||||||
n.save!
|
n.save!
|
||||||
n
|
n
|
||||||
|
|
@ -62,7 +64,7 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_notification(recipient, target, actor, action)
|
def self.make_notification(recipient, target, actor, action)
|
||||||
n = Notification.new(:target_id => target.id,
|
n = Notification.new(:target => target,
|
||||||
:action => action,
|
:action => action,
|
||||||
:recipient_id => recipient.id)
|
:recipient_id => recipient.id)
|
||||||
n.actors << actor
|
n.actors << actor
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110209204702) do
|
ActiveRecord::Schema.define(:version => 20110211021925) do
|
||||||
|
|
||||||
create_table "aspect_memberships", :force => true do |t|
|
create_table "aspect_memberships", :force => true do |t|
|
||||||
t.integer "aspect_id", :null => false
|
t.integer "aspect_id", :null => false
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,20 @@ describe Mention do
|
||||||
Mention.new.notification_type.should == 'mentioned'
|
Mention.new.notification_type.should == 'mentioned'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'after destroy' do
|
||||||
|
it 'destroys a notification' do
|
||||||
|
@user = alice
|
||||||
|
@sm = Factory(:status_message)
|
||||||
|
@m = Mention.create(:person => @user.person, :post=> @sm)
|
||||||
|
|
||||||
|
|
||||||
|
pp Notification.first
|
||||||
|
|
||||||
|
lambda{
|
||||||
|
@m.destroy
|
||||||
|
}.should change(Notification, :count).by(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue