Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove mock_redis (#15985)

Jarek Radoszaaf432df86ad
diff --git a/Gemfile b/Gemfile
index ffff6f24371..eab0ed0bfa5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -158,7 +158,6 @@ end
group :test, :development do
gem 'rspec'
- gem 'mock_redis'
gem 'listen', require: false
gem 'certified', require: false
gem 'fabrication', require: false
diff --git a/Gemfile.lock b/Gemfile.lock
index 0d2a0ec3b2d..8209a9a638e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -241,8 +241,6 @@ GEM
ffi (~> 1.9)
minitest (5.15.0)
mocha (1.13.0)
- mock_redis (0.29.0)
- ruby2_keywords
msgpack (1.4.5)
multi_json (1.15.0)
multi_xml (0.6.0)
@@ -556,7 +554,6 @@ DEPENDENCIES
mini_suffix
minitest
mocha
- mock_redis
multi_json
mustache
nokogiri
diff --git a/spec/components/common_passwords/common_passwords_spec.rb b/spec/components/common_passwords/common_passwords_spec.rb
index c68620d6e9e..4533de82008 100644
--- a/spec/components/common_passwords/common_passwords_spec.rb
+++ b/spec/components/common_passwords/common_passwords_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
describe CommonPasswords do
-
it "the passwords file should exist" do
expect(File.exist?(described_class::PASSWORD_FILE)).to eq(true)
end
@@ -39,31 +38,25 @@ describe CommonPasswords do
end
describe '#password_list' do
+ before { Discourse.redis.flushdb }
+ after { Discourse.redis.flushdb }
+
it "loads the passwords file if redis doesn't have it" do
- mock_redis = mock("redis")
- mock_redis.stubs(:exists).returns(false)
- mock_redis.stubs(:scard).returns(0)
- described_class.stubs(:redis).returns(mock_redis)
+ Discourse.redis.without_namespace.stubs(:scard).returns(0)
described_class.expects(:load_passwords).returns(['password'])
list = described_class.password_list
expect(list).to respond_to(:include?)
end
it "doesn't load the passwords file if redis has it" do
- mock_redis = mock("redis")
- mock_redis.stubs(:exists).returns(true)
- mock_redis.stubs(:scard).returns(10000)
- described_class.stubs(:redis).returns(mock_redis)
+ Discourse.redis.without_namespace.stubs(:scard).returns(10000)
described_class.expects(:load_passwords).never
list = described_class.password_list
expect(list).to respond_to(:include?)
end
it "loads the passwords file if redis has an empty list" do
- mock_redis = mock("redis")
- mock_redis.stubs(:exists).returns(true)
- mock_redis.stubs(:scard).returns(0)
- described_class.stubs(:redis).returns(mock_redis)
+ Discourse.redis.without_namespace.stubs(:scard).returns(0)
described_class.expects(:load_passwords).returns(['password'])
list = described_class.password_list
expect(list).to respond_to(:include?)
@@ -72,7 +65,6 @@ describe CommonPasswords do
context "missing password file" do
it "tolerates it" do
- described_class.stubs(:redis).returns(stub_everything(sismember: false, exists: false, scard: 0))
File.stubs(:readlines).with(described_class::PASSWORD_FILE).raises(Errno::ENOENT)
expect(described_class.common_password?("password")).to eq(false)
end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index ef6f87dc6e3..90cf2c176b2 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -99,16 +99,6 @@ ENV['DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE'] = '1'
module TestSetup
# This is run before each test and before each before_all block
def self.test_setup(x = nil)
- # TODO not sure about this, we could use a mock redis implementation here:
- # this gives us really clean "flush" semantics, however the side-effect is that
- # we are no longer using a clean redis implementation, a preferable solution may
- # be simply flushing before tests, trouble is that redis may be reused with dev
- # so that would mean the dev would act weird
- #
- # perf benefit seems low (shaves 20 secs off a 4 minute test suite)
- #
- # Discourse.redis = DiscourseMockRedis.new
-
RateLimiter.disable
PostActionNotifier.disable
SearchIndexer.disable
@@ -250,16 +240,6 @@ RSpec.configure do |config|
end
end
- class DiscourseMockRedis < MockRedis
- def without_namespace
- self
- end
-
- def delete_prefixed(prefix)
- keys("#{prefix}*").each { |k| del(k) }
- end
- end
-
config.after :each do |x|
if x.exception && ex = RspecErrorTracker.last_exception
# magic in a cause if we have none