FIX: dont error when topic without category

FIX: dont error when topic without category

diff --git a/lib/discourse_voting/topic_extension.rb b/lib/discourse_voting/topic_extension.rb
index cb386e4..55f2d6a 100644
--- a/lib/discourse_voting/topic_extension.rb
+++ b/lib/discourse_voting/topic_extension.rb
@@ -9,7 +9,7 @@ module DiscourseVoting
     end
 
     def can_vote?
-      SiteSetting.voting_enabled && Category.can_vote?(category_id) && category.topic_id != id
+      SiteSetting.voting_enabled && Category.can_vote?(category_id) && category && category.topic_id != id
     end
 
     def vote_count
diff --git a/spec/voting_spec.rb b/spec/voting_spec.rb
index f4535f1..eb906b7 100644
--- a/spec/voting_spec.rb
+++ b/spec/voting_spec.rb
@@ -227,5 +227,10 @@ describe DiscourseVoting do
       expect(DiscourseVoting::Vote.where(user: user0, archive: false).map(&:topic_id)).to contain_exactly(topic0.id, topic1.id, topic2.id)
       expect(DiscourseVoting::Vote.where(user: user0, archive: true).map(&:topic_id)).to eq([])
     end
+
+    it 'is not erroring when topic without category' do
+      topic1.category.destroy
+      expect(topic1.reload.can_vote?).to be_falsey
+    end
   end
 end

GitHub sha: e2c2f517