mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06: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: 357011eb3b
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:
parent
79f5a7750c
commit
35e17ce115
@ -6,7 +6,7 @@ class PostReplyKey < ActiveRecord::Base
|
||||
|
||||
before_validation { self.reply_key ||= self.class.generate_reply_key }
|
||||
|
||||
validates :post_id, presence: true, uniqueness: { scope: :user_id }
|
||||
validates :post_id, presence: true
|
||||
validates :user_id, presence: true
|
||||
validates :reply_key, presence: true
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user