spotlight-dor-resources 0.5.0 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56c5a12edcfd124b75e2cab49b8b87b1bf582fe0
4
- data.tar.gz: e3bee3aa6e93e08d63347448ccecad16e0463030
3
+ metadata.gz: ff7c24c04a2998179946c35ce06eecf7147e988f
4
+ data.tar.gz: 7ac0182530a6580139ec6ee6616bd49acb797aec
5
5
  SHA512:
6
- metadata.gz: 72a1d35be252f42957cf9885ab59884a859dab1c5c507c79c2d310dd6b5b08e041476d545dd451948129a2638b899356684e46f132a559498fce3de07fa43342
7
- data.tar.gz: 1c81e09e883d45a8c88d1c6357c510b3d1fc47fd2c76379b3dd66eb93b0c93e2be14b8e710c1cb790f4930a1c267eadddcc8658ec7e06bd588c04108179ed53c
6
+ metadata.gz: 0b0b9ab1e57ebedc5392135feb69e5c924f21a90e1017b7ee8dca06e8b57a954a9f5e6757cf49162abda75143492e6a0b92bd59f22b67a351fe38ddf963ccbd3
7
+ data.tar.gz: edc984c0749324b1fcababd7e7194d153171d63dfd08c67acfcea5a02cd2945ba51da64b3498e74a542a7e097504a18427ae09f4e88bde532825f37f0462828d
@@ -0,0 +1,41 @@
1
+ module Spotlight::Resources
2
+ ##
3
+ # Resources controller allowing curators to create new
4
+ # exhibit resources from a list of DRUIDs.
5
+ class DorHarvesterController < ApplicationController
6
+ before_action :authenticate_user!
7
+ load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
8
+ before_action :build_resource
9
+ authorize_resource
10
+
11
+ def create
12
+ @resource.update(resource_params)
13
+
14
+ if @resource.save
15
+ redirect_to spotlight.admin_exhibit_catalog_index_path(current_exhibit)
16
+ else
17
+ redirect_to spotlight.new_exhibit_resource_path(current_exhibit)
18
+ end
19
+ end
20
+
21
+ def update
22
+ @resource.update(resource_params)
23
+
24
+ if @resource.save
25
+ redirect_to spotlight.admin_exhibit_catalog_index_path(current_exhibit)
26
+ else
27
+ redirect_to spotlight.new_exhibit_resource_path(current_exhibit)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def build_resource
34
+ @resource = Spotlight::Resources::DorHarvester.instance(current_exhibit)
35
+ end
36
+
37
+ def resource_params
38
+ params.require(:resources_dor_harvester).permit(:druid_list)
39
+ end
40
+ end
41
+ end
@@ -1,8 +1,16 @@
1
1
  module Spotlight::Resources
2
2
  # Base Resource indexer for objects in DOR
3
- class DorResource < Spotlight::Resource
3
+ class DorHarvester < Spotlight::Resource
4
4
  include ActiveSupport::Benchmarkable
5
5
 
6
+ store :data, accessors: [:druid_list]
7
+
8
+ class << self
9
+ def instance(current_exhibit)
10
+ find_or_initialize_by exhibit: current_exhibit
11
+ end
12
+ end
13
+
6
14
  ##
7
15
  # Generate solr documents for the DOR resources identified by this object
8
16
  #
@@ -22,8 +30,14 @@ module Spotlight::Resources
22
30
  end
23
31
  end
24
32
 
25
- def resource
26
- @resource ||= Spotlight::Dor::Resources.indexer.resource doc_id
33
+ def resources
34
+ @resources ||= druids.map do |d|
35
+ Spotlight::Dor::Resources.indexer.resource d
36
+ end
37
+ end
38
+
39
+ def druids
40
+ @druids ||= druid_list.split("\n").map(&:strip)
27
41
  end
28
42
 
29
43
  private
@@ -34,12 +48,14 @@ module Spotlight::Resources
34
48
  #
35
49
  # @return [Enumerator] an enumerator of resources to index
36
50
  def indexable_resources
37
- return to_enum(:indexable_resources) { 1 + resource.items.size } unless block_given?
51
+ return to_enum(:indexable_resources) { resources.size + resources.sum { |r| r.items.size } } unless block_given?
38
52
 
39
- yield resource
53
+ resources.each do |resource|
54
+ yield resource
40
55
 
41
- resource.items.each do |r|
42
- yield r
56
+ resource.items.each do |r|
57
+ yield r
58
+ end
43
59
  end
