Relax uniqueness constraint to allow nil (#38934)

This commit is contained in:
David Roetzel 2026-05-07 12:08:50 +02:00 committed by GitHub
parent c47922602f
commit 11803e3d04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -30,7 +30,7 @@ class CollectionItem < ApplicationRecord
delegate :local?, :remote?, to: :collection
validates :account_id, uniqueness: { scope: :collection_id }
validates :account_id, uniqueness: { scope: :collection_id, allow_nil: true }
validates :position, numericality: { only_integer: true, greater_than: 0 }
validates :activity_uri, presence: true, if: :local_item_with_remote_account?
validates :approval_uri, presence: true, unless: -> { local? || account&.local? || !accepted? }

View File

@ -41,6 +41,19 @@ RSpec.describe CollectionItem do
subject { Fabricate.build(:unverified_remote_collection_item) }
it { is_expected.to validate_presence_of(:object_uri) }
context 'when another item without account exists' do
subject { Fabricate.build(:unverified_remote_collection_item, collection:) }
let(:collection) { Fabricate(:remote_collection) }
before do
Fabricate(:unverified_remote_collection_item, collection:)
collection.reload
end
it { is_expected.to be_valid }
end
end
end