Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework CollectionMembershipValidator to skip overwriting collections
the validator should limit itself to validating that the collections are allowed. whether or not validation is ever run, `#sync` should apply the form values to the target resource. ensure this happens by moving the value population behavior into a reform populator. without this work, the `Hyrax::CollectionMembershipValidator` was erasing existing collection membership. validators should never change the records being validated.
- Loading branch information
tamsin johnson
committed
May 11, 2022
1 parent
a9e13ca
commit 43eb185
Showing
6 changed files
with
118 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
spec/validators/hyrax/collection_membership_validator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Hyrax::CollectionMembershipValidator do | ||
subject(:validator) { described_class.new } | ||
let(:work) { FactoryBot.build(:hyrax_work, :as_collection_member) } | ||
let(:form) { Hyrax::Forms::ResourceForm(Monograph).new(work) } | ||
|
||
describe '#validate' do | ||
it 'is valid' do | ||
expect { validator.validate(form) } | ||
.not_to change { form.errors } | ||
.from be_empty | ||
end | ||
|
||
it 'does not change existing collections' do | ||
expect { validator.validate(form) } | ||
.not_to change { form.member_of_collection_ids } | ||
end | ||
end | ||
end |