diff --git a/test/helpers/upload_test_helper.rb b/test/helpers/upload_test_helper.rb new file mode 100644 index 000000000..3b29574e6 --- /dev/null +++ b/test/helpers/upload_test_helper.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index a766dbd6e..7fc0825e8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,33 +16,6 @@ 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 MockMemcache def initialize @memory = {} diff --git a/test/unit/advertisement_test.rb b/test/unit/advertisement_test.rb index 42a06038f..bc429ec74 100644 --- a/test/unit/advertisement_test.rb +++ b/test/unit/advertisement_test.rb @@ -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") diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 686de5058..3887a7355 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -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