attachs 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +98 -0
- data/Rakefile +34 -0
- data/app/controllers/attachs/presets_controller.rb +17 -0
- data/config/locales/en.yml +8 -0
- data/config/locales/es.yml +8 -0
- data/config/routes.rb +5 -0
- data/lib/attachs.rb +16 -0
- data/lib/attachs/active_record/base.rb +145 -0
- data/lib/attachs/engine.rb +7 -0
- data/lib/attachs/magick/image.rb +85 -0
- data/lib/attachs/railtie.rb +20 -0
- data/lib/attachs/storages/local.rb +61 -0
- data/lib/attachs/storages/s3.rb +77 -0
- data/lib/attachs/types/file.rb +113 -0
- data/lib/attachs/types/image.rb +40 -0
- data/lib/attachs/validators/attachment_content_type_validator.rb +11 -0
- data/lib/attachs/validators/attachment_presence_validator.rb +9 -0
- data/lib/attachs/validators/attachment_size_validator.rb +27 -0
- data/lib/attachs/validators/base.rb +13 -0
- data/lib/attachs/version.rb +5 -0
- data/lib/generators/attachs/s3/config_generator.rb +13 -0
- data/lib/generators/attachs/s3/templates/s3.yml +16 -0
- data/lib/tasks/attachs_tasks.rake +71 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/all_attached.rb +16 -0
- data/test/dummy/app/models/file_attached.rb +3 -0
- data/test/dummy/app/models/image_attached.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +29 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130820222342_create_file_attacheds.rb +9 -0
- data/test/dummy/db/migrate/20130820222355_create_image_attacheds.rb +9 -0
- data/test/dummy/db/migrate/20130820222534_create_all_attacheds.rb +19 -0
- data/test/dummy/db/schema.rb +44 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +28 -0
- data/test/dummy/log/test.log +8545 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/uploads/files/file.txt +1 -0
- 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.txt +1 -0
- data/test/dummy/test/fixtures/file_big.txt +1 -0
- data/test/dummy/test/fixtures/file_empty.txt +1 -0
- 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/local_file_record_test.rb +20 -0
- data/test/local_file_string_test.rb +23 -0
- data/test/local_file_upload_test.rb +30 -0
- data/test/local_generate_test.rb +25 -0
- data/test/local_image_record_test.rb +25 -0
- data/test/local_image_string_test.rb +34 -0
- data/test/local_image_upload_test.rb +27 -0
- data/test/local_records_test.rb +52 -0
- data/test/local_validators_test.rb +71 -0
- data/test/s3_file_record_tes.rb +21 -0
- data/test/s3_file_string_tes.rb +24 -0
- data/test/s3_file_upload_tes.rb +31 -0
- data/test/s3_image_record_tes.rb +26 -0
- data/test/s3_image_string_tes.rb +31 -0
- data/test/s3_image_upload_tes.rb +28 -0
- data/test/s3_records_tes.rb +56 -0
- data/test/s3_validators_tes.rb +72 -0
- data/test/test_helper.rb +49 -0
- metadata +250 -0
@@ -0,0 +1,71 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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 = 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
|
+
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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class S3FileUploadTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
load_s3
|
7
|
+
@file = Attachs::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.attachs.base_url = base_url
|
23
|
+
assert_equal ::File.join(base_url, @file.path), @file.url
|
24
|
+
Rails.application.config.attachs.base_url = ''
|
25
|
+
|
26
|
+
@file.delete
|
27
|
+
assert_not_object_s3 uploads_url
|
28
|
+
assert !@file.exists?
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class S3ImageRecordTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
load_s3
|
7
|
+
@record = ImageAttached.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
|
@@ -0,0 +1,31 @@
|
|
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 = Attachs::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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class S3ImageUploadTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
load_s3
|
7
|
+
options = { presets: [:small, :big] }
|
8
|
+
@image = Attachs::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
|
@@ -0,0 +1,56 @@
|
|
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 = FileAttached.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 = FileAttached.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 = ImageAttached.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
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class S3ValidatorsTest < ActiveSupport::TestCase
|
4
|
+
include ActionView::Helpers::NumberHelper
|
5
|
+
|
6
|
+
setup do
|
7
|
+
load_s3
|
8
|
+
@record = AllAttached.new
|
9
|
+
end
|
10
|
+
|
11
|
+
test "should check if file is present" do
|
12
|
+
assert !@record.valid?
|
13
|
+
assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
|
14
|
+
|
15
|
+
@record.image_presence = fixture_file_upload('/image.jpg', 'image/jpeg')
|
16
|
+
assert !@record.valid?
|
17
|
+
assert_equal [], @record.errors[:image_presence]
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should check the file content type" do
|
21
|
+
@record.image_content_type = fixture_file_upload('/file.txt', 'text/plain')
|
22
|
+
assert !@record.valid?
|
23
|
+
assert_equal [I18n.t('errors.messages.attachment_content_type', types: 'jpg')], @record.errors[:image_content_type]
|
24
|
+
|
25
|
+
@record.file_content_type = fixture_file_upload('/image.jpg', 'image/jpeg')
|
26
|
+
assert !@record.valid?
|
27
|
+
assert_equal [I18n.t('errors.messages.attachment_content_type', types: 'txt')], @record.errors[:file_content_type]
|
28
|
+
end
|
29
|
+
|
30
|
+
test "should check the file size" do
|
31
|
+
@record.file_size = fixture_file_upload('/file_big.txt', 'text/plain')
|
32
|
+
assert !@record.valid?
|
33
|
+
assert_equal [I18n.t('errors.messages.attachment_size_less_than', count: number_to_human_size(15.kilobytes))], @record.errors[:file_size]
|
34
|
+
|
35
|
+
@record.file_size = fixture_file_upload('/file_empty.txt', 'text/plain')
|
36
|
+
assert !@record.valid?
|
37
|
+
assert_equal [I18n.t('errors.messages.attachment_size_greater_than', count: number_to_human_size(10.bytes))], @record.errors[:file_size]
|
38
|
+
|
39
|
+
@record.file_size = fixture_file_upload('/file.txt', 'text/plain')
|
40
|
+
assert !@record.valid?
|
41
|
+
assert_equal [], @record.errors[:file_size]
|
42
|
+
|
43
|
+
@record.image_size = fixture_file_upload('/image_big.jpg', 'image/jpeg')
|
44
|
+
assert !@record.valid?
|
45
|
+
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]
|
46
|
+
|
47
|
+
@record.image_size = fixture_file_upload('/image_empty.jpg', 'image/jpeg')
|
48
|
+
assert !@record.valid?
|
49
|
+
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]
|
50
|
+
|
51
|
+
@record.image_size = fixture_file_upload('/image.jpg', 'image/jpeg')
|
52
|
+
assert !@record.valid?
|
53
|
+
assert_equal [], @record.errors[:image_size]
|
54
|
+
end
|
55
|
+
|
56
|
+
test "should check all the validations together" do
|
57
|
+
@record.file_all = fixture_file_upload('/file.txt', 'text/plain')
|
58
|
+
assert !@record.valid?
|
59
|
+
assert_equal [], @record.errors[:file_all]
|
60
|
+
|
61
|
+
@record.image_all = fixture_file_upload('/image.jpg', 'image/jpeg')
|
62
|
+
assert !@record.valid?
|
63
|
+
assert_equal [], @record.errors[:image_all]
|
64
|
+
|
65
|
+
assert !@record.valid?
|
66
|
+
assert_equal [I18n.t('errors.messages.blank')], @record.errors[:file_default]
|
67
|
+
|
68
|
+
assert !@record.valid?
|
69
|
+
assert_equal [I18n.t('errors.messages.blank')], @record.errors[:image_default]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
|
+
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
5
|
+
require 'rails/test_help'
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Load database
|
18
|
+
config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', __FILE__)))
|
19
|
+
config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
|
20
|
+
ActiveRecord::Base.establish_connection(config['test'])
|
21
|
+
load(File.expand_path('../dummy/db/schema.rb', __FILE__))
|
22
|
+
|
23
|
+
# Addons
|
24
|
+
class ActiveSupport::TestCase
|
25
|
+
include ActionDispatch::TestProcess
|
26
|
+
|
27
|
+
def load_s3
|
28
|
+
require 'aws-sdk' unless defined?(AWS)
|
29
|
+
@storage_type = Rails.application.config.attachs.storage
|
30
|
+
Rails.application.config.attachs.storage = :s3
|
31
|
+
Attachs::Storages::S3.config = YAML.load_file(Rails.root.join('config', 's3.yml')) if Attachs::Storages::S3.config.blank?
|
32
|
+
self.class.teardown { Rails.application.config.attachs.storage = @storage_type }
|
33
|
+
end
|
34
|
+
|
35
|
+
def fixture_file_upload_s3(fixture, type, path, default=false)
|
36
|
+
upload = fixture_file_upload(fixture, type)
|
37
|
+
storage = Attachs::Storages::S3.new(default)
|
38
|
+
storage.store(upload, path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def assert_object_s3(url)
|
42
|
+
assert_equal '200', Net::HTTP.get_response(url).code
|
43
|
+
end
|
44
|
+
|
45
|
+
def assert_not_object_s3(url)
|
46
|
+
assert_equal '403', Net::HTTP.get_response(url).code
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attachs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattways
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Minimalistic toolkit to attach file and images to records.
|
56
|
+
email:
|
57
|
+
- contact@mattways.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- app/controllers/attachs/presets_controller.rb
|
63
|
+
- config/locales/en.yml
|
64
|
+
- config/locales/es.yml
|
65
|
+
- config/routes.rb
|
66
|
+
- lib/attachs/active_record/base.rb
|
67
|
+
- lib/attachs/engine.rb
|
68
|
+
- lib/attachs/magick/image.rb
|
69
|
+
- lib/attachs/railtie.rb
|
70
|
+
- lib/attachs/storages/local.rb
|
71
|
+
- lib/attachs/storages/s3.rb
|
72
|
+
- lib/attachs/types/file.rb
|
73
|
+
- lib/attachs/types/image.rb
|
74
|
+
- lib/attachs/validators/attachment_content_type_validator.rb
|
75
|
+
- lib/attachs/validators/attachment_presence_validator.rb
|
76
|
+
- lib/attachs/validators/attachment_size_validator.rb
|
77
|
+
- lib/attachs/validators/base.rb
|
78
|
+
- lib/attachs/version.rb
|
79
|
+
- lib/attachs.rb
|
80
|
+
- lib/generators/attachs/s3/config_generator.rb
|
81
|
+
- lib/generators/attachs/s3/templates/s3.yml
|
82
|
+
- lib/tasks/attachs_tasks.rake
|
83
|
+
- MIT-LICENSE
|
84
|
+
- Rakefile
|
85
|
+
- README.rdoc
|
86
|
+
- test/dummy/app/assets/javascripts/application.js
|
87
|
+
- test/dummy/app/assets/stylesheets/application.css
|
88
|
+
- test/dummy/app/controllers/application_controller.rb
|
89
|
+
- test/dummy/app/helpers/application_helper.rb
|
90
|
+
- test/dummy/app/models/all_attached.rb
|
91
|
+
- test/dummy/app/models/file_attached.rb
|
92
|
+
- test/dummy/app/models/image_attached.rb
|
93
|
+
- test/dummy/app/views/layouts/application.html.erb
|
94
|
+
- test/dummy/bin/bundle
|
95
|
+
- test/dummy/bin/rails
|
96
|
+
- test/dummy/bin/rake
|
97
|
+
- test/dummy/config/application.rb
|
98
|
+
- test/dummy/config/boot.rb
|
99
|
+
- test/dummy/config/database.yml
|
100
|
+
- test/dummy/config/environment.rb
|
101
|
+
- test/dummy/config/environments/development.rb
|
102
|
+
- test/dummy/config/environments/production.rb
|
103
|
+
- test/dummy/config/environments/test.rb
|
104
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
105
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
106
|
+
- test/dummy/config/initializers/inflections.rb
|
107
|
+
- test/dummy/config/initializers/mime_types.rb
|
108
|
+
- test/dummy/config/initializers/secret_token.rb
|
109
|
+
- test/dummy/config/initializers/session_store.rb
|
110
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
111
|
+
- test/dummy/config/locales/en.yml
|
112
|
+
- test/dummy/config/routes.rb
|
113
|
+
- test/dummy/config.ru
|
114
|
+
- test/dummy/db/development.sqlite3
|
115
|
+
- test/dummy/db/migrate/20130820222342_create_file_attacheds.rb
|
116
|
+
- test/dummy/db/migrate/20130820222355_create_image_attacheds.rb
|
117
|
+
- test/dummy/db/migrate/20130820222534_create_all_attacheds.rb
|
118
|
+
- test/dummy/db/schema.rb
|
119
|
+
- test/dummy/db/test.sqlite3
|
120
|
+
- test/dummy/log/development.log
|
121
|
+
- test/dummy/log/test.log
|
122
|
+
- test/dummy/public/404.html
|
123
|
+
- test/dummy/public/422.html
|
124
|
+
- test/dummy/public/500.html
|
125
|
+
- test/dummy/public/favicon.ico
|
126
|
+
- test/dummy/public/uploads/files/file.txt
|
127
|
+
- test/dummy/public/uploads/images/big/image.jpg
|
128
|
+
- test/dummy/public/uploads/images/original/image.jpg
|
129
|
+
- test/dummy/public/uploads/images/small/image.jpg
|
130
|
+
- test/dummy/Rakefile
|
131
|
+
- test/dummy/README.rdoc
|
132
|
+
- test/dummy/test/fixtures/file.txt
|
133
|
+
- test/dummy/test/fixtures/file_big.txt
|
134
|
+
- test/dummy/test/fixtures/file_empty.txt
|
135
|
+
- test/dummy/test/fixtures/image.jpg
|
136
|
+
- test/dummy/test/fixtures/image_big.jpg
|
137
|
+
- test/dummy/test/fixtures/image_empty.jpg
|
138
|
+
- test/local_file_record_test.rb
|
139
|
+
- test/local_file_string_test.rb
|
140
|
+
- test/local_file_upload_test.rb
|
141
|
+
- test/local_generate_test.rb
|
142
|
+
- test/local_image_record_test.rb
|
143
|
+
- test/local_image_string_test.rb
|
144
|
+
- test/local_image_upload_test.rb
|
145
|
+
- test/local_records_test.rb
|
146
|
+
- test/local_validators_test.rb
|
147
|
+
- test/s3_file_record_tes.rb
|
148
|
+
- test/s3_file_string_tes.rb
|
149
|
+
- test/s3_file_upload_tes.rb
|
150
|
+
- test/s3_image_record_tes.rb
|
151
|
+
- test/s3_image_string_tes.rb
|
152
|
+
- test/s3_image_upload_tes.rb
|
153
|
+
- test/s3_records_tes.rb
|
154
|
+
- test/s3_validators_tes.rb
|
155
|
+
- test/test_helper.rb
|
156
|
+
homepage: https://github.com/mattways/attachs
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.0.3
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Attachs for Rails.
|
180
|
+
test_files:
|
181
|
+
- test/dummy/app/assets/javascripts/application.js
|
182
|
+
- test/dummy/app/assets/stylesheets/application.css
|
183
|
+
- test/dummy/app/controllers/application_controller.rb
|
184
|
+
- test/dummy/app/helpers/application_helper.rb
|
185
|
+
- test/dummy/app/models/all_attached.rb
|
186
|
+
- test/dummy/app/models/file_attached.rb
|
187
|
+
- test/dummy/app/models/image_attached.rb
|
188
|
+
- test/dummy/app/views/layouts/application.html.erb
|
189
|
+
- test/dummy/bin/bundle
|
190
|
+
- test/dummy/bin/rails
|
191
|
+
- test/dummy/bin/rake
|
192
|
+
- test/dummy/config/application.rb
|
193
|
+
- test/dummy/config/boot.rb
|
194
|
+
- test/dummy/config/database.yml
|
195
|
+
- test/dummy/config/environment.rb
|
196
|
+
- test/dummy/config/environments/development.rb
|
197
|
+
- test/dummy/config/environments/production.rb
|
198
|
+
- test/dummy/config/environments/test.rb
|
199
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
200
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
201
|
+
- test/dummy/config/initializers/inflections.rb
|
202
|
+
- test/dummy/config/initializers/mime_types.rb
|
203
|
+
- test/dummy/config/initializers/secret_token.rb
|
204
|
+
- test/dummy/config/initializers/session_store.rb
|
205
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
206
|
+
- test/dummy/config/locales/en.yml
|
207
|
+
- test/dummy/config/routes.rb
|
208
|
+
- test/dummy/config.ru
|
209
|
+
- test/dummy/db/development.sqlite3
|
210
|
+
- test/dummy/db/migrate/20130820222342_create_file_attacheds.rb
|
211
|
+
- test/dummy/db/migrate/20130820222355_create_image_attacheds.rb
|
212
|
+
- test/dummy/db/migrate/20130820222534_create_all_attacheds.rb
|
213
|
+
- test/dummy/db/schema.rb
|
214
|
+
- test/dummy/db/test.sqlite3
|
215
|
+
- test/dummy/log/development.log
|
216
|
+
- test/dummy/log/test.log
|
217
|
+
- test/dummy/public/404.html
|
218
|
+
- test/dummy/public/422.html
|
219
|
+
- test/dummy/public/500.html
|
220
|
+
- test/dummy/public/favicon.ico
|
221
|
+
- test/dummy/public/uploads/files/file.txt
|
222
|
+
- test/dummy/public/uploads/images/big/image.jpg
|
223
|
+
- test/dummy/public/uploads/images/original/image.jpg
|
224
|
+
- test/dummy/public/uploads/images/small/image.jpg
|
225
|
+
- test/dummy/Rakefile
|
226
|
+
- test/dummy/README.rdoc
|
227
|
+
- test/dummy/test/fixtures/file.txt
|
228
|
+
- test/dummy/test/fixtures/file_big.txt
|
229
|
+
- test/dummy/test/fixtures/file_empty.txt
|
230
|
+
- test/dummy/test/fixtures/image.jpg
|
231
|
+
- test/dummy/test/fixtures/image_big.jpg
|
232
|
+
- test/dummy/test/fixtures/image_empty.jpg
|
233
|
+
- test/local_file_record_test.rb
|
234
|
+
- test/local_file_string_test.rb
|
235
|
+
- test/local_file_upload_test.rb
|
236
|
+
- test/local_generate_test.rb
|
237
|
+
- test/local_image_record_test.rb
|
238
|
+
- test/local_image_string_test.rb
|
239
|
+
- test/local_image_upload_test.rb
|
240
|
+
- test/local_records_test.rb
|
241
|
+
- test/local_validators_test.rb
|
242
|
+
- test/s3_file_record_tes.rb
|
243
|
+
- test/s3_file_string_tes.rb
|
244
|
+
- test/s3_file_upload_tes.rb
|
245
|
+
- test/s3_image_record_tes.rb
|
246
|
+
- test/s3_image_string_tes.rb
|
247
|
+
- test/s3_image_upload_tes.rb
|
248
|
+
- test/s3_records_tes.rb
|
249
|
+
- test/s3_validators_tes.rb
|
250
|
+
- test/test_helper.rb
|