Skip to content

Commit 051e7d7

Browse files
Refactor Fingerprint model to use "value" field
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.
1 parent 07f310a commit 051e7d7

7 files changed

Lines changed: 32 additions & 32 deletions

File tree

app/models/fingerprint.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
#
55
# Table name: fingerprints
66
#
7-
# id :integer not null, primary key
8-
# fingerprint :string
9-
# created_at :datetime not null
10-
# updated_at :datetime not null
7+
# id :integer not null, primary key
8+
# value :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
1111
#
1212
class Fingerprint < ApplicationRecord
1313
has_many :terms, dependent: :nullify
1414

15-
validates :fingerprint, uniqueness: true
15+
validates :value, uniqueness: true
1616

17-
alias_attribute :fingerprint_value, :fingerprint
17+
alias_attribute :fingerprint_value, :value
1818

1919
# This is similar to the SuggestedResource fingerprint method, with the exception that it also replaces &quot; with "
2020
# during its operation. This switch may also need to be added to the SuggestedResource method, at which point they can

app/models/term.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def calculate_categorizations
9191
# related Fingerprint method.
9292
def register_fingerprint
9393
new_record = {
94-
fingerprint: Fingerprint.calculate(phrase)
94+
value: Fingerprint.calculate(phrase)
9595
}
9696
self.fingerprint = Fingerprint.find_or_create_by(new_record)
9797
end

db/migrate/20241210185701_create_fingerprints.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class CreateFingerprints < ActiveRecord::Migration[7.1]
22
def change
33
create_table :fingerprints do |t|
4-
t.string :fingerprint, index: { unique: true, name: 'unique_fingerprint' }
4+
t.string :value, index: { unique: true, name: 'unique_fingerprint' }
55
t.timestamps
66
end
77
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/fingerprints.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@
22
#
33
# Table name: fingerprints
44
#
5-
# id :integer not null, primary key
6-
# fingerprint :string
7-
# created_at :datetime not null
8-
# updated_at :datetime not null
5+
# id :integer not null, primary key
6+
# value :string
7+
# created_at :datetime not null
8+
# updated_at :datetime not null
99
#
1010
cool:
11-
fingerprint: cool search super
11+
value: cool search super
1212

1313
hi:
14-
fingerprint: hello world
14+
value: hello world
1515

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

1919
lcsh:
20-
fingerprint: 'geology massachusetts'
20+
value: 'geology massachusetts'
2121

2222
issn_1075_8623:
23-
fingerprint: '10758623'
23+
value: '10758623'
2424

2525
doi:
26-
fingerprint: '101016jphysio201012004'
26+
value: '101016jphysio201012004'
2727

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

3131
journal_nature_medicine:
32-
fingerprint: 'medicine nature'
32+
value: 'medicine nature'
3333

3434
suggested_resource_jstor:
35-
fingerprint: 'jstor'
35+
value: 'jstor'
3636

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

4040
citation:
41-
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'
41+
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'

test/models/fingerprint_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#
55
# Table name: fingerprints
66
#
7-
# id :integer not null, primary key
8-
# fingerprint :string
9-
# created_at :datetime not null
10-
# updated_at :datetime not null
7+
# id :integer not null, primary key
8+
# value :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
1111
#
1212
require 'test_helper'
1313

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

1818
assert_raises(ActiveRecord::RecordInvalid) do
19-
Fingerprint.create!(fingerprint: tf.fingerprint)
19+
Fingerprint.create!(value: tf.value)
2020
end
2121
end
2222

test/models/term_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TermTest < ActiveSupport::TestCase
3939
phrase: 'foo'
4040
}
4141

42-
assert_nil Fingerprint.find_by(fingerprint: 'foo')
42+
assert_nil Fingerprint.find_by(value: 'foo')
4343

4444
Term.create!(new_term)
4545

@@ -368,7 +368,7 @@ class TermTest < ActiveSupport::TestCase
368368

369369
tf = t.fingerprint
370370

371-
assert_equal t.fingerprint_value, tf.fingerprint
371+
assert_equal t.fingerprint_value, tf.value
372372
end
373373

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

0 commit comments

Comments
 (0)