Skip to content

Commit

Permalink
Edit or remove committee members. Connected to stories #1616 and #1675.
Browse files Browse the repository at this point in the history
I cleared the committee members and chairs before passing the new params
from the form to the actor.

I fixed the methods that keep the committee_chair_name and
committee_members_names in sync with the committee_chair and
committee_members fields.
  • Loading branch information
val99erie committed Aug 21, 2018
1 parent dc427be commit 39a1beb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/controllers/hyrax/etds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions app/models/etd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions spec/controllers/hyrax/etds_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
16 changes: 16 additions & 0 deletions spec/models/etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39a1beb

Please sign in to comment.