For performance reasons, use `delete_all` when removing a user's email logs

This commit is contained in:
Robin Ward 2014-11-28 14:20:43 -05:00
parent 37a3e956b6
commit cb0e7a5724
2 changed files with 12 additions and 1 deletions

View File

@ -25,7 +25,7 @@ class User < ActiveRecord::Base
has_many :post_actions, dependent: :destroy
has_many :user_badges, -> {where('user_badges.badge_id IN (SELECT id FROM badges where enabled)')}, dependent: :destroy
has_many :badges, through: :user_badges
has_many :email_logs, dependent: :destroy
has_many :email_logs, dependent: :delete_all
has_many :post_timings
has_many :topic_allowed_users, dependent: :destroy
has_many :topics_allowed, through: :topic_allowed_users, source: :topic

View File

@ -283,6 +283,17 @@ describe UserDestroyer do
end
end
context 'user got an email' do
let(:user) { Fabricate(:user) }
let!(:email_log) { Fabricate(:email_log, user: user) }
it "deletes the email log" do
expect {
UserDestroyer.new(@admin).destroy(user, {delete_posts: true})
}.to change { EmailLog.count }.by(-1)
end
end
context 'user liked things' do
before do
@topic = Fabricate(:topic, user: Fabricate(:user))