Fix #4444: Pool navigation is broken when post appears twice in same pool.
Don't allow the same post to be added to the same pool twice. This was only legitimately needed in a handful of cases. It was much more common for posts to be mistakenly added to the same pool twice.
This commit is contained in:
@@ -129,7 +129,7 @@ class Pool < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def normalize_post_ids
|
def normalize_post_ids
|
||||||
self.post_ids = post_ids.uniq if is_collection?
|
self.post_ids = post_ids.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def revert_to!(version)
|
def revert_to!(version)
|
||||||
|
|||||||
@@ -233,9 +233,12 @@ class PoolTest < ActiveSupport::TestCase
|
|||||||
assert_equal("A_B", @pool.name)
|
assert_equal("A_B", @pool.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "normalize its post ids" do
|
should "not allow duplicate posts" do
|
||||||
@pool.update(category: "collection", post_ids: [1, 2, 2, 3, 1])
|
@pool.update(category: "collection", post_ids: [1, 2, 2, 3, 1])
|
||||||
assert_equal([1, 2, 3], @pool.post_ids)
|
assert_equal([1, 2, 3], @pool.post_ids)
|
||||||
|
|
||||||
|
@pool.update(category: "series", post_ids: [1, 2, 2, 3, 1])
|
||||||
|
assert_equal([1, 2, 3], @pool.post_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when validating names" do
|
context "when validating names" do
|
||||||
|
|||||||
Reference in New Issue
Block a user