44
60
  end
45
61
 
@@ -0,0 +1,10 @@
1
+ <%= bootstrap_form_for(Spotlight::Resources::DorHarvester.instance(current_exhibit), url: spotlight_dor_resources_engine.exhibit_dor_harvester_path(exhibit_id: current_exhibit), layout: :horizontal, label_col: 'col-md-2', control_col: 'col-sm-6 col-md-6') do |f| %>
2
+ <%= f.text_area :druid_list, rows: 10 %>
3
+
4
+ <div class="form-actions">
5
+ <div class="primary-actions">
6
+ <%= cancel_link "", :back, class: 'btn btn-default' %>
7
+ <%= f.submit t('.add_item'), class: 'btn btn-primary' %>
8
+ </div>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,35 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ activerecord:
24
+ attributes:
25
+ spotlight/resources/dor_harvester:
26
+ druid_list: Object IDs
27
+ help:
28
+ spotlight/resources/dor_harvester:
29
+ druid_list: Collection object PURLs, one per line (e.g. qb438pg7646)
30
+ spotlight:
31
+ resources:
32
+ dor_harvester:
33
+ form:
34
+ add_item: Add items
35
+ title: SDR
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Spotlight::Dor::Resources::Engine.routes.draw do
2
+ resources :exhibits, path: '/', only: [] do
3
+ resource :dor_harvester, controller: :"spotlight/resources/dor_harvester", only: [:create, :update]
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module Spotlight
4
+ module Dor
5
+ module Resources
6
+ # :nodoc:
7
+ class InstallGenerator < Rails::Generators::Base
8
+ desc 'This generator mounts the Spotlight::Dor::Resources engine'
9
+
10
+ def inject_spotlight_dor_resources_routes
11
+ route "mount Spotlight::Dor::Resources::Engine, at: 'spotlight_dor_resources'"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,13 +4,14 @@ require 'spotlight/dor/resources'
4
4
  module Spotlight::Dor::Resources
5
5
  # :nodoc:
6
6
  class Engine < ::Rails::Engine
7
- initializer 'spotlight.dor.initialize' do
8
- Spotlight::Engine.config.resource_providers << Spotlight::Resources::Searchworks
9
- Spotlight::Engine.config.resource_providers << Spotlight::Resources::Purl
10
- Spotlight::Dor::Resources::Engine.config.parallel_options = { in_threads: 1 }
11
- Spotlight::Dor::Resources::Engine.config.base_stacks_url = 'https://stacks.stanford.edu'
12
- Spotlight::Dor::Resources::Engine.config.stacks_file_url = "#{config.base_stacks_url}/file"
13
- Spotlight::Dor::Resources::Engine.config.stacks_iiif_url = "#{config.base_stacks_url}/image/iiif"
7
+ config.parallel_options = { in_threads: 1 }
8
+ config.base_stacks_url = 'https://stacks.stanford.edu'
9
+ config.stacks_file_url = "#{config.base_stacks_url}/file"
10
+ config.stacks_iiif_url = "#{config.base_stacks_url}/image/iiif"
11
+
12
+ initializer 'spotlight.resources.dor_harvester.initialize' do
13
+ Spotlight::Engine.config.external_resources_partials ||= []
14
+ Spotlight::Engine.config.external_resources_partials << 'spotlight/resources/dor_harvester/form'
14
15
  end
15
16
  end
16
17
  end
@@ -2,7 +2,7 @@ module Spotlight
2
2
  module Dor
3
3
  # :nodoc:
4
4
  module Resources
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
8
8
  end
@@ -6,7 +6,7 @@ describe 'gdor indexing integration test', :vcr do
6
6
  end
7
7
 
8
8
  subject do
9
- r = Spotlight::Resources::Purl.new(url: 'https://purl.stanford.edu/xf680rd3068')
9
+ r = Spotlight::Resources::DorHarvester.new(druid_list: 'xf680rd3068')
10
10
  allow(r).to receive(:to_global_id).and_return('x')
11
11
  allow(r).to receive(:exhibit).and_return(exhibit)
12
12
  r.to_solr.first
@@ -30,7 +30,7 @@ describe 'gdor indexing integration test', :vcr do
30
30
 
31
31
  it 'can write doc to solr with latest exhibits_solr_conf', vcr: false do
32
32
  # hd778hw9236 has B.C. date -- good for checking Solr field types
