rails_uploads 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. metadata +19 -371
  3. data/MIT-LICENSE +0 -20
  4. data/README.rdoc +0 -108
  5. data/Rakefile +0 -40
  6. data/app/controllers/rails_uploads/presets_controller.rb +0 -17
  7. data/config/locales/en.yml +0 -8
  8. data/config/locales/es.yml +0 -8
  9. data/config/routes.rb +0 -5
  10. data/lib/generators/uploads/s3/config_generator.rb +0 -13
  11. data/lib/generators/uploads/s3/templates/s3.yml +0 -16
  12. data/lib/rails_uploads.rb +0 -16
  13. data/lib/rails_uploads/active_record/base.rb +0 -139
  14. data/lib/rails_uploads/engine.rb +0 -7
  15. data/lib/rails_uploads/magick/image.rb +0 -83
  16. data/lib/rails_uploads/railtie.rb +0 -20
  17. data/lib/rails_uploads/storages/local.rb +0 -57
  18. data/lib/rails_uploads/storages/s3.rb +0 -68
  19. data/lib/rails_uploads/types/file.rb +0 -115
  20. data/lib/rails_uploads/types/image.rb +0 -45
  21. data/lib/rails_uploads/validators/attachment_content_type_validator.rb +0 -11
  22. data/lib/rails_uploads/validators/attachment_presence_validator.rb +0 -9
  23. data/lib/rails_uploads/validators/attachment_size_validator.rb +0 -27
  24. data/lib/rails_uploads/validators/base.rb +0 -13
  25. data/lib/rails_uploads/version.rb +0 -5
  26. data/lib/tasks/rails_uploads_tasks.rake +0 -89
  27. data/test/dummy/README.rdoc +0 -261
  28. data/test/dummy/Rakefile +0 -7
  29. data/test/dummy/app/assets/images/image.jpg +0 -0
  30. data/test/dummy/app/assets/javascripts/application.js +0 -15
  31. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  32. data/test/dummy/app/controllers/application_controller.rb +0 -3
  33. data/test/dummy/app/helpers/application_helper.rb +0 -2
  34. data/test/dummy/app/models/file_upload.rb +0 -4
  35. data/test/dummy/app/models/image_upload.rb +0 -4
  36. data/test/dummy/app/models/validation_upload.rb +0 -17
  37. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  38. data/test/dummy/config.ru +0 -4
  39. data/test/dummy/config/application.rb +0 -65
  40. data/test/dummy/config/boot.rb +0 -10
  41. data/test/dummy/config/database.yml +0 -25
  42. data/test/dummy/config/environment.rb +0 -5
  43. data/test/dummy/config/environments/development.rb +0 -37
  44. data/test/dummy/config/environments/production.rb +0 -67
  45. data/test/dummy/config/environments/test.rb +0 -37
  46. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  47. data/test/dummy/config/initializers/inflections.rb +0 -15
  48. data/test/dummy/config/initializers/mime_types.rb +0 -5
  49. data/test/dummy/config/initializers/secret_token.rb +0 -7
  50. data/test/dummy/config/initializers/session_store.rb +0 -8
  51. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  52. data/test/dummy/config/locales/en.yml +0 -5
  53. data/test/dummy/config/routes.rb +0 -5
  54. data/test/dummy/config/s3.yml +0 -15
  55. data/test/dummy/db/development.sqlite3 +0 -0
  56. data/test/dummy/db/migrate/20130108201834_create_file_uploads.rb +0 -10
  57. data/test/dummy/db/migrate/20130110194721_create_validation_uploads.rb +0 -19
  58. data/test/dummy/db/migrate/20130124013431_create_image_uploads.rb +0 -10
  59. data/test/dummy/db/schema.rb +0 -43
  60. data/test/dummy/db/test.sqlite3 +0 -0
  61. data/test/dummy/log/development.log +0 -23
  62. data/test/dummy/log/test.log +0 -25090
  63. data/test/dummy/public/404.html +0 -26
  64. data/test/dummy/public/422.html +0 -26
  65. data/test/dummy/public/500.html +0 -25
  66. data/test/dummy/public/favicon.ico +0 -0
  67. data/test/dummy/public/uploads/files/file.txt +0 -1
  68. data/test/dummy/public/uploads/images/big/image.jpg +0 -0
  69. data/test/dummy/public/uploads/images/original/image.jpg +0 -0
  70. data/test/dummy/public/uploads/images/small/image.jpg +0 -0
  71. data/test/dummy/script/rails +0 -6
  72. data/test/dummy/test/fixtures/file.txt +0 -1
  73. data/test/dummy/test/fixtures/file_big.txt +0 -1
  74. data/test/dummy/test/fixtures/file_empty.txt +0 -1
  75. data/test/dummy/test/fixtures/image.jpg +0 -0
  76. data/test/dummy/test/fixtures/image_big.jpg +0 -0
  77. data/test/dummy/test/fixtures/image_empty.jpg +0 -0
  78. data/test/dummy/tmp/uploads/files/13687482983108968.jpg +0 -0
  79. data/test/dummy/tmp/uploads/files/13687483348482658.jpg +0 -0
  80. data/test/dummy/tmp/uploads/files/13687483563901100.jpg +0 -0
  81. data/test/dummy/tmp/uploads/files/13687484108914220.jpg +0 -0
  82. data/test/dummy/tmp/uploads/files/13687489381697390.jpg +0 -0
  83. data/test/dummy/tmp/uploads/files/13687490968011022.jpg +0 -0
  84. data/test/dummy/tmp/uploads/files/13687491524768450.jpg +0 -0
  85. data/test/dummy/tmp/uploads/files/13687494425396302.jpg +0 -0
  86. data/test/dummy/tmp/uploads/files/13687513450654020.jpg +0 -0
  87. data/test/dummy/tmp/uploads/files/13687514839373922.txt +0 -1
  88. data/test/dummy/tmp/uploads/files/13688181722986792.jpg +0 -0
  89. data/test/dummy/tmp/uploads/files/13688181729459798.jpg +0 -0
  90. data/test/dummy/tmp/uploads/images/big/13687484103672162.jpg +0 -0
  91. data/test/dummy/tmp/uploads/images/big/13687484106303082.jpg +0 -0
  92. data/test/dummy/tmp/uploads/images/big/13687489377129980.jpg +0 -0
  93. data/test/dummy/tmp/uploads/images/big/13687489379459820.jpg +0 -0
  94. data/test/dummy/tmp/uploads/images/big/13687490965463210.jpg +0 -0
  95. data/test/dummy/tmp/uploads/images/big/13687491522552230.jpg +0 -0
  96. data/test/dummy/tmp/uploads/images/big/13688181724596422.jpg +0 -0
  97. data/test/dummy/tmp/uploads/images/big/13688181727051510.jpg +0 -0
  98. data/test/dummy/tmp/uploads/images/big/13688259257147068.jpg +0 -0
  99. data/test/dummy/tmp/uploads/images/big/13688280071286788.jpg +0 -0
  100. data/test/dummy/tmp/uploads/images/big/13688281527981960.jpg +0 -0
  101. data/test/dummy/tmp/uploads/images/big/13688360981527310.jpg +0 -0
  102. data/test/dummy/tmp/uploads/images/big/13688360983686640.jpg +0 -0
  103. data/test/dummy/tmp/uploads/images/big/13688977138132322.jpg +0 -0
  104. data/test/dummy/tmp/uploads/images/big/13688977290079510.jpg +0 -0
  105. data/test/dummy/tmp/uploads/images/big/13688978966174670.jpg +0 -0
  106. data/test/dummy/tmp/uploads/images/original/13687482977916958.jpg +0 -0
  107. data/test/dummy/tmp/uploads/images/original/13687482979328390.jpg +0 -0
  108. data/test/dummy/tmp/uploads/images/original/13687482981277580.jpg +0 -0
  109. data/test/dummy/tmp/uploads/images/original/13687483343313990.jpg +0 -0
  110. data/test/dummy/tmp/uploads/images/original/13687483344710930.jpg +0 -0
  111. data/test/dummy/tmp/uploads/images/original/13687483346647770.jpg +0 -0
  112. data/test/dummy/tmp/uploads/images/original/13687483558679350.jpg +0 -0
  113. data/test/dummy/tmp/uploads/images/original/13687483560070410.jpg +0 -0
  114. data/test/dummy/tmp/uploads/images/original/13687483562001660.jpg +0 -0
  115. data/test/dummy/tmp/uploads/images/original/13687484103672162.jpg +0 -0
  116. data/test/dummy/tmp/uploads/images/original/13687484106303082.jpg +0 -0
  117. data/test/dummy/tmp/uploads/images/original/13687489377129980.jpg +0 -0
  118. data/test/dummy/tmp/uploads/images/original/13687489379459820.jpg +0 -0
  119. data/test/dummy/tmp/uploads/images/original/13687490965463210.jpg +0 -0
  120. data/test/dummy/tmp/uploads/images/original/13687491522552230.jpg +0 -0
  121. data/test/dummy/tmp/uploads/images/original/13688181723027610.jpg +0 -0
  122. data/test/dummy/tmp/uploads/images/original/13688181724596422.jpg +0 -0
  123. data/test/dummy/tmp/uploads/images/original/13688181727051510.jpg +0 -0
  124. data/test/dummy/tmp/uploads/images/original/13688259257147068.jpg +0 -0
  125. data/test/dummy/tmp/uploads/images/original/13688280071286788.jpg +0 -0
  126. data/test/dummy/tmp/uploads/images/original/13688281527981960.jpg +0 -0
  127. data/test/dummy/tmp/uploads/images/original/13688360981527310.jpg +0 -0
  128. data/test/dummy/tmp/uploads/images/original/13688360983686640.jpg +0 -0
  129. data/test/dummy/tmp/uploads/images/original/13688977138132322.jpg +0 -0
  130. data/test/dummy/tmp/uploads/images/original/13688977290079510.jpg +0 -0
  131. data/test/dummy/tmp/uploads/images/original/13688978966174670.jpg +0 -0
  132. data/test/dummy/tmp/uploads/images/small/13687484103672162.jpg +0 -0
  133. data/test/dummy/tmp/uploads/images/small/13687484106303082.jpg +0 -0
  134. data/test/dummy/tmp/uploads/images/small/13687489377129980.jpg +0 -0
  135. data/test/dummy/tmp/uploads/images/small/13687489379459820.jpg +0 -0
  136. data/test/dummy/tmp/uploads/images/small/13687490965463210.jpg +0 -0
  137. data/test/dummy/tmp/uploads/images/small/13687491522552230.jpg +0 -0
  138. data/test/dummy/tmp/uploads/images/small/13688181723027610.jpg +0 -0
  139. data/test/dummy/tmp/uploads/images/small/13688181724596422.jpg +0 -0
  140. data/test/dummy/tmp/uploads/images/small/13688181727051510.jpg +0 -0
  141. data/test/dummy/tmp/uploads/images/small/13688259257147068.jpg +0 -0
  142. data/test/dummy/tmp/uploads/images/small/13688280071286788.jpg +0 -0
  143. data/test/dummy/tmp/uploads/images/small/13688281527981960.jpg +0 -0
  144. data/test/dummy/tmp/uploads/images/small/13688360981527310.jpg +0 -0
  145. data/test/dummy/tmp/uploads/images/small/13688360983686640.jpg +0 -0
  146. data/test/dummy/tmp/uploads/images/small/13688977138132322.jpg +0 -0
  147. data/test/dummy/tmp/uploads/images/small/13688977290079510.jpg +0 -0
  148. data/test/dummy/tmp/uploads/images/small/13688978966174670.jpg +0 -0
  149. data/test/fixtures/file.txt +0 -1
  150. data/test/fixtures/file_big.txt +0 -1
  151. data/test/fixtures/file_empty.txt +0 -1
  152. data/test/fixtures/image.jpg +0 -0
  153. data/test/fixtures/image_big.jpg +0 -0
  154. data/test/fixtures/image_empty.jpg +0 -0
  155. data/test/integration/local_generate_test.rb +0 -25
  156. data/test/test_helper.rb +0 -50
  157. data/test/unit/local_file_record_test.rb +0 -20
  158. data/test/unit/local_file_string_test.rb +0 -23
  159. data/test/unit/local_file_upload_test.rb +0 -30
  160. data/test/unit/local_image_record_test.rb +0 -25
  161. data/test/unit/local_image_string_test.rb +0 -34
  162. data/test/unit/local_image_upload_test.rb +0 -27
  163. data/test/unit/local_records_test.rb +0 -52
  164. data/test/unit/local_validators_test.rb +0 -71
  165. data/test/unit/s3_file_record_tes.rb +0 -21
  166. data/test/unit/s3_file_string_tes.rb +0 -24
  167. data/test/unit/s3_file_upload_tes.rb +0 -31
  168. data/test/unit/s3_image_record_tes.rb +0 -26
  169. data/test/unit/s3_image_string_tes.rb +0 -31
  170. data/test/unit/s3_image_upload_tes.rb +0 -28
  171. data/test/unit/s3_records_tes.rb +0 -56
  172. data/test/unit/s3_validators_tes.rb +0 -71
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImagePresetsTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- @record = ImageUpload.create(:image => fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- end
8
-
9
- test "should save/destory main image and thumbs" do
10
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @record.image.filename)
11
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @record.image.filename)
12
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @record.image.filename)
13
-
14
- assert ::File.exists?(original)
15
- assert ::File.exists?(big)
16
- assert ::File.exists?(small)
17
-
18
- @record.destroy
19
-
20
- assert !::File.exists?(original)
21
- assert !::File.exists?(big)
22
- assert !::File.exists?(small)
23
- end
24
-
25
- end
@@ -1,34 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImageStringTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'original')
7
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'big')
8
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'small')
9
- filename = 'image.jpg'
10
- fixture = fixture_file_upload("/#{filename}", 'image/jpeg')
11
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'original', filename)
12
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'big', filename)
13
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'small', filename)
14
- options = { :presets => [:small, :big] }
15
- @image = RailsUploads::Types::Image.new(filename, options)
16
- end
17
-
18
- test "should destory main image and thumbs" do
19
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
20
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
21
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
22
-
23
- assert ::File.exists?(original)
24
- assert ::File.exists?(big)
25
- assert ::File.exists?(small)
26
-
27
- @image.delete
28
-
29
- assert !::File.exists?(original)
30
- assert !::File.exists?(big)
31
- assert !::File.exists?(small)
32
- end
33
-
34
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImageUploadTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- options = { :presets => [:small, :big] }
7
- @image = RailsUploads::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'), options)
8
- @image.store
9
- end
10
-
11
- test "should save/destory main image and thumbs" do
12
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
13
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
14
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
15
-
16
- assert ::File.exists?(original)
17
- assert ::File.exists?(big)
18
- assert ::File.exists?(small)
19
-
20
- @image.delete
21
-
22
- assert !::File.exists?(original)
23
- assert !::File.exists?(big)
24
- assert !::File.exists?(small)
25
- end
26
-
27
- end
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalRecordsTest < ActiveSupport::TestCase
4
-
5
- test "should save/update/destroy from the database and save/destroy the file" do
6
- record = FileUpload.create(:file => fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- image_filename = record.file.filename
8
- image_path = Rails.root.join('tmp', 'uploads', 'files', image_filename)
9
- assert ::File.exists?(image_path)
10
-
11
- record.update_attributes :file => fixture_file_upload('/file.txt', 'text/plain')
12
- file_filename = record.file.filename
13
- assert_not_equal image_filename, file_filename
14
- file_path = Rails.root.join('tmp', 'uploads', 'files', file_filename)
15
- assert !::File.exists?(image_path)
16
- assert ::File.exists?(file_path)
17
-
18
- record.destroy
19
- assert !::File.exists?(file_path)
20
- end
21
-
22
- test "should take default file/image and shouldn't store/delete it" do
23
- record = FileUpload.create
24
- file_filename = 'file.txt'
25
- assert_equal ::File.join('uploads', 'files', file_filename), record.file.path
26
- file_realpath = Rails.root.join('public', 'uploads', 'files', file_filename)
27
- assert ::File.exists?(file_realpath)
28
-
29
- record.destroy
30
- assert record.file.exists?
31
- assert ::File.exists?(file_realpath)
32
-
33
- record = ImageUpload.create
34
- image_filename = 'image.jpg'
35
- assert_equal ::File.join('uploads', 'images', 'original', 'image.jpg'), record.image.path
36
- image_original_realpath = Rails.root.join('public', 'uploads', 'images', 'original', image_filename)
37
- assert ::File.exists?(image_original_realpath)
38
- assert_equal ::File.join('uploads', 'images', 'small', 'image.jpg'), record.image.path(:small)
39
- image_small_realpath = Rails.root.join('public', 'uploads', 'images', 'small', image_filename)
40
- assert ::File.exists?(image_small_realpath)
41
- assert_equal ::File.join('uploads', 'images', 'big', 'image.jpg'), record.image.path(:big)
42
- image_big_realpath = Rails.root.join('public', 'uploads', 'images', 'big', image_filename)
43
- assert ::File.exists?(image_big_realpath)
44
-
45
- record.destroy
46
- assert record.image.exists?
47
- assert ::File.exists?(image_original_realpath)
48
- assert ::File.exists?(image_small_realpath)
49
- assert ::File.exists?(image_big_realpath)
50
- end
51
-
52
- end
@@ -1,71 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalValidatorsTest < ActiveSupport::TestCase
4
- include ActionView::Helpers::NumberHelper
5
-
6
- setup do
7
- @record = ValidationUpload.new
8
- end
9
-
10
- test "should check if file is present" do
11
- assert !@record.valid?
12
- assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
13
-
14
- @record.image_presence = fixture_file_upload('/image.jpg', 'image/jpeg')
15
- assert !@record.valid?
16
- assert_equal [], @record.errors[:image_presence]
17
- end
18
-
19
- test "should check the file content type" do
20
- @record.image_content_type = fixture_file_upload('/file.txt', 'text/plain')
21
- assert !@record.valid?
22
- assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'jpg')], @record.errors[:image_content_type]
23
-
24
- @record.file_content_type = fixture_file_upload('/image.jpg', 'image/jpeg')
25
- assert !@record.valid?
26
- assert_equal [I18n.t('errors.messages.attachment_content_type', :types => 'txt')], @record.errors[:file_content_type]
27
- end
28
-
29
- test "should check the file size" do
30
- @record.file_size = fixture_file_upload('/file_big.txt', 'text/plain')
31
- assert !@record.valid?
32
- assert_equal [I18n.t('errors.messages.attachment_size_less_than', :count => number_to_human_size(15.kilobytes))], @record.errors[:file_size]
33
-
34
- @record.file_size = fixture_file_upload('/file_empty.txt', 'text/plain')
35
- assert !@record.valid?
36
- assert_equal [I18n.t('errors.messages.attachment_size_greater_than', :count => number_to_human_size(10.bytes))], @record.errors[:file_size]
37
-
38
- @record.file_size = fixture_file_upload('/file.txt', 'text/plain')
39
- assert !@record.valid?
40
- assert_equal [], @record.errors[:file_size]
41
-
42
- @record.image_size = fixture_file_upload('/image_big.jpg', 'image/jpeg')
43
- assert !@record.valid?
44
- assert_equal [I18n.t('errors.messages.attachment_size_in', :min => number_to_human_size(2.kilobytes), :max => number_to_human_size(60.kilobytes))], @record.errors[:image_size]
45
-
46
- @record.image_size = fixture_file_upload('/image_empty.jpg', 'image/jpeg')
47
- assert !@record.valid?
48
- assert_equal [I18n.t('errors.messages.attachment_size_in', :min => number_to_human_size(2.kilobytes), :max => number_to_human_size(60.kilobytes))], @record.errors[:image_size]
49
-
50
- @record.image_size = fixture_file_upload('/image.jpg', 'image/jpeg')
51
- assert !@record.valid?
52
- assert_equal [], @record.errors[:image_size]
53
- end
54
-
55
- test "should check all the validations together" do
56
- @record.file_all = fixture_file_upload('/file.txt', 'text/plain')
57
- assert !@record.valid?
58
- assert_equal [], @record.errors[:file_all]
59
-
60
- @record.image_all = fixture_file_upload('/image.jpg', 'image/jpeg')
61
- assert !@record.valid?
62
- assert_equal [], @record.errors[:image_all]
63
-
64
- assert !@record.valid?
65
- assert_equal [I18n.t('errors.messages.blank')], @record.errors[:file_default]
66
-
67
- assert !@record.valid?
68
- assert_equal [I18n.t('errors.messages.blank')], @record.errors[:image_default]
69
- end
70
-
71
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3FileRecordTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- @record = FileUpload.create(:file => fixture_file_upload('/file.txt', 'text/plain'))
8
- end
9
-
10
- test "should maintain properties and delete correctly" do
11
- assert @record.file.exists?
12
- assert_equal 11, @record.file.size
13
- assert_equal '.txt', @record.file.extname
14
-
15
- uploads_url = @record.file.url
16
- @record.destroy
17
- assert_not_object_s3 uploads_url
18
- assert !@record.file.exists?
19
- end
20
-
21
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3FileStringTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- filename = 'file.txt'
8
- fixture_file_upload_s3 "/#{filename}", 'text/plain', ::File.join('uploads', 'files', filename)
9
- @file = RailsUploads::Types::File.new(filename)
10
- end
11
-
12
- test "should maintain properties and delete correctly" do
13
- assert @file.exists?
14
- assert_equal 11, @file.size
15
- assert_equal '.txt', @file.extname
16
- assert_equal ::File.join('uploads', 'files', @file.filename), @file.path
17
-
18
- uploads_url = @file.url
19
- @file.delete
20
- assert_not_object_s3 uploads_url
21
- assert !@file.exists?
22
- end
23
-
24
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3FileUploadTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- @file = RailsUploads::Types::File.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
8
- end
9
-
10
- test "file should exists and mantain properties" do
11
- assert @file.exists?
12
- assert_equal 58841, @file.size
13
- assert_equal '.jpg', @file.extname
14
- end
15
-
16
- test "should store/delete file correctly and accept cdn" do
17
- @file.store
18
- uploads_url = @file.url
19
- assert_object_s3 uploads_url
20
-
21
- base_url = 'http://cdn.example.com'
22
- Rails.application.config.uploads.base_url = base_url
23
- assert_equal ::File.join(base_url, @file.path), @file.url
24
- Rails.application.config.uploads.base_url = ''
25
-
26
- @file.delete
27
- assert_not_object_s3 uploads_url
28
- assert !@file.exists?
29
- end
30
-
31
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3ImageRecordTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- @record = ImageUpload.create(:image => fixture_file_upload('/image.jpg', 'image/jpeg'))
8
- end
9
-
10
- test "should save/destory main image and thumbs" do
11
- original = @record.image.url
12
- big = @record.image.url(:big)
13
- small = @record.image.url(:small)
14
-
15
- assert_object_s3 original
16
- assert_object_s3 big
17
- assert_object_s3 small
18
-
19
- @record.destroy
20
-
21
- assert_not_object_s3 original
22
- assert_not_object_s3 big
23
- assert_not_object_s3 small
24
- end
25
-
26
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3ImageStringTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- filename = 'image.jpg'
8
- fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'original', filename)
9
- fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'big', filename)
10
- fixture_file_upload_s3 "/#{filename}", 'image/jpeg', ::File.join('uploads', 'images', 'small', filename)
11
- options = { :presets => [:small, :big] }
12
- @image = RailsUploads::Types::Image.new(filename, options)
13
- end
14
-
15
- test "should save/destory main image and thumbs" do
16
- original = @image.url
17
- big = @image.url(:big)
18
- small = @image.url(:small)
19
-
20
- assert_object_s3 original
21
- assert_object_s3 big
22
- assert_object_s3 small
23
-
24
- @image.delete
25
-
26
- assert_not_object_s3 original
27
- assert_not_object_s3 big
28
- assert_not_object_s3 small
29
- end
30
-
31
- end
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3ImageUploadTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- options = { :presets => [:small, :big] }
8
- @image = RailsUploads::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'), options)
9
- @image.store
10
- end
11
-
12
- test "should save/destory main image and thumbs" do
13
- original = @image.url
14
- big = @image.url(:big)
15
- small = @image.url(:small)
16
-
17
- assert_object_s3 original
18
- assert_object_s3 big
19
- assert_object_s3 small
20
-
21
- @image.delete
22
-
23
- assert_not_object_s3 original
24
- assert_not_object_s3 big
25
- assert_not_object_s3 small
26
- end
27
-
28
- end
@@ -1,56 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3RecordsTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- end
8
-
9
- test "should save/update/destroy from the database and save/destroy the file" do
10
- record = FileUpload.create(:file => fixture_file_upload('/image.jpg', 'image/jpeg'))
11
- image_filename = record.file.filename
12
- image_url = record.file.url
13
- assert_object_s3 image_url
14
-
15
- record.update_attributes :file => fixture_file_upload('/file.txt', 'text/plain')
16
- file_filename = record.file.filename
17
- assert_not_equal image_filename, file_filename
18
- file_url = record.file.url
19
- assert_not_object_s3 image_url
20
- assert_object_s3 file_url
21
-
22
- record.destroy
23
- assert_not_object_s3 file_url
24
- end
25
-
26
- test "should take default file/image and shouldn't store/delete it" do
27
- record = FileUpload.create
28
- file_filename = 'file.txt'
29
- assert_equal ::File.join('uploads', 'files', file_filename), record.file.path
30
- file_url = record.file.url
31
- assert_object_s3 file_url
32
-
33
- record.destroy
34
- assert record.file.exists?
35
- assert_object_s3 file_url
36
-
37
- record = ImageUpload.create
38
- image_filename = 'image.jpg'
39
- assert_equal ::File.join('uploads', 'images', 'original', image_filename), record.image.path
40
- image_original_url = record.image.url
41
- assert_object_s3 image_original_url
42
- assert_equal ::File.join('uploads', 'images', 'small', image_filename), record.image.path(:small)
43
- image_small_url = record.image.url(:small)
44
- assert_object_s3 image_small_url
45
- assert_equal ::File.join('uploads', 'images', 'big', image_filename), record.image.path(:big)
46
- image_big_url = record.image.url(:big)
47
- assert_object_s3 image_big_url
48
-
49
- record.destroy
50
- assert record.image.exists?
51
- assert_object_s3 image_original_url
52
- assert_object_s3 image_small_url
53
- assert_object_s3 image_big_url
54
- end
55
-
56
- end