Fix #4901: Duplicate disapprovals
* Add uniqueness constraint on post_disapprovals (user_id, post_id). * Add fix script to remove existing duplicates.
This commit is contained in:
@@ -45,4 +45,20 @@ class ApplicationRecordTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "ApplicationRecord#destroy_duplicates!" do
|
||||
should "destroy all duplicates" do
|
||||
@post1 = create(:post, score: 42)
|
||||
@post2 = create(:post, score: 42)
|
||||
@post3 = create(:post, score: 42)
|
||||
@post4 = create(:post, score: 23)
|
||||
|
||||
Post.destroy_duplicates!(:score)
|
||||
|
||||
assert_equal(true, Post.exists?(@post1.id))
|
||||
assert_equal(false, Post.exists?(@post2.id))
|
||||
assert_equal(false, Post.exists?(@post3.id))
|
||||
assert_equal(true, Post.exists?(@post4.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user