FIX: Check type of existing reviewables when new reviewable is created (#13662)
This commit is contained in:
parent
9969631cef
commit
14a13dc192
|
@ -139,8 +139,8 @@ class Reviewable < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
reviewable.created_new!
|
reviewable.created_new!
|
||||||
|
|
||||||
if target.blank?
|
if target.blank? || !Reviewable.where(target: target, type: reviewable.type).exists?
|
||||||
# If there is no target there's no chance of a conflict
|
# If there is no target, or no existing reviewable with matching target and type, there's no chance of a conflict
|
||||||
reviewable.save!
|
reviewable.save!
|
||||||
else
|
else
|
||||||
# In this case, a reviewable might already exist for this (type, target_id) index.
|
# In this case, a reviewable might already exist for this (type, target_id) index.
|
||||||
|
|
|
@ -78,6 +78,14 @@ RSpec.describe Reviewable, type: :model do
|
||||||
expect(r1.pending?).to eq(true)
|
expect(r1.pending?).to eq(true)
|
||||||
expect(r0.pending?).to eq(false)
|
expect(r0.pending?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "will create a new reviewable when an existing reviewable exists the same target with different type" do
|
||||||
|
r0 = Fabricate(:reviewable_queued_post)
|
||||||
|
r0.perform(admin, :approve_post)
|
||||||
|
|
||||||
|
r1 = ReviewableFlaggedPost.needs_review!(created_by: admin, target: r0.target)
|
||||||
|
expect(r1.pending?).to eq(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".list_for" do
|
context ".list_for" do
|
||||||
|
|
Loading…
Reference in New Issue