relaton 1.20.1 → 1.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +48 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +2 -2
  5. data/CLAUDE.md +68 -0
  6. data/Gemfile +5 -5
  7. data/docs/README.adoc +20 -0
  8. data/lib/relaton/db.rb +64 -0
  9. data/lib/relaton/version.rb +1 -1
  10. data/relaton.gemspec +3 -2
  11. data/spec/relaton/db_spec.rb +193 -0
  12. data/spec/relaton_spec.rb +12 -6
  13. data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +2031 -1357
  14. data/spec/vcr_cassetes/api_relaton_org.yml +9 -9
  15. data/spec/vcr_cassetes/api_relaton_org_unavailable.yml +11 -11
  16. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +17 -17
  17. data/spec/vcr_cassetes/cie_001_1980.yml +17 -17
  18. data/spec/vcr_cassetes/cipm_meeting_43.yml +1354 -1361
  19. data/spec/vcr_cassetes/doi_10_6028_nist_ir_8245.yml +56 -63
  20. data/spec/vcr_cassetes/ecma_6.yml +17 -17
  21. data/spec/vcr_cassetes/en_10160_1999.yml +13265 -12589
  22. data/spec/vcr_cassetes/gb_t_20223_2006.yml +458 -458
  23. data/spec/vcr_cassetes/ieee_528_2019.yml +2413 -2250
  24. data/spec/vcr_cassetes/iso_19115_1.yml +1445 -1240
  25. data/spec/vcr_cassetes/iso_19115_1_2.yml +19 -19
  26. data/spec/vcr_cassetes/iso_19115_1_std.yml +1443 -1238
  27. data/spec/vcr_cassetes/iso_19115_all_parts.yml +11 -11
  28. data/spec/vcr_cassetes/iso_19133_2005.yml +9 -9
  29. data/spec/vcr_cassetes/iso_combined_applied.yml +19 -19
  30. data/spec/vcr_cassetes/iso_combined_included.yml +18 -18
  31. data/spec/vcr_cassetes/iso_dis.yml +9 -9
  32. data/spec/vcr_cassetes/ogc_19_025r1.yml +200 -196
  33. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +964 -958
  34. data/spec/vcr_cassetes/rfc_8341.yml +50 -34
  35. metadata +21 -6
  36. data/.hound.yml +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13dbf084ccd28b8edc98d3e9b8774eb6eef7998f73627332fb7f92809cf635fd
4
- data.tar.gz: d81e1084ff58259e9d2f91d1cbbb1b6590ab6531a15f643209091fcdba1ea978
3
+ metadata.gz: 94c3b2f7f4a364ddd5771661f9bb0c2d6e4d393fe9608a53ee4e1270e3431092
4
+ data.tar.gz: de220c6644cc24fdc75f1be9b7ceff7a8631e26c76a62c8ced7d514d58a50621
5
5
  SHA512:
