diff --git a/app/controllers/hyrax/etds_controller.rb b/app/controllers/hyrax/etds_controller.rb index 326f6e303..816937233 100644 --- a/app/controllers/hyrax/etds_controller.rb +++ b/app/controllers/hyrax/etds_controller.rb @@ -77,6 +77,8 @@ def update end if params['request_from_form'] == 'true' + curation_concern.committee_chair = nil + curation_concern.committee_members = nil update_with_response_for_form else super diff --git a/app/models/etd.rb b/app/models/etd.rb index 81f37f4b0..33381ca2a 100644 --- a/app/models/etd.rb +++ b/app/models/etd.rb @@ -209,12 +209,10 @@ def set_research_field_ids end def index_committee_chair_name - return unless committee_chair && committee_chair.first self.committee_chair_name = committee_chair.map(&:name_and_affiliation) end def index_committee_members_names - return unless committee_members && committee_members.first self.committee_members_names = committee_members.map(&:name_and_affiliation) end diff --git a/spec/controllers/hyrax/etds_controller_spec.rb b/spec/controllers/hyrax/etds_controller_spec.rb index 091b22dc4..0c9e40014 100644 --- a/spec/controllers/hyrax/etds_controller_spec.rb +++ b/spec/controllers/hyrax/etds_controller_spec.rb @@ -55,6 +55,43 @@ etd.reload end + context 'editing or removing committee members and chairs' do + let(:etd) { FactoryBot.build(:etd, default_attrs.merge(committee_chair_attributes: [arthur, lancelot], committee_members_attributes: [morgan, guin])) } + + let(:arthur) { { name: ['Arthur'], affiliation: ['Emory University'] } } + let(:lancelot) { { name: ['Lancelot'], affiliation: ['Another University'] } } + let(:morgan) { { name: ['Morgan'], affiliation: ['Emory University'] } } + let(:guin) { { name: ['Guinevere'], affiliation: ['Another University'] } } + + let(:new_attrs) do + { + committee_chair_attributes: { '0' => new_arthur }, + committee_members_attributes: { '0' => new_morgan } + } + end + + let(:new_arthur) { { name: ['Arthur (edited)'], affiliation: ['Edited University'] } } + let(:new_morgan) { { name: ['Morgan (edited)'], affiliation: ['Emory University'] } } + + before do + new_ui = Rails.application.config_for(:new_ui).fetch('enabled', false) + skip('This spec will fail if not using new UI') unless new_ui + + patch :update, params: { id: etd, etd: new_attrs, request_from_form: 'true' } + etd.reload # Test persisted state + end + + it 'updates committee members and chairs' do + expect(etd.committee_chair.count).to eq 1 + expect(etd.committee_chair.first.name).to eq ['Arthur (edited)'] + expect(etd.committee_chair.first.affiliation).to eq ['Edited University'] + + expect(etd.committee_members.count).to eq 1 + expect(etd.committee_members.first.name).to eq ['Morgan (edited)'] + expect(etd.committee_members.first.affiliation).to eq ['Emory University'] + end + end + context 'adding a new supplemental file' do let(:uf) { FactoryBot.create(:uploaded_file, :supplementary, title: ['old uf title'], user_id: user.id) } diff --git a/spec/models/etd_spec.rb b/spec/models/etd_spec.rb index 9021b3090..831a69b2c 100644 --- a/spec/models/etd_spec.rb +++ b/spec/models/etd_spec.rb @@ -192,6 +192,22 @@ etd.reload # Make sure the new data is persisted expect(etd.committee_chair_name).to contain_exactly('New Name, Emory University') end + + it "updates committee_members_names when committee members are deleted" do + expect(etd.committee_members_names).to contain_exactly("Manns, Joseph, Emory University", "Craighead, W Edward, Emory University") + etd.committee_members = nil + etd.save! + etd.reload # Make sure the new data is persisted + expect(etd.committee_members_names).to eq [] + end + + it "updates committee_chair_name when committee chairs are deleted" do + expect(etd.committee_chair_name).to eq ['Treadway, Michael T, Emory University'] + etd.committee_chair = nil + etd.save! + etd.reload # Make sure the new data is persisted + expect(etd.committee_chair_name).to eq [] + end end context "committee members" do