From 7949bb9a7ec6a45e36a80b127bff979464de0f27 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 10 Oct 2017 19:43:58 -0400 Subject: [PATCH] fix #1836 - Adding works to collection should forward to collection show --- .../hyrax/dashboard/collections_controller.rb | 3 ++- .../hyrax/dashboard/collections/_form.html.erb | 1 + .../dashboard/collections_controller_spec.rb | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/hyrax/dashboard/collections_controller.rb b/app/controllers/hyrax/dashboard/collections_controller.rb index 205e2ccbd1..53bfcf34eb 100644 --- a/app/controllers/hyrax/dashboard/collections_controller.rb +++ b/app/controllers/hyrax/dashboard/collections_controller.rb @@ -214,7 +214,8 @@ def uploaded_files(uploaded_file_ids) end def update_referer - edit_dashboard_collection_path(@collection) + (params[:referer_anchor] || '') + return edit_dashboard_collection_path(@collection) + (params[:referer_anchor] || '') if params[:stay_on_edit] + dashboard_collection_path(@collection) end def determine_banner_data diff --git a/app/views/hyrax/dashboard/collections/_form.html.erb b/app/views/hyrax/dashboard/collections/_form.html.erb index efced2d9bd..d987393c4c 100644 --- a/app/views/hyrax/dashboard/collections/_form.html.erb +++ b/app/views/hyrax/dashboard/collections/_form.html.erb @@ -58,6 +58,7 @@ <% end %> <%= hidden_field_tag :type, params[:type] %> + <%= hidden_field_tag :stay_on_edit, true %> <%= hidden_field_tag :collection_type_gid, @collection.collection_type_gid %> <% if params[:batch_document_ids].present? %> <% params[:batch_document_ids].each do |batch_item| %> diff --git a/spec/controllers/hyrax/dashboard/collections_controller_spec.rb b/spec/controllers/hyrax/dashboard/collections_controller_spec.rb index c23ba5c288..145aab76b5 100644 --- a/spec/controllers/hyrax/dashboard/collections_controller_spec.rb +++ b/spec/controllers/hyrax/dashboard/collections_controller_spec.rb @@ -133,16 +133,27 @@ end end - it "adds members to the collection" do + it "adds members to the collection from edit form" do expect do put :update, params: { id: collection, collection: { members: 'add' }, - batch_document_ids: [asset3.id] } + batch_document_ids: [asset3.id], + stay_on_edit: true } end.to change { collection.reload.member_objects.size }.by(1) expect(response).to redirect_to routes.url_helpers.edit_dashboard_collection_path(collection, locale: 'en') expect(assigns[:collection].member_objects).to match_array [asset1, asset2, asset3] end + it "adds members to the collection from other than the edit form" do + expect do + put :update, params: { id: collection, + collection: { members: 'add' }, + batch_document_ids: [asset3.id] } + end.to change { collection.reload.member_objects.size }.by(1) + expect(response).to redirect_to routes.url_helpers.dashboard_collection_path(collection, locale: 'en') + expect(assigns[:collection].member_objects).to match_array [asset1, asset2, asset3] + end + it "removes members from the collection" do # TODO: Using size until count is fixed https://github.com/projecthydra-labs/activefedora-aggregation/issues/78 expect do