mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
update pr based on review
This commit is contained in:
parent
be1df3ba75
commit
3986367f3f
2 changed files with 19 additions and 27 deletions
|
@ -10,14 +10,11 @@ module Jobs
|
||||||
.count
|
.count
|
||||||
.each_key do |email|
|
.each_key do |email|
|
||||||
|
|
||||||
query = users.where("email_tokens.email = ?", email)
|
query = users.where("email_tokens.email = ?", email).order(id: :asc)
|
||||||
.order(id: :asc)
|
|
||||||
|
|
||||||
original_user = query.first
|
original_user = query.first
|
||||||
|
|
||||||
query.offset(1)
|
query.offset(1).each do |user|
|
||||||
.each do |user|
|
|
||||||
|
|
||||||
user.posts.each do |post|
|
user.posts.each do |post|
|
||||||
post.set_owner(original_user, acting_user)
|
post.set_owner(original_user, acting_user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,36 +1,31 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Jobs::FixPrimaryEmailsForStagedUsers do
|
RSpec.describe Jobs::FixPrimaryEmailsForStagedUsers do
|
||||||
let(:common_email) { 'test@reply' }
|
|
||||||
let(:staged_user) { Fabricate(:user, staged: true, active: false) }
|
|
||||||
let(:staged_user2) { Fabricate(:user, staged: true, active: false) }
|
|
||||||
let(:staged_user3) { Fabricate(:user, staged: true, active: false) }
|
|
||||||
let(:active_user) { Fabricate(:coding_horror) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
[staged_user, staged_user2, staged_user3].each do |user|
|
|
||||||
user.email_tokens = [Fabricate.create(:email_token, email: common_email, user: user)]
|
|
||||||
end
|
|
||||||
|
|
||||||
UserEmail.delete_all
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should clean up duplicated staged users' do
|
it 'should clean up duplicated staged users' do
|
||||||
expect { described_class.new.execute_onceoff({}) }
|
common_email = 'test@reply'
|
||||||
.to change { User.count }.by(-2)
|
|
||||||
|
|
||||||
expect(User.all).to contain_exactly(Discourse.system_user, staged_user, active_user)
|
staged_user = Fabricate(:user, staged: true, active: false)
|
||||||
expect(staged_user.reload.email).to eq(common_email)
|
staged_user2 = Fabricate(:user, staged: true, active: false)
|
||||||
end
|
staged_user3 = Fabricate(:user, staged: true, active: false)
|
||||||
|
|
||||||
it 'should move posts owned by duplicate users to the original' do
|
|
||||||
post1 = Fabricate(:post, user: staged_user2)
|
post1 = Fabricate(:post, user: staged_user2)
|
||||||
post2 = Fabricate(:post, user: staged_user2)
|
post2 = Fabricate(:post, user: staged_user2)
|
||||||
post3 = Fabricate(:post, user: staged_user3)
|
post3 = Fabricate(:post, user: staged_user3)
|
||||||
|
|
||||||
expect { described_class.new.execute_onceoff({}) }
|
[staged_user, staged_user2, staged_user3].each do |user|
|
||||||
.to change { staged_user.posts.count }.by(+3)
|
user.email_tokens = [Fabricate.create(:email_token, email: common_email, user: user)]
|
||||||
|
end
|
||||||
|
|
||||||
|
active_user = Fabricate(:coding_horror)
|
||||||
|
|
||||||
|
UserEmail.delete_all
|
||||||
|
|
||||||
|
expect { described_class.new.execute_onceoff({}) }
|
||||||
|
.to change { User.count }.by(-2)
|
||||||
|
.and change { staged_user.posts.count }.by(3)
|
||||||
|
|
||||||
|
expect(User.all).to contain_exactly(Discourse.system_user, staged_user, active_user)
|
||||||
expect(staged_user.posts.all).to contain_exactly(post1, post2, post3)
|
expect(staged_user.posts.all).to contain_exactly(post1, post2, post3)
|
||||||
|
expect(staged_user.reload.email).to eq(common_email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue