blacklight-spotlight 2.12.1 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Spotlight::ReindexJob do
4
+ include ActiveJob::TestHelper
5
+
4
6
  let(:exhibit) { FactoryBot.create(:exhibit) }
5
7
  let(:resource) { FactoryBot.create(:resource) }
6
8
  let(:user) { FactoryBot.create(:user) }
7
9
  let(:log_entry) { Spotlight::ReindexingLogEntry.create(exhibit: exhibit, user: user) }
8
10
 
9
11
  before do
12
+ ActiveJob::Base.queue_adapter = :test
10
13
  allow_any_instance_of(Spotlight::Resource).to receive(:reindex)
11
14
  end
12
15
 
@@ -70,4 +73,33 @@ describe Spotlight::ReindexJob do
70
73
  subject.perform_now
71
74
  end
72
75
  end
76
+
77
+ describe 'validity' do
78
+ subject { described_class.new(resource, nil, 'xyz') }
79
+
80
+ let(:mock_checker) { instance_double(Spotlight::ValidityChecker) }
81
+
82
+ before do
83
+ allow(described_class).to receive(:validity_checker).and_return(mock_checker)
84
+ allow(mock_checker).to receive(:mint).with(resource).and_return('xyz')
85
+ end
86
+
87
+ it 'mints a new validity token' do
88
+ expect { described_class.perform_later(resource) }.to have_enqueued_job(described_class).with(resource, nil, 'xyz')
89
+ end
90
+
91
+ it 'does nothing if the token is no longer valid' do
92
+ allow(mock_checker).to receive(:check).with(resource, 'xyz').and_return(false)
93
+ expect(resource).not_to receive(:reindex)
94
+
95
+ subject.perform_now
96
+ end
97
+
98
+ it 'indexes the resource if the token is valid' do
99
+ allow(mock_checker).to receive(:check).with(resource, 'xyz').and_return(true)
100
+ expect(resource).to receive(:reindex)
101
+
102
+ subject.perform_now
103
+ end
104
+ end
73
105
  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: 2.12.1
4
+ version: 2.13.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: 2019-12-06 00:00:00.000000000 Z
14
+ date: 2019-12-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -1023,6 +1023,7 @@ files:
1023
1023
  - app/services/spotlight/resources/iiif_builder.rb
1024
1024
  - app/services/spotlight/solr_document_builder.rb
1025
1025
  - app/services/spotlight/upload_solr_document_builder.rb
1026
+ - app/services/spotlight/validity_checker.rb
1026
1027
  - app/uploaders/spotlight/attachment_uploader.rb
1027
1028
  - app/uploaders/spotlight/featured_image_uploader.rb
1028
1029
  - app/values/custom_field_name.rb