attachs 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +254 -0
- data/Rakefile +0 -2
- data/lib/attachs.rb +37 -10
- data/lib/attachs/active_record/base.rb +58 -95
- data/lib/attachs/active_record/connection_adapters.rb +40 -0
- data/lib/attachs/active_record/migration.rb +17 -0
- data/lib/attachs/active_record/validators.rb +7 -0
- data/lib/attachs/active_record/validators/attachment_content_type_validator.rb +30 -0
- data/lib/attachs/active_record/validators/attachment_presence_validator.rb +22 -0
- data/lib/attachs/active_record/validators/attachment_size_validator.rb +39 -0
- data/lib/attachs/attachment.rb +114 -0
- data/{config → lib/attachs}/locales/en.yml +2 -1
- data/{config → lib/attachs}/locales/es.yml +2 -1
- data/lib/attachs/railtie.rb +31 -11
- data/lib/attachs/storages/base.rb +68 -0
- data/lib/attachs/storages/local.rb +61 -37
- data/lib/attachs/storages/s3.rb +66 -57
- data/lib/attachs/tools/magick.rb +52 -0
- data/lib/attachs/types/base.rb +22 -0
- data/lib/attachs/types/default.rb +21 -0
- data/lib/attachs/types/regular.rb +21 -0
- data/lib/attachs/version.rb +1 -1
- data/lib/generators/attachs/install_generator.rb +13 -0
- data/lib/generators/attachs/templates/attachs.rb +2 -0
- data/lib/tasks/attachs.rake +30 -0
- data/test/attachment_test.rb +19 -0
- data/test/dummy/app/models/medium.rb +5 -0
- data/test/dummy/app/models/picture.rb +2 -0
- data/test/dummy/config/application.rb +1 -7
- data/test/dummy/config/initializers/attachs.rb +25 -0
- data/test/dummy/config/initializers/secret_token.rb +1 -0
- data/test/dummy/config/routes.rb +0 -1
- data/test/dummy/db/migrate/20140808012639_create_media.rb +11 -0
- data/test/dummy/db/schema.rb +14 -25
- data/test/dummy/log/development.log +9 -27
- data/test/dummy/log/test.log +52130 -11207
- data/test/dummy/test/fixtures/180x150.gif +0 -0
- data/test/generator_test.rb +18 -0
- data/test/local_storage_test.rb +57 -0
- data/test/magick_tool_test.rb +42 -0
- data/test/migration_test.rb +65 -0
- data/test/s3_storage_tes.rb +56 -0
- data/test/tasks_test.rb +61 -0
- data/test/test_helper.rb +17 -17
- data/test/validators_test.rb +100 -0
- metadata +85 -120
- data/README.rdoc +0 -104
- data/app/controllers/attachs/presets_controller.rb +0 -17
- data/config/routes.rb +0 -5
- data/lib/attachs/engine.rb +0 -7
- data/lib/attachs/magick/image.rb +0 -85
- data/lib/attachs/types/file.rb +0 -131
- data/lib/attachs/types/image.rb +0 -58
- data/lib/attachs/validators/attachment_content_type_validator.rb +0 -11
- data/lib/attachs/validators/attachment_presence_validator.rb +0 -9
- data/lib/attachs/validators/attachment_size_validator.rb +0 -21
- data/lib/attachs/validators/base.rb +0 -13
- data/lib/generators/attachs/s3/config_generator.rb +0 -13
- data/lib/generators/attachs/s3/templates/s3.yml +0 -16
- data/lib/tasks/attachs_tasks.rake +0 -71
- data/test/dummy/app/models/all_attached.rb +0 -16
- data/test/dummy/app/models/file_attached.rb +0 -3
- data/test/dummy/app/models/image_attached.rb +0 -3
- data/test/dummy/app/models/private_file_attached.rb +0 -3
- data/test/dummy/app/models/private_image_attached.rb +0 -3
- data/test/dummy/db/migrate/20130820222342_create_file_attacheds.rb +0 -9
- data/test/dummy/db/migrate/20130820222355_create_image_attacheds.rb +0 -9
- data/test/dummy/db/migrate/20130820222534_create_all_attacheds.rb +0 -19
- 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/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/13898788260004868.txt +0 -1
- data/test/local_file_record_test.rb +0 -31
- data/test/local_file_string_test.rb +0 -23
- data/test/local_file_upload_test.rb +0 -30
- data/test/local_generate_test.rb +0 -25
- data/test/local_image_record_test.rb +0 -25
- data/test/local_image_string_test.rb +0 -34
- data/test/local_image_upload_test.rb +0 -27
- data/test/local_records_test.rb +0 -52
- data/test/local_validators_test.rb +0 -71
- data/test/s3_file_record_tes.rb +0 -21
- data/test/s3_file_string_tes.rb +0 -24
- data/test/s3_file_upload_tes.rb +0 -31
- data/test/s3_image_record_tes.rb +0 -26
- data/test/s3_image_string_tes.rb +0 -31
- data/test/s3_image_upload_tes.rb +0 -28
- data/test/s3_records_tes.rb +0 -56
- data/test/s3_validators_tes.rb +0 -72
@@ -1,16 +0,0 @@
|
|
1
|
-
class AllAttached < ActiveRecord::Base
|
2
|
-
has_attached_file :file_presence, :file_content_type, :file_size, :file_all
|
3
|
-
has_attached_file :file_default, default: 'file.txt'
|
4
|
-
has_attached_image :image_presence, :image_content_type, :image_size, :image_all, presets: :big
|
5
|
-
has_attached_image :image_default, presets: [:big, :small], default: 'image.jpg'
|
6
|
-
validates :file_presence, attachment_presence: true
|
7
|
-
validates :file_content_type, attachment_content_type: { in: ['txt'] }
|
8
|
-
validates :file_size, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
|
9
|
-
validates :file_all, attachment_presence: true, attachment_content_type: { in: ['txt'] }, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
|
10
|
-
validates :file_default, attachment_presence: true, attachment_content_type: { in: ['txt'] }, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
|
11
|
-
validates :image_presence, attachment_presence: true
|
12
|
-
validates :image_content_type, attachment_content_type: { in: ['jpg'] }
|
13
|
-
validates :image_size, attachment_size: { in: 2.kilobytes..60.kilobytes }
|
14
|
-
validates :image_all, attachment_presence: true, attachment_content_type: { in: ['jpg'] }, attachment_size: { in: 2.kilobytes..60.kilobytes }
|
15
|
-
validates :image_default, attachment_presence: true, attachment_content_type: { in: ['jpg'] }, attachment_size: { in: 2.kilobytes..60.kilobytes }
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class CreateAllAttacheds < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :all_attacheds do |t|
|
4
|
-
t.string :image
|
5
|
-
t.string :file_presence
|
6
|
-
t.string :file_content_type
|
7
|
-
t.string :file_size
|
8
|
-
t.string :file_all
|
9
|
-
t.string :file_default
|
10
|
-
t.string :image_presence
|
11
|
-
t.string :image_content_type
|
12
|
-
t.string :image_size
|
13
|
-
t.string :image_all
|
14
|
-
t.string :image_default
|
15
|
-
|
16
|
-
t.timestamps
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
1234567890
|
Binary file
|
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
|
@@ -1 +0,0 @@
|
|
1
|
-
|
Binary file
|
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
1234567890
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalFileRecordTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@record = FileAttached.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
|
-
test "should delete correctly using delete_attr method" do
|
21
|
-
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @record.file.filename)
|
22
|
-
|
23
|
-
@record.delete_file = '1'
|
24
|
-
assert @record.file_changed?
|
25
|
-
|
26
|
-
@record.save
|
27
|
-
assert !::File.exists?(uploads_path)
|
28
|
-
assert !@record.file.exists?
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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 = Attachs::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
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalFileUploadTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@file = Attachs::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.attachs.base_url = base_url
|
22
|
-
assert_equal ::File.join(base_url, @file.path), @file.url
|
23
|
-
Rails.application.config.attachs.base_url = ''
|
24
|
-
|
25
|
-
@file.delete
|
26
|
-
assert !::File.exists?(uploads_path)
|
27
|
-
assert !@file.exists?
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/local_generate_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalGenerateTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@image = Attachs::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
|
7
|
-
@image.store
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown do
|
11
|
-
@image.delete
|
12
|
-
end
|
13
|
-
|
14
|
-
test "should generate preset" do
|
15
|
-
realpath = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
16
|
-
::File.delete realpath
|
17
|
-
|
18
|
-
path = ::File.join('', 'uploads', 'images', 'small', @image.filename)
|
19
|
-
get path
|
20
|
-
assert_redirected_to path
|
21
|
-
|
22
|
-
assert ::File.exists?(realpath)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalImagePresetsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@record = ImageAttached.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 = Attachs::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 = Attachs::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
|
data/test/local_records_test.rb
DELETED
@@ -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 = FileAttached.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 = FileAttached.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 = ImageAttached.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 = AllAttached.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
|
data/test/s3_file_record_tes.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3FileRecordTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
load_s3
|
7
|
-
@record = FileAttached.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
|