DEV: Remove mock_redis (#15985)
Was used just in one spec file. And we prefer to run specs against a real redis server.
This commit is contained in:
parent
6a5ef27eaa
commit
aaf432df86
1
Gemfile
1
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue