added job and spec for BatchLocalReceive. wip
This commit is contained in:
parent
149b1832fd
commit
f0df6deed3
2 changed files with 51 additions and 0 deletions
21
app/models/jobs/receive_local_batch.rb
Normal file
21
app/models/jobs/receive_local_batch.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class ReceiveLocalBatch < Base
|
||||
require File.join(Rails.root, 'lib/postzord/receiver')
|
||||
|
||||
@queue = :receive
|
||||
def self.perform_delegate(author_id, post_id, recipient_user_ids)
|
||||
end
|
||||
def self.create_visibilities(post, recipient_user_ids)
|
||||
aspects = Aspect.where(:user_id => recipient_user_ids).joins(:contacts).where(:contacts => {:person_id => post.author_id}).select('aspects.id')
|
||||
aspects.each do |aspect|
|
||||
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
|
||||
post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
30
spec/models/jobs/receive_local_batch_spec.rb
Normal file
30
spec/models/jobs/receive_local_batch_spec.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper'
|
||||
describe Job::ReceiveLocalBatch do
|
||||
#takes author id, post id and array of receiving user ids
|
||||
#for each recipient, it gets the aspects that the author is in
|
||||
#Gets all the aspect ids, and inserts into post_visibilities for each aspect
|
||||
#Then it sockets to those users
|
||||
#And notifies mentioned people
|
||||
before do
|
||||
@post = alice.build_post(:status_message, :text => 'Hey Bob')
|
||||
@post.save!
|
||||
end
|
||||
describe '.perform_delegate' do
|
||||
it 'calls .create_visibilities' do
|
||||
end
|
||||
it 'sockets to users' do
|
||||
end
|
||||
it 'notifies mentioned users' do
|
||||
end
|
||||
end
|
||||
describe '.create_visibilities' do
|
||||
it 'creates a visibility for each user' do
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_false
|
||||
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_true
|
||||
end
|
||||
end
|
||||
describe '.socket_to_users' do
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue