docbrown/spec/services/users/delete_articles_spec.rb
Anna Buianova 8c58be75f5 Self-deleting user account (#4480) [deploy]
* Start with self deleting account

* Moved deleting user content and activity out of moderator hierarchy

* Added tests for the users delete services

* Tests for Users::DeleteComments

* User self-deletion (start)

* Some tests for user self-delete

* Specs for user self-deletion

* Test flash settings on users delete

* Added basic specs for the Users::DeleteJob

* Send notification when a user was destroyed

* Rename Users::DeleteJob to SelfDelete

* Change texts about self-deletion

* Fix users delete job spec

* Rescue and log exceptions while self-deleting user

* Added visible flash notices after deleting user

* Remove unneeded css for flash notice

* Fix link to a ghost account

* Remove redundant css

* Added github and twitter oauth apps links
2019-11-11 14:59:01 -05:00

40 lines
1.3 KiB
Ruby

require "rails_helper"
RSpec.describe Users::DeleteArticles, type: :service do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:article) { create(:article, user: user) }
let!(:article2) { create(:article, user: user) }
let!(:article3) { create(:article, user: user2) }
it "deletes articles" do
described_class.call(user)
expect(Article.find_by(id: article.id)).to be_nil
expect(Article.find_by(id: article2.id)).to be_nil
expect(Article.find(article3.id)).to be_present
end
context "with comments" do
let(:buster) { double }
before do
allow(buster).to receive(:bust_comment)
allow(buster).to receive(:bust_article)
allow(buster).to receive(:bust_user)
create_list(:comment, 2, commentable: article, user: user2)
end
it "deletes articles' comments" do
described_class.call(user)
expect(Comment.where(commentable_id: article, commentable_type: "Article").any?).to be false
end
it "busts cache" do
described_class.call(user, buster)
expect(buster).to have_received(:bust_comment).with(article).twice
expect(buster).to have_received(:bust_user).with(user2).at_least(:once)
expect(buster).to have_received(:bust_article).with(article)
end
end
end