rails_uploads 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +35 -9
- data/app/controllers/rails_uploads/application_controller.rb +1 -0
- data/app/controllers/rails_uploads/presets_controller.rb +2 -4
- data/lib/rails_uploads.rb +2 -0
- data/lib/rails_uploads/active_record/base.rb +60 -55
- data/lib/rails_uploads/magick/image.rb +3 -3
- data/lib/rails_uploads/railtie.rb +6 -1
- data/lib/rails_uploads/storages/local.rb +57 -0
- data/lib/rails_uploads/storages/s3.rb +61 -0
- data/lib/rails_uploads/types/file.rb +35 -43
- data/lib/rails_uploads/types/image.rb +12 -28
- data/lib/rails_uploads/validators/attachment_content_type_validator.rb +2 -4
- data/lib/rails_uploads/validators/attachment_presence_validator.rb +0 -2
- data/lib/rails_uploads/validators/attachment_size_validator.rb +4 -6
- data/lib/rails_uploads/version.rb +1 -1
- data/lib/tasks/rails_uploads_tasks.rake +31 -3
- data/test/dummy/app/models/file_upload.rb +1 -1
- data/test/dummy/app/models/image_upload.rb +1 -1
- data/test/dummy/app/models/validation_upload.rb +2 -2
- data/test/dummy/config/s3.yml +15 -0
- data/test/dummy/log/development.log +1 -0
- data/test/dummy/log/test.log +11581 -0
- data/test/dummy/public/uploads/images/{original/default.jpg → big/image.jpg} +0 -0
- data/test/dummy/public/uploads/images/small/image.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687482983108968.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687483348482658.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687483563901100.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687484108914220.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687489381697390.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687490968011022.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687491524768450.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687494425396302.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13687513450654020.jpg +0 -0
- data/test/dummy/{public/uploads/files/default.txt → tmp/uploads/files/13687514839373922.txt} +0 -0
- data/test/dummy/tmp/uploads/files/13688181722986792.jpg +0 -0
- data/test/dummy/tmp/uploads/files/13688181729459798.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687484103672162.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687484106303082.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687489377129980.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687489379459820.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687490965463210.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13687491522552230.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688181724596422.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688181727051510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688259257147068.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688280071286788.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688281527981960.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688360981527310.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688360983686640.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688977138132322.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688977290079510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/big/13688978966174670.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687482977916958.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687482979328390.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687482981277580.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483343313990.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483344710930.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483346647770.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483558679350.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483560070410.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687483562001660.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687484103672162.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687484106303082.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687489377129980.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687489379459820.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687490965463210.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13687491522552230.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688181723027610.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688181724596422.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688181727051510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688259257147068.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688280071286788.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688281527981960.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688360981527310.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688360983686640.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688977138132322.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688977290079510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/original/13688978966174670.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687484103672162.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687484106303082.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687489377129980.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687489379459820.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687490965463210.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13687491522552230.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688181723027610.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688181724596422.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688181727051510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688259257147068.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688280071286788.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688281527981960.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688360981527310.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688360983686640.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688977138132322.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688977290079510.jpg +0 -0
- data/test/dummy/tmp/uploads/images/small/13688978966174670.jpg +0 -0
- data/test/{generate_test.rb → integration/local_generate_test.rb} +12 -14
- data/test/test_helper.rb +29 -0
- data/test/unit/local_file_record_test.rb +20 -0
- data/test/unit/local_file_string_test.rb +23 -0
- data/test/unit/local_file_upload_test.rb +30 -0
- data/test/unit/local_image_record_test.rb +25 -0
- data/test/{image_string_test.rb → unit/local_image_string_test.rb} +19 -21
- data/test/unit/local_image_upload_test.rb +27 -0
- data/test/unit/local_records_test.rb +52 -0
- data/test/{validators_test.rb → unit/local_validators_test.rb} +15 -28
- data/test/unit/s3_file_record_tes.rb +21 -0
- data/test/unit/s3_file_string_tes.rb +24 -0
- data/test/unit/s3_file_upload_tes.rb +31 -0
- data/test/unit/s3_image_record_tes.rb +26 -0
- data/test/unit/s3_image_string_tes.rb +31 -0
- data/test/unit/s3_image_upload_tes.rb +28 -0
- data/test/unit/s3_records_tes.rb +56 -0
- data/test/unit/s3_validators_tes.rb +71 -0
- metadata +204 -25
- data/test/file_string_test.rb +0 -35
- data/test/file_upload_test.rb +0 -41
- data/test/image_presets_test.rb +0 -32
- data/test/image_upload_test.rb +0 -34
- data/test/rails_uploads_test.rb +0 -9
- data/test/records_test.rb +0 -55
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/dummy/{public/uploads/files/default.txt → tmp/uploads/files/13687514839373922.txt}
RENAMED
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,27 +1,25 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include ActionDispatch::TestProcess
|
3
|
+
class LocalGenerateTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
|
-
setup
|
5
|
+
setup do
|
6
|
+
@image = RailsUploads::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
|
7
|
+
@image.store
|
8
|
+
end
|
9
|
+
|
10
|
+
teardown do
|
11
|
+
@image.delete
|
12
|
+
end
|
7
13
|
|
8
14
|
test "should generate preset" do
|
9
|
-
|
10
|
-
|
15
|
+
realpath = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
16
|
+
::File.delete realpath
|
11
17
|
|
18
|
+
path = ::File.join('', 'uploads', 'images', 'small', @image.filename)
|
12
19
|
get path
|
13
20
|
assert_redirected_to path
|
14
21
|
|
15
|
-
realpath = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
16
22
|
assert ::File.exists?(realpath)
|
17
|
-
@image.delete
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
|
22
|
-
def create_image
|
23
|
-
@image = RailsUploads::Types::Image.new(fixture_file_upload(::File.join('', 'image.jpg'), 'image/jpeg'))
|
24
|
-
@image.store
|
25
23
|
end
|
26
24
|
|
27
25
|
end
|
data/test/test_helper.rb
CHANGED
@@ -19,3 +19,32 @@ config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', _
|
|
19
19
|
config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
|
20
20
|
ActiveRecord::Base.establish_connection(config['test'])
|
21
21
|
load(File.expand_path('../dummy/db/schema.rb', __FILE__))
|
22
|
+
|
23
|
+
# Addons
|
24
|
+
|
25
|
+
class ActiveSupport::TestCase
|
26
|
+
include ActionDispatch::TestProcess
|
27
|
+
|
28
|
+
def load_s3
|
29
|
+
require 'aws-sdk' unless defined?(AWS)
|
30
|
+
@storage_type = Rails.application.config.uploads.storage
|
31
|
+
Rails.application.config.uploads.storage = :s3
|
32
|
+
RailsUploads::Storages::S3.config = YAML.load_file(Rails.root.join('config', 's3.yml')) if RailsUploads::Storages::S3.config.blank?
|
33
|
+
self.class.teardown { Rails.application.config.uploads.storage = @storage_type }
|
34
|
+
end
|
35
|
+
|
36
|
+
def fixture_file_upload_s3(fixture, type, path, tmp=true)
|
37
|
+
upload = fixture_file_upload(fixture, type)
|
38
|
+
storage = RailsUploads::Storages::S3.new(tmp)
|
39
|
+
storage.store(upload, path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_object_s3(url)
|
43
|
+
assert_equal '200', Net::HTTP.get_response(url).code
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_not_object_s3(url)
|
47
|
+
assert_equal '403', Net::HTTP.get_response(url).code
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalFileRecordTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@record = FileUpload.create(:file => fixture_file_upload('/file.txt', 'text/plain'))
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should maintain properties and delete correctly" do
|
10
|
+
assert @record.file.exists?
|
11
|
+
assert_equal 11, @record.file.size
|
12
|
+
assert_equal '.txt', @record.file.extname
|
13
|
+
|
14
|
+
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @record.file.filename)
|
15
|
+
@record.destroy
|
16
|
+
assert !::File.exists?(uploads_path)
|
17
|
+
assert !@record.file.exists?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalFileStringTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'files')
|
7
|
+
filename = 'file.txt'
|
8
|
+
FileUtils.cp fixture_file_upload("/#{filename}", 'text/plain'), Rails.root.join('tmp', 'uploads', 'files', filename)
|
9
|
+
@file = RailsUploads::Types::File.new(filename)
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should maintain properties and delete correctly" do
|
13
|
+
assert @file.exists?
|
14
|
+
assert_equal 11, @file.size
|
15
|
+
assert_equal '.txt', @file.extname
|
16
|
+
|
17
|
+
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename)
|
18
|
+
@file.delete
|
19
|
+
assert !::File.exists?(uploads_path)
|
20
|
+
assert !@file.exists?
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalFileUploadTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@file = RailsUploads::Types::File.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
|
7
|
+
end
|
8
|
+
|
9
|
+
test "file should exists and mantain properties" do
|
10
|
+
assert @file.exists?
|
11
|
+
assert_equal 58841, @file.size
|
12
|
+
assert_equal '.jpg', @file.extname
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should store/delete file correctly and accept cdn" do
|
16
|
+
@file.store
|
17
|
+
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename)
|
18
|
+
assert ::File.exists?(uploads_path)
|
19
|
+
|
20
|
+
base_url = 'http://cdn.example.com'
|
21
|
+
Rails.application.config.uploads.base_url = base_url
|
22
|
+
assert_equal ::File.join(base_url, @file.path), @file.url
|
23
|
+
Rails.application.config.uploads.base_url = ''
|
24
|
+
|
25
|
+
@file.delete
|
26
|
+
assert !::File.exists?(uploads_path)
|
27
|
+
assert !@file.exists?
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalImagePresetsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@record = ImageUpload.create(:image => fixture_file_upload('/image.jpg', 'image/jpeg'))
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should save/destory main image and thumbs" do
|
10
|
+
original = Rails.root.join('tmp', 'uploads', 'images', 'original', @record.image.filename)
|
11
|
+
big = Rails.root.join('tmp', 'uploads', 'images', 'big', @record.image.filename)
|
12
|
+
small = Rails.root.join('tmp', 'uploads', 'images', 'small', @record.image.filename)
|
13
|
+
|
14
|
+
assert ::File.exists?(original)
|
15
|
+
assert ::File.exists?(big)
|
16
|
+
assert ::File.exists?(small)
|
17
|
+
|
18
|
+
@record.destroy
|
19
|
+
|
20
|
+
assert !::File.exists?(original)
|
21
|
+
assert !::File.exists?(big)
|
22
|
+
assert !::File.exists?(small)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,36 +1,34 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class LocalImageStringTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup
|
5
|
+
setup do
|
6
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'original')
|
7
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'big')
|
8
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'small')
|
9
|
+
filename = 'image.jpg'
|
10
|
+
fixture = fixture_file_upload("/#{filename}", 'image/jpeg')
|
11
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'original', filename)
|
12
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'big', filename)
|
13
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'small', filename)
|
14
|
+
options = { :presets => [:small, :big] }
|
15
|
+
@image = RailsUploads::Types::Image.new(filename, options)
|
16
|
+
end
|
6
17
|
|
7
18
|
test "should destory main image and thumbs" do
|
19
|
+
original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
|
20
|
+
big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
|
21
|
+
small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
8
22
|
|
9
|
-
|
10
|
-
|
11
|
-
|
23
|
+
assert ::File.exists?(original)
|
24
|
+
assert ::File.exists?(big)
|
25
|
+
assert ::File.exists?(small)
|
12
26
|
|
13
27
|
@image.delete
|
14
28
|
|
15
29
|
assert !::File.exists?(original)
|
16
30
|
assert !::File.exists?(big)
|
17
31
|
assert !::File.exists?(small)
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
def create_image
|
24
|
-
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'original')
|
25
|
-
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'big')
|
26
|
-
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'small')
|
27
|
-
filename = 'image.jpg'
|
28
|
-
fixture = ::File.join(ActiveSupport::TestCase.fixture_path, filename)
|
29
|
-
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'original', filename)
|
30
|
-
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'big', filename)
|
31
|
-
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'small', filename)
|
32
|
-
@options = { :presets => [:small, :big] }
|
33
|
-
@image = RailsUploads::Types::Image.new(filename, @options)
|
34
32
|
end
|
35
33
|
|
36
34
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalImageUploadTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
options = { :presets => [:small, :big] }
|
7
|
+
@image = RailsUploads::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'), options)
|
8
|
+
@image.store
|
9
|
+
end
|
10
|
+
|
11
|
+
test "should save/destory main image and thumbs" do
|
12
|
+
original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
|
13
|
+
big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
|
14
|
+
small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
15
|
+
|
16
|
+
assert ::File.exists?(original)
|
17
|
+
assert ::File.exists?(big)
|
18
|
+
assert ::File.exists?(small)
|
19
|
+
|
20
|
+
@image.delete
|
21
|
+
|
22
|
+
assert !::File.exists?(original)
|
23
|
+
assert !::File.exists?(big)
|
24
|
+
assert !::File.exists?(small)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalRecordsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "should save/update/destroy from the database and save/destroy the file" do
|
6
|
+
record = FileUpload.create(:file => fixture_file_upload('/image.jpg', 'image/jpeg'))
|
7
|
+
image_filename = record.file.filename
|
8
|
+
image_path = Rails.root.join('tmp', 'uploads', 'files', image_filename)
|
9
|
+
assert ::File.exists?(image_path)
|
10
|
+
|
11
|
+
record.update_attributes :file => fixture_file_upload('/file.txt', 'text/plain')
|
12
|
+
file_filename = record.file.filename
|
13
|
+
assert_not_equal image_filename, file_filename
|
14
|
+
file_path = Rails.root.join('tmp', 'uploads', 'files', file_filename)
|
15
|
+
assert !::File.exists?(image_path)
|
16
|
+
assert ::File.exists?(file_path)
|
17
|
+
|
18
|
+
record.destroy
|
19
|
+
assert !::File.exists?(file_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should take default file/image and shouldn't store/delete it" do
|
23
|
+
record = FileUpload.create
|
24
|
+
file_filename = 'file.txt'
|
25
|
+
assert_equal ::File.join('uploads', 'files', file_filename), record.file.path
|
26
|
+
file_realpath = Rails.root.join('public', 'uploads', 'files', file_filename)
|
27
|
+
assert ::File.exists?(file_realpath)
|
28
|
+
|
29
|
+
record.destroy
|
30
|
+
assert record.file.exists?
|
31
|
+
assert ::File.exists?(file_realpath)
|
32
|
+
|
33
|
+
record = ImageUpload.create
|
34
|
+
image_filename = 'image.jpg'
|
35
|
+
assert_equal ::File.join('uploads', 'images', 'original', 'image.jpg'), record.image.path
|
36
|
+
image_original_realpath = Rails.root.join('public', 'uploads', 'images', 'original', image_filename)
|
37
|
+
assert ::File.exists?(image_original_realpath)
|
38
|
+
assert_equal ::File.join('uploads', 'images', 'small', 'image.jpg'), record.image.path(:small)
|
39
|
+
image_small_realpath = Rails.root.join('public', 'uploads', 'images', 'small', image_filename)
|
40
|
+
assert ::File.exists?(image_small_realpath)
|
41
|
+
assert_equal ::File.join('uploads', 'images', 'big', 'image.jpg'), record.image.path(:big)
|
42
|
+
image_big_realpath = Rails.root.join('public', 'uploads', 'images', 'big', image_filename)
|
43
|
+
assert ::File.exists?(image_big_realpath)
|
44
|
+
|
45
|
+
record.destroy
|
46
|
+
assert record.image.exists?
|
47
|
+
assert ::File.exists?(image_original_realpath)
|
48
|
+
assert ::File.exists?(image_small_realpath)
|
49
|
+
assert ::File.exists?(image_big_realpath)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|