2010-03-18 18:29:41 -04:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
2010-08-18 18:42:33 -04:00
|
|
|
|
2013-06-05 18:37:33 -04:00
|
|
|
if ENV["SIMPLECOV"]
|
|
|
|
require 'simplecov'
|
|
|
|
SimpleCov.start 'rails' do
|
2017-02-04 22:28:33 -05:00
|
|
|
add_group "Libraries", ["app/logical", "lib"]
|
|
|
|
add_group "Presenters", "app/presenters"
|
2013-06-05 18:37:33 -04:00
|
|
|
end
|
|
|
|
end
|
2010-12-05 22:27:45 -05:00
|
|
|
|
2010-08-18 18:42:33 -04:00
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
2010-02-04 15:08:49 -05:00
|
|
|
require 'rails/test_help'
|
2015-05-28 16:32:36 -04:00
|
|
|
require 'cache'
|
2017-06-29 19:05:01 -04:00
|
|
|
require 'webmock/minitest'
|
2010-02-04 15:08:49 -05:00
|
|
|
|
2010-02-06 16:48:40 -05:00
|
|
|
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
|
2018-01-14 16:03:53 -05:00
|
|
|
Dir[File.expand_path(File.dirname(__FILE__) + "/test_helpers/*.rb")].each {|file| require file}
|
2010-02-04 15:08:49 -05:00
|
|
|
|
2018-01-20 19:25:59 -05:00
|
|
|
Dotenv.load(Rails.root + ".env.local")
|
|
|
|
|
2017-02-04 22:27:59 -05:00
|
|
|
Shoulda::Matchers.configure do |config|
|
|
|
|
config.integrate do |with|
|
2018-04-02 13:51:26 -04:00
|
|
|
with.test_framework :minitest
|
2017-02-04 22:27:59 -05:00
|
|
|
with.library :rails
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
module TestHelpers
|
|
|
|
def create(factory_bot_model, params = {})
|
|
|
|
record = FactoryBot.build(factory_bot_model, params)
|
|
|
|
record.save
|
|
|
|
raise ActiveRecord::RecordInvalid.new(record) if record.errors.any?
|
|
|
|
record
|
|
|
|
end
|
|
|
|
|
|
|
|
def as(user, &block)
|
|
|
|
CurrentUser.as(user, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_user(&block)
|
|
|
|
CurrentUser.as(@user, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_admin(&block)
|
|
|
|
CurrentUser.as_admin(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-01-13 20:21:05 -05:00
|
|
|
class ActiveSupport::TestCase
|
|
|
|
include PostArchiveTestHelper
|
2018-01-14 16:03:53 -05:00
|
|
|
include PoolArchiveTestHelper
|
2017-06-21 12:02:33 -04:00
|
|
|
include ReportbooruHelper
|
|
|
|
include DownloadTestHelper
|
2018-01-14 16:03:53 -05:00
|
|
|
include IqdbTestHelper
|
|
|
|
include SavedSearchTestHelper
|
|
|
|
include UploadTestHelper
|
2018-04-02 13:51:26 -04:00
|
|
|
include TestHelpers
|
2017-06-21 12:02:33 -04:00
|
|
|
|
|
|
|
setup do
|
|
|
|
mock_popular_search_service!
|
|
|
|
mock_missed_search_service!
|
2017-07-01 12:49:08 -04:00
|
|
|
WebMock.allow_net_connect!
|
2018-01-02 17:32:38 -05:00
|
|
|
Danbooru.config.stubs(:enable_sock_puppet_validation?).returns(false)
|
2018-03-14 17:57:29 -04:00
|
|
|
|
|
|
|
storage_manager = StorageManager::Local.new(base_dir: "#{Rails.root}/public/data/test")
|
|
|
|
Danbooru.config.stubs(:storage_manager).returns(storage_manager)
|
2018-03-18 17:33:26 -04:00
|
|
|
Danbooru.config.stubs(:backup_storage_manager).returns(StorageManager::Null.new)
|
2017-06-21 12:02:33 -04:00
|
|
|
end
|
2017-04-15 22:51:56 -04:00
|
|
|
|
|
|
|
teardown do
|
2018-03-20 00:17:24 -04:00
|
|
|
FileUtils.rm_rf(Danbooru.config.storage_manager.base_dir)
|
2017-04-15 22:51:56 -04:00
|
|
|
Cache.clear
|
|
|
|
end
|
2017-01-13 20:21:05 -05:00
|
|
|
end
|
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
class ActionDispatch::IntegrationTest
|
|
|
|
include PostArchiveTestHelper
|
|
|
|
include PoolArchiveTestHelper
|
|
|
|
include TestHelpers
|
|
|
|
|
|
|
|
def method_authenticated(method_name, url, user, options)
|
|
|
|
Thread.current[:test_user_id] = user.id
|
|
|
|
self.send(method_name, url, options)
|
|
|
|
ensure
|
|
|
|
Thread.current[:test_user_id] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_auth(url, user, options = {})
|
|
|
|
method_authenticated(:get, url, user, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_auth(url, user, options = {})
|
|
|
|
method_authenticated(:post, url, user, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def put_auth(url, user, options = {})
|
|
|
|
method_authenticated(:put, url, user, options)
|
2017-01-13 20:21:05 -05:00
|
|
|
end
|
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
def delete_auth(url, user, options = {})
|
|
|
|
method_authenticated(:delete, url, user, options)
|
2017-01-13 20:21:05 -05:00
|
|
|
end
|
2017-04-15 22:51:56 -04:00
|
|
|
|
2017-11-20 19:29:59 -05:00
|
|
|
def setup
|
|
|
|
super
|
2018-01-02 17:32:38 -05:00
|
|
|
Danbooru.config.stubs(:enable_sock_puppet_validation?).returns(false)
|
2017-11-20 19:29:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
2017-04-15 22:51:56 -04:00
|
|
|
Cache.clear
|
|
|
|
end
|
2017-01-13 20:21:05 -05:00
|
|
|
end
|
|
|
|
|
2017-02-03 18:24:10 -05:00
|
|
|
Delayed::Worker.delay_jobs = false
|
2017-12-21 12:56:12 -05:00
|
|
|
|
|
|
|
Rails.application.load_seed
|