diff --git a/app/models/relayable_retraction.rb b/app/models/relayable_retraction.rb index 1f593f5cc..554f678ad 100644 --- a/app/models/relayable_retraction.rb +++ b/app/models/relayable_retraction.rb @@ -51,7 +51,7 @@ class RelayableRetraction retraction.sender = sender retraction.target = target retraction.target_author_signature = retraction.sign_with_key(sender.encryption_key) if sender.person == target.author - retraction.parent_author_signature = retraction.sign_with_key(sender.encryption_key) if sender.person == target.parent.author + retraction.parent_author_signature = retraction.sign_with_key(sender.encryption_key) if defined?(target.parent) && sender.person == target.parent.author retraction end diff --git a/app/models/user.rb b/app/models/user.rb index a1566f4d3..b93c093ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -230,21 +230,29 @@ class User < ActiveRecord::Base end ######### Posts and Such ############### - def retract(target) + def retract(target, opts={}) if target.respond_to?(:relayable?) && target.relayable? retraction = RelayableRetraction.build(self, target) else retraction = Retraction.for(target) end - opts = {} - if target.is_a?(Post) - opts[:additional_subscribers] = target.resharers + if target.is_a?(Post) && target.reshares.size != 0 + reshare_retraction = RelayableRetraction.build(self, target) end +# if target.is_a?(Post) +# opts[:additional_subscribers] = target.resharers +# end + mailman = Postzord::Dispatch.new(self, retraction, opts) mailman.post + if reshare_retraction + mailman = Postzord::Dispatch.new(self, reshare_retraction) + mailman.post + end + retraction.perform(self) retraction diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 0a4a3ef13..8c63d93b2 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -61,7 +61,7 @@ - if (post.author_id != current_user.person.id) && (post.public?) && !reshare?(post) · %span.reshare_action - = link_to "Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" + = link_to "#{(post.reshares.size unless post.reshares.size == 0)} Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" · = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' diff --git a/features/repost.feature b/features/repost.feature index 4dd29df78..39567dc9f 100644 --- a/features/repost.feature +++ b/features/repost.feature @@ -91,9 +91,8 @@ Feature: public repost Then I should see "reshare this!" Then I should see a ".reshare" And I should see "Bob" + And I go to the home page - And I go to the destroy user session page - And I sign in as "bob@bob.bob" And I should see "1 Reshare" Scenario: Can have text diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index 6aee4a074..0d96356c5 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -8,7 +8,7 @@ describe Retraction do before do @aspect = alice.aspects.first alice.contacts.create(:person => eve.person, :aspects => [@aspect]) - @post = alice.post :status_message, :text => "Destroy!", :to => @aspect.id + @post = alice.post(:status_message, :public => true, :text => "Destroy!", :to => @aspect.id) end describe 'serialization' do @@ -20,12 +20,24 @@ describe Retraction do end describe '#subscribers' do - it 'returns the subscribers to the post for all objects other than person' do - retraction = Retraction.for(@post) - obj = retraction.instance_variable_get(:@object) - wanted_subscribers = obj.subscribers(alice) - obj.should_receive(:subscribers).with(alice).and_return(wanted_subscribers) - retraction.subscribers(alice).map{|s| s.id}.should =~ wanted_subscribers.map{|s| s.id} + context 'posts' do + before do + @retraction = Retraction.for(@post) + @obj = @retraction.instance_variable_get(:@object) + @wanted_subscribers = @obj.subscribers(alice) + end + + it 'returns the subscribers to the post for all objects other than person' do + @retraction.subscribers(alice).map(&:id).should =~ @wanted_subscribers.map(&:id) + end + + it 'does not return the authors of reshares' do + @post.reshares << Factory.create(:reshare, :root => @post, :author => bob.person) + @post.save! + + @wanted_subscribers -= [bob.person] + @retraction.subscribers(alice).map(&:id).should =~ @wanted_subscribers.map(&:id) + end end context 'setting subscribers' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7cc3944c4..23a25a49b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -756,14 +756,14 @@ describe User do describe '#retract' do before do @retraction = mock + + @post = Factory(:status_message, :author => bob.person, :public => true) end context "regular retractions" do before do Retraction.stub(:for).and_return(@retraction) @retraction.stub(:perform) - - @post = Factory(:status_message, :author => bob.person, :public => true) end it 'sends a retraction' do @@ -787,13 +787,25 @@ describe User do end it 'performs the retraction' do - + pending end end context "relayable retractions" do - it 'sends a relayable retraction if the object is relayable' do + before do + @post.reshares << Factory.create(:reshare, :author => remote_raphael) + @post.save! + end + it 'sends a relayable retraction if the object is relayable' do + r_ret = RelayableRetraction.build(bob, @post) + RelayableRetraction.should_receive(:build).and_return(r_ret) + + dis = mock + dis.should_receive(:post) + Postzord::Dispatch.should_receive(:new).with(bob, r_ret).and_return(dis) + + bob.retract(@post) end end end