33
- r = Spotlight::Resources::Purl.new(url: 'https://purl.stanford.edu/hd778hw9236')
33
+ r = Spotlight::Resources::DorHarvester.new(druid_list: 'hd778hw9236')
34
34
  allow(r).to receive(:to_global_id).and_return('x')
35
35
  allow(r).to receive(:exhibit).and_return(exhibit)
36
36
  r.reindex
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spotlight::Resources::Purl do
4
- let :exhibit do
5
- double(solr_data: {}, blacklight_config: Blacklight::Configuration.new)
6
- end
3
+ describe Spotlight::Resources::DorHarvester do
4
+ let(:exhibit) { FactoryGirl.create(:exhibit) }
5
+
7
6
  let :blacklight_solr do
8
7
  double
9
8
  end
10
9
 
11
- subject { described_class.new url: 'http://purl.stanford.edu/xf680rd3068' }
10
+ subject { described_class.new druid_list: 'xf680rd3068' }
11
+ let(:resource) { subject.resources.first }
12
12
 
13
13
  before do
14
14
  allow(subject).to receive(:exhibit).and_return(exhibit)
@@ -16,58 +16,43 @@ describe Spotlight::Resources::Purl do
16
16
  allow(subject).to receive(:to_global_id).and_return('x')
17
17
  end
18
18
 
19
- describe '.can_provide?' do
20
- subject { described_class }
21
- it 'is true for a PURL URL' do
22
- expect(subject.can_provide?(double(url: 'https://purl.stanford.edu/xyz'))).to eq true
23
- expect(subject.can_provide?(double(url: 'http://purl.stanford.edu/xyz'))).to eq true
24
- end
25
-
26
- it 'is false other URLs' do
27
- expect(subject.can_provide?(double(url: 'https://example.com/xyz'))).to eq false
19
+ describe '.instance' do
20
+ subject { described_class.instance(exhibit).tap(&:save) }
21
+ it 'behaves like a singleton' do
22
+ expect(described_class.instance(exhibit)).to eq subject
28
23
  end
29
24
  end
30
25
 
31
- describe '#doc_id' do
32
- it 'extracts DRUIDs from a PURL url' do
33
- subject.url = 'http://purl.stanford.edu/xyz'
34
- expect(subject.doc_id).to eq 'xyz'
35
- end
36
-
37
- it 'extracts DRUIDs from a PURL format url' do
38
- subject.url = 'http://purl.stanford.edu/xf680rd3068.xml'
39
- expect(subject.doc_id).to eq 'xf680rd3068'
40
- end
41
-
42
- it "extracts DRUIDs from a PURL's viewer url" do
43
- subject.url = 'http://purl.stanford.edu/xf680rd3068#image/1/small'
44
- expect(subject.doc_id).to eq 'xf680rd3068'
26
+ describe '#druids' do
27
+ it 'extracts an array of DRUIDs from the list of druids' do
28
+ expect(subject.druids).to match_array 'xf680rd3068'
45
29
  end
46
30
  end
47
31
 
48
- describe '#resource' do
32
+ describe '#resources' do
49
33
  it 'is a Harvestdor::Indexer resource' do
50
- expect(subject.resource).to be_a_kind_of Harvestdor::Indexer::Resource
34
+ expect(resource).to be_a_kind_of Harvestdor::Indexer::Resource
51
35
  end
52
36
 
53
37
  it 'has the correct druid' do
54
- expect(subject.resource.druid).to eq 'xf680rd3068'
38
+ expect(resource.druid).to eq 'xf680rd3068'
55
39
  end
56
40
 
57
41
  it 'has the correct indexer' do
58
- expect(subject.resource.indexer).to eq Spotlight::Dor::Resources.indexer.harvestdor
42
+ expect(resource.indexer).to eq Spotlight::Dor::Resources.indexer.harvestdor
59
43
  end
60
44
  end
61
45
 
62
46
  describe '#reindex' do
63
47
  before do
64
48
  allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document).and_return(upstream: true)
65
- allow(subject.resource).to receive(:collection?).and_return(false)
49
+ allow(resource).to receive(:collection?).and_return(false)
50
+ allow(exhibit).to receive(:solr_data).and_return({})
66
51
  end
67
52
 
68
53
  it 'adds a document to solr' do
69
54
  solr_data = [{ spotlight_resource_id_ssim: subject.to_global_id,
70
- spotlight_resource_type_ssim: 'spotlight/resources/purls',
55
+ spotlight_resource_type_ssim: 'spotlight/resources/dor_harvesters',
71
56
  upstream: true }]
