require "spec_helper" require "relaton_iso" require "fileutils" RSpec.describe Asciidoctor::Standoc do IETF_123_SHORT = <<~EOS Rubber latex -- Sampling RFC 123 International Organization for Standardization ISO www.iso.org Published EOS ISO_123_SHORT = <<~EOS Rubber latex -- Sampling ISO 123 International Organization for Standardization ISO www.iso.org Published EOS ISO_124_SHORT = <<~EOS #{Date.today} Latex, rubber -- Determination of total solids content ISO 124 International Organization for Standardization ISO www.iso.org Published EOS ISO_124_SHORT_ALT = <<~EOS #{Date.today} Latex, rubber -- Replacement ISO 124 International Organization for Standardization ISO www.iso.org 6060 EOS ISO_124_DATED = <<~EOS #{Date.today} Latex, rubber Determination of total solids content Latex, rubber – Determination of total solids content Latex de caoutchouc Détermination des matières solides totales Latex de caoutchouc – Détermination des matières solides totales https://www.iso.org/standard/61884.html https://www.iso.org/obp/ui/#!iso:std:61884:en https://www.iso.org/contents/data/standard/06/18/61884.detail.rss ISO 124:2014 124 2014 International Organization for Standardization ISO www.iso.org 7 en fr ISO 124:2014 specifies methods for the determination of the total solids content of natural rubber field and concentrated latices and synthetic rubber latex. These methods are not necessarily suitable for latex from natural sources other than the Hevea brasiliensis, for vulcanized latex, for compounded latex, or for artificial dispersions of rubber. L'ISO 124:2014 spécifie des méthodes pour la détermination des matières solides totales dans le latex de plantation, le latex de concentré de caoutchouc naturel et le latex de caoutchouc synthétique. Ces méthodes ne conviennent pas nécessairement au latex d'origine naturelle autre que celui de l'Hevea brasiliensis, au latex vulcanisé, aux mélanges de latex, ou aux dispersions artificielles de caoutchouc. 90 93 2014 ISO ISO 124:2011 international-standard ISO/TC 45/SC 3Raw materials (including latex) for use in the rubber industry 83.040.10 Latex and raw rubber ISO 124 EOS ISO_123_UNDATED = <<~EOS #{Date.today} Rubber latex Sampling Rubber latex – Sampling Latex de caoutchouc Échantillonnage Latex de caoutchouc – Échantillonnage https://www.iso.org/standard/23281.html https://www.iso.org/obp/ui/#!iso:std:23281:en https://www.iso.org/contents/data/standard/02/32/23281.detail.rss ISO 123 123 International Organization for Standardization ISO www.iso.org 3 en fr 90 93 2001 ISO ISO 123:1985 #{Date.today} Rubber latex – Sampling Rubber latex – Sampling Latex de caoutchouc – Échantillonnage Latex de caoutchouc – Échantillonnage https://www.iso.org/standard/23281.html https://www.iso.org/obp/ui/#!iso:std:23281:en https://www.iso.org/contents/data/standard/02/32/23281.detail.rss ISO 123:2001 123 2001 International Organization for Standardization ISO www.iso.org 3 en fr 90 93 2001 ISO ISO 123:1985 international-standard ISO/TC 45/SC 3Raw materials (including latex) for use in the rubber industry 83.040.10 Latex and raw rubber ISO 123 EOS ISO_123_DATED = <<~EOS #{Date.today} Rubber latex Sampling Rubber latex – Sampling Latex de caoutchouc Échantillonnage Latex de caoutchouc – Échantillonnage https://www.iso.org/standard/23281.html https://www.iso.org/obp/ui/#!iso:std:23281:en https://www.iso.org/contents/data/standard/02/32/23281.detail.rss ISO 123:2001 123 2001 International Organization for Standardization ISO www.iso.org 3 en fr 90 93 2001 ISO ISO 123:1985 international-standard ISO/TC 45/SC 3Raw materials (including latex) for use in the rubber industry 83.040.10 Latex and raw rubber ISO 123 EOS it "does not activate biblio caches if isobib disabled" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf File.expand_path("~/.iev.pstore1") FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true FileUtils.rm_rf "relaton/cache" FileUtils.rm_rf "test.iev.pstore" Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be false expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false expect(File.exist?("relaton/cache")).to be false expect(File.exist?("test.iev.pstore")).to be false FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true FileUtils.rm_rf File.expand_path("~/.iev.pstore") FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true end it "does not activate biblio caches if isobib caching disabled" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf File.expand_path("~/.iev.pstore1") FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true FileUtils.rm_rf "relaton/cache" FileUtils.rm_rf "test.iev.pstore" mock_isobib_get_123 Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be false expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false expect(File.exist?("relaton/cache")).to be false expect(File.exist?("test.iev.pstore")).to be false FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.rm_rf File.expand_path("~/.iev.pstore") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true end it "flushes biblio caches" do relaton_bib_file = File.expand_path("~/.relaton/cache") relaton_bib_file1 = File.expand_path("~/.relaton-bib.pstore1") iev_file = File.expand_path("~/.iev/cache") iev_file1 = File.expand_path("~/.iev.pstore1") FileUtils.rm_rf relaton_bib_file1 if File.exist? relaton_bib_file1 FileUtils.mv relaton_bib_file, relaton_bib_file1 if File.exist? relaton_bib_file FileUtils.rm_rf iev_file1 if File.exist? iev_file1 FileUtils.mv iev_file, iev_file1 if File.exist? iev_file File.open("#{Dir.home}/.relaton/cache", "w") { |f| f.write "XXX" } FileUtils.rm_rf File.expand_path("~/.iev/cache") # mock_isobib_get_123 VCR.use_cassette "isobib_get_123_2001" do Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{FLUSH_CACHE_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT end expect(File.exist?("#{Dir.home}/.relaton/cache")).to be true expect(File.exist?("#{Dir.home}/.iev/cache")).to be false mock_open_uri('103-01-02') Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) [bibliography] == Normative References * [[[iev,IEV]]], _iev_ == Terms and definitions === Automation [.source] <> INPUT expect(File.exist?("#{Dir.home}/.iev/cache")).to be true db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to include("#{Date.today.to_s}") expect(entry).to be_equivalent_to(ISO_123_DATED) FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.rm_rf File.expand_path("~/.iev/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev/cache"), force: true end it "does not fetch references for ISO references in preparation" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "relaton/cache" Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:--]]] footnote:[The standard is in press] _Standard_ INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be true db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil entry = db.load_entry("ISO(ISO 123:--)") expect(entry).to be nil FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "inserts prefixes to fetched reference identifiers other than ISO IEC" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "relaton/cache" mock_isobib_get_123 mock_ietfbib_get_123 out = Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} <> <> [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ * [[[ietf123,RFC 123]]] _Standard_ INPUT expect(out).to include '' expect(out).to include '' end it "activates global cache" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "relaton/cache" VCR.use_cassette "isobib_get_123_2001" do Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT end #mock_isobib_get_123 #Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) ##{CACHED_ISOBIB_BLANK_HDR} #[bibliography] #== Normative References # #* [[[iso123,ISO 123:2001]]] _Standard_ #INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be true expect(File.exist?("relaton/cache")).to be false db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to_not be nil FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "activates local cache" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "relaton/cache" mock_isobib_get_123 Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{LOCAL_CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be true expect(File.exist?("relaton/cache")).to be true db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to_not be nil db = Relaton::Db.new "relaton/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to_not be nil FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "renames local cache" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "test/cache" mock_isobib_get_123 Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) = Document title Author :docfile: test.adoc :nodoc: :novalid: :local-cache: test [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT expect(File.exist?("test/cache")).to be true db = Relaton::Db.new "test/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to_not be nil FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "activates only local cache" do relaton_bib_file = File.expand_path("~/.relaton/cache") relaton_bib_file1 = File.expand_path("~/.relaton-bib.pstore1") FileUtils.rm_rf relaton_bib_file1 if File.exist? relaton_bib_file1 FileUtils.mv(relaton_bib_file, relaton_bib_file1, force: true) if File.exist? relaton_bib_file FileUtils.rm_rf "relaton/cache" mock_isobib_get_123 Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{LOCAL_ONLY_CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT expect(File.exist?("#{Dir.home}/.relaton/cache")).to be false expect(File.exist?("relaton/cache")).to be true db = Relaton::Db.new "relaton/cache", nil entry = db.load_entry("ISO(ISO 123:2001)") expect(entry).to_not be nil FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "fetches uncached references" do FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil bibitem = RelatonIsoBib::XMLParser.from_xml ISO_123_DATED bibitem.instance_variable_set :@fetched, (Date.today - 2) db.save_entry("ISO(ISO 123:2001)", bibitem.to_xml) #{ #"fetched" => (Date.today - 2).to_s, #"bib" => RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED) #} #) # mock_isobib_get_124 VCR.use_cassette "isobib_get_124" do Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ * [[[iso124,ISO 124:2014]]] _Standard_ INPUT end entry = db.load_entry("ISO(ISO 123:2001)") #expect(db.fetched("ISO(ISO 123:2001)")).to eq(Date.today.to_s) expect(entry).to include("#{(Date.today - 2).to_s}") #expect(entry).to be_equivalent_to(ISO_123_DATED) entry = db.load_entry("ISO(ISO 124:2014)") #expect(db.fetched("ISO(ISO 124:2014)")).to eq(Date.today.to_s) expect(entry).to include("#{Date.today.to_s}") expect(entry).to be_equivalent_to(ISO_124_DATED) FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "expires stale undated references" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil bibitem = RelatonIsoBib::XMLParser.from_xml ISO_123_SHORT bibitem.instance_variable_set :@fetched, (Date.today - 90) db.save_entry("ISO 123", bibitem.to_xml) #{ #"fetched" => (Date.today - 90), #"bib" => RelatonIsoBib::XMLParser.from_xml(ISO_123_SHORT) #} #) # mock_isobib_get_123_undated VCR.use_cassette "isobib_get_123" do Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123]]] _Standard_ INPUT end entry = db.load_entry("ISO(ISO 123)") #expect(db.fetched("ISO(ISO 123)")).to eq(Date.today.to_s) expect(entry).to include("#{Date.today.to_s}") #expect(entry).to be_equivalent_to(ISO_123_UNDATED) # NN TEMP FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "does not expire stale dated references" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true bibitem = RelatonIsoBib::XMLParser.from_xml ISO_123_DATED bibitem.instance_variable_set :@fetched, (Date.today - 90) db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil db.save_entry("ISO(ISO 123:2001)", bibitem.to_xml) # { # "fetched" => (Date.today - 90), # "bib" => RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED) # } # ) Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iso123,ISO 123:2001]]] _Standard_ INPUT entry = db.load_entry("ISO(ISO 123:2001)") #expect(db.fetched("ISO(ISO 123:2001)")).to eq((Date.today - 90).to_s) expect(entry).to include("#{Date.today - 90}") # expect(entry).to be_equivalent_to(ISO_123_DATED) It can't be true since fetched date is changed FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "prioritises local over global cache values" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf "relaton/cache" db = Relaton::Db.new "#{Dir.home}/.relaton/cache", nil db.save_entry("ISO(ISO 123:2001)", RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED).to_xml) # { # "fetched" => Date.today, # "bib" => RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED) # } # ) db.save_entry("ISO(ISO 124)", RelatonIsoBib::XMLParser.from_xml(ISO_124_SHORT).to_xml) # { # "fetched" => Date.today, # "bib" => RelatonIsoBib::XMLParser.from_xml(ISO_124_SHORT) # } # ) localdb = Relaton::Db.new "relaton/cache", nil localdb.save_entry("ISO(ISO 124)", RelatonIsoBib::XMLParser.from_xml(ISO_124_SHORT_ALT).to_xml) # { # "fetched" => Date.today, # "bib" => RelatonIsoBib::XMLParser.from_xml(ISO_124_SHORT_ALT) # } # ) input = <<~EOS #{LOCAL_CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[ISO123-2001,ISO 123:2001]]] _Standard_ * [[[ISO124,ISO 124]]] _Standard_ EOS Asciidoctor.convert(input, backend: :standoc, header_footer: true) expect(db.load_entry("ISO(ISO 123:2001)")).to include("Rubber latex") expect(db.load_entry("ISO(ISO 124)")).to include("Latex, rubber -- Determination of total solids content") expect(localdb.load_entry("ISO(ISO 123:2001)")).to include("Rubber latex") expect(localdb.load_entry("ISO(ISO 124)")).to include("Latex, rubber -- Replacement") FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end private def mock_isobib_get_123 expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", "2001", {:title=>"Standard"}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED)) end def mock_isobib_get_123_undated expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", nil, {:title=>"Standard"}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_UNDATED)) end def mock_isobib_get_124 expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 124", "2014", {:title=>"Standard"}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_124_DATED)) end def mock_ietfbib_get_123 expect(RelatonIetf::IetfBibliography).to receive(:get).with("RFC 123", nil, {:title=>"Standard"}).and_return(RelatonIsoBib::XMLParser.from_xml(IETF_123_SHORT)) end end