From b3df9c564e4566c96781c4d1896c3979244f1f79 Mon Sep 17 00:00:00 2001 From: jrhoads Date: Tue, 14 Jun 2022 14:57:59 -0400 Subject: [PATCH] Downcase re3data_id in ReferenceRepository.update_from_client --- app/models/reference_repository.rb | 6 +++--- spec/models/reference_repository_spec.rb | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/reference_repository.rb b/app/models/reference_repository.rb index 2ae468950..8debbc7a3 100644 --- a/app/models/reference_repository.rb +++ b/app/models/reference_repository.rb @@ -50,10 +50,10 @@ def self.create_from_re3repo(repo) def self.update_from_client(client) rr = ReferenceRepository.find_or_create_by(client_id: client.uid) - if client.re3data_id && (not rr.re3doi) + if client.re3data_id && (rr.re3doi.blank?) rr.re3doi = client.re3data_id - if !rr.validate - ReferenceRepository.find_by(re3doi: client.re3data_id, client_id: nil).try(:destroy) + if !rr.valid? + ReferenceRepository.find_by(re3doi: client.re3data_id.downcase, client_id: nil).try(:destroy) end rr.save else diff --git a/spec/models/reference_repository_spec.rb b/spec/models/reference_repository_spec.rb index 26d03cf91..2d43be658 100644 --- a/spec/models/reference_repository_spec.rb +++ b/spec/models/reference_repository_spec.rb @@ -53,21 +53,22 @@ end it "propegate from clients but re3data_id exists" do - doi = "10.17616/r3989r" + Rails.logger.level = :fatal + doi = "10.17616/R3P01C" create(:reference_repository, re3doi: doi) client = create(:client) expect(client.re3data_id).to be_nil - repository_client = ReferenceRepository.find_by(client_id: client.uid) expect(repository_client.re3doi).to be_nil - client.re3data = "https://doi.org/" + doi - expect(client.save).to be true + expect( + client.update({ re3data: "https://doi.org/" + doi }) + ).to be true expect(client.re3data_id).to eq(doi) repository_client2 = ReferenceRepository.find_by(client_id: client.uid) - expect(repository_client2.re3doi).to eq(doi) + expect(repository_client2.re3doi).to eq(doi.downcase) end end