OMG SO MANY EMAILS, fixed

This commit is contained in:
Raphael Sofaer 2011-05-11 16:07:24 -07:00
parent 6fa433ced8
commit 970190fb7a
2 changed files with 29 additions and 11 deletions

View file

@ -5,16 +5,16 @@
class Like < ActiveRecord::Base class Like < ActiveRecord::Base
require File.join(Rails.root, 'lib/diaspora/web_socket') require File.join(Rails.root, 'lib/diaspora/web_socket')
include ROXML include ROXML
include Diaspora::Webhooks include Diaspora::Webhooks
include Diaspora::Relayable include Diaspora::Relayable
include Diaspora::Guid include Diaspora::Guid
include Diaspora::Socketable include Diaspora::Socketable
xml_attr :positive xml_attr :positive
xml_attr :diaspora_handle xml_attr :diaspora_handle
belongs_to :post belongs_to :post
belongs_to :author, :class_name => 'Person' belongs_to :author, :class_name => 'Person'
@ -23,24 +23,24 @@ class Like < ActiveRecord::Base
def diaspora_handle def diaspora_handle
self.author.diaspora_handle self.author.diaspora_handle
end end
def diaspora_handle= nh def diaspora_handle= nh
self.author = Webfinger.new(nh).fetch self.author = Webfinger.new(nh).fetch
end end
def parent_class def parent_class
Post Post
end end
def parent def parent
self.post self.post
end end
def parent= parent def parent= parent
self.post = parent self.post = parent
end end
def notification_type(user, person) def notification_type(user, person)
Notifications::Liked unless user.person == person Notifications::Liked if self.post.author == user.person && user.person != person
end end
end end

View file

@ -34,6 +34,24 @@ describe Like do
end end
end end
describe '#notification_type' do
before do
@like = @bob.like(1, :on => @status)
end
it 'should be notifications liked if you are the post owner' do
@like.notification_type(@alice, @bob.person).should be Notifications::Liked
end
it 'should not notify you if you are the like-r owner' do
@like.notification_type(@bob, @alice.person).should be_nil
end
it 'should not notify you if you did not create the post' do
@like.notification_type(@bob, @alice.person).should be_nil
end
end
describe 'xml' do describe 'xml' do
before do before do
@liker = Factory.create(:user) @liker = Factory.create(:user)
@ -67,11 +85,11 @@ describe Like do
@local_luke, @local_leia, @remote_raphael = set_up_friends @local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = Factory.create(:status_message, :author => @remote_raphael) @remote_parent = Factory.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first @local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.like(1, :on => @local_parent) @object_by_parent_author = @local_luke.like(1, :on => @local_parent)
@object_by_recipient = @local_leia.build_like(1, :on => @local_parent) @object_by_recipient = @local_leia.build_like(1, :on => @local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup @dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.like(0, :on => @remote_parent) @object_on_remote_parent = @local_luke.like(0, :on => @remote_parent)
end end
it_should_behave_like 'it is relayable' it_should_behave_like 'it is relayable'