rails_uploads 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. data/README.rdoc +35 -9
  2. data/app/controllers/rails_uploads/application_controller.rb +1 -0
  3. data/app/controllers/rails_uploads/presets_controller.rb +2 -4
  4. data/lib/rails_uploads.rb +2 -0
  5. data/lib/rails_uploads/active_record/base.rb +60 -55
  6. data/lib/rails_uploads/magick/image.rb +3 -3
  7. data/lib/rails_uploads/railtie.rb +6 -1
  8. data/lib/rails_uploads/storages/local.rb +57 -0
  9. data/lib/rails_uploads/storages/s3.rb +61 -0
  10. data/lib/rails_uploads/types/file.rb +35 -43
  11. data/lib/rails_uploads/types/image.rb +12 -28
  12. data/lib/rails_uploads/validators/attachment_content_type_validator.rb +2 -4
  13. data/lib/rails_uploads/validators/attachment_presence_validator.rb +0 -2
  14. data/lib/rails_uploads/validators/attachment_size_validator.rb +4 -6
  15. data/lib/rails_uploads/version.rb +1 -1
  16. data/lib/tasks/rails_uploads_tasks.rake +31 -3
  17. data/test/dummy/app/models/file_upload.rb +1 -1
  18. data/test/dummy/app/models/image_upload.rb +1 -1
  19. data/test/dummy/app/models/validation_upload.rb +2 -2
  20. data/test/dummy/config/s3.yml +15 -0
  21. data/test/dummy/log/development.log +1 -0
  22. data/test/dummy/log/test.log +11581 -0
  23. data/test/dummy/public/uploads/images/{original/default.jpg → big/image.jpg} +0 -0
  24. data/test/dummy/public/uploads/images/small/image.jpg +0 -0
  25. data/test/dummy/tmp/uploads/files/13687482983108968.jpg +0 -0
  26. data/test/dummy/tmp/uploads/files/13687483348482658.jpg +0 -0
  27. data/test/dummy/tmp/uploads/files/13687483563901100.jpg +0 -0
  28. data/test/dummy/tmp/uploads/files/13687484108914220.jpg +0 -0
  29. data/test/dummy/tmp/uploads/files/13687489381697390.jpg +0 -0
  30. data/test/dummy/tmp/uploads/files/13687490968011022.jpg +0 -0
  31. data/test/dummy/tmp/uploads/files/13687491524768450.jpg +0 -0
  32. data/test/dummy/tmp/uploads/files/13687494425396302.jpg +0 -0
  33. data/test/dummy/tmp/uploads/files/13687513450654020.jpg +0 -0
  34. data/test/dummy/{public/uploads/files/default.txt → tmp/uploads/files/13687514839373922.txt} +0 -0
  35. data/test/dummy/tmp/uploads/files/13688181722986792.jpg +0 -0
  36. data/test/dummy/tmp/uploads/files/13688181729459798.jpg +0 -0
  37. data/test/dummy/tmp/uploads/images/big/13687484103672162.jpg +0 -0
  38. data/test/dummy/tmp/uploads/images/big/13687484106303082.jpg +0 -0
  39. data/test/dummy/tmp/uploads/images/big/13687489377129980.jpg +0 -0
  40. data/test/dummy/tmp/uploads/images/big/13687489379459820.jpg +0 -0
  41. data/test/dummy/tmp/uploads/images/big/13687490965463210.jpg +0 -0
  42. data/test/dummy/tmp/uploads/images/big/13687491522552230.jpg +0 -0
  43. data/test/dummy/tmp/uploads/images/big/13688181724596422.jpg +0 -0
  44. data/test/dummy/tmp/uploads/images/big/13688181727051510.jpg +0 -0
  45. data/test/dummy/tmp/uploads/images/big/13688259257147068.jpg +0 -0
  46. data/test/dummy/tmp/uploads/images/big/13688280071286788.jpg +0 -0
  47. data/test/dummy/tmp/uploads/images/big/13688281527981960.jpg +0 -0
  48. data/test/dummy/tmp/uploads/images/big/13688360981527310.jpg +0 -0
  49. data/test/dummy/tmp/uploads/images/big/13688360983686640.jpg +0 -0
  50. data/test/dummy/tmp/uploads/images/big/13688977138132322.jpg +0 -0
  51. data/test/dummy/tmp/uploads/images/big/13688977290079510.jpg +0 -0
  52. data/test/dummy/tmp/uploads/images/big/13688978966174670.jpg +0 -0
  53. data/test/dummy/tmp/uploads/images/original/13687482977916958.jpg +0 -0
  54. data/test/dummy/tmp/uploads/images/original/13687482979328390.jpg +0 -0
  55. data/test/dummy/tmp/uploads/images/original/13687482981277580.jpg +0 -0
  56. data/test/dummy/tmp/uploads/images/original/13687483343313990.jpg +0 -0
  57. data/test/dummy/tmp/uploads/images/original/13687483344710930.jpg +0 -0
  58. data/test/dummy/tmp/uploads/images/original/13687483346647770.jpg +0 -0
  59. data/test/dummy/tmp/uploads/images/original/13687483558679350.jpg +0 -0
  60. data/test/dummy/tmp/uploads/images/original/13687483560070410.jpg +0 -0
  61. data/test/dummy/tmp/uploads/images/original/13687483562001660.jpg +0 -0
  62. data/test/dummy/tmp/uploads/images/original/13687484103672162.jpg +0 -0
  63. data/test/dummy/tmp/uploads/images/original/13687484106303082.jpg +0 -0
  64. data/test/dummy/tmp/uploads/images/original/13687489377129980.jpg +0 -0
  65. data/test/dummy/tmp/uploads/images/original/13687489379459820.jpg +0 -0
  66. data/test/dummy/tmp/uploads/images/original/13687490965463210.jpg +0 -0
  67. data/test/dummy/tmp/uploads/images/original/13687491522552230.jpg +0 -0
  68. data/test/dummy/tmp/uploads/images/original/13688181723027610.jpg +0 -0
  69. data/test/dummy/tmp/uploads/images/original/13688181724596422.jpg +0 -0
  70. data/test/dummy/tmp/uploads/images/original/13688181727051510.jpg +0 -0
  71. data/test/dummy/tmp/uploads/images/original/13688259257147068.jpg +0 -0
  72. data/test/dummy/tmp/uploads/images/original/13688280071286788.jpg +0 -0
  73. data/test/dummy/tmp/uploads/images/original/13688281527981960.jpg +0 -0
  74. data/test/dummy/tmp/uploads/images/original/13688360981527310.jpg +0 -0
  75. data/test/dummy/tmp/uploads/images/original/13688360983686640.jpg +0 -0
  76. data/test/dummy/tmp/uploads/images/original/13688977138132322.jpg +0 -0
  77. data/test/dummy/tmp/uploads/images/original/13688977290079510.jpg +0 -0
  78. data/test/dummy/tmp/uploads/images/original/13688978966174670.jpg +0 -0
  79. data/test/dummy/tmp/uploads/images/small/13687484103672162.jpg +0 -0
  80. data/test/dummy/tmp/uploads/images/small/13687484106303082.jpg +0 -0
  81. data/test/dummy/tmp/uploads/images/small/13687489377129980.jpg +0 -0
  82. data/test/dummy/tmp/uploads/images/small/13687489379459820.jpg +0 -0
  83. data/test/dummy/tmp/uploads/images/small/13687490965463210.jpg +0 -0
  84. data/test/dummy/tmp/uploads/images/small/13687491522552230.jpg +0 -0
  85. data/test/dummy/tmp/uploads/images/small/13688181723027610.jpg +0 -0
  86. data/test/dummy/tmp/uploads/images/small/13688181724596422.jpg +0 -0
  87. data/test/dummy/tmp/uploads/images/small/13688181727051510.jpg +0 -0
  88. data/test/dummy/tmp/uploads/images/small/13688259257147068.jpg +0 -0
  89. data/test/dummy/tmp/uploads/images/small/13688280071286788.jpg +0 -0
  90. data/test/dummy/tmp/uploads/images/small/13688281527981960.jpg +0 -0
  91. data/test/dummy/tmp/uploads/images/small/13688360981527310.jpg +0 -0
  92. data/test/dummy/tmp/uploads/images/small/13688360983686640.jpg +0 -0
  93. data/test/dummy/tmp/uploads/images/small/13688977138132322.jpg +0 -0
  94. data/test/dummy/tmp/uploads/images/small/13688977290079510.jpg +0 -0
  95. data/test/dummy/tmp/uploads/images/small/13688978966174670.jpg +0 -0
  96. data/test/{generate_test.rb → integration/local_generate_test.rb} +12 -14
  97. data/test/test_helper.rb +29 -0
  98. data/test/unit/local_file_record_test.rb +20 -0
  99. data/test/unit/local_file_string_test.rb +23 -0
  100. data/test/unit/local_file_upload_test.rb +30 -0
  101. data/test/unit/local_image_record_test.rb +25 -0
  102. data/test/{image_string_test.rb → unit/local_image_string_test.rb} +19 -21
  103. data/test/unit/local_image_upload_test.rb +27 -0
  104. data/test/unit/local_records_test.rb +52 -0
  105. data/test/{validators_test.rb → unit/local_validators_test.rb} +15 -28
  106. data/test/unit/s3_file_record_tes.rb +21 -0
  107. data/test/unit/s3_file_string_tes.rb +24 -0
  108. data/test/unit/s3_file_upload_tes.rb +31 -0
  109. data/test/unit/s3_image_record_tes.rb +26 -0
  110. data/test/unit/s3_image_string_tes.rb +31 -0
  111. data/test/unit/s3_image_upload_tes.rb +28 -0
  112. data/test/unit/s3_records_tes.rb +56 -0
  113. data/test/unit/s3_validators_tes.rb +71 -0
  114. metadata +204 -25
  115. data/test/file_string_test.rb +0 -35
  116. data/test/file_upload_test.rb +0 -41
  117. data/test/image_presets_test.rb +0 -32
  118. data/test/image_upload_test.rb +0 -34
  119. data/test/rails_uploads_test.rb +0 -9
  120. data/test/records_test.rb +0 -55
@@ -1,68 +1,62 @@
1
1
  require 'test_helper'
2
2
 
3
- class ValidatorsTest < ActiveSupport::TestCase
4
- include ActionDispatch::TestProcess
3
+ class LocalValidatorsTest < ActiveSupport::TestCase
5
4
 
6
- setup :create_record
5
+ setup do
6
+ @record = ValidationUpload.new
7
+ end
7
8
 
8
9
  test "should check if file is present" do
9
-
10
10
  assert !@record.valid?
11
11
  assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
12
12
 
13
- @record.image_presence = fixture_file_upload(::File.join('', 'image.jpg'), 'image/jpeg')
13
+ @record.image_presence = fixture_file_upload('/image.jpg', 'image/jpeg')
14
14
  assert !@record.valid?
15
15
  assert_equal [], @record.errors[:image_presence]
16
-
17
16
  end
18
17
 
19
18
  test "should check the file content type" do
20
-
21
- @record.image_content_type = fixture_file_upload(::File.join('', 'file.txt'), 'text/plain')
19
+ @record.image_content_type = fixture_file_upload('/file.txt', 'text/plain')
22
20
  assert !@record.valid?
23
21
  assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'jpg')], @record.errors[:image_content_type]
24
22
 
25
- @record.file_content_type = fixture_file_upload(::File.join('', 'image.jpg'), 'image/jpeg')
23
+ @record.file_content_type = fixture_file_upload('/image.jpg', 'image/jpeg')
26
24
  assert !@record.valid?
