Protect against pre-existing post_visibilities, log them so we can find out where they are coming from.'
This commit is contained in:
parent
24335aa5bf
commit
e2f78a8b8c
2 changed files with 14 additions and 4 deletions
|
|
@ -17,8 +17,12 @@ module Job
|
||||||
def self.create_visibilities(post, recipient_user_ids)
|
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.user_id')
|
aspects = Aspect.where(:user_id => recipient_user_ids).joins(:contacts).where(:contacts => {:person_id => post.author_id}).select('aspects.id, aspects.user_id')
|
||||||
aspects.each do |aspect|
|
aspects.each do |aspect|
|
||||||
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
|
begin
|
||||||
post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user
|
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
|
||||||
|
rescue ActiveRecord::RecordNotUnique => e
|
||||||
|
Rails.logger.info(:event => :unexpected_pv, :aspect_id => aspect.id, :post_id => post.id)
|
||||||
|
#The post was already visible to that aspect
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.socket_to_users(post, recipient_user_ids)
|
def self.socket_to_users(post, recipient_user_ids)
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,15 @@ describe Job::ReceiveLocalBatch do
|
||||||
end
|
end
|
||||||
describe '.create_visibilities' do
|
describe '.create_visibilities' do
|
||||||
it 'creates a visibility for each user' do
|
it 'creates a visibility for each user' do
|
||||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_false
|
PostVisibility.exists?(:aspect_id => bob.aspects.first.id, :post_id => @post.id).should be_false
|
||||||
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
||||||
PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_true
|
PostVisibility.exists?(:aspect_id => bob.aspects.first.id, :post_id => @post.id).should be_true
|
||||||
|
end
|
||||||
|
it 'does not raise if a visibility already exists' do
|
||||||
|
PostVisibility.create!(:aspect_id => bob.aspects.first.id, :post_id => @post.id)
|
||||||
|
lambda {
|
||||||
|
Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id])
|
||||||
|
}.should_not raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe '.socket_to_users' do
|
describe '.socket_to_users' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue