MSSM like notification are concatinated, and backfilled some like tests
This commit is contained in:
parent
a68031179b
commit
d4d3b1e44c
6 changed files with 58 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ class Like < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
validates_uniqueness_of :post_id, :scope => :author_id
|
||||
validates_presence_of :author, :post
|
||||
|
||||
def diaspora_handle
|
||||
self.author.diaspora_handle
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Notification < ActiveRecord::Base
|
|||
def self.notify(recipient, target, actor)
|
||||
if target.respond_to? :notification_type
|
||||
if note_type = target.notification_type(recipient, actor)
|
||||
if target.is_a? Comment
|
||||
if(target.is_a? Comment) || (target.is_a? Like)
|
||||
n = note_type.concatenate_or_create(recipient, target.post, actor, note_type)
|
||||
else
|
||||
n = note_type.make_notification(recipient, target, actor, note_type)
|
||||
|
|
@ -33,6 +33,8 @@ class Notification < ActiveRecord::Base
|
|||
def email_the_user(target, actor)
|
||||
self.recipient.mail(self.mail_job, self.recipient_id, actor.id, target.id)
|
||||
end
|
||||
|
||||
|
||||
def mail_job
|
||||
raise NotImplementedError.new('Subclass this.')
|
||||
end
|
||||
|
|
@ -43,9 +45,7 @@ private
|
|||
:target_type => target.class.base_class,
|
||||
:recipient_id => recipient.id,
|
||||
:unread => true).first
|
||||
unless n.actors.include?(actor)
|
||||
n.actors << actor
|
||||
end
|
||||
n.actors = n.actors | [actor]
|
||||
|
||||
n.unread = true
|
||||
n.save!
|
||||
|
|
@ -58,7 +58,7 @@ private
|
|||
def self.make_notification(recipient, target, actor, notification_type)
|
||||
n = notification_type.new(:target => target,
|
||||
:recipient_id => recipient.id)
|
||||
n.actors << actor
|
||||
n.actors = n.actors | [actor]
|
||||
n.unread = false if target.is_a? Request
|
||||
n.save!
|
||||
n
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ Factory.define :searchable_person, :parent => :person do |p|
|
|||
end
|
||||
end
|
||||
|
||||
Factory.define :like do |x|
|
||||
x.association :author, :factory => :person
|
||||
x.association :post, :factory => :status_message
|
||||
end
|
||||
|
||||
Factory.define :user do |u|
|
||||
u.sequence(:username) { |n| "bob#{n}#{r_str}" }
|
||||
u.sequence(:email) { |n| "bob#{n}#{r_str}@pivotallabs.com" }
|
||||
|
|
|
|||
21
spec/helpers/notifications_helper_spec.rb
Normal file
21
spec/helpers/notifications_helper_spec.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
|
||||
describe NotificationsHelper do
|
||||
describe '#notification_people_link' do
|
||||
describe 'for a like' do
|
||||
it 'displays #{list of actors}' do
|
||||
@user = Factory(:user)
|
||||
@person = Factory(:person)
|
||||
p = Factory(:status_message, :author => @user.person)
|
||||
person2 = Factory(:person)
|
||||
notification = Notification.notify(@user, Factory(:like, :author => @person, :post => p), @person)
|
||||
notification2 = Notification.notify(@user, Factory(:like, :author => person2, :post => p), person2)
|
||||
|
||||
output = notification_people_link(notification2)
|
||||
output.should include person2.name
|
||||
output.should include @person.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -15,6 +15,10 @@ describe Like do
|
|||
@status = bob.post(:status_message, :text => "hello", :to => @alices_aspect.id)
|
||||
end
|
||||
|
||||
it 'has a valid factory' do
|
||||
Factory(:like).should be_valid
|
||||
end
|
||||
|
||||
describe 'User#like' do
|
||||
it "should be able to like on one's own status" do
|
||||
alice.like(1, :on => @status)
|
||||
|
|
|
|||
|
|
@ -92,6 +92,28 @@ describe Notification do
|
|||
end
|
||||
end
|
||||
|
||||
context 'multiple likes' do
|
||||
it 'concatinates the like notifications' do
|
||||
p = Factory(:status_message, :author => @user.person)
|
||||
person2 = Factory(:person)
|
||||
notification = Notification.notify(@user, Factory(:like, :author => @person, :post => p), @person)
|
||||
notification2 = Notification.notify(@user, Factory(:like, :author => person2, :post => p), person2)
|
||||
notification.id.should == notification2.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'multiple comments' do
|
||||
it 'concatinates the comment notifications' do
|
||||
p = Factory(:status_message, :author => @user.person)
|
||||
person2 = Factory(:person)
|
||||
notification = Notification.notify(@user, Factory(:comment, :author => @person, :post => p), @person)
|
||||
notification2 = Notification.notify(@user, Factory(:comment, :author => person2, :post => p), person2)
|
||||
notification.id.should == notification2.id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
context 'multiple people' do
|
||||
|
||||
before do
|
||||
|
|
|
|||
Loading…
Reference in a new issue