A platform for community discussion. Free, open, simple.
DEV: Remove mock_redis (#15985)
Jarek Radoszaaf432df86ad
diff --git a/Gemfile b/Gemfileindex ffff6f24371..eab0ed0bfa5 100644--- a/Gemfile+++ b/Gemfile@@ -158,7 +158,6 @@ endgroup :test, :development dogem 'rspec'- gem 'mock_redis'gem 'listen', require: falsegem 'certified', require: falsegem 'fabrication', require: falsediff --git a/Gemfile.lock b/Gemfile.lockindex 0d2a0ec3b2d..8209a9a638e 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -241,8 +241,6 @@ GEMffi (~> 1.9)minitest (5.15.0)mocha (1.13.0)- mock_redis (0.29.0)- ruby2_keywordsmsgpack (1.4.5)multi_json (1.15.0)multi_xml (0.6.0)@@ -556,7 +554,6 @@ DEPENDENCIESmini_suffixminitestmocha- mock_redismulti_jsonmustachenokogiridiff --git a/spec/components/common_passwords/common_passwords_spec.rb b/spec/components/common_passwords/common_passwords_spec.rbindex 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" doexpect(File.exist?(described_class::PASSWORD_FILE)).to eq(true)end@@ -39,31 +38,25 @@ describe CommonPasswords doenddescribe '#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_listexpect(list).to respond_to(:include?)endit "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).neverlist = described_class.password_listexpect(list).to respond_to(:include?)endit "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_listexpect(list).to respond_to(:include?)@@ -72,7 +65,6 @@ describe CommonPasswords docontext "missing password file" doit "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)enddiff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex 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 blockdef 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.disablePostActionNotifier.disableSearchIndexer.disable@@ -250,16 +240,6 @@ RSpec.configure do |config|endend- 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