Skip to content
Extraits de code Groupes Projets
Valider 199eb894 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

clean up posting spec, move socket_to_uid into add_to_streams

parent 836b5685
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -166,8 +166,7 @@ class User ...@@ -166,8 +166,7 @@ class User
#socket post #socket post
Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}") Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}")
push_to_aspects(post, aspect_ids) push_to_aspects(post, aspects_from_ids(aspect_ids))
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) && !post.pending
if post.public if post.public
self.services.each do |service| self.services.each do |service|
...@@ -200,6 +199,7 @@ class User ...@@ -200,6 +199,7 @@ class User
self.raw_visible_posts << post self.raw_visible_posts << post
self.save self.save
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid
target_aspects = aspects_from_ids(aspect_ids) target_aspects = aspects_from_ids(aspect_ids)
target_aspects.each do |aspect| target_aspects.each do |aspect|
aspect.posts << post aspect.posts << post
...@@ -219,23 +219,13 @@ class User ...@@ -219,23 +219,13 @@ class User
end end
end end
def push_to_aspects(post, aspect_ids) def push_to_aspects(post, aspects)
if aspect_ids == :all || aspect_ids == "all"
aspects = self.aspects
elsif aspect_ids.is_a?(Array) && aspect_ids.first.class == Aspect
aspects = aspect_ids
else
aspects = self.aspects.find_all_by_id(aspect_ids)
end
#send to the aspects #send to the aspects
target_contacts = [] target_contacts = aspects.inject([]) { |contacts,aspect|
contacts = contacts | aspect.contacts
aspects.each { |aspect|
target_contacts = target_contacts | aspect.contacts
} }
push_to_hub(post) if post.respond_to?(:public) && post.public push_to_hub(post) if post.respond_to?(:public) && post.public
push_to_people(post, self.person_objects(target_contacts)) push_to_people(post, self.person_objects(target_contacts))
end end
...@@ -250,7 +240,7 @@ class User ...@@ -250,7 +240,7 @@ class User
person.reload # Sadly, we need this for Ruby 1.9. person.reload # Sadly, we need this for Ruby 1.9.
# person.owner will always return a ProxyObject. # person.owner will always return a ProxyObject.
# calling nil? performs a necessary evaluation. # calling nil? performs a necessary evaluation.
unless person.owner.nil? if person.owner_id
Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}") Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}")
person.owner.receive(post.to_diaspora_xml, self.person) person.owner.receive(post.to_diaspora_xml, self.person)
else else
......
...@@ -37,6 +37,10 @@ describe User do ...@@ -37,6 +37,10 @@ describe User do
aspect1.reload.post_ids.should include @post.id aspect1.reload.post_ids.should include @post.id
end end
it 'sockets the post to the poster' do
@post.should_receive(:socket_to_uid).with(user.id, anything)
user.add_to_streams(@post, @aspect_ids)
end
end end
describe '#aspects_from_ids' do describe '#aspects_from_ids' do
...@@ -67,45 +71,34 @@ describe User do ...@@ -67,45 +71,34 @@ describe User do
end end
describe '#dispatch_post' do describe '#dispatch_post' do
it 'should put the post in the aspect post array' do let(:status) {user.build_post(:status_message, @status_opts)}
post = user.post(:status_message, :message => "hey", :to => aspect.id) before do
aspect.reload @message = "hello, world!"
aspect.posts.should include post @status_opts = {:to => "all", :message => @message}
end
it "should add the post to that user's visible posts" do
status_message = user.post :status_message, :message => "hi", :to => aspect.id
user.reload
user.raw_visible_posts.include?(status_message).should be true
end end
it "posts to services if post is public" do it "posts to services if post is public" do
message = "hello, world!" @status_opts[:public] = true
user.should_receive(:post_to_twitter).with(service1, message).exactly(1).times status.save
user.should_receive(:post_to_facebook).with(service2, message).exactly(1).times user.should_receive(:post_to_twitter).with(service1, @message).once
user.post :status_message, :message => message, :to => "all", :public => true user.should_receive(:post_to_facebook).with(service2, @message).once
user.dispatch_post(status, :to => "all")
end end
it "does not post to services if post is not public" do it "does not post to services if post is not public" do
user.should_receive(:post_to_twitter).exactly(0).times @status_opts[:public] = false
user.should_receive(:post_to_facebook).exactly(0).times status.save
user.post :status_message, :message => "hi", :to => "all" user.should_not_receive(:post_to_twitter)
end user.should_not_receive(:post_to_facebook)
user.dispatch_post(status, :to => "all")
it 'should not socket a pending post' do
sm = user.build_post(:status_message, :message => "your mom", :to => aspect.id, :pending => true)
sm.should_not_receive(:socket_to_uid)
user.dispatch_post(sm, :to => aspect.id)
end end
end end
describe '#post' do describe '#post' do
it 'should not create a post with invalid aspect' do it 'should not create a post with invalid aspect' do
pending "this would just causes db polution" pending "this would just cause db polution"
post_count = Post.count proc {
proc { user.post(:status_message, :message => "hey", :to => aspect2.id) }.should raise_error /Cannot post to an aspect you do not own./ user.post(:status_message, :message => "hey", :to => aspect2.id)
Post.count.should == post_count }.should_not change(Post, :count)
end end
end end
...@@ -139,12 +132,12 @@ describe User do ...@@ -139,12 +132,12 @@ describe User do
describe '#push_to_aspects' do describe '#push_to_aspects' do
it 'should push a post to a aspect' do it 'should push a post to a aspect' do
user.should_receive(:push_to_person).twice user.should_receive(:push_to_person).twice
user.push_to_aspects(post, aspect.id) user.push_to_aspects(post, [aspect])
end end
it 'should push a post to contacts in all aspects' do it 'should push a post to contacts in all aspects' do
user.should_receive(:push_to_person).exactly(3).times user.should_receive(:push_to_person).exactly(3).times
user.push_to_aspects(post, :all) user.push_to_aspects(post, user.aspects)
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter