From 6540d8b957f24b41dd03cd4b280769252a3312c8 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 3 Dec 2019 10:45:32 +0100 Subject: [PATCH] DEV: uses Discourse.redis instead of $redis --- app/controllers/public_controller.rb | 2 +- app/helpers/helper.rb | 2 +- spec/helpers/helper_spec.rb | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index 527cd51..d5a645d 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -7,7 +7,7 @@ class DiscourseChat::PublicController < ApplicationController params.require(:secret) redis_key = "chat_integration:transcript:#{params[:secret]}" - content = $redis.get(redis_key) + content = Discourse.redis.get(redis_key) if content render json: { content: content } diff --git a/app/helpers/helper.rb b/app/helpers/helper.rb index c98b07a..501f798 100644 --- a/app/helpers/helper.rb +++ b/app/helpers/helper.rb @@ -192,7 +192,7 @@ module DiscourseChat def self.save_transcript(transcript) secret = SecureRandom.hex redis_key = "chat_integration:transcript:#{secret}" - $redis.setex(redis_key, 3600, transcript) + Discourse.redis.setex(redis_key, 3600, transcript) secret end diff --git a/spec/helpers/helper_spec.rb b/spec/helpers/helper_spec.rb index 0750200..fc2acc8 100644 --- a/spec/helpers/helper_spec.rb +++ b/spec/helpers/helper_spec.rb @@ -311,13 +311,13 @@ RSpec.describe DiscourseChat::Manager do it 'saves a transcript to redis' do key = DiscourseChat::Helper.save_transcript("Some content here") - expect($redis.get("chat_integration:transcript:#{key}")).to eq("Some content here") + expect(Discourse.redis.get("chat_integration:transcript:#{key}")).to eq("Some content here") - ttl = $redis.pttl("chat_integration:transcript:#{key}") + ttl = Discourse.redis.pttl("chat_integration:transcript:#{key}") # Slight hack since freeze_time doens't work on redis - expect($redis.pttl("chat_integration:transcript:#{key}")).to be <= (3601 * 1000) - expect($redis.pttl("chat_integration:transcript:#{key}")).to be >= (3599 * 1000) + expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be <= (3601 * 1000) + expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be >= (3599 * 1000) end end