27
25
  assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'txt')], @record.errors[:file_content_type]
28
-
29
26
  end
30
27
 
31
28
  test "should check the file size" do
32
-
33
- @record.file_size = fixture_file_upload(::File.join('', 'file_big.txt'), 'text/plain')
29
+ @record.file_size = fixture_file_upload('/file_big.txt', 'text/plain')
34
30
  assert !@record.valid?
35
31
  assert_equal [I18n.t('errors.messages.attachment_size_less_than', :less_than => 15.kilobytes)], @record.errors[:file_size]
36
32
 
37
- @record.file_size = fixture_file_upload(::File.join('', 'file_empty.txt'), 'text/plain')
33
+ @record.file_size = fixture_file_upload('/file_empty.txt', 'text/plain')
38
34
  assert !@record.valid?
39
35
  assert_equal [I18n.t('errors.messages.attachment_size_greater_than', :greater_than => 10.bytes)], @record.errors[:file_size]
40
36
 
41
- @record.file_size = fixture_file_upload(::File.join('', 'file.txt'), 'text/plain')
37
+ @record.file_size = fixture_file_upload('/file.txt', 'text/plain')
42
38
  assert !@record.valid?
43
39
  assert_equal [], @record.errors[:file_size]
44
40
 
45
- @record.image_size = fixture_file_upload(::File.join('', 'image_big.jpg'), 'image/jpeg')
41
+ @record.image_size = fixture_file_upload('/image_big.jpg', 'image/jpeg')
46
42
  assert !@record.valid?