6
- metadata.gz: b6191397dde96436e07a88c62b4995991f50b1aae1d347a52b5ee5262e494498a4c7991ff62e9924086e39023956342900a914d527b77bfa8299b2b97c13b89d
7
- data.tar.gz: 817aca4c0d54b585cffa7d14c1645fa9bcd078aa281ab33aaa51e8c2cc125a07d4ea6a268b62b507baa06dce66410c2d2cd46a9fb7fd0ad019636e6470ce9d6b
6
+ metadata.gz: 621a9fa3ed13274e4f031eec041c26436824ce1fe5020ad7deffbec4d3c218f71a467104af276568ccec4fcc9b93a79362d7eb5d61b59d0308bede27e9df7d33
7
+ data.tar.gz: a8e60d3d61262b91617a9c0090a1220b8ac36b0cffcfabd683519b6da43713157235d74f0d72d09def1e7d78dff966133629a57ab4d2cd17441313e760d3fbb9
@@ -0,0 +1,48 @@
1
+ name: Rubocop
2
+
3
+ on: pull_request
4
+
5
+ permissions:
6
+ contents: read
7
+ pull-requests: write
8
+
9
+ jobs:
10
+ rubocop:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ with:
15
+ fetch-depth: 1
16
+ - name: Determine Ruby version for ruby/setup-ruby
17
+ shell: bash
18
+ run: |
19
+ RUBY_VERSION=${{ vars.RUBY_VERSION }}
20
+
21
+ if [[ -r .rubocop.yml ]]
22
+ then
23
+ RUBY_VERSION=$( \
24
+ command grep \
25
+ -E '^\s*TargetRubyVersion:\s*[0-9]+(\.[0-9]+)*' \
26
+ .rubocop.yml \
27
+ | command awk '{print $2}' \
28
+ )
29
+ fi
30
+
31
+ if [[ -z $RUBY_VERSION ]]
32
+ then
33
+ # Let setup-ruby determine the Ruby version if no .ruby-version,
34
+ # .tool-versions or mise.toml file exists
35
+ RUBY_VERSION=default
36
+ fi
37
+
38
+ echo "RUBY_VERSION=$RUBY_VERSION" >> $GITHUB_ENV
39
+ - uses: ruby/setup-ruby@v1
40
+ with:
41
+ # input ruby-version needs to be specified if no .ruby-version,
42
+ # .tool-versions or mise.toml file exists
43
+ #
44
+ # Use the version that matches the one in gemspec & .rubocop.yml
45
+ ruby-version: ${{ env.RUBY_VERSION }}
46
+ - uses: reclaim-the-stack/rubocop-action@v1.1.0
47
+ with:
48
+ gem_versions: rubocop:1.84.2 rubocop-performance:1.26.1 rubocop-rails:2.34.3
data/.gitignore CHANGED
@@ -8,3 +8,5 @@ testcache2
8
8
  .vscode/
9
9
  pkg/
10
10
  Gemfile.lock
11
+ .rubocop-remote-87c7cdd254a8d09d005ee06efac7acc0.yml
12
+ .claude/
data/.rubocop.yml CHANGED
@@ -2,11 +2,11 @@
2
2
  # https://github.com/riboseinc/oss-guides
3
3
  # All project-specific additions and overrides should be specified in this file.
4
4
 
5
- require: rubocop-rails
5
+ plugins: rubocop-rails
6
6
 
7
7
  inherit_from:
8
8
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
9
  AllCops:
10
- TargetRubyVersion: 3.0
10
+ TargetRubyVersion: 3.1
11
11
  Rails:
12
12
  Enabled: false
