Skip to content

Commit 8990e7b

Browse files
committed
Test fix
1 parent d0d28d7 commit 8990e7b

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/models/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Event < ApplicationRecord
115115
has_one :llm_interaction, inverse_of: :event, dependent: :destroy
116116
accepts_nested_attributes_for :llm_interaction, allow_destroy: true
117117
has_one :edit_suggestion, as: :suggestible, dependent: :destroy
118-
has_one :link_monitor, as: :lcheck, dependent: :destroy
118+
has_one :link_monitor, as: :lcheck, dependent: :destroy, inverse_of: :link_checkable
119119
has_many :collection_items, as: :resource
120120
has_many :collections, through: :collection_items
121121
has_many :event_materials, dependent: :destroy

app/models/link_monitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class LinkMonitor < ApplicationRecord
2-
belongs_to :link_checkable, polymorphic: true, foreign_key: :lcheck_id, foreign_type: :lcheck_type
2+
belongs_to :link_checkable, polymorphic: true, foreign_key: :lcheck_id, foreign_type: :lcheck_type, inverse_of: :link_monitor
33
before_create :set_initial_date
44
after_commit :reindex_resource, on: :update
55

test/models/link_monitor_test.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,30 @@ class LinkMonitorTest < ActiveSupport::TestCase
122122
end
123123

124124
test 'reindex after status changing' do
125+
e = events(:one)
126+
index = []
127+
# I have to do this because `solr_enabled` is disabled when the Event class is loaded,
128+
# so it does not get the `solr_index` method even after I toggle it on below,
129+
# which prevents me using Minitest's `stub` to stub out `solr_index`.
130+
e.define_singleton_method(:solr_index) { index << self }
125131
with_settings(solr_enabled: true) do
126-
e = events(:one)
127132
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
133+
lm.update_column(:fail_count, 3)
134+
assert_empty index
135+
lm.fail!(404)
136+
assert lm.failing?
137+
assert_includes index, e
134138
end
135139
end
136140

137141
test 'do not try and reindex non-solr resource' do
138142
with_settings(solr_enabled: true) do
139143
er = external_resources(:biotools)
140144
lm = er.create_link_monitor
145+
lm.update_column(:fail_count, 3)
141146
assert_nothing_raised do
142147
lm.fail!(404)
148+
assert lm.failing?
143149
end
144150
end
145151
end

0 commit comments

Comments
 (0)