72
57
  expect(blacklight_solr).to receive(:update).with(params: { commitWithin: 500 },
73
58
  data: solr_data.to_json,
@@ -81,21 +66,22 @@ describe Spotlight::Resources::Purl do
81
66
  before do
82
67
  allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document)
83
68
  end
69
+
84
70
  context 'with a collection' do
85
71
  before do
86
- allow(subject.resource).to receive(:collection?).and_return(true)
72
+ allow(resource).to receive(:collection?).and_return(true)
87
73
  end
88
74
 
89
75
  it 'provides a solr document for the collection' do
90
- allow(subject.resource).to receive(:items).and_return([])
91
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
76
+ allow(resource).to receive(:items).and_return([])
77
+ expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(resource).and_return(upstream: true)
92
78
  expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
93
79
  end
94
80
 
95
81
  it 'provides a solr document for the items too' do
96
82
  item = double(druid: 'xyz')
97
- allow(subject.resource).to receive(:items).and_return([item])
98
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(collection: true)
83
+ allow(resource).to receive(:items).and_return([item])
84
+ expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(resource).and_return(collection: true)
99
85
  expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(item).and_return(item: true)
100
86
  solr_doc = subject.to_solr.to_a
101
87
  expect(solr_doc.first).to include :collection
@@ -103,13 +89,13 @@ describe Spotlight::Resources::Purl do
103
89
  end
104
90
 
105
91
  it 'traps indexing errors' do
106
- allow(subject.resource).to receive(:items).and_return([])
92
+ allow(resource).to receive(:items).and_return([])
107
93
  expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).and_raise(RuntimeError.new)
108
94
  expect { subject.to_solr.to_a }.not_to raise_error
109
95
  end
110
96
 
111
97
  it 'log and raises other types of errors errors' do
112
- allow(subject.resource).to receive(:items).and_return([])
98
+ allow(resource).to receive(:items).and_return([])
113
99
  expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).and_raise(StandardError.new)
114
100
  expect(subject.send(:logger)).to receive(:error).with(/Error processing xf680rd3068/)
115
101
  expect { subject.to_solr.to_a }.to raise_error StandardError
@@ -118,8 +104,8 @@ describe Spotlight::Resources::Purl do
118
104
 
119
105
  context 'with a single item' do
120
106
  it 'provides a solr document for the resource' do
121
- allow(subject.resource).to receive(:collection?).and_return(false)
122
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
107
+ allow(resource).to receive(:collection?).and_return(false)
108
+ expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(resource).and_return(upstream: true)
123
109
  expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
124
110
  end
125
111
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  ENV["RAILS_ENV"] ||= 'test'
2
2
 
3
- require 'database_cleaner'
4
3
  require 'devise'
5
4
  require 'engine_cart'
6
5
  require 'vcr'
@@ -9,6 +8,13 @@ EngineCart.load_application!
9
8
  require 'rspec/rails'
10
9
  require 'capybara'
11
10
 
11
+ require 'factory_girl_rails'
12
+ FactoryGirl.definition_file_paths ||= []
13
+ FactoryGirl.definition_file_paths << "#{Gem.loaded_specs['blacklight-spotlight'].full_gem_path}/spec/factories"
14
+ FactoryGirl.find_definitions
15
+
16
+ require 'database_cleaner'
17
+
12
18
  if ENV["COVERAGE"] or ENV["CI"]
13
19
  require 'simplecov'
14
20
  require 'coveralls' if ENV["CI"]
@@ -26,6 +26,7 @@ class TestAppGenerator < Rails::Generators::Base
26
26
  remove_file 'app/controllers/catalog_controller.rb'
27
27
 
28
28
  generate 'spotlight:install', '-f --mailer_default_url_host=localhost:3000'
29
+ rake 'db:migrate'
29
30
  end
30
31
 
31
32
  def add_catalog_controller
@@ -35,5 +36,9 @@ class TestAppGenerator < Rails::Generators::Base
35
36
  def configure_gdor
36
37
  copy_file 'gdor.yml', 'config/gdor.yml', force: true
37
38
  end
39
+
40
+ def run_spotlight_dor_resources_generator
41
+ generate 'spotlight:dor:resources:install'
42
+ end
38
43
 
