diff --git a/app/models/like.rb b/app/models/like.rb index 84acba523..a7363b60d 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -5,16 +5,16 @@ class Like < ActiveRecord::Base require File.join(Rails.root, 'lib/diaspora/web_socket') include ROXML - + include Diaspora::Webhooks include Diaspora::Relayable include Diaspora::Guid - + include Diaspora::Socketable - + xml_attr :positive xml_attr :diaspora_handle - + belongs_to :post belongs_to :author, :class_name => 'Person' @@ -23,24 +23,24 @@ class Like < ActiveRecord::Base def diaspora_handle self.author.diaspora_handle end - + def diaspora_handle= nh self.author = Webfinger.new(nh).fetch end - + def parent_class Post end - + def parent self.post end - + def parent= parent self.post = parent end def notification_type(user, person) - Notifications::Liked unless user.person == person + Notifications::Liked if self.post.author == user.person && user.person != person end end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index 9fea70324..1988e0411 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -34,6 +34,24 @@ describe Like do 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 before do @liker = Factory.create(:user) @@ -67,11 +85,11 @@ describe Like do @local_luke, @local_leia, @remote_raphael = set_up_friends @remote_parent = Factory.create(:status_message, :author => @remote_raphael) @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_recipient = @local_leia.build_like(1, :on => @local_parent) @dup_object_by_parent_author = @object_by_parent_author.dup - + @object_on_remote_parent = @local_luke.like(0, :on => @remote_parent) end it_should_behave_like 'it is relayable'