Skip to content

Commit

Permalink
Refactor Fingerprint model to use "value" field
Browse files Browse the repository at this point in the history
Until now, we've been building the Fingerprint model to include a field
also named "fingerprint" for the actual string value of the fingerprint.
This removes that duplication by changing the field name to be "value".

As a result of updating the migration with this new terminology, we also
update the alias / delegation up to the Term model, so terms can still
find the string via the term.fingerprint_value attribute.

The fixtures use the updated field name, and some references to the new
field name (in application code and in tests) are updated.
  • Loading branch information
matt-bernhardt committed Dec 13, 2024
1 parent 07f310a commit 051e7d7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions app/models/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#
# Table name: fingerprints
#
# id :integer not null, primary key
# fingerprint :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# value :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Fingerprint < ApplicationRecord
has_many :terms, dependent: :nullify

validates :fingerprint, uniqueness: true
validates :value, uniqueness: true

alias_attribute :fingerprint_value, :fingerprint
alias_attribute :fingerprint_value, :value

# This is similar to the SuggestedResource fingerprint method, with the exception that it also replaces &quot; with "
# during its operation. This switch may also need to be added to the SuggestedResource method, at which point they can
Expand Down
2 changes: 1 addition & 1 deletion app/models/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def calculate_categorizations
# related Fingerprint method.
def register_fingerprint
new_record = {
fingerprint: Fingerprint.calculate(phrase)
value: Fingerprint.calculate(phrase)
}
self.fingerprint = Fingerprint.find_or_create_by(new_record)
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20241210185701_create_fingerprints.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateFingerprints < ActiveRecord::Migration[7.1]
def change
create_table :fingerprints do |t|
t.string :fingerprint, index: { unique: true, name: 'unique_fingerprint' }
t.string :value, index: { unique: true, name: 'unique_fingerprint' }
t.timestamps
end
end
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions test/fixtures/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
#
# Table name: fingerprints
#
# id :integer not null, primary key
# fingerprint :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# value :string
# created_at :datetime not null
# updated_at :datetime not null
#
cool:
fingerprint: cool search super
value: cool search super

hi:
fingerprint: hello world
value: hello world

pmid_38908367:
fingerprint: '2024 38908367 activation aging al and cell dna et hallmarks hs methylation multiple pmid shim targets tert'
value: '2024 38908367 activation aging al and cell dna et hallmarks hs methylation multiple pmid shim targets tert'

lcsh:
fingerprint: 'geology massachusetts'
value: 'geology massachusetts'

issn_1075_8623:
fingerprint: '10758623'
value: '10758623'

doi:
fingerprint: '101016jphysio201012004'
value: '101016jphysio201012004'

isbn_9781319145446:
fingerprint: '11th 2016 9781319145446 al biology d e ed et freeman h hillis isbn life m of sadava science the w'
value: '11th 2016 9781319145446 al biology d e ed et freeman h hillis isbn life m of sadava science the w'

journal_nature_medicine:
fingerprint: 'medicine nature'
value: 'medicine nature'

suggested_resource_jstor:
fingerprint: 'jstor'
value: 'jstor'

multiple_detections:
fingerprint: '103389fpubh202000014 32154200 a air and doi environmental frontiers health impacts in of pmid pollution public review'
value: '103389fpubh202000014 32154200 a air and doi environmental frontiers health impacts in of pmid pollution public review'

citation:
fingerprint: '12 2 2005 2007 6 a accessed altun available context current dec education experience httpcieedasueduvolume6number12 hypertext in issues july language learners no of on online reading serial the understanding vol web'
value: '12 2 2005 2007 6 a accessed altun available context current dec education experience httpcieedasueduvolume6number12 hypertext in issues july language learners no of on online reading serial the understanding vol web'
10 changes: 5 additions & 5 deletions test/models/fingerprint_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
# Table name: fingerprints
#
# id :integer not null, primary key
# fingerprint :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# value :string
# created_at :datetime not null
# updated_at :datetime not null
#
require 'test_helper'

Expand All @@ -16,7 +16,7 @@ class FingerprintTest < ActiveSupport::TestCase
tf = Fingerprint.first

assert_raises(ActiveRecord::RecordInvalid) do
Fingerprint.create!(fingerprint: tf.fingerprint)
Fingerprint.create!(value: tf.value)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/models/term_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TermTest < ActiveSupport::TestCase
phrase: 'foo'
}

assert_nil Fingerprint.find_by(fingerprint: 'foo')
assert_nil Fingerprint.find_by(value: 'foo')

Term.create!(new_term)

Expand Down Expand Up @@ -368,7 +368,7 @@ class TermTest < ActiveSupport::TestCase

tf = t.fingerprint

assert_equal t.fingerprint_value, tf.fingerprint
assert_equal t.fingerprint_value, tf.value
end

test 'Term.fingerprint returns nil of there is no fingerprint' do
Expand Down

0 comments on commit 051e7d7

Please sign in to comment.