From 6f30ff1a609270148197e8e063bc38a7288c9a61 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Wed, 3 Nov 2021 10:20:28 +0000 Subject: [PATCH] Issue #DCC649 - Fix for the contributor to fail to save on Contributor page if not required Affiliation field not set. Changes: - In ContributorsController an if condition has been changed in process_org() method Replaced 'return nil if org.blank? && !allow' by 'return hash if org.blank? && !allow' where 'hash remove_org_selection_params(params_in: hash)' - RSpec test spec/controllers/contributors_controller_spec.rb method 'it "with restrict_orgs=true, returns nil if the org could not be converted" do' replaced by 'it "with restrict_orgs=true, returns hash if the org could not be converted" do' --- app/controllers/contributors_controller.rb | 3 ++- spec/controllers/contributors_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/contributors_controller.rb b/app/controllers/contributors_controller.rb index d5246f9a5b..9dd63fca83 100644 --- a/app/controllers/contributors_controller.rb +++ b/app/controllers/contributors_controller.rb @@ -117,9 +117,10 @@ def process_org(hash:) allow = !Rails.configuration.x.application.restrict_orgs org = org_from_params(params_in: hash, allow_create: allow) - return nil if org.blank? && !allow hash = remove_org_selection_params(params_in: hash) + + return hash if org.blank? && !allow return hash unless org.present? hash[:org_id] = org.id diff --git a/spec/controllers/contributors_controller_spec.rb b/spec/controllers/contributors_controller_spec.rb index c999c39b0e..2645261250 100644 --- a/spec/controllers/contributors_controller_spec.rb +++ b/spec/controllers/contributors_controller_spec.rb @@ -154,11 +154,11 @@ hash = @controller.send(:process_org, hash: @params_hash[:contributor]) expect(hash).to eql(@params_hash[:contributor]) end - it "with restrict_orgs=true, returns nil if the org could not be converted" do + it "with restrict_orgs=true, returns hash if the org could not be converted" do Rails.configuration.x.application.restrict_orgs = true @controller.stubs(:org_from_params).returns(nil) hash = @controller.send(:process_org, hash: @params_hash[:contributor]) - expect(hash).to eql(nil) + expect(hash).to eql(@params_hash[:contributor]) end it "sets the org_id to the idea of the org" do new_org = create(:org)