47
43
  assert_equal [I18n.t('errors.messages.attachment_size_in', :greater_than => 2.kilobytes, :less_than => 60.kilobytes)], @record.errors[:image_size]
48
44
 
49
- @record.image_size = fixture_file_upload(::File.join('', 'image_empty.jpg'), 'image/jpeg')
45
+ @record.image_size = fixture_file_upload('/image_empty.jpg', 'image/jpeg')
50
46
  assert !@record.valid?
51
47
  assert_equal [I18n.t('errors.messages.attachment_size_in', :greater_than => 2.kilobytes, :less_than => 60.kilobytes)], @record.errors[:image_size]
52
48
 
53
- @record.image_size = fixture_file_upload(::File.join('', 'image.jpg'), 'image/jpeg')
49
+ @record.image_size = fixture_file_upload('/image.jpg', 'image/jpeg')
54
50
  assert !@record.valid?
55
51
  assert_equal [], @record.errors[:image_size]
56
-
57
52
  end
58
53
 
59
54
  test "should check all the validations together" do
60
-
61
- @record.file_all = fixture_file_upload(::File.join('', 'file.txt'), 'text/plain')
55
+ @record.file_all = fixture_file_upload('/file.txt', 'text/plain')
62
56
  assert !@record.valid?
63
57
  assert_equal [], @record.errors[:file_all]
64
58
 
65
- @record.image_all = fixture_file_upload(::File.join('', 'image.jpg'), 'image/jpeg')
59
+ @record.image_all = fixture_file_upload('/image.jpg', 'image/jpeg')
66
60
  assert !@record.valid?
67
61
  assert_equal [], @record.errors[:image_all]
68
62
 
@@ -71,13 +65,6 @@ class ValidatorsTest < ActiveSupport::TestCase
71
65
 
72
66
  assert !@record.valid?
73
67
  assert_equal [], @record.errors[:image_default]
74
-
75
- end
76
-
77
- protected
78
-
79
- def create_record
80
- @record = ValidationUpload.new
81
68
  end
82
69
 
83
70
  end
@@ -0,0 +1,21 @@
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
@@ -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 = 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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,26 @@
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
@@ -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 = 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
@@ -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 = 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
@@ -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 = 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
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class S3ValidatorsTest < ActiveSupport::TestCase
4
+
5
+ setup do
6
+ load_s3
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', :less_than => 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', :greater_than => 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', :greater_than => 2.kilobytes, :less_than => 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', :greater_than => 2.kilobytes, :less_than => 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 [], @record.errors[:file_default]
66
+
67
+ assert !@record.valid?
68
+ assert_equal [], @record.errors[:image_default]
69
+ end
70
+
71
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_uploads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-14 00:00:00.000000000 Z
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.2.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-sdk
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: sqlite3
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -57,6 +73,8 @@ files:
57
73
  - lib/rails_uploads/engine.rb
58
74
  - lib/rails_uploads/magick/image.rb
59
75
  - lib/rails_uploads/railtie.rb
76
+ - lib/rails_uploads/storages/local.rb
77
+ - lib/rails_uploads/storages/s3.rb
60
78
  - lib/rails_uploads/types/file.rb
61
79
  - lib/rails_uploads/types/image.rb
62
80
  - lib/rails_uploads/validators/attachment_content_type_validator.rb
@@ -93,6 +111,7 @@ files:
93
111
  - test/dummy/config/initializers/wrap_parameters.rb
94
112
  - test/dummy/config/locales/en.yml
95
113
  - test/dummy/config/routes.rb
114
+ - test/dummy/config/s3.yml
96
115
  - test/dummy/config.ru
97
116
  - test/dummy/db/development.sqlite3
98
117
  - test/dummy/db/migrate/20130108201834_create_file_uploads.rb
@@ -106,10 +125,10 @@ files:
106
125
  - test/dummy/public/422.html
107
126
  - test/dummy/public/500.html
108
127
  - test/dummy/public/favicon.ico
109
- - test/dummy/public/uploads/files/default.txt
110
128
  - test/dummy/public/uploads/files/file.txt
111
- - test/dummy/public/uploads/images/original/default.jpg
129
+ - test/dummy/public/uploads/images/big/image.jpg
112
130
  - test/dummy/public/uploads/images/original/image.jpg
