Merge pull request #2877 from evazion/fix-tests
Fix remaining test failures
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -3,7 +3,8 @@ source 'https://rubygems.org/'
|
||||
gem 'dotenv-rails', :require => "dotenv/rails-now"
|
||||
|
||||
group :test do
|
||||
gem "shoulda"
|
||||
gem "shoulda-context"
|
||||
gem "shoulda-matchers"
|
||||
gem "factory_girl"
|
||||
gem "mocha", :require => "mocha/setup"
|
||||
gem "ffaker"
|
||||
|
||||
38
Gemfile.lock
38
Gemfile.lock
@@ -85,7 +85,7 @@ GEM
|
||||
bcrypt (>= 3.1.3)
|
||||
buftok (0.2.0)
|
||||
builder (3.2.3)
|
||||
byebug (6.0.0)
|
||||
byebug (9.0.6)
|
||||
capistrano (3.4.0)
|
||||
i18n
|
||||
rake (>= 10.0.0)
|
||||
@@ -105,7 +105,7 @@ GEM
|
||||
capistrano (~> 3.1, >= 3.1.0)
|
||||
chronic (0.10.2)
|
||||
cityhash (0.8.1)
|
||||
coderay (1.1.0)
|
||||
coderay (1.1.1)
|
||||
coffee-rails (4.1.0)
|
||||
coffee-script (>= 2.2.0)
|
||||
railties (>= 4.0.0, < 5.0)
|
||||
@@ -134,12 +134,12 @@ GEM
|
||||
equalizer (0.0.11)
|
||||
erubis (2.7.0)
|
||||
execjs (2.6.0)
|
||||
factory_girl (4.5.0)
|
||||
factory_girl (4.8.0)
|
||||
activesupport (>= 3.0.0)
|
||||
fakeweb (1.3.0)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffaker (2.1.0)
|
||||
ffaker (2.4.0)
|
||||
ffi (1.9.10-x64-mingw32)
|
||||
gctools (0.2.4)
|
||||
get_process_mem (0.2.1)
|
||||
@@ -182,7 +182,7 @@ GEM
|
||||
http_parser.rb (0.6.0)
|
||||
httpclient (2.8.0)
|
||||
hurley (0.2)
|
||||
i18n (0.7.0)
|
||||
i18n (0.8.0)
|
||||
jeweler (2.3.2)
|
||||
builder
|
||||
bundler (>= 1.0)
|
||||
@@ -227,7 +227,7 @@ GEM
|
||||
mime-types (2.99.3)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.10.1)
|
||||
mocha (1.1.0)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
@@ -260,15 +260,10 @@ GEM
|
||||
pg (0.18.2-x64-mingw32)
|
||||
protected_attributes (1.1.3)
|
||||
activemodel (>= 4.0.1, < 5.0)
|
||||
pry (0.10.1)
|
||||
pry (0.10.4)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
pry (0.10.1-x64-mingw32)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
win32console (~> 1.3)
|
||||
psych (2.2.2)
|
||||
public_suffix (2.0.5)
|
||||
rack (1.6.5)
|
||||
@@ -333,12 +328,9 @@ GEM
|
||||
sprockets (~> 2.8, < 3.0)
|
||||
sprockets-rails (~> 2.0)
|
||||
semver2 (3.4.2)
|
||||
shoulda (3.5.0)
|
||||
shoulda-context (~> 1.0, >= 1.0.1)
|
||||
shoulda-matchers (>= 1.4.1, < 3.0)
|
||||
shoulda-context (1.2.1)
|
||||
shoulda-matchers (2.8.0)
|
||||
activesupport (>= 3.0.0)
|
||||
shoulda-context (1.2.2)
|
||||
shoulda-matchers (3.1.1)
|
||||
activesupport (>= 4.0.0)
|
||||
signet (0.7.2)
|
||||
addressable (~> 2.3)
|
||||
faraday (~> 0.9)
|
||||
@@ -348,9 +340,9 @@ GEM
|
||||
actionpack (> 4, < 5.1)
|
||||
activemodel (> 4, < 5.1)
|
||||
simple_oauth (0.3.1)
|
||||
simplecov (0.10.0)
|
||||
simplecov (0.13.0)
|
||||
docile (~> 1.1.0)
|
||||
json (~> 1.8)
|
||||
json (>= 1.8, < 3)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.0)
|
||||
slop (3.6.0)
|
||||
@@ -380,7 +372,7 @@ GEM
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
timecop (0.8.0)
|
||||
timecop (0.8.1)
|
||||
tins (1.6.0)
|
||||
twitter (5.14.0)
|
||||
addressable (~> 2.3)
|
||||
@@ -414,7 +406,6 @@ GEM
|
||||
webrobots (0.1.1)
|
||||
whenever (0.9.4)
|
||||
chronic (>= 0.6.3)
|
||||
win32console (1.3.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
@@ -467,7 +458,8 @@ DEPENDENCIES
|
||||
rubyzip
|
||||
sanitize (~> 3.1.0)
|
||||
sass-rails (~> 4.0.0)
|
||||
shoulda
|
||||
shoulda-context
|
||||
shoulda-matchers
|
||||
simple_form
|
||||
simplecov
|
||||
sprockets-rails
|
||||
|
||||
@@ -10,6 +10,8 @@ class PixivWebAgent
|
||||
|
||||
def self.build
|
||||
mech = Mechanize.new
|
||||
mech.keep_alive = false
|
||||
|
||||
phpsessid = Cache.get(SESSION_CACHE_KEY)
|
||||
comicsessid = Cache.get(COMIC_SESSION_CACHE_KEY)
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ module Sources
|
||||
def agent
|
||||
@agent ||= begin
|
||||
mech = Mechanize.new
|
||||
mech.keep_alive = false
|
||||
|
||||
session = Cache.get("nico-seiga-session")
|
||||
if session
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagAliasCorrectionsControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagAliasRequestsControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagAliasesControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -49,7 +48,7 @@ class TagAliasesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
# TODO: Broken in shoulda-matchers 2.8.0. Need to upgrade to 3.1.1.
|
||||
should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update)
|
||||
# should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update)
|
||||
end
|
||||
|
||||
context "for an approved alias" do
|
||||
|
||||
@@ -9,7 +9,6 @@ class TagImplicationRequestsControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagImplicationsControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
23
test/helpers/upload_test_helper.rb
Normal file
23
test/helpers/upload_test_helper.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module UploadTestHelper
|
||||
def upload_file(path, content_type, filename)
|
||||
tempfile = Tempfile.new(filename)
|
||||
FileUtils.copy_file(path, tempfile.path)
|
||||
|
||||
(class << tempfile; self; end).class_eval do
|
||||
alias local_path path
|
||||
define_method(:tempfile) {self}
|
||||
define_method(:original_filename) {filename}
|
||||
define_method(:content_type) {content_type}
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
def upload_jpeg(path)
|
||||
upload_file(path, "image/jpeg", File.basename(path))
|
||||
end
|
||||
|
||||
def upload_zip(path)
|
||||
upload_file(path, "application/zip", File.basename(path))
|
||||
end
|
||||
end
|
||||
@@ -3,10 +3,8 @@ ENV["RAILS_ENV"] = "test"
|
||||
if ENV["SIMPLECOV"]
|
||||
require 'simplecov'
|
||||
SimpleCov.start 'rails' do
|
||||
add_filter ".bundle"
|
||||
add_filter "script/"
|
||||
add_filter "test/"
|
||||
add_filter "config/"
|
||||
add_group "Libraries", ["app/logical", "lib"]
|
||||
add_group "Presenters", "app/presenters"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,87 +14,9 @@ require 'cache'
|
||||
|
||||
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
|
||||
|
||||
module UploadTestMethods
|
||||
def upload_file(path, content_type, filename)
|
||||
tempfile = Tempfile.new(filename)
|
||||
FileUtils.copy_file(path, tempfile.path)
|
||||
(class << tempfile; self; end).class_eval do
|
||||
alias local_path path
|
||||
define_method(:tempfile) {self}
|
||||
define_method(:original_filename) {filename}
|
||||
define_method(:content_type) {content_type}
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
def upload_jpeg(path)
|
||||
upload_file(path, "image/jpeg", File.basename(path))
|
||||
end
|
||||
|
||||
def upload_zip(path)
|
||||
upload_file(path, "application/zip", File.basename(path))
|
||||
end
|
||||
end
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
include UploadTestMethods
|
||||
end
|
||||
|
||||
class ActionController::TestCase
|
||||
include UploadTestMethods
|
||||
|
||||
def assert_authentication_passes(action, http_method, role, params, session)
|
||||
__send__(http_method, action, params, session.merge(:user_id => @users[role].id))
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def assert_authentication_fails(action, http_method, role)
|
||||
__send__(http_method, action, params, session.merge(:user_id => @users[role].id))
|
||||
assert_redirected_to(new_sessions_path)
|
||||
end
|
||||
end
|
||||
|
||||
class MockMemcache
|
||||
def initialize
|
||||
@memory = {}
|
||||
end
|
||||
|
||||
def flush_all
|
||||
@memory = {}
|
||||
end
|
||||
|
||||
def fetch key, expiry = 0, raw = false
|
||||
if @memory.has_key?(key)
|
||||
@memory[key]
|
||||
else
|
||||
@memory[key] = yield
|
||||
end
|
||||
@memory[key]
|
||||
end
|
||||
|
||||
def incr key
|
||||
@memory[key] += 1
|
||||
end
|
||||
|
||||
def decr key
|
||||
@memory[key] -= 1
|
||||
end
|
||||
|
||||
def set key, value, expiry = 0
|
||||
@memory[key] = value
|
||||
end
|
||||
|
||||
def get key
|
||||
@memory[key]
|
||||
end
|
||||
|
||||
def delete key, delay = 0
|
||||
@memory.delete key
|
||||
end
|
||||
|
||||
def get_multi *keys
|
||||
Hash[[keys.map{ |key| [key, @memory[key]] }]]
|
||||
Shoulda::Matchers.configure do |config|
|
||||
config.integrate do |with|
|
||||
with.library :rails
|
||||
end
|
||||
end
|
||||
|
||||
@@ -104,4 +24,5 @@ if defined?(MEMCACHE)
|
||||
Object.send(:remove_const, :MEMCACHE)
|
||||
end
|
||||
|
||||
MEMCACHE = MockMemcache.new
|
||||
MEMCACHE = MemcacheMock.new
|
||||
Delayed::Worker.delay_jobs = false
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/upload_test_helper'
|
||||
|
||||
class AdvertisementTest < ActiveSupport::TestCase
|
||||
include UploadTestHelper
|
||||
|
||||
context "An advertisement" do
|
||||
setup do
|
||||
Danbooru.config.stubs(:advertisement_path).returns("/tmp")
|
||||
|
||||
@@ -3,9 +3,7 @@ require 'test_helper'
|
||||
class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
context "The alias and implication importer" do
|
||||
setup do
|
||||
Delayed::Worker.delay_jobs = true
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.user = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -21,9 +19,9 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process it" do
|
||||
assert_difference("Delayed::Job.count", 2) do
|
||||
@importer.process!
|
||||
end
|
||||
@importer.process!
|
||||
assert(TagAlias.exists?(antecedent_name: "abc", consequent_name: "def"))
|
||||
assert(TagImplication.exists?(antecedent_name: "aaa", consequent_name: "bbb"))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -6,7 +6,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -27,7 +27,6 @@ module Downloads
|
||||
|
||||
context "An ugoira site for pixiv" do
|
||||
setup do
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@tempfile = Tempfile.new("danbooru-test")
|
||||
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654", @tempfile.path)
|
||||
@download.download!
|
||||
|
||||
@@ -13,7 +13,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
mock_saved_search_service!
|
||||
end
|
||||
|
||||
@@ -520,7 +519,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "with an artist tag that is then changed to copyright" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:builder_user)
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@post = Post.find(@post.id)
|
||||
@post.update(:tag_string => "art:abc")
|
||||
@post = Post.find(@post.id)
|
||||
@@ -528,10 +526,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
@post.reload
|
||||
end
|
||||
|
||||
teardown do
|
||||
Delayed::Worker.delay_jobs = true
|
||||
end
|
||||
|
||||
should "update the category of the tag" do
|
||||
assert_equal(Tag.categories.copyright, Tag.find_by_name("abc").category)
|
||||
end
|
||||
@@ -1336,7 +1330,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
subject { @post }
|
||||
|
||||
should_not allow_value("S", "safe", "derp").for(:rating)
|
||||
should_not allow_value("s", "q", "e").for(:rating)
|
||||
should_not allow_value("s", "e").for(:rating)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
context "a related tag query without a category constraint" do
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
@@ -27,7 +26,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
|
||||
|
||||
should "have the correct statistics hash" do
|
||||
assert_equal("zzz", @correction.statistics_hash["antecedent_cache"])
|
||||
assert_equal(nil, @correction.statistics_hash["consequent_cache"])
|
||||
assert_nil(@correction.statistics_hash["consequent_cache"])
|
||||
assert_equal(-3, @correction.statistics_hash["antecedent_count"])
|
||||
assert_equal(1, @correction.statistics_hash["consequent_count"])
|
||||
end
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagAliasRequestTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -12,7 +12,6 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
mock_saved_search_service!
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ class TagImplicationRequestTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -8,7 +8,6 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@user = FactoryGirl.create(:user)
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -5,7 +5,6 @@ class TagSubscriptionTest < ActiveSupport::TestCase
|
||||
user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Delayed::Worker.delay_jobs = false
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ class TagTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/iqdb_test_helper'
|
||||
require 'helpers/upload_test_helper'
|
||||
|
||||
class UploadTest < ActiveSupport::TestCase
|
||||
include IqdbTestHelper
|
||||
include UploadTestHelper
|
||||
|
||||
def setup
|
||||
super
|
||||
@@ -16,13 +18,11 @@ class UploadTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
Delayed::Worker.delay_jobs = true
|
||||
|
||||
@upload.delete_temp_file if @upload
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
context "an invalid user deletion" do
|
||||
context "for an invalid password" do
|
||||
setup do
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -20,7 +19,6 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
|
||||
context "for an admin" do
|
||||
setup do
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@user = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -37,8 +35,6 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
|
||||
context "a valid user deletion" do
|
||||
setup do
|
||||
Delayed::Worker.delay_jobs = false
|
||||
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
Reference in New Issue
Block a user