tests: fix tests for Rails.cache.

This commit is contained in:
evazion
2017-04-15 21:51:56 -05:00
parent 192190a313
commit c0e5c400a7
46 changed files with 14 additions and 69 deletions

View File

@@ -37,6 +37,10 @@ class Cache
nil nil
end end
def self.clear
Rails.cache.clear
end
def self.sanitize(key) def self.sanitize(key)
key.gsub(/\W/) {|x| "%#{x.ord}"}.slice(0, 230) key.gsub(/\W/) {|x| "%#{x.ord}"}.slice(0, 230)
end end

View File

@@ -7,7 +7,6 @@ module Moderator
@mod = FactoryGirl.create(:moderator_user) @mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @mod CurrentUser.user = @mod
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@user_1 = FactoryGirl.create(:user) @user_1 = FactoryGirl.create(:user)
@user_2 = FactoryGirl.create(:user, :inviter_id => @mod.id) @user_2 = FactoryGirl.create(:user, :inviter_id => @mod.id)

View File

@@ -8,7 +8,6 @@ module Moderator
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
FactoryGirl.create(:comment) FactoryGirl.create(:comment)
MEMCACHE.flush_all
end end
should "find by ip addr" do should "find by ip addr" do

View File

@@ -8,7 +8,6 @@ class PostsControllerTest < ActionController::TestCase
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa") @post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa")
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class TagAliasCorrectionsControllerTest < ActionController::TestCase
@admin = FactoryGirl.create(:admin_user) @admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") @tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
end end

View File

@@ -6,7 +6,6 @@ class TagAliasRequestsControllerTest < ActionController::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class TagAliasesControllerTest < ActionController::TestCase
@user = FactoryGirl.create(:admin_user) @user = FactoryGirl.create(:admin_user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -8,7 +8,6 @@ class TagImplicationRequestsControllerTest < ActionController::TestCase
end end
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class TagImplicationsControllerTest < ActionController::TestCase
@user = FactoryGirl.create(:admin_user) @user = FactoryGirl.create(:admin_user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -21,12 +21,12 @@ Shoulda::Matchers.configure do |config|
end end
end end
if defined?(MEMCACHE)
Object.send(:remove_const, :MEMCACHE)
end
class ActiveSupport::TestCase class ActiveSupport::TestCase
include PostArchiveTestHelper include PostArchiveTestHelper
teardown do
Cache.clear
end
end end
class ActionController::TestCase class ActionController::TestCase
@@ -41,9 +41,12 @@ class ActionController::TestCase
__send__(http_method, action, params, session.merge(:user_id => @users[role].id)) __send__(http_method, action, params, session.merge(:user_id => @users[role].id))
assert_redirected_to(new_sessions_path) assert_redirected_to(new_sessions_path)
end end
teardown do
Cache.clear
end
end end
MEMCACHE = MemcacheMock.new
Delayed::Worker.delay_jobs = false Delayed::Worker.delay_jobs = false
require "helpers/reportbooru_helper" require "helpers/reportbooru_helper"

View File

@@ -18,7 +18,6 @@ class ArtistTest < ActiveSupport::TestCase
user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)} user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -3,7 +3,6 @@ require 'test_helper'
class ArtistUrlTest < ActiveSupport::TestCase class ArtistUrlTest < ActiveSupport::TestCase
context "An artist url" do context "An artist url" do
setup do setup do
MEMCACHE.flush_all
CurrentUser.user = FactoryGirl.create(:user) CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
end end

View File

@@ -6,7 +6,6 @@ class CommentTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -3,7 +3,6 @@ require 'test_helper'
class DmailTest < ActiveSupport::TestCase class DmailTest < ActiveSupport::TestCase
context "A dmail" do context "A dmail" do
setup do setup do
MEMCACHE.flush_all
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "1.2.3.4" CurrentUser.ip_addr = "1.2.3.4"

View File

@@ -5,7 +5,6 @@ class FavoriteTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Favorite # need to force loading the favorite model Favorite # need to force loading the favorite model
end end

View File

@@ -5,7 +5,6 @@ class IpBanTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now) Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
end end

View File

@@ -7,7 +7,6 @@ class JanitorTrialTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @admin CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -9,7 +9,6 @@ module Moderator
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now) Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
FactoryGirl.create(:comment) FactoryGirl.create(:comment)
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class NoteTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -13,7 +13,6 @@ class PoolTest < ActiveSupport::TestCase
end end
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
mock_pool_archive_service! mock_pool_archive_service!
PoolArchive.sqs_service.stubs(:merge?).returns(false) PoolArchive.sqs_service.stubs(:merge?).returns(false)

View File

@@ -6,7 +6,6 @@ class PostAppealTest < ActiveSupport::TestCase
@alice = FactoryGirl.create(:user) @alice = FactoryGirl.create(:user)
CurrentUser.user = @alice CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Danbooru.config.stubs(:max_appeals_per_day).returns(5) Danbooru.config.stubs(:max_appeals_per_day).returns(5)
end end

View File

@@ -8,7 +8,6 @@ class PostArchiveTest < ActiveSupport::TestCase
end end
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class PostDisapprovalTest < ActiveSupport::TestCase
@alice = FactoryGirl.create(:moderator_user) @alice = FactoryGirl.create(:moderator_user)
CurrentUser.user = @alice CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -8,7 +8,6 @@ class PostFlagTest < ActiveSupport::TestCase
end end
CurrentUser.user = @alice CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = FactoryGirl.create(:post, :tag_string => "aaa") @post = FactoryGirl.create(:post, :tag_string => "aaa")
end end

View File

