From 7add21367fb551174b07ba13803c16e5bd132458 Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Mon, 12 Sep 2022 11:20:59 -0400 Subject: [PATCH] Don't default member_of_collection_ids in collection_params This default is not necessary and had the side effect of removing pre-existing member_of_collection_ids when updating collections Co-authored-by: Jose Blanco --- .../hyrax/dashboard/collections_controller.rb | 1 - ...llections_controller_with_resource_spec.rb | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/hyrax/dashboard/collections_controller.rb b/app/controllers/hyrax/dashboard/collections_controller.rb index b2a2f89f92..e2a91687f8 100644 --- a/app/controllers/hyrax/dashboard/collections_controller.rb +++ b/app/controllers/hyrax/dashboard/collections_controller.rb @@ -422,7 +422,6 @@ def collection_params params.permit(collection: {})[:collection] .merge(params.permit(:collection_type_gid) .with_defaults(collection_type_gid: default_collection_type_gid)) - .merge(member_of_collection_ids: Array(params[:parent_id])) end end diff --git a/spec/controllers/hyrax/dashboard/collections_controller_with_resource_spec.rb b/spec/controllers/hyrax/dashboard/collections_controller_with_resource_spec.rb index c0f60ee47a..3b967cf7ff 100644 --- a/spec/controllers/hyrax/dashboard/collections_controller_with_resource_spec.rb +++ b/spec/controllers/hyrax/dashboard/collections_controller_with_resource_spec.rb @@ -526,6 +526,25 @@ end end end + + context 'with nested collection' do + let(:parent_collection) { FactoryBot.valkyrie_create(:collection_resource) } + let(:collection) do + FactoryBot.valkyrie_create(:collection_resource, + :public, + title: ["My collection"], + creator: ["Mr. Smith"], + depositor: user.user_key, + edit_users: [user], + member_of_collection_ids: [parent_collection.id]) + end + + it 'retains parent collection relationship' do + put :update, params: { id: collection, collection: { description: ['Videos of importance'] } } + expect(assigns[:collection].description).to eq ['Videos of importance'] + expect(assigns[:collection].member_of_collection_ids).to eq [parent_collection.id] + end + end end describe "#show" do