Skip to content

Commit

Permalink
use old NDL search link if iss_itemno ends with '-00'
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Feb 10, 2024
1 parent 29bb273 commit 1f2daa2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/helpers/enju_biblio/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def identifier_link(identifier)
when 'doi'
link_to identifier.body, "https://doi.org/#{identifier.body}"
when 'iss_itemno'
link_to identifier.body, "https://ndlsearch.ndl.go.jp/books/#{identifier.body}"
if identifier.body =~ /\AR[0-9A-Za-z]+?-I[0-9A-Za-z]+?-00\z/
link_to identifier.body, "https://iss.ndl.go.jp/books/#{identifier.body}"
else
link_to identifier.body, "https://ndlsearch.ndl.go.jp/books/#{identifier.body}"
end
when 'lccn'
link_to identifier.body, "https://lccn.loc.gov/#{identifier.body}"
when 'ncid'
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/identifiers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryBot.define do
factory :identifier do
sequence(:body){|n| "identifier_body_#{n}"}
identifier_type_id{FactoryBot.create(:identifier_type).id}
association(:manifestation)
association :identifier_type
association :manifestation
end
end

Expand Down
26 changes: 25 additions & 1 deletion spec/helpers/enju_biblio/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,31 @@
expect(helper.form_icon(nil)).to match /src=\"\/assets\/icons\/help-/
end

it "should render form_icon if carrier_type's attachment is blank " do
it "should render form_icon if carrier_type's attachment is blank" do
expect(helper.form_icon(FactoryBot.create(:carrier_type))).to match /src=\"\/assets\/icons\/help-/
end

it "should link to old NDL search if iss_itemno ends with '-00'" do
expect(
helper.identifier_link(
FactoryBot.build(
:identifier,
body: 'R100000039-I001413988-00',
identifier_type: IdentifierType.find_by(name: 'iss_itemno')
)
)
).to eq "<a href=\"https://iss.ndl.go.jp/books/R100000039-I001413988-00\">R100000039-I001413988-00</a>"
end

it "should link to new NDL search if iss_itemno doesn't end with '-00'" do
expect(
helper.identifier_link(
FactoryBot.build(
:identifier,
body: 'R100000039-I001413988',
identifier_type: IdentifierType.find_by(name: 'iss_itemno')
)
)
).to eq "<a href=\"https://ndlsearch.ndl.go.jp/books/R100000039-I001413988\">R100000039-I001413988</a>"
end
end

0 comments on commit 1f2daa2

Please sign in to comment.