test/test_helper.rb in rails_uploads-0.1.5 vs test/test_helper.rb in rails_uploads-0.2.0
- old
+ new
@@ -17,5 +17,34 @@
# Load database
config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', __FILE__)))
config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
ActiveRecord::Base.establish_connection(config['test'])
load(File.expand_path('../dummy/db/schema.rb', __FILE__))
+
+# Addons
+
+class ActiveSupport::TestCase
+ include ActionDispatch::TestProcess
+
+ def load_s3
+ require 'aws-sdk' unless defined?(AWS)
+ @storage_type = Rails.application.config.uploads.storage
+ Rails.application.config.uploads.storage = :s3
+ RailsUploads::Storages::S3.config = YAML.load_file(Rails.root.join('config', 's3.yml')) if RailsUploads::Storages::S3.config.blank?
+ self.class.teardown { Rails.application.config.uploads.storage = @storage_type }
+ end
+
+ def fixture_file_upload_s3(fixture, type, path, tmp=true)
+ upload = fixture_file_upload(fixture, type)
+ storage = RailsUploads::Storages::S3.new(tmp)
+ storage.store(upload, path)
+ end
+
+ def assert_object_s3(url)
+ assert_equal '200', Net::HTTP.get_response(url).code
+ end
+
+ def assert_not_object_s3(url)
+ assert_equal '403', Net::HTTP.get_response(url).code
+ end
+
+end