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:
evazion
2022-05-01 01:55:03 -05:00
parent 4542f38023
commit f4ad1b09da
2 changed files with 5 additions and 2 deletions

View File

@@ -129,7 +129,7 @@ class Pool < ApplicationRecord
end
def normalize_post_ids
self.post_ids = post_ids.uniq if is_collection?
self.post_ids = post_ids.uniq
end
def revert_to!(version)

View File

@@ -233,9 +233,12 @@ class PoolTest < ActiveSupport::TestCase
assert_equal("A_B", @pool.name)
end
should "normalize its post ids" do
should "not allow duplicate posts" do
@pool.update(category: "collection", post_ids: [1, 2, 2, 3, 1])
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
context "when validating names" do