-
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.
refactor: extracts Subject from Subjects
- Loading branch information
Showing
6 changed files
with
195 additions
and
180 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 |
---|---|---|
@@ -1,6 +1,25 @@ | ||
module Common | ||
class Subjects | ||
class Subject | ||
module Subject | ||
class << self | ||
def subject_field?(field) | ||
SUBJECT_FIELDS.include?(field.tag) | ||
end | ||
|
||
# Delegate LC determination to the class itself. | ||
def lc_subject_field?(field) | ||
LCSubject.lc_subject_field?(field) | ||
end | ||
|
||
# Pass off a new subject to the appropriate class | ||
def new(field) | ||
if lc_subject_field?(field) | ||
LCSubject.from_field(field) | ||
else | ||
NonLCSubject.new(field) | ||
end | ||
end | ||
end | ||
end | ||
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
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
37 changes: 37 additions & 0 deletions
37
umich_catalog_indexing/spec/common/subjects/subject_spec.rb
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,37 @@ | ||
require "common/subjects" | ||
RSpec.describe Common::Subjects::Subject do | ||
def get_record(path) | ||
MARC::XMLReader.new(path).first | ||
end | ||
let(:record) do | ||
get_record("./spec/fixtures/unauthorized_immigrants.xml") | ||
end | ||
let(:subject_fields) do | ||
Common::Subjects.new(record).subject_fields | ||
end | ||
let(:lc_subject_field) do | ||
subject_fields.first | ||
end | ||
let(:non_lc_subject_field) do | ||
subject_fields[2] | ||
end | ||
|
||
context ".subject_field?" do | ||
it "returns true for appropriate subject field" do | ||
expect(described_class.subject_field?(lc_subject_field)).to eq(true) | ||
end | ||
it "returns false for field with incorrect tag" do | ||
not_subject = instance_double(MARC::DataField, tag: "800") | ||
expect(described_class.subject_field?(not_subject)).to eq(false) | ||
end | ||
end | ||
|
||
context ".new" do | ||
it "returns an object that knows it's an LCSubject" do | ||
expect(described_class.new(lc_subject_field).lc_subject_field?).to eq(true) | ||
end | ||
it "returns an object that knows it's an Non LCSubject" do | ||
expect(described_class.new(non_lc_subject_field).lc_subject_field?).to eq(false) | ||
end | ||
end | ||
end |
Oops, something went wrong.