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:
evazion
2021-10-12 20:22:00 -05:00
parent 92e20713e3
commit e72446463e
5 changed files with 60 additions and 1 deletions

View File

@@ -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