131
+ - test/dummy/public/uploads/images/small/image.jpg
113
132
  - test/dummy/Rakefile
114
133
  - test/dummy/README.rdoc
115
134
  - test/dummy/script/rails
@@ -119,22 +138,101 @@ files:
119
138
  - test/dummy/test/fixtures/image.jpg
120
139
  - test/dummy/test/fixtures/image_big.jpg
121
140
  - test/dummy/test/fixtures/image_empty.jpg
122
- - test/file_string_test.rb
123
- - test/file_upload_test.rb
141
+ - test/dummy/tmp/uploads/files/13687482983108968.jpg
142
+ - test/dummy/tmp/uploads/files/13687483348482658.jpg
143
+ - test/dummy/tmp/uploads/files/13687483563901100.jpg
144
+ - test/dummy/tmp/uploads/files/13687484108914220.jpg
145
+ - test/dummy/tmp/uploads/files/13687489381697390.jpg
146
+ - test/dummy/tmp/uploads/files/13687490968011022.jpg
147
+ - test/dummy/tmp/uploads/files/13687491524768450.jpg
148
+ - test/dummy/tmp/uploads/files/13687494425396302.jpg
149
+ - test/dummy/tmp/uploads/files/13687513450654020.jpg
150
+ - test/dummy/tmp/uploads/files/13687514839373922.txt
151
+ - test/dummy/tmp/uploads/files/13688181722986792.jpg
152
+ - test/dummy/tmp/uploads/files/13688181729459798.jpg
153
+ - test/dummy/tmp/uploads/images/big/13687484103672162.jpg
154
+ - test/dummy/tmp/uploads/images/big/13687484106303082.jpg
155
+ - test/dummy/tmp/uploads/images/big/13687489377129980.jpg
156
+ - test/dummy/tmp/uploads/images/big/13687489379459820.jpg
157
+ - test/dummy/tmp/uploads/images/big/13687490965463210.jpg
158
+ - test/dummy/tmp/uploads/images/big/13687491522552230.jpg
159
+ - test/dummy/tmp/uploads/images/big/13688181724596422.jpg
160
+ - test/dummy/tmp/uploads/images/big/13688181727051510.jpg
161
+ - test/dummy/tmp/uploads/images/big/13688259257147068.jpg
162
+ - test/dummy/tmp/uploads/images/big/13688280071286788.jpg
163
+ - test/dummy/tmp/uploads/images/big/13688281527981960.jpg
164
+ - test/dummy/tmp/uploads/images/big/13688360981527310.jpg
165
+ - test/dummy/tmp/uploads/images/big/13688360983686640.jpg
166
+ - test/dummy/tmp/uploads/images/big/13688977138132322.jpg
167
+ - test/dummy/tmp/uploads/images/big/13688977290079510.jpg
168
+ - test/dummy/tmp/uploads/images/big/13688978966174670.jpg
169
+ - test/dummy/tmp/uploads/images/original/13687482977916958.jpg
170
+ - test/dummy/tmp/uploads/images/original/13687482979328390.jpg
171
+ - test/dummy/tmp/uploads/images/original/13687482981277580.jpg
172
+ - test/dummy/tmp/uploads/images/original/13687483343313990.jpg
173
+ - test/dummy/tmp/uploads/images/original/13687483344710930.jpg
174
+ - test/dummy/tmp/uploads/images/original/13687483346647770.jpg
175
+ - test/dummy/tmp/uploads/images/original/13687483558679350.jpg
176
+ - test/dummy/tmp/uploads/images/original/13687483560070410.jpg
177
+ - test/dummy/tmp/uploads/images/original/13687483562001660.jpg
178
+ - test/dummy/tmp/uploads/images/original/13687484103672162.jpg
179
+ - test/dummy/tmp/uploads/images/original/13687484106303082.jpg
180
+ - test/dummy/tmp/uploads/images/original/13687489377129980.jpg
181
+ - test/dummy/tmp/uploads/images/original/13687489379459820.jpg
182
+ - test/dummy/tmp/uploads/images/original/13687490965463210.jpg
183
+ - test/dummy/tmp/uploads/images/original/13687491522552230.jpg
184
+ - test/dummy/tmp/uploads/images/original/13688181723027610.jpg
185
+ - test/dummy/tmp/uploads/images/original/13688181724596422.jpg
186
+ - test/dummy/tmp/uploads/images/original/13688181727051510.jpg
187
+ - test/dummy/tmp/uploads/images/original/13688259257147068.jpg
188
+ - test/dummy/tmp/uploads/images/original/13688280071286788.jpg
189
+ - test/dummy/tmp/uploads/images/original/13688281527981960.jpg
190
+ - test/dummy/tmp/uploads/images/original/13688360981527310.jpg
191
+ - test/dummy/tmp/uploads/images/original/13688360983686640.jpg
192
+ - test/dummy/tmp/uploads/images/original/13688977138132322.jpg
193
+ - test/dummy/tmp/uploads/images/original/13688977290079510.jpg
194
+ - test/dummy/tmp/uploads/images/original/13688978966174670.jpg
195
+ - test/dummy/tmp/uploads/images/small/13687484103672162.jpg
196
+ - test/dummy/tmp/uploads/images/small/13687484106303082.jpg
197
+ - test/dummy/tmp/uploads/images/small/13687489377129980.jpg
198
+ - test/dummy/tmp/uploads/images/small/13687489379459820.jpg
199
+ - test/dummy/tmp/uploads/images/small/13687490965463210.jpg
200
+ - test/dummy/tmp/uploads/images/small/13687491522552230.jpg
201
+ - test/dummy/tmp/uploads/images/small/13688181723027610.jpg
202
+ - test/dummy/tmp/uploads/images/small/13688181724596422.jpg
203
+ - test/dummy/tmp/uploads/images/small/13688181727051510.jpg
204
+ - test/dummy/tmp/uploads/images/small/13688259257147068.jpg
205
+ - test/dummy/tmp/uploads/images/small/13688280071286788.jpg
206
+ - test/dummy/tmp/uploads/images/small/13688281527981960.jpg
207
+ - test/dummy/tmp/uploads/images/small/13688360981527310.jpg
208
+ - test/dummy/tmp/uploads/images/small/13688360983686640.jpg
209
+ - test/dummy/tmp/uploads/images/small/13688977138132322.jpg
210
+ - test/dummy/tmp/uploads/images/small/13688977290079510.jpg
211
+ - test/dummy/tmp/uploads/images/small/13688978966174670.jpg
124
212
  - test/fixtures/file.txt