data/CLAUDE.md ADDED
@@ -0,0 +1,68 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ # Run full test suite
9
+ bundle exec rake # or: bundle exec rspec
10
+
11
+ # Run a single spec file
12
+ bundle exec rspec spec/relaton/db_spec.rb
13
+
14
+ # Run a specific test by line number
15
+ bundle exec rspec spec/relaton/db_spec.rb:234
16
+
17
+ # Lint
18
+ bundle exec rubocop
19
+
20
+ # Lint with auto-fix
21
+ bundle exec rubocop -a
22
+ ```
23
+
24
+ ## Architecture
25
+
26
+ Relaton is a Ruby gem that fetches, caches, and manages bibliographic references to technical standards from 25+ organizations (ISO, IEC, IETF, NIST, IEEE, etc.).
27
+
28
+ ### Plugin Registry Pattern
29
+
30
+ **Relaton::Registry** (singleton) auto-discovers and manages backend processor gems (relaton-iso, relaton-iec, relaton-ietf, etc.). Each processor implements the **Relaton::Processor** interface (`get`, `from_xml`, `hash_to_bib`, `prefix`, `defaultprefix`). The registry routes reference codes to the correct processor by matching prefixes (e.g., "ISO 19115" → `:relaton_iso`).
31
+
32
+ ### Db (lib/relaton/db.rb) — Main Public API
33
+
34
+ `Relaton::Db#fetch(ref, year, opts)` is the primary entry point. It:
35
+ 1. Identifies the processor via Registry prefix matching
36
+ 2. Handles combined references (`+` for derivedFrom, `,` for amendments) in `combine_doc`
37
+ 3. Delegates to `check_bibliocache` which manages the dual-cache lookup and network fetch flow
38
+
39
+ The dual-cache strategy uses a **global cache** (`~/.relaton/cache`) and an optional **local cache** (project-level). `check_bibliocache` checks local first, falls back to global, and syncs between them.
40
+
41
+ ### DbCache (lib/relaton/db_cache.rb) — File-based Storage
42
+
43
+ Stores entries as files under `{dir}/{prefix}/{filename}.{ext}` (e.g., `testcache/iso/iso_19115-1.xml`). Key behaviors:
44
+ - Cache keys are wrapped like `ISO(ISO 19115-1:2014)` and converted to filenames via regex
45
+ - Entries can be XML, "not_found {date}", or "redirection {target_key}"
46
+ - Undated references expire after 60 days; dated ones persist indefinitely
47
+ - Version tracking per prefix directory invalidates cache when processor grammar changes
48
+ - File locking (`LOCK_EX`) for thread-safe concurrent writes
49
+
50
+ ### WorkersPool (lib/relaton/workers_pool.rb)
51
+
52
+ Thread pool for `fetch_async`. Default 10 threads per processor, overridable via `RELATON_FETCH_PARALLEL` env var.
53
+
54
+ ### Cache Key Format
55
+
56
+ `std_id` builds keys like `ISO(ISO 19115-1:2014 (all parts) after-2020-01-01)`. The filename regex in `db_cache.rb` uses `[^)]+` — suffixes use `-` not parentheses to avoid breaking it.
57
+
58
+ ## Testing
59
+
60
+ - RSpec with VCR cassettes in `spec/vcr_cassetes/` for recorded HTTP interactions
61
+ - Tests create `testcache`/`testcache2` directories and clean them in `before(:each)`
62
+ - Cache-related tests need `<fetched>` elements in XML for `valid_entry?` to return true
63
+ - Integration tests in `spec/relaton_spec.rb`; unit tests mirror `lib/` structure under `spec/relaton/`
64
+
65
+ ## Style
66
+
67
+ - RuboCop config inherits from [Ribose OSS guides](https://github.com/riboseinc/oss-guides), target Ruby 3.1
68
+ - Thread safety via `@semaphore` (Mutex) around cache reads/writes in Db
data/Gemfile CHANGED
@@ -3,16 +3,16 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in gemspec
4
4
  gemspec
5
5
 
6
- gem "byebug", "~> 11.0"
6
+ gem "byebug"
7
7
  gem "equivalent-xml", "~> 0.6"
8
8
  gem "guard", "~> 2.14"
9
9
  gem "guard-rspec", "~> 4.7"
10
- gem "pry-byebug", "~> 3.9.0"
10
+ gem "pry-byebug"
11
11
  gem "rake", "~> 13.0"
12
12
  gem "rspec", "~> 3.6"
13
- gem "rubocop", "~> 1.17.0"
14
- gem "rubocop-performance", "~> 1.11.0"
15
- gem "rubocop-rails", "~> 2.10.0"
13
+ gem "rubocop"
14
+ gem "rubocop-performance"
15
+ gem "rubocop-rails"
16
16
  gem "simplecov", "~> 0.15"
17
17
  gem "timecop", "~> 0.9"
18
18
  gem "vcr", "~> 6"
data/docs/README.adoc CHANGED
@@ -176,6 +176,8 @@ Arguments:
176
176
  - `:keep_yer` - (Boolean) should be `true` if undated reference should return an actual reference with the year
177
177
  - `:retries` - (Number) number of network retries. Default 1
178
178
  - `:no_cache` - (Boolean) should be `true` if cache should be ignored
179
+ - `:publication_date_after` - (String) filter for documents published on or after this date (inclusive, `"YYYY-MM-DD"`)
180
+ - `:publication_date_before` - (String) filter for documents published before this date (exclusive, `"YYYY-MM-DD"`)
179
181
 
180
182
  [source,ruby]
181
183
  ----
@@ -235,6 +237,24 @@ refs.size.times do
235
237
  end
236
238
  ----
237
239
 
240
+ ==== Fetch with publication date filter
241
+
242
+ The `:publication_date_after` and `:publication_date_before` options restrict results to documents published within a date range. The range is inclusive of `:publication_date_after` and exclusive of `:publication_date_before`.
243
+
244
+ When a date filter is used, the cache is checked first for an existing entry whose publication date satisfies the range. If no match is found, a date-specific cache entry is created.
245
+
246
+ [source,ruby]
247
+ ----
248
+ # Fetch documents published on or after 2018-01-01
249
+ x = db.fetch("ISO 19115-1", nil, publication_date_after: "2018-01-01")
250
+
251
+ # Fetch documents published before 2020-01-01
252
+ x = db.fetch("ISO 19115-1", nil, publication_date_before: "2020-01-01")
253
+
254
+ # Fetch documents published within a range
255
+ x = db.fetch("ISO 19115-1", nil, publication_date_after: "2018-01-01", publication_date_before: "2020-01-01")
256
+ ----
257
+
238
258
  ==== Fetch by URN
239
259
 
240
260
  This functionality works only for IEC documents.
data/lib/relaton/db.rb CHANGED
@@ -47,6 +47,11 @@ module Relaton
47
47
  # actual reference with year
48
48
  # @option opts [Integer] :retries (1) Number of network retries
49
49
  # @option opts [Boolean] :no_cache If true then don't use cache
50
+ # @option opts [String] :publication_date_before published before this date
51
+ # (exclusive, formats: "YYYY", "YYYY-MM", or "YYYY-MM-DD")
52
+ # @option opts [String] :publication_date_after published on or
53
+ # after this date (inclusive, formats: "YYYY", "YYYY-MM",
54
+ # or "YYYY-MM-DD")
50
55
  #
51
56
  # @return [nil, RelatonBib::BibliographicItem,
52
57
  # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
@@ -329,6 +334,12 @@ module Relaton
329
334
  ret = code
330
335
  ret += (stdclass == :relaton_gb ? "-" : ":") + year if year
331
336
  ret += " (all parts)" if opts[:all_parts]
337
+ if opts[:publication_date_after]
338
+ ret += " after-#{opts[:publication_date_after]}"
339
+ end
340
+ if opts[:publication_date_before]
341
+ ret += " before-#{opts[:publication_date_before]}"
342
+ end
332
343
  ["#{prefix}(#{ret.strip})", code]
333
344
  end
334
345
 
@@ -379,6 +390,23 @@ module Relaton
379
390
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
380
391
  # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
381
392
  def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
393
+ # When date filters are present, check if the base
394
+ # (non-date-filtered) cache entry satisfies the range
395
+ if opts[:publication_date_before] || opts[:publication_date_after]
396
+ base_opts = opts.except(
397
+ :publication_date_before, :publication_date_after
398
+ )
399
+ base_id, = std_id(code, year, base_opts, stdclass)
400
+ db = @local_db || @db
401
+ if db&.valid_entry?(base_id, year)
402
+ entry = db[base_id]
403
+ if entry && !entry.match?(/^not_found/) &&
404
+ pub_date_in_range?(entry, opts)
405
+ return bib_retval(entry, stdclass)
406
+ end
407
+ end
408
+ end
409
+
382
410
  id, searchcode = std_id(code, year, opts, stdclass)
383
411
  db = @local_db || @db
384
412
  altdb = @local_db && @db ? @db : nil
@@ -512,6 +540,42 @@ module Relaton
512
540
  bib.respond_to?(:to_xml) ? bib.to_xml(bibdata: true) : "not_found #{Date.today}"
513
541
  end
514
542
 
543
+ # Check if an XML entry's published date falls within the requested range.
544
+ # Range semantics: [after, before) — inclusive start, exclusive end.
545
+ #
546
+ # @param entry [String] XML string
547
+ # @param opts [Hash]
548
+ # @return [Boolean]
549
+ def pub_date_in_range?(entry, opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
550
+ doc = Nokogiri::XML(entry)
551
+ date_str = doc.at("//date[@type='published']/on")&.text
552
+ return false unless date_str
553
+
554
+ date = parse_pub_date(date_str)
555
+ return false unless date
556
+
557
+ after = opts[:publication_date_after]
558
+ return false if after && date < Date.parse(after.to_s)
559
+
560
+ before = opts[:publication_date_before]
561
+ return false if before && date >= Date.parse(before.to_s)
562
+
563
+ true
564
+ end
565
+
566
+ # @param str [String] date string in "YYYY", "YYYY-MM",
567
+ # or "YYYY-MM-DD" format
568
+ # @return [Date, nil]
569
+ def parse_pub_date(str)
570
+ case str
571
+ when /^\d{4}-\d{1,2}-\d{1,2}/ then Date.parse(str)
572
+ when /^\d{4}-\d{1,2}/ then Date.strptime(str, "%Y-%m")
573
+ when /^\d{4}/ then Date.strptime(str, "%Y")
574
+ end
575
+ rescue ArgumentError
576
+ nil
577
+ end
578
+
515
579
  # @param dir [String, nil] DB directory
516
580
  # @return [Relaton::DbCache, NilClass]
517
581
  def open_cache_biblio(dir) # rubocop:disable Metrics/MethodLength
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.20.1".freeze
2
+ VERSION = "1.20.2".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
  spec.files = `git ls-files`.split("\n")
29
29
  # spec.test_files = `git ls-files -- {spec}/*`.split("\n")
30
- spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
30
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
31
31
 
32
32
  spec.add_dependency "relaton-3gpp", "~> 1.20.0"
33
33
  spec.add_dependency "relaton-bipm", "~> 1.20.0"
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency "relaton-etsi", "~> 1.20.0"
42
42
  spec.add_dependency "relaton-gb", "~> 1.20.0"
43
43
  spec.add_dependency "relaton-iana", "~> 1.20.0"
44
- spec.add_dependency "relaton-iec", "~> 1.20.0"
44
+ spec.add_dependency "relaton-iec", "~> 1.20.3"
45
45
  spec.add_dependency "relaton-ieee", "~> 1.20.0"
46
46
  spec.add_dependency "relaton-ietf", "~> 1.20.0"
47
47
  spec.add_dependency "relaton-iho", "~> 1.20.0"
@@ -57,4 +57,5 @@ Gem::Specification.new do |spec|
57
57
  spec.add_dependency "relaton-un", "~> 1.20.0"
58
58
  spec.add_dependency "relaton-w3c", "~> 1.20.0"
59
59
  spec.add_dependency "relaton-xsf", "~> 1.20.0"
60
+ spec.add_development_dependency "rubocop-rails"
60
61
  end
@@ -91,6 +91,199 @@ RSpec.describe Relaton::Db do
91
91
  end
92
92
  end
93
93
 
94
+ context "#pub_date_in_range?" do
95
+ let(:xml_with_date) do
96
+ <<~XML
97
+ <bibitem id="ISO123">
98
+ <title>Test</title>
99
+ <date type="published"><on>2019-06-15</on></date>
100
+ </bibitem>
101
+ XML
102
+ end
103
+
104
+ let(:xml_year_only) do
105
+ <<~XML
106
+ <bibitem id="ISO123">
107
+ <title>Test</title>
108
+ <date type="published"><on>2019</on></date>
109
+ </bibitem>
110
+ XML
111
+ end
112
+
113
+ let(:xml_year_month) do
114
+ <<~XML
115
+ <bibitem id="ISO123">
116
+ <title>Test</title>
117
+ <date type="published"><on>2019-06</on></date>
118
+ </bibitem>
119
+ XML
120
+ end
121
+
122
+ let(:xml_no_date) do
123
+ <<~XML
124
+ <bibitem id="ISO123">
125
+ <title>Test</title>
126
+ </bibitem>
127
+ XML
128
+ end
129
+
130
+ it "returns true when date is within range" do
131
+ result = subject.send(
132
+ :pub_date_in_range?, xml_with_date,
133
+ publication_date_after: "2019-01-01",
134
+ publication_date_before: "2020-01-01"
135
+ )
136
+ expect(result).to be true
137
+ end
138
+
139
+ it "returns false when date is before :publication_date_after" do
140
+ result = subject.send(
141
+ :pub_date_in_range?, xml_with_date,
142
+ publication_date_after: "2020-01-01"
143
+ )
144
+ expect(result).to be false
145
+ end
146
+
147
+ it "returns false when date is on or after :publication_date_before (exclusive)" do
148
+ result = subject.send(
149
+ :pub_date_in_range?, xml_with_date,
150
+ publication_date_before: "2019-06-15"
151
+ )
152
+ expect(result).to be false
153
+ end
154
+
155
+ it "returns true when date equals :publication_date_after (inclusive)" do
156
+ result = subject.send(
157
+ :pub_date_in_range?, xml_with_date,
158
+ publication_date_after: "2019-06-15"
159
+ )
160
+ expect(result).to be true
161
+ end
162
+
163
+ it "handles year-only dates" do
164
+ result = subject.send(
165
+ :pub_date_in_range?, xml_year_only,
166
+ publication_date_after: "2018-01-01",
167
+ publication_date_before: "2020-01-01"
168
+ )
169
+ expect(result).to be true
170
+ end
171
+
172
+ it "handles year-month dates" do
173
+ result = subject.send(
174
+ :pub_date_in_range?, xml_year_month,
175
+ publication_date_after: "2019-05-01",
176
+ publication_date_before: "2019-07-01"
177
+ )
178
+ expect(result).to be true
179
+ end
180
+
181
+ it "returns false when no published date exists" do
182
+ result = subject.send(:pub_date_in_range?, xml_no_date,
183
+ publication_date_after: "2019-01-01")
184
+ expect(result).to be false
185
+ end
186
+
187
+ it "returns true with only :publication_date_after when date matches" do
188
+ result = subject.send(:pub_date_in_range?, xml_with_date,
189
+ publication_date_after: "2019-01-01")
190
+ expect(result).to be true
191
+ end
192
+
193
+ it "returns true with only :publication_date_before when date matches" do
194
+ result = subject.send(:pub_date_in_range?, xml_with_date,
195
+ publication_date_before: "2020-01-01")
196
+ expect(result).to be true
197
+ end
198
+ end
199
+
200
+ context "#std_id with date options" do
201
+ it "includes after suffix" do
202
+ id, code = subject.send(
203
+ :std_id, "ISO 19115-1", nil,
204
+ { publication_date_after: "2018-01-01" }, :relaton_iso
205
+ )
206
+ expect(id).to eq "ISO(ISO 19115-1 after-2018-01-01)"
207
+ expect(code).to eq "ISO 19115-1"
208
+ end
209
+
210
+ it "includes before suffix" do
211
+ id, code = subject.send(
212
+ :std_id, "ISO 19115-1", nil,
213
+ { publication_date_before: "2020-12-31" }, :relaton_iso
214
+ )
215
+ expect(id).to eq "ISO(ISO 19115-1 before-2020-12-31)"
216
+ expect(code).to eq "ISO 19115-1"
217
+ end
218
+
219
+ it "includes both after and before suffixes" do
220
+ id, code = subject.send(
221
+ :std_id, "ISO 19115-1", nil,
222
+ { publication_date_after: "2018-01-01",
223
+ publication_date_before: "2020-12-31" },
224
+ :relaton_iso
225
+ )
226
+ expect(id).to eq(
227
+ "ISO(ISO 19115-1 after-2018-01-01 before-2020-12-31)"
228
+ )
229
+ expect(code).to eq "ISO 19115-1"
230
+ end
231
+
232
+ it "does not change key without date options" do
233
+ id, code = subject.send(:std_id, "ISO 19115-1", nil, {}, :relaton_iso)
234
+ expect(id).to eq "ISO(ISO 19115-1)"
235
+ expect(code).to eq "ISO 19115-1"
236
+ end
237
+
238
+ it "combines with year and all_parts" do
239
+ id, = subject.send(
240
+ :std_id, "ISO 19115-1", "2014",
241
+ { all_parts: true,
242
+ publication_date_after: "2014-01-01" },
243
+ :relaton_iso
244
+ )
245
+ expect(id).to eq(
246
+ "ISO(ISO 19115-1:2014 (all parts) after-2014-01-01)"
247
+ )
248
+ end
249
+ end
250
+
251
+ context "#check_bibliocache with date options" do
252
+ let(:db) { Relaton::Db.new "testcache", nil }
253
+
254
+ before(:each) do
255
+ db.save_entry "ISO(ISO 123)", <<~XML
256
+ <bibitem id="ISO123">
257
+ <fetched>#{Date.today}</fetched>
258
+ <title>Test</title>
259
+ <date type="published"><on>2019-06-15</on></date>
260
+ </bibitem>
261
+ XML
262
+ end
263
+
264
+ after(:each) { db.clear }
265
+
266
+ it "returns base cached entry when date matches" do
267
+ item = db.send(
268
+ :check_bibliocache, "ISO 123", nil,
269
+ { publication_date_after: "2019-01-01",
270
+ fetch_db: true }, :relaton_iso
271
+ )
272
+ expect(item).to be_instance_of(
273
+ RelatonIsoBib::IsoBibliographicItem
274
+ )
275
+ end
276
+
277
+ it "does not return base cached entry when date does not match" do
278
+ item = db.send(
279
+ :check_bibliocache, "ISO 123", nil,
280
+ { publication_date_after: "2020-01-01",
281
+ fetch_db: true }, :relaton_iso
282
+ )
283
+ expect(item).to be_nil
284
+ end
285
+ end
286
+
94
287
  context "class methods" do
95
288
  it "::init_bib_caches" do
96
289
  expect(FileUtils).to receive(:rm_rf).with(/\/\.relaton\/cache$/)
data/spec/relaton_spec.rb CHANGED
@@ -1,8 +1,16 @@
1
1
  RSpec.describe Relaton::Db do
2
- before :each do
2
+ before :each do |example|
3
3
  FileUtils.rm_rf %w(testcache testcache2)
4
4
  @db = Relaton::Db.new "testcache", "testcache2"
5
5
  Relaton.instance_variable_set :@configuration, nil
6
+
7
+ if example.metadata[:vcr]
8
+ require "relaton/index"
9
+ allow_any_instance_of(Relaton::Index::Type)
10
+ .to receive(:actual?).and_return(false)
11
+ allow_any_instance_of(Relaton::Index::FileIO)
12
+ .to receive(:check_file).and_return(nil)
13
+ end
6
14
  end
7
15
 
8
16
  it "rejects an illegal reference prefix" do
@@ -255,11 +263,9 @@ RSpec.describe Relaton::Db do
255
263
  expect(bib.docidentifier.first.id).to eq "CCSDS 230.2-G-1"
256
264
  end
257
265
 
258
- it "get IEEE reference" do
259
- VCR.use_cassette "ieee_528_2019" do
260
- bib = @db.fetch "IEEE 528-2019"
261
- expect(bib).to be_instance_of RelatonIeee::IeeeBibliographicItem
262
- end
266
+ it "get IEEE reference", vcr: "ieee_528_2019" do
267
+ bib = @db.fetch "IEEE Std 528-2019"
268
+ expect(bib).to be_instance_of RelatonIeee::IeeeBibliographicItem
263
269
  end
264
270
 
265
271
  it "get IHO reference" do