Relax uniqueness constraint to allow nil (#38934)
This commit is contained in:
parent
c47922602f
commit
11803e3d04
@ -30,7 +30,7 @@ class CollectionItem < ApplicationRecord
|
|||||||
|
|
||||||
delegate :local?, :remote?, to: :collection
|
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 :position, numericality: { only_integer: true, greater_than: 0 }
|
||||||
validates :activity_uri, presence: true, if: :local_item_with_remote_account?
|
validates :activity_uri, presence: true, if: :local_item_with_remote_account?
|
||||||
validates :approval_uri, presence: true, unless: -> { local? || account&.local? || !accepted? }
|
validates :approval_uri, presence: true, unless: -> { local? || account&.local? || !accepted? }
|
||||||
|
|||||||
@ -41,6 +41,19 @@ RSpec.describe CollectionItem do
|
|||||||
subject { Fabricate.build(:unverified_remote_collection_item) }
|
subject { Fabricate.build(:unverified_remote_collection_item) }
|
||||||
|
|
||||||
it { is_expected.to validate_presence_of(:object_uri) }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user