125
213
  - test/fixtures/file_big.txt
126
214
  - test/fixtures/file_empty.txt
127
215
  - test/fixtures/image.jpg
128
216
  - test/fixtures/image_big.jpg
129
217
  - test/fixtures/image_empty.jpg
130
- - test/generate_test.rb
131
- - test/image_presets_test.rb
132
- - test/image_string_test.rb
133
- - test/image_upload_test.rb
134
- - test/rails_uploads_test.rb
135
- - test/records_test.rb
218
+ - test/integration/local_generate_test.rb
136
219
  - test/test_helper.rb
137
- - test/validators_test.rb
220
+ - test/unit/local_file_record_test.rb
221
+ - test/unit/local_file_string_test.rb
222
+ - test/unit/local_file_upload_test.rb
223
+ - test/unit/local_image_record_test.rb
224
+ - test/unit/local_image_string_test.rb
225
+ - test/unit/local_image_upload_test.rb
226
+ - test/unit/local_records_test.rb
227
+ - test/unit/local_validators_test.rb
228
+ - test/unit/s3_file_record_tes.rb
229
+ - test/unit/s3_file_string_tes.rb
230
+ - test/unit/s3_file_upload_tes.rb
231
+ - test/unit/s3_image_record_tes.rb
232
+ - test/unit/s3_image_string_tes.rb
233
+ - test/unit/s3_image_upload_tes.rb
234
+ - test/unit/s3_records_tes.rb
235
+ - test/unit/s3_validators_tes.rb
138
236
  homepage: https://github.com/mattways/rails_uploads
139
237
  licenses: []
140
238
  post_install_message:
@@ -153,7 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
251
  - - ! '>='
154
252
  - !ruby/object:Gem::Version
155
253
  version: '0'
156
- requirements: []
254
+ requirements:
255
+ - ImageMagick
157
256
  rubyforge_project:
158
257
  rubygems_version: 1.8.23
159
258
  signing_key:
@@ -184,6 +283,7 @@ test_files:
184
283
  - test/dummy/config/initializers/wrap_parameters.rb
185
284
  - test/dummy/config/locales/en.yml
186
285
  - test/dummy/config/routes.rb
