Skip to content

Commit

Permalink
Downcase re3data_id in ReferenceRepository.update_from_client
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhoads committed Jun 14, 2022
1 parent bb008a7 commit b3df9c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/models/reference_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions spec/models/reference_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b3df9c5

Please sign in to comment.