Skip to content

Commit d0d28d7

Browse files
committed
Do not try and reindex link checkable object that is not indexable
1 parent 88676c1 commit d0d28d7

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

app/models/link_monitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ def status_changed?
5050
def reindex_resource
5151
return unless TeSS::Config.solr_enabled
5252
return unless status_changed?
53-
link_checkable.solr_index
53+
link_checkable.solr_index if link_checkable&.respond_to?(:solr_index)
5454
end
5555
end

test/fixtures/external_resources.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ biotools:
1515
url: https://bio.tools/tool/SR-Tesseler
1616
title: SR-Tesseler
1717

18-
1918
biotwools:
2019
source: event_with_external_resource (Event)
2120
url: https://bio.tools/tool/FuNeL

test/models/link_monitor_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,27 @@ class LinkMonitorTest < ActiveSupport::TestCase
120120
refute @link_monitor.failing?
121121
refute @link_monitor.status_changed?
122122
end
123+
124+
test 'reindex after status changing' do
125+
with_settings(solr_enabled: true) do
126+
e = events(:one)
127+
lm = e.create_link_monitor
128+
index = []
129+
e.stub(:solr_index, -> { index << e }) do
130+
assert_empty index
131+
lm.fail!(404)
132+
assert_includes index, e
133+
end
134+
end
135+
end
136+
137+
test 'do not try and reindex non-solr resource' do
138+
with_settings(solr_enabled: true) do
139+
er = external_resources(:biotools)
140+
lm = er.create_link_monitor
141+
assert_nothing_raised do
142+
lm.fail!(404)
143+
end
144+
end
145+
end
123146
end

0 commit comments

Comments
 (0)