286
+ - test/dummy/config/s3.yml
187
287
  - test/dummy/config.ru
188
288
  - test/dummy/db/development.sqlite3
189
289
  - test/dummy/db/migrate/20130108201834_create_file_uploads.rb
@@ -197,10 +297,10 @@ test_files:
197
297
  - test/dummy/public/422.html
198
298
  - test/dummy/public/500.html
199
299
  - test/dummy/public/favicon.ico
200
- - test/dummy/public/uploads/files/default.txt
201
300
  - test/dummy/public/uploads/files/file.txt
202
- - test/dummy/public/uploads/images/original/default.jpg
301
+ - test/dummy/public/uploads/images/big/image.jpg
203
302
  - test/dummy/public/uploads/images/original/image.jpg
303
+ - test/dummy/public/uploads/images/small/image.jpg
204
304
  - test/dummy/Rakefile
205
305
  - test/dummy/README.rdoc
206
306
  - test/dummy/script/rails
@@ -210,19 +310,98 @@ test_files:
210
310
  - test/dummy/test/fixtures/image.jpg
211
311
  - test/dummy/test/fixtures/image_big.jpg
212
312
  - test/dummy/test/fixtures/image_empty.jpg
213
- - test/file_string_test.rb
214
- - test/file_upload_test.rb
313
+ - test/dummy/tmp/uploads/files/13687482983108968.jpg
314
+ - test/dummy/tmp/uploads/files/13687483348482658.jpg
315
+ - test/dummy/tmp/uploads/files/13687483563901100.jpg
316
+ - test/dummy/tmp/uploads/files/13687484108914220.jpg
317
+ - test/dummy/tmp/uploads/files/13687489381697390.jpg
318
+ - test/dummy/tmp/uploads/files/13687490968011022.jpg
319
+ - test/dummy/tmp/uploads/files/13687491524768450.jpg
320
+ - test/dummy/tmp/uploads/files/13687494425396302.jpg
321
+ - test/dummy/tmp/uploads/files/13687513450654020.jpg
322
+ - test/dummy/tmp/uploads/files/13687514839373922.txt
323
+ - test/dummy/tmp/uploads/files/13688181722986792.jpg
324
+ - test/dummy/tmp/uploads/files/13688181729459798.jpg
325
+ - test/dummy/tmp/uploads/images/big/13687484103672162.jpg
326
+ - test/dummy/tmp/uploads/images/big/13687484106303082.jpg
327
+ - test/dummy/tmp/uploads/images/big/13687489377129980.jpg
328
+ - test/dummy/tmp/uploads/images/big/13687489379459820.jpg
329
+ - test/dummy/tmp/uploads/images/big/13687490965463210.jpg
330
+ - test/dummy/tmp/uploads/images/big/13687491522552230.jpg
331
+ - test/dummy/tmp/uploads/images/big/13688181724596422.jpg
332
+ - test/dummy/tmp/uploads/images/big/13688181727051510.jpg
333
+ - test/dummy/tmp/uploads/images/big/13688259257147068.jpg
334
+ - test/dummy/tmp/uploads/images/big/13688280071286788.jpg
335
+ - test/dummy/tmp/uploads/images/big/13688281527981960.jpg
336
+ - test/dummy/tmp/uploads/images/big/13688360981527310.jpg
337
+ - test/dummy/tmp/uploads/images/big/13688360983686640.jpg
338
+ - test/dummy/tmp/uploads/images/big/13688977138132322.jpg
339
+ - test/dummy/tmp/uploads/images/big/13688977290079510.jpg
340
+ - test/dummy/tmp/uploads/images/big/13688978966174670.jpg
341
+ - test/dummy/tmp/uploads/images/original/13687482977916958.jpg
342
+ - test/dummy/tmp/uploads/images/original/13687482979328390.jpg
343
+ - test/dummy/tmp/uploads/images/original/13687482981277580.jpg
344
+ - test/dummy/tmp/uploads/images/original/13687483343313990.jpg
345
+ - test/dummy/tmp/uploads/images/original/13687483344710930.jpg
346
+ - test/dummy/tmp/uploads/images/original/13687483346647770.jpg
347
+ - test/dummy/tmp/uploads/images/original/13687483558679350.jpg
348
+ - test/dummy/tmp/uploads/images/original/13687483560070410.jpg
349
+ - test/dummy/tmp/uploads/images/original/13687483562001660.jpg
350
+ - test/dummy/tmp/uploads/images/original/13687484103672162.jpg
351
+ - test/dummy/tmp/uploads/images/original/13687484106303082.jpg
352
+ - test/dummy/tmp/uploads/images/original/13687489377129980.jpg
353
+ - test/dummy/tmp/uploads/images/original/13687489379459820.jpg
354
+ - test/dummy/tmp/uploads/images/original/13687490965463210.jpg
355
+ - test/dummy/tmp/uploads/images/original/13687491522552230.jpg
356
+ - test/dummy/tmp/uploads/images/original/13688181723027610.jpg
357
+ - test/dummy/tmp/uploads/images/original/13688181724596422.jpg
358
+ - test/dummy/tmp/uploads/images/original/13688181727051510.jpg
359
+ - test/dummy/tmp/uploads/images/original/13688259257147068.jpg
360
+ - test/dummy/tmp/uploads/images/original/13688280071286788.jpg
361
+ - test/dummy/tmp/uploads/images/original/13688281527981960.jpg
362
+ - test/dummy/tmp/uploads/images/original/13688360981527310.jpg
363
+ - test/dummy/tmp/uploads/images/original/13688360983686640.jpg
364
+ - test/dummy/tmp/uploads/images/original/13688977138132322.jpg
365
+ - test/dummy/tmp/uploads/images/original/13688977290079510.jpg
366
+ - test/dummy/tmp/uploads/images/original/13688978966174670.jpg
367
+ - test/dummy/tmp/uploads/images/small/13687484103672162.jpg
368
+ - test/dummy/tmp/uploads/images/small/13687484106303082.jpg
369
+ - test/dummy/tmp/uploads/images/small/13687489377129980.jpg
370
+ - test/dummy/tmp/uploads/images/small/13687489379459820.jpg
371
+ - test/dummy/tmp/uploads/images/small/13687490965463210.jpg
372
+ - test/dummy/tmp/uploads/images/small/13687491522552230.jpg
373
+ - test/dummy/tmp/uploads/images/small/13688181723027610.jpg
374
+ - test/dummy/tmp/uploads/images/small/13688181724596422.jpg
375
+ - test/dummy/tmp/uploads/images/small/13688181727051510.jpg
376
+ - test/dummy/tmp/uploads/images/small/13688259257147068.jpg
377
+ - test/dummy/tmp/uploads/images/small/13688280071286788.jpg
378
+ - test/dummy/tmp/uploads/images/small/13688281527981960.jpg
379
+ - test/dummy/tmp/uploads/images/small/13688360981527310.jpg
380
+ - test/dummy/tmp/uploads/images/small/13688360983686640.jpg
381
+ - test/dummy/tmp/uploads/images/small/13688977138132322.jpg
382
+ - test/dummy/tmp/uploads/images/small/13688977290079510.jpg
383
+ - test/dummy/tmp/uploads/images/small/13688978966174670.jpg
215
384
  - test/fixtures/file.txt
