diff --git a/test/helpers/download_helper.rb b/test/helpers/download_helper.rb new file mode 100644 index 000000000..5a8efd928 --- /dev/null +++ b/test/helpers/download_helper.rb @@ -0,0 +1,24 @@ +module DownloadTestHelper + def assert_downloaded(expected_filesize, source) + tempfile = Tempfile.new("danbooru-test") + download = Downloads::File.new(source, tempfile.path) + + assert_nothing_raised(Downloads::File::Error) do + download.download! + end + + assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}") + end + + def assert_rewritten(expected_source, test_source) + tempfile = Tempfile.new("danbooru-test") + download = Downloads::File.new(test_source, tempfile.path) + + rewritten_source, headers, _ = download.before_download(test_source, {}, {}) + assert_equal(expected_source, rewritten_source, "Tested source URL: #{test_source}") + end + + def assert_not_rewritten(source) + assert_rewritten(source, source) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 16d22d0eb..623090386 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,9 +11,9 @@ end require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'cache' -require 'helpers/post_archive_test_helper' Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file} +Dir[File.expand_path(File.dirname(__FILE__) + "/helpers/*.rb")].each {|file| require file} Shoulda::Matchers.configure do |config| config.integrate do |with| @@ -23,6 +23,13 @@ end class ActiveSupport::TestCase include PostArchiveTestHelper + include ReportbooruHelper + include DownloadTestHelper + + setup do + mock_popular_search_service! + mock_missed_search_service! + end teardown do Cache.clear @@ -49,13 +56,3 @@ end Delayed::Worker.delay_jobs = false TestAfterCommit.enabled = false - -require "helpers/reportbooru_helper" -class ActiveSupport::TestCase - include ReportbooruHelper - - setup do - mock_popular_search_service! - mock_missed_search_service! - end -end diff --git a/test/unit/downloads/pixiv_test.rb b/test/unit/downloads/pixiv_test.rb index ed2349975..17da0da7c 100644 --- a/test/unit/downloads/pixiv_test.rb +++ b/test/unit/downloads/pixiv_test.rb @@ -2,29 +2,6 @@ require 'test_helper' module Downloads class PixivTest < ActiveSupport::TestCase - def assert_downloaded(expected_filesize, source) - tempfile = Tempfile.new("danbooru-test") - download = Downloads::File.new(source, tempfile.path) - - assert_nothing_raised(Downloads::File::Error) do - download.download! - end - - assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}") - end - - def assert_rewritten(expected_source, test_source) - tempfile = Tempfile.new("danbooru-test") - download = Downloads::File.new(test_source, tempfile.path) - - rewritten_source, headers, _ = download.before_download(test_source, {}, {}) - assert_equal(expected_source, rewritten_source, "Tested source URL: #{test_source}") - end - - def assert_not_rewritten(source) - assert_rewritten(source, source) - end - context "An ugoira site for pixiv" do setup do @tempfile = Tempfile.new("danbooru-test")