mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
1
Gemfile
1
Gemfile
@@ -158,7 +158,6 @@ end
|
|||||||
|
|
||||||
group :test, :development do
|
group :test, :development do
|
||||||
gem 'rspec'
|
gem 'rspec'
|
||||||
gem 'mock_redis'
|
|
||||||
gem 'listen', require: false
|
gem 'listen', require: false
|
||||||
gem 'certified', require: false
|
gem 'certified', require: false
|
||||||
gem 'fabrication', require: false
|
gem 'fabrication', require: false
|
||||||
|
|||||||
@@ -241,8 +241,6 @@ GEM
|
|||||||
ffi (~> 1.9)
|
ffi (~> 1.9)
|
||||||
minitest (5.15.0)
|
minitest (5.15.0)
|
||||||
mocha (1.13.0)
|
mocha (1.13.0)
|
||||||
mock_redis (0.29.0)
|
|
||||||
ruby2_keywords
|
|
||||||
msgpack (1.4.5)
|
msgpack (1.4.5)
|
||||||
multi_json (1.15.0)
|
multi_json (1.15.0)
|
||||||
multi_xml (0.6.0)
|
multi_xml (0.6.0)
|
||||||
@@ -556,7 +554,6 @@ DEPENDENCIES
|
|||||||
mini_suffix
|
mini_suffix
|
||||||
minitest
|
minitest
|
||||||
mocha
|
mocha
|
||||||
mock_redis
|
|
||||||
multi_json
|
multi_json
|
||||||
mustache
|
mustache
|
||||||
nokogiri
|
nokogiri
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe CommonPasswords do
|
describe CommonPasswords do
|
||||||
|
|
||||||
it "the passwords file should exist" do
|
it "the passwords file should exist" do
|
||||||
expect(File.exist?(described_class::PASSWORD_FILE)).to eq(true)
|
expect(File.exist?(described_class::PASSWORD_FILE)).to eq(true)
|
||||||
end
|
end
|
||||||
@@ -39,31 +38,25 @@ describe CommonPasswords do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#password_list' do
|
describe '#password_list' do
|
||||||
|
before { Discourse.redis.flushdb }
|
||||||
|
after { Discourse.redis.flushdb }
|
||||||
|
|
||||||
it "loads the passwords file if redis doesn't have it" do
|
it "loads the passwords file if redis doesn't have it" do
|
||||||
mock_redis = mock("redis")
|
Discourse.redis.without_namespace.stubs(:scard).returns(0)
|
||||||
mock_redis.stubs(:exists).returns(false)
|
|
||||||
mock_redis.stubs(:scard).returns(0)
|
|
||||||
described_class.stubs(:redis).returns(mock_redis)
|
|
||||||
described_class.expects(:load_passwords).returns(['password'])
|
described_class.expects(:load_passwords).returns(['password'])
|
||||||
list = described_class.password_list
|
list = described_class.password_list
|
||||||
expect(list).to respond_to(:include?)
|
expect(list).to respond_to(:include?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't load the passwords file if redis has it" do
|
it "doesn't load the passwords file if redis has it" do
|
||||||
mock_redis = mock("redis")
|
Discourse.redis.without_namespace.stubs(:scard).returns(10000)
|
||||||
mock_redis.stubs(:exists).returns(true)
|
|
||||||
mock_redis.stubs(:scard).returns(10000)
|
|
||||||
described_class.stubs(:redis).returns(mock_redis)
|
|
||||||
described_class.expects(:load_passwords).never
|
described_class.expects(:load_passwords).never
|
||||||
list = described_class.password_list
|
list = described_class.password_list
|
||||||
expect(list).to respond_to(:include?)
|
expect(list).to respond_to(:include?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads the passwords file if redis has an empty list" do
|
it "loads the passwords file if redis has an empty list" do
|
||||||
mock_redis = mock("redis")
|
Discourse.redis.without_namespace.stubs(:scard).returns(0)
|
||||||
mock_redis.stubs(:exists).returns(true)
|
|
||||||
mock_redis.stubs(:scard).returns(0)
|
|
||||||
described_class.stubs(:redis).returns(mock_redis)
|
|
||||||
described_class.expects(:load_passwords).returns(['password'])
|
described_class.expects(:load_passwords).returns(['password'])
|
||||||
list = described_class.password_list
|
list = described_class.password_list
|
||||||
expect(list).to respond_to(:include?)
|
expect(list).to respond_to(:include?)
|
||||||
@@ -72,7 +65,6 @@ describe CommonPasswords do
|
|||||||
|
|
||||||
context "missing password file" do
|
context "missing password file" do
|
||||||
it "tolerates it" 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)
|
File.stubs(:readlines).with(described_class::PASSWORD_FILE).raises(Errno::ENOENT)
|
||||||
expect(described_class.common_password?("password")).to eq(false)
|
expect(described_class.common_password?("password")).to eq(false)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -99,16 +99,6 @@ ENV['DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE'] = '1'
|
|||||||
module TestSetup
|
module TestSetup
|
||||||
# This is run before each test and before each before_all block
|
# This is run before each test and before each before_all block
|
||||||
def self.test_setup(x = nil)
|
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
|
RateLimiter.disable
|
||||||
PostActionNotifier.disable
|
PostActionNotifier.disable
|
||||||
SearchIndexer.disable
|
SearchIndexer.disable
|
||||||
@@ -250,16 +240,6 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
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|
|
config.after :each do |x|
|
||||||
if x.exception && ex = RspecErrorTracker.last_exception
|
if x.exception && ex = RspecErrorTracker.last_exception
|
||||||
# magic in a cause if we have none
|
# magic in a cause if we have none
|
||||||
|
|||||||
Reference in New Issue
Block a user