216
385
  - test/fixtures/file_big.txt
217
386
  - test/fixtures/file_empty.txt
218
387
  - test/fixtures/image.jpg
219
388
  - test/fixtures/image_big.jpg
220
389
  - test/fixtures/image_empty.jpg
221
- - test/generate_test.rb
222
- - test/image_presets_test.rb
223
- - test/image_string_test.rb
224
- - test/image_upload_test.rb
225
- - test/rails_uploads_test.rb
226
- - test/records_test.rb
390
+ - test/integration/local_generate_test.rb
227
391
  - test/test_helper.rb
228
- - test/validators_test.rb
392
+ - test/unit/local_file_record_test.rb
393
+ - test/unit/local_file_string_test.rb
394
+ - test/unit/local_file_upload_test.rb
395
+ - test/unit/local_image_record_test.rb
396
+ - test/unit/local_image_string_test.rb
397
+ - test/unit/local_image_upload_test.rb
398
+ - test/unit/local_records_test.rb
399
+ - test/unit/local_validators_test.rb
400
+ - test/unit/s3_file_record_tes.rb
401
+ - test/unit/s3_file_string_tes.rb
402
+ - test/unit/s3_file_upload_tes.rb
403
+ - test/unit/s3_image_record_tes.rb
404
+ - test/unit/s3_image_string_tes.rb
405
+ - test/unit/s3_image_upload_tes.rb
406
+ - test/unit/s3_records_tes.rb
407
+ - test/unit/s3_validators_tes.rb