39
44
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  # newer versions of harvestdor-indexer have performance improvements for collections
27
27
  spec.add_dependency 'harvestdor-indexer', '~> 2.3'
28
28
  spec.add_dependency 'rails'
29
- spec.add_dependency 'blacklight-spotlight', ['~> 0.6', '< 0.16.0']
29
+ spec.add_dependency 'blacklight-spotlight', '~> 0.16'
30
30
  spec.add_dependency 'parallel'
31
31
  spec.add_development_dependency 'bundler', '~> 1.5'
32
32
  spec.add_development_dependency 'rake'
@@ -39,4 +39,11 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'engine_cart', '~> 0.8'
40
40
  spec.add_development_dependency 'database_cleaner'
41
41
  spec.add_development_dependency 'exhibits_solr_conf'
42
+ spec.add_development_dependency 'factory_girl_rails'
43
+
44
+ # FIXME: we shouldn't need explicit sitemap_generator dependency here as it should come with spotlight
45
+ # but travis fails without it (though tests run fine locally)
46
+ # cbeer: "we're injecting the dependency into the host app. maybe we're just
47
+ # missing a `bundle install` somewhere to fix that up"
48
+ spec.add_development_dependency 'sitemap_generator'
42
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotlight-dor-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -86,20 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.6'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: 0.16.0
89
+ version: '0.16'
93
90
  type: :runtime
94
91
  prerelease: false
95
92
  version_requirements: !ruby/object:Gem::Requirement
96
93
  requirements:
97
94
  - - "~>"
98
95
  - !ruby/object:Gem::Version
99
- version: '0.6'
100
- - - "<"
101
- - !ruby/object:Gem::Version
102
- version: 0.16.0
96
+ version: '0.16'
103
97
  - !ruby/object:Gem::Dependency
104
98
  name: parallel
105
99
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +262,34 @@ dependencies:
268
262
  - - ">="
269
263
  - !ruby/object:Gem::Version
270
264
  version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: factory_girl_rails
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: sitemap_generator
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
271
293
  description:
272
294
  email:
273
295
  - cabeer@stanford.edu
@@ -284,18 +306,19 @@ files:
284
306
  - LICENSE.txt
285
307
  - README.md
286
308
  - Rakefile
287
- - app/models/spotlight/resources/dor_resource.rb
288
- - app/models/spotlight/resources/harvestdor.rb
289
- - app/models/spotlight/resources/purl.rb
290
- - app/models/spotlight/resources/searchworks.rb
309
+ - app/controllers/spotlight/resources/dor_harvester_controller.rb
310
+ - app/models/spotlight/resources/dor_harvester.rb
311
+ - app/views/spotlight/resources/dor_harvester/_form.html.erb
312
+ - config/locales/spotlight-dor-resources.en.yml
313
+ - config/routes.rb
314
+ - lib/generators/spotlight/dor/resources/install_generator.rb
291
315
  - lib/spotlight/dor/indexer.rb
292
316
  - lib/spotlight/dor/resources.rb
293
317
  - lib/spotlight/dor/resources/engine.rb
294
318
  - lib/spotlight/dor/resources/version.rb
295
319
  - spec/integration/gdor_integration_spec.rb
296
320
  - spec/lib/spotlight/dor/indexer_spec.rb
297
- - spec/models/spotlight/resources/purl_spec.rb
298
- - spec/models/spotlight/resources/searchworks_spec.rb
321
+ - spec/models/spotlight/resources/dor_harvester_spec.rb
299
322
  - spec/spec_helper.rb
300
323
  - spec/test_app_templates/catalog_controller.rb
301
324
  - spec/test_app_templates/gdor.yml
@@ -332,8 +355,7 @@ summary: Spotlight resource indexer for DOR resources.
332
355
  test_files:
333
356
  - spec/integration/gdor_integration_spec.rb
334
357
  - spec/lib/spotlight/dor/indexer_spec.rb
335
- - spec/models/spotlight/resources/purl_spec.rb
336
- - spec/models/spotlight/resources/searchworks_spec.rb
358
+ - spec/models/spotlight/resources/dor_harvester_spec.rb
337
359
  - spec/spec_helper.rb
338
360
  - spec/test_app_templates/catalog_controller.rb
339
361
  - spec/test_app_templates/gdor.yml
