Skip to content

Commit

Permalink
add spec for validating membership restrictions of existing cols
Browse files Browse the repository at this point in the history
the prior implementation of this validator ignored and overwrote existing
collections. the forms don't expand existing `member_of_collection_ids` into
attributes for submission, so it's important that we validate membership based
both on the existing ids AND any new submitted attributes.

the newer implementation handles this case, so this adds a regression test for
the requirement.
  • Loading branch information
tamsin johnson authored and no-reply committed May 14, 2022
1 parent 84d8d17 commit f2df82e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion spec/validators/hyrax/collection_membership_validator_spec.rb
Expand Up @@ -81,10 +81,31 @@
end
end

context 'and work is in another collection that IS posing a conflict' do
context 'and work is already ni collections with membership restriction conflicts' do
let(:work) { FactoryBot.build(:hyrax_work, member_of_collection_ids: [sm_col1.id]) }
let(:sm_col1) { FactoryBot.valkyrie_create(:hyrax_collection, collection_type_gid: single_mem_col_type.to_global_id) }
let(:sm_col2) { FactoryBot.valkyrie_create(:hyrax_collection, collection_type_gid: single_mem_col_type.to_global_id) }

let(:mem_of_cols_attrs) do
{ "0" => { "id" => sm_col2.id.to_s, "_destroy" => "false" } }
end

it 'adds validation errors' do
validator.validate(form)

expect(form.errors)
.to contain_exactly(
start_with('Member of collection ids Error: ' \
'You have specified more than one of ' \
'the same single-membership collection type')
)
end
end

context 'and work is added to collections with membership restriction conflicts' do
let(:work) { FactoryBot.build(:hyrax_work) }
let(:sm_col1) { FactoryBot.valkyrie_create(:hyrax_collection, collection_type_gid: single_mem_col_type.to_global_id) }
let(:sm_col2) { FactoryBot.valkyrie_create(:hyrax_collection, collection_type_gid: single_mem_col_type.to_global_id) }
let(:mem_of_cols_attrs) do
{ "0" => { "id" => sm_col1.id.to_s, "_destroy" => "false" },
"1" => { "id" => sm_col2.id.to_s, "_destroy" => "false" } }
Expand Down

0 comments on commit f2df82e

Please sign in to comment.