FIX: Merging users failed when PM was sent to source and target user
This commit is contained in:
parent
c11e8c9a64
commit
ec29869350
|
@ -355,7 +355,7 @@ class UserMerger
|
|||
conditions: ["x.action_type = y.action_type",
|
||||
"x.target_topic_id IS NOT DISTINCT FROM y.target_topic_id",
|
||||
"x.target_post_id IS NOT DISTINCT FROM y.target_post_id",
|
||||
"x.acting_user_id IN (:source_user_id, :target_user_id)"])
|
||||
"(x.acting_user_id IN (:source_user_id, :target_user_id) OR x.acting_user_id IS NOT DISTINCT FROM y.acting_user_id)"])
|
||||
update_user_id(:user_actions,
|
||||
user_id_column_name: "acting_user_id",
|
||||
conditions: ["x.action_type = y.action_type",
|
||||
|
|
|
@ -702,7 +702,7 @@ describe UserMerger do
|
|||
|
||||
context "user actions" do
|
||||
# action_type and user_id are not nullable
|
||||
# target_topic_id and acting_user_id are nullable, but always a value
|
||||
# target_topic_id and acting_user_id are nullable, but always have a value
|
||||
|
||||
let(:post1) { Fabricate(:post) }
|
||||
let(:post2) { Fabricate(:post) }
|
||||
|
@ -724,6 +724,14 @@ describe UserMerger do
|
|||
target_post_id: post.id)
|
||||
end
|
||||
|
||||
def log_got_private_message(acting_user, user, topic)
|
||||
UserAction.log_action!(action_type: UserAction::GOT_PRIVATE_MESSAGE,
|
||||
user_id: user.id,
|
||||
acting_user_id: acting_user.id,
|
||||
target_topic_id: topic.id,
|
||||
target_post_id: -1)
|
||||
end
|
||||
|
||||
it "merges when target_post_id is not set" do
|
||||
a1 = log_pending_action(source_user, post1)
|
||||
a2 = log_pending_action(source_user, post2)
|
||||
|
@ -754,6 +762,42 @@ describe UserMerger do
|
|||
acting_user_id: target_user.id).pluck(:id)
|
||||
expect(action_ids).to contain_exactly(a2.id, a3.id)
|
||||
end
|
||||
|
||||
it "merges when acting_user is neither source_user nor target_user" do
|
||||
coding_horror = Fabricate(:coding_horror)
|
||||
|
||||
pm_topic1 = Fabricate(:private_message_topic, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: walter),
|
||||
Fabricate.build(:topic_allowed_user, user: source_user),
|
||||
Fabricate.build(:topic_allowed_user, user: target_user),
|
||||
Fabricate.build(:topic_allowed_user, user: coding_horror),
|
||||
])
|
||||
|
||||
pm_topic2 = Fabricate(:private_message_topic, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: walter),
|
||||
Fabricate.build(:topic_allowed_user, user: source_user)
|
||||
])
|
||||
|
||||
pm_topic3 = Fabricate(:private_message_topic, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: walter),
|
||||
Fabricate.build(:topic_allowed_user, user: target_user)
|
||||
])
|
||||
|
||||
a1 = log_got_private_message(walter, source_user, pm_topic1)
|
||||
a2 = log_got_private_message(walter, target_user, pm_topic1)
|
||||
a3 = log_got_private_message(walter, coding_horror, pm_topic1)
|
||||
a4 = log_got_private_message(walter, source_user, pm_topic2)
|
||||
a5 = log_got_private_message(walter, target_user, pm_topic3)
|
||||
|
||||
merge_users!
|
||||
|
||||
expect(UserAction.count).to eq(4)
|
||||
|
||||
action_ids = UserAction.where(action_type: UserAction::GOT_PRIVATE_MESSAGE,
|
||||
user_id: target_user.id,
|
||||
acting_user_id: walter.id).pluck(:id)
|
||||
expect(action_ids).to contain_exactly(a2.id, a4.id, a5.id)
|
||||
end
|
||||
end
|
||||
|
||||
it "merges archived messages" do
|
||||
|
|
Loading…
Reference in New Issue