@@ -5,7 +5,6 @@ class PostPrunerTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:admin_user) @user = FactoryGirl.create(:admin_user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Timecop.travel(2.weeks.ago) do Timecop.travel(2.weeks.ago) do
@flagger = FactoryGirl.create(:gold_user) @flagger = FactoryGirl.create(:gold_user)

View File

@@ -7,7 +7,6 @@ module PostSets
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = FactoryGirl.create(:post) @post_1 = FactoryGirl.create(:post)
@post_2 = FactoryGirl.create(:post) @post_2 = FactoryGirl.create(:post)

View File

@@ -8,7 +8,6 @@ module PostSets
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = FactoryGirl.create(:post, :tag_string => "a") @post_1 = FactoryGirl.create(:post, :tag_string => "a")
@post_2 = FactoryGirl.create(:post, :tag_string => "b") @post_2 = FactoryGirl.create(:post, :tag_string => "b")

View File

@@ -10,7 +10,6 @@ module PostSets
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
mock_pool_archive_service! mock_pool_archive_service!
start_pool_archive_transaction start_pool_archive_transaction

View File

@@ -8,7 +8,6 @@ module PostSets
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = FactoryGirl.create(:post, :tag_string => "a") @post_1 = FactoryGirl.create(:post, :tag_string => "a")
@post_2 = FactoryGirl.create(:post, :tag_string => "b") @post_2 = FactoryGirl.create(:post, :tag_string => "b")

View File

@@ -18,7 +18,6 @@ class PostTest < ActiveSupport::TestCase
end end
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
mock_saved_search_service! mock_saved_search_service!
end end

View File

@@ -8,7 +8,6 @@ class PostVersionTest < ActiveSupport::TestCase
end end
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -8,7 +8,6 @@ class PostVoteTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = FactoryGirl.create(:post) @post = FactoryGirl.create(:post)
end end

View File

@@ -5,7 +5,6 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -5,7 +5,6 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
context "a related tag query without a category constraint" do context "a related tag query without a category constraint" do

View File

@@ -41,10 +41,6 @@ class SavedSearchTest < ActiveSupport::TestCase
end end
context "Fetching the post ids for a search" do context "Fetching the post ids for a search" do
setup do
MEMCACHE.expects(:get).returns(nil)
end
teardown do teardown do
FakeWeb.clean_registry FakeWeb.clean_registry
end end

View File

@@ -6,13 +6,11 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
@mod = FactoryGirl.create(:moderator_user) @mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @mod CurrentUser.user = @mod
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = FactoryGirl.create(:post, :tag_string => "aaa") @post = FactoryGirl.create(:post, :tag_string => "aaa")
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") @tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
end end
teardown do teardown do
MEMCACHE.flush_all
CurrentUser.user = nil CurrentUser.user = nil
CurrentUser.ip_addr = nil CurrentUser.ip_addr = nil
end end

View File

@@ -6,11 +6,9 @@ class TagAliasRequestTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do
MEMCACHE.flush_all
CurrentUser.user = nil CurrentUser.user = nil
CurrentUser.ip_addr = nil CurrentUser.ip_addr = nil
end end

View File

@@ -11,7 +11,6 @@ class TagAliasTest < ActiveSupport::TestCase
CurrentUser.user = user CurrentUser.user = user
end end
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
mock_saved_search_service! mock_saved_search_service!
end end

View File

@@ -6,11 +6,9 @@ class TagImplicationRequestTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do
MEMCACHE.flush_all
CurrentUser.user = nil CurrentUser.user = nil
CurrentUser.ip_addr = nil CurrentUser.ip_addr = nil
end end

View File

@@ -7,7 +7,6 @@ class TagImplicationTest < ActiveSupport::TestCase
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -5,7 +5,6 @@ class TagSubscriptionTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -5,7 +5,6 @@ class TagTest < ActiveSupport::TestCase
user = FactoryGirl.create(:builder_user) user = FactoryGirl.create(:builder_user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do
@@ -32,10 +31,6 @@ class TagTest < ActiveSupport::TestCase
end end
context "A tag category fetcher" do context "A tag category fetcher" do
setup do
MEMCACHE.flush_all
end
should "fetch for a single tag" do should "fetch for a single tag" do
FactoryGirl.create(:artist_tag, :name => "test") FactoryGirl.create(:artist_tag, :name => "test")
assert_equal(Tag.categories.artist, Tag.category_for("test")) assert_equal(Tag.categories.artist, Tag.category_for("test"))
@@ -57,10 +52,6 @@ class TagTest < ActiveSupport::TestCase
end end
context "A tag category mapping" do context "A tag category mapping" do
setup do
MEMCACHE.flush_all
end
should "exist" do should "exist" do
assert_nothing_raised {Tag.categories} assert_nothing_raised {Tag.categories}
end end
@@ -97,10 +88,6 @@ class TagTest < ActiveSupport::TestCase
end end
context "A tag" do context "A tag" do
setup do
MEMCACHE.flush_all
end
should "be lockable by a moderator" do should "be lockable by a moderator" do
@tag = FactoryGirl.create(:tag) @tag = FactoryGirl.create(:tag)
@tag.update_attributes({:is_locked => true}, :as => :moderator) @tag.update_attributes({:is_locked => true}, :as => :moderator)
@@ -123,11 +110,11 @@ class TagTest < ActiveSupport::TestCase
should "reset its category after updating" do should "reset its category after updating" do
tag = FactoryGirl.create(:artist_tag) tag = FactoryGirl.create(:artist_tag)
tag.update_category_cache_for_all tag.update_category_cache_for_all
assert_equal(Tag.categories.artist, MEMCACHE.get("tc:#{tag.name}")) assert_equal(Tag.categories.artist, Cache.get("tc:#{tag.name}"))
tag.update_attribute(:category, Tag.categories.copyright) tag.update_attribute(:category, Tag.categories.copyright)
tag.update_category_cache_for_all tag.update_category_cache_for_all
assert_equal(Tag.categories.copyright, MEMCACHE.get("tc:#{tag.name}")) assert_equal(Tag.categories.copyright, Cache.get("tc:#{tag.name}"))
end end
end end

View File

@@ -17,7 +17,6 @@ class UploadTest < ActiveSupport::TestCase
user = FactoryGirl.create(:contributor_user) user = FactoryGirl.create(:contributor_user)
CurrentUser.user = user CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -4,7 +4,6 @@ class UserFeedbackTest < ActiveSupport::TestCase
context "A user's feedback" do context "A user's feedback" do
setup do setup do
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -6,7 +6,6 @@ class UserTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end end
teardown do teardown do

View File

@@ -2,7 +2,6 @@ require 'test_helper'
class WikiPageTest < ActiveSupport::TestCase class WikiPageTest < ActiveSupport::TestCase
setup do setup do
MEMCACHE.flush_all
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
end end