mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
FIX: Email Send post has already been taken error (#16992)
* FIX: Email Send post has already been taken error Adding a failing test first before coming up with a good solution. Related: 357011eb3b4e9c5fb860a34ecbb2f5cb89e89a7a The above commit changed ``` PostReplyKey.find_or_create_by_safe! ``` to ``` PostReplyKey.create_or_find_by! ``` But I don't think it is working as a 1-1 replacement because of the `Validation failed: Post has already been taken` error we are receiving with this change. Also we need to make sure we don't re-introduce any concurrency issues. Reported: https://meta.discourse.org/t/224706/13 * Remove rails unique constraint and rely on db index I believe this is what is causing `create_or_find_by!` to fail. Because we have a unique constraint in the db I think we can remove this rails unique constraint? * clean up spec wording
This commit is contained in:
@ -767,6 +767,14 @@ describe Email::Sender do
|
||||
expect(post_reply_key.post_id).to eq(post.id)
|
||||
expect { email_sender.send }.to change { PostReplyKey.count }.by(0)
|
||||
end
|
||||
|
||||
it 'should find existing key' do
|
||||
existing_post_reply_key = PostReplyKey.create(post_id: post.id, user_id: user.id)
|
||||
expect { email_sender.send }.to change { PostReplyKey.count }.by(0)
|
||||
post_reply_key = PostReplyKey.last
|
||||
expect(post_reply_key).to eq(existing_post_reply_key)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user