-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from MITLibraries/tco-110-journals
Split Detector::Journals model into two, extending BulkChecker into the detection model
- Loading branch information
Showing
11 changed files
with
123 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: journals | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# additional_info :json | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
# Journal is the list of academic journals which are known to TACOS. This list of records is referred to by the | ||
# Detector::Journal model in order to determine whether a given term matches a known journal. The names of these | ||
# journals are stored in lowercase, which matches how the Detector::Journal processes incoming terms, in order to | ||
# prevent capitalization differences resulting in a false negative. | ||
class Journal < ApplicationRecord | ||
before_save :downcase_fields! | ||
|
||
private | ||
|
||
# Downcasing all names before saving allows for more efficient matching by ensuring our index is lowercase. | ||
# If we find we need the non-lowercase Journal name in the future, we could store that as `additional_info` json | ||
def downcase_fields! | ||
name.downcase! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateJournals < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :journals do |t| | ||
t.string :name | ||
t.json :additional_info | ||
|
||
t.timestamps | ||
end | ||
add_index :journals, :name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class DropDetectorJournals < ActiveRecord::Migration[7.1] | ||
def up | ||
drop_table :detector_journals | ||
end | ||
|
||
def down | ||
create_table :detector_journals do |t| | ||
t.string :name | ||
t.json :additional_info | ||
|
||
t.timestamps | ||
end | ||
add_index :detector_journals, :name | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/fixtures/detector/journals.yml → test/fixtures/journals.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: journals | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# additional_info :json | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
require 'test_helper' | ||
|
||
class JournalTest < ActiveSupport::TestCase | ||
test 'mixed titles are downcased when saved' do | ||
mixed_case = 'ThIs Is A tItLe' | ||
actual = Journal.create(name: mixed_case) | ||
actual.reload | ||
|
||
assert_not_equal(mixed_case, actual.name) | ||
assert_equal(mixed_case.downcase, actual.name) | ||
end | ||
end |