@@ -1,4 +0,0 @@
1
- module Spotlight::Resources
2
- class Harvestdor < Spotlight::Resource
3
- end
4
- end
@@ -1,14 +0,0 @@
1
- module Spotlight::Resources
2
- # Resource provider for PURL pages
3
- class Purl < Spotlight::Resources::DorResource
4
- self.weight = -1000
5
-
6
- def self.can_provide?(res)
7
- res.url.match(%r{^https?://purl.stanford.edu/}).present?
8
- end
9
-
10
- def doc_id
11
- url.match(%r{^https?://purl.stanford.edu/([^#/\.]+)})[1]
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Spotlight::Resources
2
- # Resource provider for searchworks pages
3
- class Searchworks < Spotlight::Resources::DorResource
4
- self.weight = -1000
5
-
6
- def self.can_provide?(res)
7
- res.url.match(%r{^https?://searchworks[^\.]*.stanford.edu/}).present?
8
- end
9
-
10
- def doc_id
11
- url.match(%r{^https?://searchworks[^\.]*.stanford.edu/.*view/([^/\.#]+)})[1]
12
- end
13
- end
14
- end
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spotlight::Resources::Searchworks do
4
- let :exhibit do
5
- double(solr_data: {}, blacklight_config: Blacklight::Configuration.new)
6
- end
7
-
8
- subject { described_class.new url: 'http://searchworks.stanford.edu/view/xf680rd3068' }
9
-
10
- before do
11
- allow(subject).to receive(:exhibit).and_return(exhibit)
12
- allow(subject).to receive(:to_global_id).and_return('x')
13
- end
14
-
15
- describe '.can_provide?' do
16
- subject { described_class }
17
- it 'is true for a searchworks URL' do
18
- expect(subject.can_provide?(double(url: 'https://searchworks.stanford.edu/xyz'))).to eq true
19
- expect(subject.can_provide?(double(url: 'http://searchworks.stanford.edu/xyz'))).to eq true
20
- end
21
- it 'is true for a searchworks-test URLs' do
22
- expect(subject.can_provide?(double(url: 'https://searchworks-test.stanford.edu/xyz'))).to eq true
23
- expect(subject.can_provide?(double(url: 'http://searchworks-test.stanford.edu/xyz'))).to eq true
24
- end
25
-
26
- it 'is false for a other URLs' do
27
- expect(subject.can_provide?(double(url: 'https://example.comu/xyz'))).to eq false
28
- end
29
- end
30
-
31
- describe '#doc_id' do
32
- it 'extracts DRUIDs from a searchworks url' do
33
- subject.url = 'http://searchworks.stanford.edu/view/xf680rd3068'
34
- expect(subject.doc_id).to eq 'xf680rd3068'
35
- end
36
-
37
- it 'extracts DRUIDs from a searchworks, format-specific url' do
38
- subject.url = 'http://searchworks.stanford.edu/view/xf680rd3068.xml'
39
- expect(subject.doc_id).to eq 'xf680rd3068'
40
- end
41
- end
42
-
43
- describe '#resource' do
44
- it 'is a Harvestdor::Indexer resource' do
45
- expect(subject.resource).to be_a_kind_of Harvestdor::Indexer::Resource
46
- end
47
-
48
- it 'has the correct druid' do
49
- expect(subject.resource.druid).to eq 'xf680rd3068'
50
- end
51
-
52
- it 'has the correct indexer' do
53
- expect(subject.resource.indexer).to eq Spotlight::Dor::Resources.indexer.harvestdor
54
- end
55
- end
56
-
57
- describe '#to_solr' do
58
- before do
59
- allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document)
60
- end
61
- context 'with a collection' do
62
- before do
63
- allow(subject.resource).to receive(:collection?).and_return(true)
64
- end
65
-
66
- it 'provides a solr document for the collection' do
67
- allow(subject.resource).to receive(:items).and_return([])
68
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
69
- expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
70
- end
71
-
72
- it 'provides a solr document for the items too' do
73
- item = double(druid: 'xyz')
74
- allow(subject.resource).to receive(:items).and_return([item])
75
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(collection: true)
76
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(item).and_return(item: true)
77
- solr_doc = subject.to_solr.to_a
78
- expect(solr_doc.first).to include :collection
79
- expect(solr_doc.last).to include :item
80
- end
81
- end
82
-
83
- context 'with a single item' do
84
- before do
85
- allow(subject.resource).to receive(:collection?).and_return(false)
86
- end
87
-
88
- it 'provides a solr document for the resource' do
89
- expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
90
- expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
91
- end
92
- end
93
- end
94
- end