rails_uploads 0.2.9 → 0.3.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.
- checksums.yaml +7 -0
- metadata +19 -371
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -108
- data/Rakefile +0 -40
- data/app/controllers/rails_uploads/presets_controller.rb +0 -17
- data/config/locales/en.yml +0 -8
- data/config/locales/es.yml +0 -8
- data/config/routes.rb +0 -5
- data/lib/generators/uploads/s3/config_generator.rb +0 -13
- data/lib/generators/uploads/s3/templates/s3.yml +0 -16
- data/lib/rails_uploads.rb +0 -16
- data/lib/rails_uploads/active_record/base.rb +0 -139
- data/lib/rails_uploads/engine.rb +0 -7
- data/lib/rails_uploads/magick/image.rb +0 -83
- data/lib/rails_uploads/railtie.rb +0 -20
- data/lib/rails_uploads/storages/local.rb +0 -57
- data/lib/rails_uploads/storages/s3.rb +0 -68
- data/lib/rails_uploads/types/file.rb +0 -115
- data/lib/rails_uploads/types/image.rb +0 -45
- data/lib/rails_uploads/validators/attachment_content_type_validator.rb +0 -11
- data/lib/rails_uploads/validators/attachment_presence_validator.rb +0 -9
- data/lib/rails_uploads/validators/attachment_size_validator.rb +0 -27
- data/lib/rails_uploads/validators/base.rb +0 -13
- data/lib/rails_uploads/version.rb +0 -5
- data/lib/tasks/rails_uploads_tasks.rake +0 -89
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/images/image.jpg +0 -0
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/file_upload.rb +0 -4
- data/test/dummy/app/models/image_upload.rb +0 -4
- data/test/dummy/app/models/validation_upload.rb +0 -17
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -65
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -5
- data/test/dummy/config/s3.yml +0 -15
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130108201834_create_file_uploads.rb +0 -10
- data/test/dummy/db/migrate/20130110194721_create_validation_uploads.rb +0 -19
- data/test/dummy/db/migrate/20130124013431_create_image_uploads.rb +0 -10
- data/test/dummy/db/schema.rb +0 -43
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -23
- data/test/dummy/log/test.log +0 -25090
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/uploads/files/file.txt +0 -1
- data/test/dummy/public/uploads/images/big/image.jpg +0 -0
- data/test/dummy/public/uploads/images/original/image.jpg +0 -0
- data/test/dummy/public/uploads/images/small/image.jpg +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/test/fixtures/file.txt +0 -1
- data/test/dummy/test/fixtures/file_big.txt +0 -1
- data/test/dummy/test/fixtures/file_empty.txt +0 -1
- data/test/dummy/test/fixtures/image.jpg +0 -0
- data/test/dummy/test/fixtures/image_big.jpg +0 -0
- data/test/dummy/test/fixtures/image_empty.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/tmp/uploads/files/13687514839373922.txt +0 -1
- 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/fixtures/file.txt +0 -1
- data/test/fixtures/file_big.txt +0 -1
- data/test/fixtures/file_empty.txt +0 -1
- data/test/fixtures/image.jpg +0 -0
- data/test/fixtures/image_big.jpg +0 -0
- data/test/fixtures/image_empty.jpg +0 -0
- data/test/integration/local_generate_test.rb +0 -25
- data/test/test_helper.rb +0 -50
- data/test/unit/local_file_record_test.rb +0 -20
- data/test/unit/local_file_string_test.rb +0 -23
- data/test/unit/local_file_upload_test.rb +0 -30
- data/test/unit/local_image_record_test.rb +0 -25
- data/test/unit/local_image_string_test.rb +0 -34
- data/test/unit/local_image_upload_test.rb +0 -27
- data/test/unit/local_records_test.rb +0 -52
- data/test/unit/local_validators_test.rb +0 -71
- data/test/unit/s3_file_record_tes.rb +0 -21
- data/test/unit/s3_file_string_tes.rb +0 -24
- data/test/unit/s3_file_upload_tes.rb +0 -31
- data/test/unit/s3_image_record_tes.rb +0 -26
- data/test/unit/s3_image_string_tes.rb +0 -31
- data/test/unit/s3_image_upload_tes.rb +0 -28
- data/test/unit/s3_records_tes.rb +0 -56
- data/test/unit/s3_validators_tes.rb +0 -71
@@ -1,25 +0,0 @@
|
|
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,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalImageStringTest < ActiveSupport::TestCase
|
4
|
-
|
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
|
17
|
-
|
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)
|
22
|
-
|
23
|
-
assert ::File.exists?(original)
|
24
|
-
assert ::File.exists?(big)
|
25
|
-
assert ::File.exists?(small)
|
26
|
-
|
27
|
-
@image.delete
|
28
|
-
|
29
|
-
assert !::File.exists?(original)
|
30
|
-
assert !::File.exists?(big)
|
31
|
-
assert !::File.exists?(small)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,27 +0,0 @@
|
|
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
|
@@ -1,52 +0,0 @@
|
|
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
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalValidatorsTest < ActiveSupport::TestCase
|
4
|
-
include ActionView::Helpers::NumberHelper
|
5
|
-
|
6
|
-
setup do
|
7
|
-
@record = ValidationUpload.new
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should check if file is present" do
|
11
|
-
assert !@record.valid?
|
12
|
-
assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
|
13
|
-
|
14
|
-
@record.image_presence = fixture_file_upload('/image.jpg', 'image/jpeg')
|
15
|
-
assert !@record.valid?
|
16
|
-
assert_equal [], @record.errors[:image_presence]
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should check the file content type" do
|
20
|
-
@record.image_content_type = fixture_file_upload('/file.txt', 'text/plain')
|
21
|
-
assert !@record.valid?
|
22
|
-
assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'jpg')], @record.errors[:image_content_type]
|
23
|
-
|
24
|
-
@record.file_content_type = fixture_file_upload('/image.jpg', 'image/jpeg')
|
25
|
-
assert !@record.valid?
|
26
|
-
assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'txt')], @record.errors[:file_content_type]
|
27
|
-
end
|
28
|
-
|
29
|
-
test "should check the file size" do
|
30
|
-
@record.file_size = fixture_file_upload('/file_big.txt', 'text/plain')
|
31
|
-
assert !@record.valid?
|
32
|
-
assert_equal [I18n.t('errors.messages.attachment_size_less_than', :count => number_to_human_size(15.kilobytes))], @record.errors[:file_size]
|
33
|
-
|
34
|
-
@record.file_size = fixture_file_upload('/file_empty.txt', 'text/plain')
|
35
|
-
assert !@record.valid?
|
36
|
-
assert_equal [I18n.t('errors.messages.attachment_size_greater_than', :count => number_to_human_size(10.bytes))], @record.errors[:file_size]
|
37
|
-
|
38
|
-
@record.file_size = fixture_file_upload('/file.txt', 'text/plain')
|
39
|
-
assert !@record.valid?
|
40
|
-
assert_equal [], @record.errors[:file_size]
|
41
|
-
|
42
|
-
@record.image_size = fixture_file_upload('/image_big.jpg', 'image/jpeg')
|
43
|
-
assert !@record.valid?
|
44
|
-
assert_equal [I18n.t('errors.messages.attachment_size_in', :min => number_to_human_size(2.kilobytes), :max => number_to_human_size(60.kilobytes))], @record.errors[:image_size]
|
45
|
-
|
46
|
-
@record.image_size = fixture_file_upload('/image_empty.jpg', 'image/jpeg')
|
47
|
-
assert !@record.valid?
|
48
|
-
assert_equal [I18n.t('errors.messages.attachment_size_in', :min => number_to_human_size(2.kilobytes), :max => number_to_human_size(60.kilobytes))], @record.errors[:image_size]
|
49
|
-
|
50
|
-
@record.image_size = fixture_file_upload('/image.jpg', 'image/jpeg')
|
51
|
-
assert !@record.valid?
|
52
|
-
assert_equal [], @record.errors[:image_size]
|
53
|
-
end
|
54
|
-
|
55
|
-
test "should check all the validations together" do
|
56
|
-
@record.file_all = fixture_file_upload('/file.txt', 'text/plain')
|
57
|
-
assert !@record.valid?
|
58
|
-
assert_equal [], @record.errors[:file_all]
|
59
|
-
|
60
|
-
@record.image_all = fixture_file_upload('/image.jpg', 'image/jpeg')
|
61
|
-
assert !@record.valid?
|
62
|
-
assert_equal [], @record.errors[:image_all]
|
63
|
-
|
64
|
-
assert !@record.valid?
|
65
|
-
assert_equal [I18n.t('errors.messages.blank')], @record.errors[:file_default]
|
66
|
-
|
67
|
-
assert !@record.valid?
|
68
|
-
assert_equal [I18n.t('errors.messages.blank')], @record.errors[:image_default]
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3FileRecordTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
@record = FileUpload.create(:file => fixture_file_upload('/file.txt', 'text/plain'))
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should maintain properties and delete correctly" do
|
11
|
-
assert @record.file.exists?
|
12
|
-
assert_equal 11, @record.file.size
|
13
|
-
assert_equal '.txt', @record.file.extname
|
14
|
-
|
15
|
-
uploads_url = @record.file.url
|
16
|
-
@record.destroy
|
17
|
-
assert_not_object_s3 uploads_url
|
18
|
-
assert !@record.file.exists?
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3FileStringTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
filename = 'file.txt'
|
8
|
-
fixture_file_upload_s3 "/#{filename}", 'text/plain', ::File.join('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
|
-
assert_equal ::File.join('uploads', 'files', @file.filename), @file.path
|
17
|
-
|
18
|
-
uploads_url = @file.url
|
19
|
-
@file.delete
|
20
|
-
assert_not_object_s3 uploads_url
|
21
|
-
assert !@file.exists?
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3FileUploadTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
@file = RailsUploads::Types::File.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
|
8
|
-
end
|
9
|
-
|
10
|
-
test "file should exists and mantain properties" do
|
11
|
-
assert @file.exists?
|
12
|
-
assert_equal 58841, @file.size
|
13
|
-
assert_equal '.jpg', @file.extname
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should store/delete file correctly and accept cdn" do
|
17
|
-
@file.store
|
18
|
-
uploads_url = @file.url
|
19
|
-
assert_object_s3 uploads_url
|
20
|
-
|
21
|
-
base_url = 'http://cdn.example.com'
|
22
|
-
Rails.application.config.uploads.base_url = base_url
|
23
|
-
assert_equal ::File.join(base_url, @file.path), @file.url
|
24
|
-
Rails.application.config.uploads.base_url = ''
|
25
|
-
|
26
|
-
@file.delete
|
27
|
-
assert_not_object_s3 uploads_url
|
28
|
-
assert !@file.exists?
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3ImageRecordTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
@record = ImageUpload.create(:image => fixture_file_upload('/image.jpg', 'image/jpeg'))
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should save/destory main image and thumbs" do
|
11
|
-
original = @record.image.url
|
12
|
-
big = @record.image.url(:big)
|
13
|
-
small = @record.image.url(:small)
|
14
|
-
|
15
|
-
assert_object_s3 original
|
16
|
-
assert_object_s3 big
|
17
|
-
assert_object_s3 small
|
18
|
-
|
19
|
-
@record.destroy
|
20
|
-
|
21
|
-
assert_not_object_s3 original
|
22
|
-
assert_not_object_s3 big
|
23
|
-
assert_not_object_s3 small
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3ImageStringTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
filename = 'image.jpg'
|
8
|
-
fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'original', filename)
|
9
|
-
fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'big', filename)
|
10
|
-
fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'small', filename)
|
11
|
-
options = { :presets => [:small, :big] }
|
12
|
-
@image = RailsUploads::Types::Image.new(filename, options)
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should save/destory main image and thumbs" do
|
16
|
-
original = @image.url
|
17
|
-
big = @image.url(:big)
|
18
|
-
small = @image.url(:small)
|
19
|
-
|
20
|
-
assert_object_s3 original
|
21
|
-
assert_object_s3 big
|
22
|
-
assert_object_s3 small
|
23
|
-
|
24
|
-
@image.delete
|
25
|
-
|
26
|
-
assert_not_object_s3 original
|
27
|
-
assert_not_object_s3 big
|
28
|
-
assert_not_object_s3 small
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3ImageUploadTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
options = { :presets => [:small, :big] }
|
8
|
-
@image = RailsUploads::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'), options)
|
9
|
-
@image.store
|
10
|
-
end
|
11
|
-
|
12
|
-
test "should save/destory main image and thumbs" do
|
13
|
-
original = @image.url
|
14
|
-
big = @image.url(:big)
|
15
|
-
small = @image.url(:small)
|
16
|
-
|
17
|
-
assert_object_s3 original
|
18
|
-
assert_object_s3 big
|
19
|
-
assert_object_s3 small
|
20
|
-
|
21
|
-
@image.delete
|
22
|
-
|
23
|
-
assert_not_object_s3 original
|
24
|
-
assert_not_object_s3 big
|
25
|
-
assert_not_object_s3 small
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/test/unit/s3_records_tes.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3RecordsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should save/update/destroy from the database and save/destroy the file" do
|
10
|
-
record = FileUpload.create(:file => fixture_file_upload('/image.jpg', 'image/jpeg'))
|
11
|
-
image_filename = record.file.filename
|
12
|
-
image_url = record.file.url
|
13
|
-
assert_object_s3 image_url
|
14
|
-
|
15
|
-
record.update_attributes :file => fixture_file_upload('/file.txt', 'text/plain')
|
16
|
-
file_filename = record.file.filename
|
17
|
-
assert_not_equal image_filename, file_filename
|
18
|
-
file_url = record.file.url
|
19
|
-
assert_not_object_s3 image_url
|
20
|
-
assert_object_s3 file_url
|
21
|
-
|
22
|
-
record.destroy
|
23
|
-
assert_not_object_s3 file_url
|
24
|
-
end
|
25
|
-
|
26
|
-
test "should take default file/image and shouldn't store/delete it" do
|
27
|
-
record = FileUpload.create
|
28
|
-
file_filename = 'file.txt'
|
29
|
-
assert_equal ::File.join('uploads', 'files', file_filename), record.file.path
|
30
|
-
file_url = record.file.url
|
31
|
-
assert_object_s3 file_url
|
32
|
-
|
33
|
-
record.destroy
|
34
|
-
assert record.file.exists?
|
35
|
-
assert_object_s3 file_url
|
36
|
-
|
37
|
-
record = ImageUpload.create
|
38
|
-
image_filename = 'image.jpg'
|
39
|
-
assert_equal ::File.join('uploads', 'images', 'original', image_filename), record.image.path
|
40
|
-
image_original_url = record.image.url
|
41
|
-
assert_object_s3 image_original_url
|
42
|
-
assert_equal ::File.join('uploads', 'images', 'small', image_filename), record.image.path(:small)
|
43
|
-
image_small_url = record.image.url(:small)
|
44
|
-
assert_object_s3 image_small_url
|
45
|
-
assert_equal ::File.join('uploads', 'images', 'big', image_filename), record.image.path(:big)
|
46
|
-
image_big_url = record.image.url(:big)
|
47
|
-
assert_object_s3 image_big_url
|
48
|
-
|
49
|
-
record.destroy
|
50
|
-
assert record.image.exists?
|
51
|
-
assert_object_s3 image_original_url
|
52
|
-
assert_object_s3 image_small_url
|
53
|
-
assert_object_s3 image_big_url
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|