From 12dfe4ab3b0a9054a09cad83274558bc97be69a4 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Sat, 29 Aug 2020 09:00:33 -0500 Subject: [PATCH] Spec Fix:Nullify Rating Votes when Deleting Users (#10071) --- spec/services/users/delete_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/services/users/delete_spec.rb b/spec/services/users/delete_spec.rb index 28c69e9c3..5b5f32bb8 100644 --- a/spec/services/users/delete_spec.rb +++ b/spec/services/users/delete_spec.rb @@ -115,6 +115,10 @@ RSpec.describe Users::Delete, type: :service do create_associations(direct_associations.select { |a| kept_association_names.include?(a.name) }) end + before do + allow(user).to receive(:trusted).and_return(true) + end + def create_associations(names) associations = [] @@ -146,6 +150,11 @@ RSpec.describe Users::Delete, type: :service do end it "keeps the kept associations" do + # Rating Vote must be for NOT the user's own article + other_article = create(:article) + rating_vote = kept_associations.detect { |a| a.is_a?(RatingVote) } + rating_vote.update(article_id: other_article.id) + expect(kept_associations).not_to be_empty user.reload described_class.call(user)