Minor follow-up bug fix for 5ff6c10.

Minor follow-up bug fix for 5ff6c10.

diff --git a/app/models/topic_timer.rb b/app/models/topic_timer.rb
index 27d4a94..55f54d0 100644
--- a/app/models/topic_timer.rb
+++ b/app/models/topic_timer.rb
@@ -126,7 +126,7 @@ class TopicTimer < ActiveRecord::Base
   end
 
   def schedule_auto_open_job(time)
-    topic.update_status('closed', true, user) if !topic&.closed
+    topic.update_status('closed', true, user) if topic && !topic.closed
 
     Jobs.enqueue_at(time, :toggle_topic_closed,
       topic_timer_id: id,
diff --git a/spec/models/topic_timer_spec.rb b/spec/models/topic_timer_spec.rb
index 40da0ec..4d1e09c 100644
--- a/spec/models/topic_timer_spec.rb
+++ b/spec/models/topic_timer_spec.rb
@@ -232,19 +232,27 @@ RSpec.describe TopicTimer, type: :model do
 
       Fabricate(:topic_timer, execute_at: Time.zone.now + 1.hour)
 
-      trashed_topic_timer = Fabricate(:topic_timer,
+      trashed_close_topic_timer = Fabricate(:topic_timer,
         execute_at: Time.zone.now - 1.hour,
         created_at: Time.zone.now - 2.hour
       )
 
-      trashed_topic_timer.topic.trash!
+      trashed_close_topic_timer.topic.trash!
+
+      trashed_open_topic_timer = Fabricate(:topic_timer,
+        execute_at: Time.zone.now - 1.hour,
+        created_at: Time.zone.now - 2.hour,
+        status_type: described_class.types[:open]
+      )
+
+      trashed_open_topic_timer.topic.trash!
 
       # creating topic timers already enqueues jobs
       # let's delete them to test ensure_consistency!
       Sidekiq::Worker.clear_all
 
       expect { described_class.ensure_consistency! }
-        .to change { Jobs::ToggleTopicClosed.jobs.count }.by(3)
+        .to change { Jobs::ToggleTopicClosed.jobs.count }.by(4)
 
       expect(job_enqueued?(job: :toggle_topic_closed, args: {
         topic_timer_id: close_topic_timer.id,
@@ -257,9 +265,14 @@ RSpec.describe TopicTimer, type: :model do
       })).to eq(true)
 
       expect(job_enqueued?(job: :toggle_topic_closed, args: {
-        topic_timer_id: trashed_topic_timer.id,
+        topic_timer_id: trashed_close_topic_timer.id,
         state: true
       })).to eq(true)
+
+      expect(job_enqueued?(job: :toggle_topic_closed, args: {
+        topic_timer_id: trashed_open_topic_timer.id,
+        state: false
+      })).to eq(true)
     end
 
     it "should enqueue remind me jobs that have been missed" do

GitHub sha: dbfb2a1e