blacklight-spotlight 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spotlight/resources/upload_controller.rb +1 -1
- data/app/controllers/spotlight/resources_controller.rb +1 -1
- data/app/models/concerns/spotlight/solr_document/uploaded_resource.rb +1 -1
- data/app/models/spotlight/resource.rb +133 -88
- data/app/models/spotlight/resource_provider.rb +24 -0
- data/db/migrate/20151110082345_add_metadata_to_spotlight_resource.rb +5 -0
- data/lib/spotlight/engine.rb +2 -0
- data/lib/spotlight/version.rb +1 -1
- data/spec/controllers/spotlight/resources/upload_controller_spec.rb +2 -3
- data/spec/controllers/spotlight/resources_controller_spec.rb +1 -2
- data/spec/features/add_item_bookmarklet_spec.rb +1 -1
- data/spec/models/spotlight/resource_provider_spec.rb +27 -0
- data/spec/models/spotlight/resource_spec.rb +59 -51
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c321ae7af7b5264e59eff345211ac2760a96cb5b
|
4
|
+
data.tar.gz: 2048a70d4aac48da5effa59328e3e7f73e132b2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95dd157f70fd3b9f4d670a17c611d6e649d004a5fee7fa71d526c2b7f75fab528a21326e66ac3c45c2268152c7e7f0cb57f5a6a620ccea2ca84e912e1c2f842d
|
7
|
+
data.tar.gz: 7e43fa7eca9cacee4e224e8a5974732578bbd00df20130b7df44f464b58d66505e568aeca905440abeaff6afe87459c2059710c6db0e94f15a8f9275f975e5d9
|
@@ -26,7 +26,7 @@ module Spotlight
|
|
26
26
|
def create
|
27
27
|
@resource.attributes = resource_params
|
28
28
|
|
29
|
-
if @resource.
|
29
|
+
if @resource.save_and_index
|
30
30
|
flash[:notice] = t('spotlight.resources.upload.success')
|
31
31
|
if params['add-and-continue']
|
32
32
|
redirect_to new_exhibit_resources_upload_path(@resource.exhibit)
|
@@ -27,7 +27,7 @@ module Spotlight
|
|
27
27
|
@resource.attributes = resource_params
|
28
28
|
@resource = @resource.becomes_provider
|
29
29
|
|
30
|
-
if @resource.
|
30
|
+
if @resource.save_and_index
|
31
31
|
if from_popup?
|
32
32
|
render layout: false, text: '<html><script>window.close();</script></html>'
|
33
33
|
else
|
@@ -10,7 +10,7 @@ module Spotlight
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def uploaded_resource
|
13
|
-
@uploaded_resource ||= GlobalID::Locator.locate first(Spotlight::
|
13
|
+
@uploaded_resource ||= GlobalID::Locator.locate first(Spotlight::Engine.config.resource_global_id_field)
|
14
14
|
rescue => e
|
15
15
|
Rails.logger.info("Unable to locate uploaded resource: #{e}")
|
16
16
|
nil
|
@@ -3,138 +3,183 @@ module Spotlight
|
|
3
3
|
# Exhibit resources
|
4
4
|
class Resource < ActiveRecord::Base
|
5
5
|
include Spotlight::SolrDocument::AtomicUpdates
|
6
|
+
include ActiveSupport::Benchmarkable
|
7
|
+
|
6
8
|
extend ActiveModel::Callbacks
|
7
9
|
define_model_callbacks :index
|
8
10
|
|
9
|
-
class_attribute :providers
|
10
11
|
class_attribute :weight
|
11
12
|
|
12
13
|
belongs_to :exhibit
|
13
14
|
serialize :data, Hash
|
14
|
-
|
15
|
-
|
15
|
+
store :metadata, accessors: [
|
16
|
+
:last_indexed_estimate,
|
17
|
+
:last_indexed_count,
|
18
|
+
:last_index_elapsed_time,
|
19
|
+
:last_indexed_finished], coder: JSON
|
16
20
|
|
17
21
|
around_index :reindex_with_lock
|
22
|
+
around_index :reindex_with_logging
|
23
|
+
after_index :commit
|
18
24
|
|
19
|
-
|
25
|
+
def becomes_provider
|
26
|
+
klass = Spotlight::ResourceProvider.for_resource(self)
|
20
27
|
|
21
|
-
|
22
|
-
|
28
|
+
if klass
|
29
|
+
self.becomes! klass
|
30
|
+
else
|
31
|
+
self
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
|
-
def
|
26
|
-
|
35
|
+
def needs_provider?
|
36
|
+
type.blank?
|
27
37
|
end
|
28
38
|
|
29
39
|
##
|
30
|
-
#
|
31
|
-
# Convert this resource into zero-to-many new solr documents. The data here
|
32
|
-
# should be merged into the resource-specific {#to_solr} data.
|
40
|
+
# Persist the record to the database, and trigger a reindex to solr
|
33
41
|
#
|
34
|
-
# @
|
35
|
-
|
36
|
-
|
37
|
-
def to_solr
|
38
|
-
(exhibit_specific_solr_data || {})
|
39
|
-
.merge(spotlight_resource_metadata_for_solr || {})
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.resource_global_id_field
|
43
|
-
:"#{Spotlight::Engine.config.solr_fields.prefix}spotlight_resource_id#{Spotlight::Engine.config.solr_fields.string_suffix}"
|
42
|
+
# @param [Hash] All arguments will be passed through to ActiveRecord's #save method
|
43
|
+
def save_and_index(*args)
|
44
|
+
save(*args) && reindex_later
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
##
|
48
|
+
# Enqueue an asynchronous reindexing job for this resource
|
49
|
+
def reindex_later
|
50
|
+
Spotlight::ReindexJob.perform_later(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
concerning :GeneratingSolrDocuments do
|
54
|
+
##
|
55
|
+
# @abstract
|
56
|
+
# Convert this resource into zero-to-many new solr documents. The data here
|
57
|
+
# should be merged into the resource-specific {#to_solr} data.
|
58
|
+
#
|
59
|
+
# @return [Hash] a single solr document hash
|
60
|
+
# @return [Enumerator<Hash>] multiple solr document hashes. This can be a
|
61
|
+
# simple array, or an lazy enumerator
|
62
|
+
def to_solr
|
63
|
+
(exhibit_specific_solr_data || {}).merge(spotlight_resource_metadata_for_solr || {})
|
49
64
|
end
|
50
|
-
end
|
51
65
|
|
52
|
-
|
53
|
-
# Index the result of {#to_solr} into the index in batches of {#batch_size}
|
54
|
-
def reindex
|
55
|
-
run_callbacks :index do
|
56
|
-
data = to_solr
|
57
|
-
return if data.blank?
|
66
|
+
protected
|
58
67
|
|
68
|
+
##
|
69
|
+
# @return an enumerator of all the indexable documents for this resource
|
70
|
+
def documents_to_index
|
71
|
+
data = to_solr
|
72
|
+
return [] if data.blank?
|
59
73
|
data &&= [data] if data.is_a? Hash
|
60
74
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
75
|
+
return to_enum(:documents_to_index) { data.size } unless block_given?
|
76
|
+
|
77
|
+
data.reject(&:blank?).each do |doc|
|
78
|
+
yield doc.reverse_merge(existing_solr_doc_hash(doc[unique_key]) || {})
|
65
79
|
end
|
66
80
|
end
|
67
|
-
end
|
68
81
|
|
69
|
-
|
70
|
-
update_columns indexed_at: Time.current
|
71
|
-
end
|
82
|
+
private
|
72
83
|
|
73
|
-
|
74
|
-
|
84
|
+
##
|
85
|
+
# Get any exhibit-specific metadata stored in e.g. sidecars, tags, etc
|
86
|
+
# This needs the generated solr document
|
87
|
+
def existing_solr_doc_hash(id)
|
88
|
+
document_model.new(unique_key => id).to_solr if document_model && id.present?
|
89
|
+
end
|
75
90
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
91
|
+
def unique_key
|
92
|
+
if document_model
|
93
|
+
document_model.unique_key.to_sym
|
94
|
+
else
|
95
|
+
:id
|
96
|
+
end
|
80
97
|
end
|
81
|
-
end
|
82
98
|
|
83
|
-
|
84
|
-
|
99
|
+
def exhibit_specific_solr_data
|
100
|
+
exhibit.solr_data if exhibit
|
101
|
+
end
|
102
|
+
|
103
|
+
def spotlight_resource_metadata_for_solr
|
104
|
+
{
|
105
|
+
Spotlight::Engine.config.resource_global_id_field => (to_global_id.to_s if persisted?),
|
106
|
+
Spotlight::SolrDocument.resource_type_field => self.class.to_s.tableize
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def document_model
|
111
|
+
exhibit.blacklight_config.document_model if exhibit
|
112
|
+
end
|
85
113
|
end
|
86
114
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
115
|
+
concerning :Indexing do
|
116
|
+
##
|
117
|
+
# Index the result of {#to_solr} into the index in batches of {#batch_size}
|
118
|
+
#
|
119
|
+
# @return [Integer] number of records indexed
|
120
|
+
def reindex
|
121
|
+
benchmark "Reindexing #{self} (batch size: #{batch_size})" do
|
122
|
+
count = 0
|
123
|
+
|
124
|
+
run_callbacks :index do
|
125
|
+
documents_to_index.each_slice(batch_size) do |batch|
|
126
|
+
write_to_index(batch)
|
127
|
+
update(last_indexed_count: (count += batch.length))
|
128
|
+
end
|
129
|
+
|
130
|
+
count
|
131
|
+
end
|
93
132
|
end
|
94
133
|
end
|
95
|
-
end
|
96
134
|
|
97
|
-
|
135
|
+
protected
|
98
136
|
|
99
|
-
|
100
|
-
|
101
|
-
|
137
|
+
def reindex_with_lock
|
138
|
+
with_lock do
|
139
|
+
yield
|
140
|
+
end
|
141
|
+
end
|
102
142
|
|
103
|
-
|
104
|
-
|
105
|
-
end
|
143
|
+
def reindex_with_logging
|
144
|
+
time_start = Time.zone.now
|
106
145
|
|
107
|
-
|
108
|
-
|
109
|
-
|
146
|
+
update(indexed_at: time_start,
|
147
|
+
last_indexed_estimate: documents_to_index.size,
|
148
|
+
last_indexed_finished: nil,
|
149
|
+
last_index_elapsed_time: nil)
|
110
150
|
|
111
|
-
|
112
|
-
Spotlight::Engine.config.solr_batch_size
|
113
|
-
end
|
151
|
+
count = yield
|
114
152
|
|
115
|
-
|
116
|
-
|
117
|
-
|
153
|
+
time_end = Time.zone.now
|
154
|
+
update(last_indexed_count: count,
|
155
|
+
last_indexed_finished: time_end,
|
156
|
+
last_index_elapsed_time: time_end - time_start)
|
157
|
+
end
|
118
158
|
|
119
|
-
|
120
|
-
{
|
121
|
-
Spotlight::Resource.resource_global_id_field => (to_global_id.to_s if persisted?),
|
122
|
-
Spotlight::SolrDocument.resource_type_field => self.class.to_s.tableize
|
123
|
-
}
|
124
|
-
end
|
159
|
+
private
|
125
160
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
def existing_solr_doc_hash(id)
|
130
|
-
document_model.new(unique_key => id).to_solr if document_model && id.present?
|
131
|
-
end
|
161
|
+
def blacklight_solr
|
162
|
+
@solr ||= RSolr.connect(connection_config)
|
163
|
+
end
|
132
164
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
165
|
+
def connection_config
|
166
|
+
Blacklight.connection_config
|
167
|
+
end
|
168
|
+
|
169
|
+
def batch_size
|
170
|
+
Spotlight::Engine.config.solr_batch_size
|
171
|
+
end
|
172
|
+
|
173
|
+
def write_to_index(batch)
|
174
|
+
blacklight_solr.update params: { commitWithin: 500 },
|
175
|
+
data: batch.to_json,
|
176
|
+
headers: { 'Content-Type' => 'application/json' }
|
177
|
+
end
|
178
|
+
|
179
|
+
def commit
|
180
|
+
blacklight_solr.commit
|
181
|
+
rescue => e
|
182
|
+
Rails.logger.warn "Unable to commit to solr: #{e}"
|
138
183
|
end
|
139
184
|
end
|
140
185
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spotlight
|
2
|
+
##
|
3
|
+
# Detect which Spotlight::Resource subclasses can provide indexing routines for
|
4
|
+
# a given resource
|
5
|
+
class ResourceProvider
|
6
|
+
class <<self
|
7
|
+
##
|
8
|
+
# @return [Class] the class that can best provide indexing for the resource
|
9
|
+
def for_resource(resource)
|
10
|
+
providers_for_resource(resource).first
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def providers
|
16
|
+
Spotlight::Engine.config.resource_providers
|
17
|
+
end
|
18
|
+
|
19
|
+
def providers_for_resource(resource)
|
20
|
+
providers.select { |provider| provider.can_provide? resource }.sort_by(&:weight)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/spotlight/engine.rb
CHANGED
@@ -70,6 +70,8 @@ module Spotlight
|
|
70
70
|
Spotlight::Engine.config.solr_fields.string_suffix = '_ssim'.freeze
|
71
71
|
Spotlight::Engine.config.solr_fields.text_suffix = '_tesim'.freeze
|
72
72
|
|
73
|
+
Spotlight::Engine.config.resource_global_id_field = :"#{config.solr_fields.prefix}spotlight_resource_id#{config.solr_fields.string_suffix}"
|
74
|
+
|
73
75
|
# The solr field that original (largest) images will be stored.
|
74
76
|
Spotlight::Engine.config.full_image_field = :full_image_url_ssm
|
75
77
|
Spotlight::Engine.config.thumbnail_field = :thumbnail_url_ssm
|
data/lib/spotlight/version.rb
CHANGED
@@ -71,12 +71,11 @@ describe Spotlight::Resources::UploadController, type: :controller do
|
|
71
71
|
let(:blacklight_solr) { double }
|
72
72
|
|
73
73
|
before do
|
74
|
-
|
75
|
-
allow_any_instance_of(Spotlight::Resource).to receive(:reindex)
|
74
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex).and_return(true)
|
76
75
|
allow_any_instance_of(Spotlight::Resource).to receive(:blacklight_solr).and_return blacklight_solr
|
77
76
|
end
|
78
77
|
it 'create a Spotlight::Resources::Upload resource' do
|
79
|
-
|
78
|
+
expect_any_instance_of(Spotlight::Resource).to receive(:reindex_later)
|
80
79
|
post :create, exhibit_id: exhibit, resources_upload: { url: 'url-data' }
|
81
80
|
expect(assigns[:resource]).to be_persisted
|
82
81
|
expect(assigns[:resource]).to be_a(Spotlight::Resources::Upload)
|
@@ -53,8 +53,7 @@ describe Spotlight::ResourcesController, type: :controller do
|
|
53
53
|
describe 'POST create' do
|
54
54
|
let(:blacklight_solr) { double }
|
55
55
|
it 'create a resource' do
|
56
|
-
|
57
|
-
expect(blacklight_solr).to receive(:commit)
|
56
|
+
expect_any_instance_of(Spotlight::Resource).to receive(:reindex_later)
|
58
57
|
allow_any_instance_of(Spotlight::Resource).to receive(:blacklight_solr).and_return blacklight_solr
|
59
58
|
post :create, exhibit_id: exhibit, resource: { url: 'info:uri' }
|
60
59
|
expect(assigns[:resource]).to be_persisted
|
@@ -23,7 +23,7 @@ describe 'adding an item using the provided bookmarklet', type: :feature do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'submits the form to create a new item' do
|
26
|
-
allow_any_instance_of(Spotlight::Resource).to receive(:
|
26
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex_later)
|
27
27
|
visit spotlight.new_exhibit_resource_path(exhibit, popup: true, resource: { url: 'info:url' })
|
28
28
|
expect(page).to have_content 'Add Resource'
|
29
29
|
expect(first('#resource_url', visible: false).value).to eq 'info:url'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spotlight::ResourceProvider do
|
4
|
+
describe '.for_resource' do
|
5
|
+
let(:thing) { double }
|
6
|
+
let(:type_a) { double('TypeA', weight: 10) }
|
7
|
+
let(:type_b) { double('TypeB', weight: 5) }
|
8
|
+
let(:providers) { [type_a, type_b] }
|
9
|
+
subject { described_class.for_resource(thing) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(described_class).to receive_messages(providers: providers)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns a class that can provide indexing for the resource' do
|
16
|
+
expect(type_a).to receive(:can_provide?).with(thing).and_return(true)
|
17
|
+
expect(type_b).to receive(:can_provide?).with(thing).and_return(false)
|
18
|
+
expect(subject).to eq type_a
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns the lowest weighted class that can provide indexing for the resource' do
|
22
|
+
expect(type_a).to receive(:can_provide?).with(thing).and_return(true)
|
23
|
+
expect(type_b).to receive(:can_provide?).with(thing).and_return(true)
|
24
|
+
expect(subject).to eq type_b
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,30 +6,6 @@ describe Spotlight::Resource, type: :model do
|
|
6
6
|
end
|
7
7
|
let(:exhibit) { FactoryGirl.create(:exhibit) }
|
8
8
|
|
9
|
-
describe '.class_for_resource' do
|
10
|
-
let(:thing) { double }
|
11
|
-
let(:type_a) { double('TypeA', weight: 10) }
|
12
|
-
let(:type_b) { double('TypeB', weight: 5) }
|
13
|
-
let(:providers) { [type_a, type_b] }
|
14
|
-
subject { described_class.class_for_resource(thing) }
|
15
|
-
|
16
|
-
before do
|
17
|
-
allow(described_class).to receive_messages(providers: providers)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns a class that can provide indexing for the resource' do
|
21
|
-
expect(type_a).to receive(:can_provide?).with(thing).and_return(true)
|
22
|
-
expect(type_b).to receive(:can_provide?).with(thing).and_return(false)
|
23
|
-
expect(subject).to eq type_a
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns the lowest weighted class that can provide indexing for the resource' do
|
27
|
-
expect(type_a).to receive(:can_provide?).with(thing).and_return(true)
|
28
|
-
expect(type_b).to receive(:can_provide?).with(thing).and_return(true)
|
29
|
-
expect(subject).to eq type_b
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
9
|
describe '#to_solr' do
|
34
10
|
before do
|
35
11
|
allow(subject).to receive(:exhibit).and_return(exhibit)
|
@@ -48,20 +24,20 @@ describe Spotlight::Resource, type: :model do
|
|
48
24
|
describe '#reindex' do
|
49
25
|
context 'with a provider that generates ids' do
|
50
26
|
subject do
|
51
|
-
Class.new(described_class)
|
52
|
-
def to_solr
|
53
|
-
super.merge(id: 123)
|
54
|
-
end
|
55
|
-
end.new(exhibit: exhibit)
|
27
|
+
Class.new(described_class).new(exhibit: exhibit)
|
56
28
|
end
|
57
29
|
|
30
|
+
let(:solr_response) { { id: 123 } }
|
31
|
+
|
58
32
|
before do
|
59
33
|
SolrDocument.new(id: 123).sidecars.create!(exhibit: exhibit, data: { document_data: true })
|
60
|
-
allow(subject).to receive_messages(to_global_id: ''
|
34
|
+
allow(subject).to receive_messages(to_global_id: '')
|
35
|
+
|
36
|
+
allow(subject).to receive(:to_solr).and_return(solr_response)
|
61
37
|
end
|
62
38
|
|
63
39
|
it 'includes exhibit document-specific data' do
|
64
|
-
|
40
|
+
allow(subject.send(:blacklight_solr)).to receive(:update) do |options|
|
65
41
|
data = JSON.parse(options[:data], symbolize_names: true)
|
66
42
|
|
67
43
|
expect(data.length).to eq 1
|
@@ -72,22 +48,69 @@ describe Spotlight::Resource, type: :model do
|
|
72
48
|
|
73
49
|
subject.reindex
|
74
50
|
end
|
51
|
+
|
52
|
+
context 'with a resource that creates multiple solr documents' do
|
53
|
+
let(:solr_response) { [{ id: 1 }, { id: 2 }] }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject.send(:blacklight_solr)).to receive(:update)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns the number of indexed objects' do
|
60
|
+
expect(subject.reindex).to eq 2
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'triggers a solr commit' do
|
64
|
+
expect(subject.send(:blacklight_solr)).to receive(:commit).once
|
65
|
+
|
66
|
+
subject.reindex
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'records indexing metadata as document attributes' do
|
70
|
+
subject.reindex
|
71
|
+
|
72
|
+
expect(subject.indexed_at).to be > Time.zone.now - 5.seconds
|
73
|
+
expect(subject.last_indexed_estimate).to eq 2
|
74
|
+
expect(subject.last_indexed_count).to eq 2
|
75
|
+
expect(subject.last_index_elapsed_time).to be < 1
|
76
|
+
end
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
81
|
describe '#becomes_provider' do
|
79
82
|
it 'converts the resource to a provider-specific resource' do
|
80
83
|
SomeClass = Class.new(described_class)
|
81
|
-
allow(
|
84
|
+
allow(Spotlight::ResourceProvider).to receive_messages(for_resource: SomeClass)
|
82
85
|
expect(subject.becomes_provider).to be_a_kind_of(SomeClass)
|
83
86
|
expect(subject.becomes_provider.type).to eq 'SomeClass'
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
describe '#save_and_index' do
|
91
|
+
before do
|
92
|
+
allow(subject.send(:blacklight_solr)).to receive(:update)
|
93
|
+
allow(subject).to receive(:reindex_later)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'saves the object' do
|
97
|
+
expect(subject).to receive(:save).and_return(true)
|
98
|
+
subject.save_and_index
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'reindexes after save' do
|
102
|
+
expect(subject).to receive(:save).and_return(true)
|
103
|
+
expect(subject).to receive(:reindex_later)
|
104
|
+
subject.save_and_index
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'if the save fails' do
|
108
|
+
it 'does not reindex' do
|
109
|
+
expect(subject).to receive(:save).and_return(false)
|
110
|
+
expect(subject).not_to receive(:reindex_later)
|
111
|
+
subject.save_and_index
|
112
|
+
end
|
113
|
+
end
|
91
114
|
end
|
92
115
|
|
93
116
|
it 'stores arbitrary data' do
|
@@ -97,19 +120,4 @@ describe Spotlight::Resource, type: :model do
|
|
97
120
|
expect(subject.data[:a]).to eq 1
|
98
121
|
expect(subject.data[:b]).to eq 2
|
99
122
|
end
|
100
|
-
|
101
|
-
describe '#update_index_time!' do
|
102
|
-
it 'updates the index_time column' do
|
103
|
-
expect(subject).to receive(:update_columns).with(hash_including(:indexed_at))
|
104
|
-
subject.update_index_time!
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#save_and_commit' do
|
109
|
-
it 'saves the object and commit to solr' do
|
110
|
-
expect(subject).to receive(:save)
|
111
|
-
expect(subject.send(:blacklight_solr)).to receive(:commit)
|
112
|
-
subject.save_and_commit
|
113
|
-
end
|
114
|
-
end
|
115
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight-spotlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-11-
|
14
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -845,6 +845,7 @@ files:
|
|
845
845
|
- app/models/spotlight/masthead.rb
|
846
846
|
- app/models/spotlight/page.rb
|
847
847
|
- app/models/spotlight/resource.rb
|
848
|
+
- app/models/spotlight/resource_provider.rb
|
848
849
|
- app/models/spotlight/resources/csv_upload.rb
|
849
850
|
- app/models/spotlight/resources/upload.rb
|
850
851
|
- app/models/spotlight/role.rb
|
@@ -1036,6 +1037,7 @@ files:
|
|
1036
1037
|
- db/migrate/20150410180016_change_collation_for_tag_names.acts_as_taggable_on_engine.rb
|
1037
1038
|
- db/migrate/20150713160101_change_spotlight_searches_to_published.rb
|
1038
1039
|
- db/migrate/20151016092343_remove_searchable_from_exhibit.rb
|
1040
|
+
- db/migrate/20151110082345_add_metadata_to_spotlight_resource.rb
|
1039
1041
|
- lib/blacklight/spotlight.rb
|
1040
1042
|
- lib/generators/spotlight/install_generator.rb
|
1041
1043
|
- lib/generators/spotlight/templates/catalog_controller.rb
|
@@ -1174,6 +1176,7 @@ files:
|
|
1174
1176
|
- spec/models/spotlight/main_navigation_spec.rb
|
1175
1177
|
- spec/models/spotlight/masthead_spec.rb
|
1176
1178
|
- spec/models/spotlight/page_spec.rb
|
1179
|
+
- spec/models/spotlight/resource_provider_spec.rb
|
1177
1180
|
- spec/models/spotlight/resource_spec.rb
|
1178
1181
|
- spec/models/spotlight/resources/open_graph_spec.rb
|
1179
1182
|
- spec/models/spotlight/resources/upload_spec.rb
|
@@ -1270,7 +1273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1270
1273
|
version: '0'
|
1271
1274
|
requirements: []
|
1272
1275
|
rubyforge_project:
|
1273
|
-
rubygems_version: 2.4.
|
1276
|
+
rubygems_version: 2.4.5.1
|
1274
1277
|
signing_key:
|
1275
1278
|
specification_version: 4
|
1276
1279
|
summary: Enable librarians, curators, and others who are responsible for digital collections
|
@@ -1394,6 +1397,7 @@ test_files:
|
|
1394
1397
|
- spec/models/spotlight/main_navigation_spec.rb
|
1395
1398
|
- spec/models/spotlight/masthead_spec.rb
|
1396
1399
|
- spec/models/spotlight/page_spec.rb
|
1400
|
+
- spec/models/spotlight/resource_provider_spec.rb
|
1397
1401
|
- spec/models/spotlight/resource_spec.rb
|
1398
1402
|
- spec/models/spotlight/resources/open_graph_spec.rb
|
1399
1403
|
- spec/models/spotlight/resources/upload_spec.rb
|