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

Protect against pre-existing post_visibilities, log them so we can find out...

Protect against pre-existing post_visibilities, log them so we can find out where they are coming from.'
parent 24335aa5
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -17,8 +17,12 @@ module Job
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.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
begin
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
def self.socket_to_users(post, recipient_user_ids)
......
......@@ -25,9 +25,15 @@ describe Job::ReceiveLocalBatch do
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
PostVisibility.exists?(:aspect_id => bob.aspects.first.id, :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
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
describe '.socket_to_users' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter