attachs 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +254 -0
  4. data/Rakefile +0 -2
  5. data/lib/attachs.rb +37 -10
  6. data/lib/attachs/active_record/base.rb +58 -95
  7. data/lib/attachs/active_record/connection_adapters.rb +40 -0
  8. data/lib/attachs/active_record/migration.rb +17 -0
  9. data/lib/attachs/active_record/validators.rb +7 -0
  10. data/lib/attachs/active_record/validators/attachment_content_type_validator.rb +30 -0
  11. data/lib/attachs/active_record/validators/attachment_presence_validator.rb +22 -0
  12. data/lib/attachs/active_record/validators/attachment_size_validator.rb +39 -0
  13. data/lib/attachs/attachment.rb +114 -0
  14. data/{config → lib/attachs}/locales/en.yml +2 -1
  15. data/{config → lib/attachs}/locales/es.yml +2 -1
  16. data/lib/attachs/railtie.rb +31 -11
  17. data/lib/attachs/storages/base.rb +68 -0
  18. data/lib/attachs/storages/local.rb +61 -37
  19. data/lib/attachs/storages/s3.rb +66 -57
  20. data/lib/attachs/tools/magick.rb +52 -0
  21. data/lib/attachs/types/base.rb +22 -0
  22. data/lib/attachs/types/default.rb +21 -0
  23. data/lib/attachs/types/regular.rb +21 -0
  24. data/lib/attachs/version.rb +1 -1
  25. data/lib/generators/attachs/install_generator.rb +13 -0
  26. data/lib/generators/attachs/templates/attachs.rb +2 -0
  27. data/lib/tasks/attachs.rake +30 -0
  28. data/test/attachment_test.rb +19 -0
  29. data/test/dummy/app/models/medium.rb +5 -0
  30. data/test/dummy/app/models/picture.rb +2 -0
  31. data/test/dummy/config/application.rb +1 -7
  32. data/test/dummy/config/initializers/attachs.rb +25 -0
  33. data/test/dummy/config/initializers/secret_token.rb +1 -0
  34. data/test/dummy/config/routes.rb +0 -1
  35. data/test/dummy/db/migrate/20140808012639_create_media.rb +11 -0
  36. data/test/dummy/db/schema.rb +14 -25
  37. data/test/dummy/log/development.log +9 -27
  38. data/test/dummy/log/test.log +52130 -11207
  39. data/test/dummy/test/fixtures/180x150.gif +0 -0
  40. data/test/generator_test.rb +18 -0
  41. data/test/local_storage_test.rb +57 -0
  42. data/test/magick_tool_test.rb +42 -0
  43. data/test/migration_test.rb +65 -0
  44. data/test/s3_storage_tes.rb +56 -0
  45. data/test/tasks_test.rb +61 -0
  46. data/test/test_helper.rb +17 -17
  47. data/test/validators_test.rb +100 -0
  48. metadata +85 -120
  49. data/README.rdoc +0 -104
  50. data/app/controllers/attachs/presets_controller.rb +0 -17
  51. data/config/routes.rb +0 -5
  52. data/lib/attachs/engine.rb +0 -7
  53. data/lib/attachs/magick/image.rb +0 -85
  54. data/lib/attachs/types/file.rb +0 -131
  55. data/lib/attachs/types/image.rb +0 -58
  56. data/lib/attachs/validators/attachment_content_type_validator.rb +0 -11
  57. data/lib/attachs/validators/attachment_presence_validator.rb +0 -9
  58. data/lib/attachs/validators/attachment_size_validator.rb +0 -21
  59. data/lib/attachs/validators/base.rb +0 -13
  60. data/lib/generators/attachs/s3/config_generator.rb +0 -13
  61. data/lib/generators/attachs/s3/templates/s3.yml +0 -16
  62. data/lib/tasks/attachs_tasks.rake +0 -71
  63. data/test/dummy/app/models/all_attached.rb +0 -16
  64. data/test/dummy/app/models/file_attached.rb +0 -3
  65. data/test/dummy/app/models/image_attached.rb +0 -3
  66. data/test/dummy/app/models/private_file_attached.rb +0 -3
  67. data/test/dummy/app/models/private_image_attached.rb +0 -3
  68. data/test/dummy/db/migrate/20130820222342_create_file_attacheds.rb +0 -9
  69. data/test/dummy/db/migrate/20130820222355_create_image_attacheds.rb +0 -9
  70. data/test/dummy/db/migrate/20130820222534_create_all_attacheds.rb +0 -19
  71. data/test/dummy/public/uploads/files/file.txt +0 -1
  72. data/test/dummy/public/uploads/images/big/image.jpg +0 -0
  73. data/test/dummy/public/uploads/images/original/image.jpg +0 -0
  74. data/test/dummy/public/uploads/images/small/image.jpg +0 -0
  75. data/test/dummy/test/fixtures/file_big.txt +0 -1
  76. data/test/dummy/test/fixtures/file_empty.txt +0 -1
  77. data/test/dummy/test/fixtures/image.jpg +0 -0
  78. data/test/dummy/test/fixtures/image_big.jpg +0 -0
  79. data/test/dummy/test/fixtures/image_empty.jpg +0 -0
  80. data/test/dummy/tmp/uploads/files/13898788260004868.txt +0 -1
  81. data/test/local_file_record_test.rb +0 -31
  82. data/test/local_file_string_test.rb +0 -23
  83. data/test/local_file_upload_test.rb +0 -30
  84. data/test/local_generate_test.rb +0 -25
  85. data/test/local_image_record_test.rb +0 -25
  86. data/test/local_image_string_test.rb +0 -34
  87. data/test/local_image_upload_test.rb +0 -27
  88. data/test/local_records_test.rb +0 -52
  89. data/test/local_validators_test.rb +0 -71
  90. data/test/s3_file_record_tes.rb +0 -21
  91. data/test/s3_file_string_tes.rb +0 -24
  92. data/test/s3_file_upload_tes.rb +0 -31
  93. data/test/s3_image_record_tes.rb +0 -26
  94. data/test/s3_image_string_tes.rb +0 -31
  95. data/test/s3_image_upload_tes.rb +0 -28
  96. data/test/s3_records_tes.rb +0 -56
  97. data/test/s3_validators_tes.rb +0 -72
@@ -1,16 +0,0 @@
1
- class AllAttached < ActiveRecord::Base
2
- has_attached_file :file_presence, :file_content_type, :file_size, :file_all
3
- has_attached_file :file_default, default: 'file.txt'
4
- has_attached_image :image_presence, :image_content_type, :image_size, :image_all, presets: :big
5
- has_attached_image :image_default, presets: [:big, :small], default: 'image.jpg'
6
- validates :file_presence, attachment_presence: true
7
- validates :file_content_type, attachment_content_type: { in: ['txt'] }
8
- validates :file_size, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
9
- validates :file_all, attachment_presence: true, attachment_content_type: { in: ['txt'] }, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
10
- validates :file_default, attachment_presence: true, attachment_content_type: { in: ['txt'] }, attachment_size: { less_than: 15.kilobytes, greater_than: 10.bytes }
11
- validates :image_presence, attachment_presence: true
12
- validates :image_content_type, attachment_content_type: { in: ['jpg'] }
13
- validates :image_size, attachment_size: { in: 2.kilobytes..60.kilobytes }
14
- validates :image_all, attachment_presence: true, attachment_content_type: { in: ['jpg'] }, attachment_size: { in: 2.kilobytes..60.kilobytes }
15
- validates :image_default, attachment_presence: true, attachment_content_type: { in: ['jpg'] }, attachment_size: { in: 2.kilobytes..60.kilobytes }
16
- end
@@ -1,3 +0,0 @@
1
- class FileAttached < ActiveRecord::Base
2
- has_attached_file :file, default: 'file.txt'
3
- end
@@ -1,3 +0,0 @@
1
- class ImageAttached < ActiveRecord::Base
2
- has_attached_image :image, presets: [:small, :big], default: 'image.jpg'
3
- end
@@ -1,3 +0,0 @@
1
- class PrivateFileAttached < ActiveRecord::Base
2
- has_attached_file :file, default: 'file.txt', private: true
3
- end
@@ -1,3 +0,0 @@
1
- class PrivateImageAttached < ActiveRecord::Base
2
- has_attached_image :image, presets: [:small, :big], default: 'image.jpg', private: true
3
- end
@@ -1,9 +0,0 @@
1
- class CreateFileAttacheds < ActiveRecord::Migration
2
- def change
3
- create_table :file_attacheds do |t|
4
- t.string :file
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class CreateImageAttacheds < ActiveRecord::Migration
2
- def change
3
- create_table :image_attacheds do |t|
4
- t.string :image
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,19 +0,0 @@
1
- class CreateAllAttacheds < ActiveRecord::Migration
2
- def change
3
- create_table :all_attacheds do |t|
4
- t.string :image
5
- t.string :file_presence
6
- t.string :file_content_type
7
- t.string :file_size
8
- t.string :file_all
9
- t.string :file_default
10
- t.string :image_presence
11
- t.string :image_content_type
12
- t.string :image_size
13
- t.string :image_all
14
- t.string :image_default
15
-
16
- t.timestamps
17
- end
18
- end
19
- end
@@ -1 +0,0 @@
1
- 1234567890
@@ -1 +0,0 @@
1
- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
@@ -1 +0,0 @@
1
-
Binary file
Binary file
@@ -1 +0,0 @@
1
- 1234567890
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalFileRecordTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- @record = FileAttached.create(file: fixture_file_upload('/file.txt', 'text/plain'))
7
- end
8
-
9
- test "should maintain properties and delete correctly" do
10
- assert @record.file.exists?
11
- assert_equal 11, @record.file.size
12
- assert_equal '.txt', @record.file.extname
13
-
14
- uploads_path = Rails.root.join('tmp', 'uploads', 'files', @record.file.filename)
15
- @record.destroy
16
- assert !::File.exists?(uploads_path)
17
- assert !@record.file.exists?
18
- end
19
-
20
- test "should delete correctly using delete_attr method" do
21
- uploads_path = Rails.root.join('tmp', 'uploads', 'files', @record.file.filename)
22
-
23
- @record.delete_file = '1'
24
- assert @record.file_changed?
25
-
26
- @record.save
27
- assert !::File.exists?(uploads_path)
28
- assert !@record.file.exists?
29
- end
30
-
31
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalFileStringTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'files')
7
- filename = 'file.txt'
8
- FileUtils.cp fixture_file_upload("/#{filename}", 'text/plain'), Rails.root.join('tmp', 'uploads', 'files', filename)
9
- @file = Attachs::Types::File.new(filename)
10
- end
11
-
12
- test "should maintain properties and delete correctly" do
13
- assert @file.exists?
14
- assert_equal 11, @file.size
15
- assert_equal '.txt', @file.extname
16
-
17
- uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename)
18
- @file.delete
19
- assert !::File.exists?(uploads_path)
20
- assert !@file.exists?
21
- end
22
-
23
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalFileUploadTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- @file = Attachs::Types::File.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- end
8
-
9
- test "file should exists and mantain properties" do
10
- assert @file.exists?
11
- assert_equal 58841, @file.size
12
- assert_equal '.jpg', @file.extname
13
- end
14
-
15
- test "should store/delete file correctly and accept cdn" do
16
- @file.store
17
- uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename)
18
- assert ::File.exists?(uploads_path)
19
-
20
- base_url = 'http://cdn.example.com'
21
- Rails.application.config.attachs.base_url = base_url
22
- assert_equal ::File.join(base_url, @file.path), @file.url
23
- Rails.application.config.attachs.base_url = ''
24
-
25
- @file.delete
26
- assert !::File.exists?(uploads_path)
27
- assert !@file.exists?
28
- end
29
-
30
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalGenerateTest < ActionDispatch::IntegrationTest
4
-
5
- setup do
6
- @image = Attachs::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- @image.store
8
- end
9
-
10
- teardown do
11
- @image.delete
12
- end
13
-
14
- test "should generate preset" do
15
- realpath = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
16
- ::File.delete realpath
17
-
18
- path = ::File.join('', 'uploads', 'images', 'small', @image.filename)
19
- get path
20
- assert_redirected_to path
21
-
22
- assert ::File.exists?(realpath)
23
- end
24
-
25
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImagePresetsTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- @record = ImageAttached.create(image: fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- end
8
-
9
- test "should save/destory main image and thumbs" do
10
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @record.image.filename)
11
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @record.image.filename)
12
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @record.image.filename)
13
-
14
- assert ::File.exists?(original)
15
- assert ::File.exists?(big)
16
- assert ::File.exists?(small)
17
-
18
- @record.destroy
19
-
20
- assert !::File.exists?(original)
21
- assert !::File.exists?(big)
22
- assert !::File.exists?(small)
23
- end
24
-
25
- end
@@ -1,34 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImageStringTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'original')
7
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'big')
8
- FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'small')
9
- filename = 'image.jpg'
10
- fixture = fixture_file_upload("/#{filename}", 'image/jpeg')
11
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'original', filename)
12
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'big', filename)
13
- FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'small', filename)
14
- options = { presets: [:small, :big] }
15
- @image = Attachs::Types::Image.new(filename, options)
16
- end
17
-
18
- test "should destory main image and thumbs" do
19
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
20
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
21
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
22
-
23
- assert ::File.exists?(original)
24
- assert ::File.exists?(big)
25
- assert ::File.exists?(small)
26
-
27
- @image.delete
28
-
29
- assert !::File.exists?(original)
30
- assert !::File.exists?(big)
31
- assert !::File.exists?(small)
32
- end
33
-
34
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalImageUploadTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- options = { presets: [:small, :big] }
7
- @image = Attachs::Types::Image.new(fixture_file_upload('/image.jpg', 'image/jpeg'), options)
8
- @image.store
9
- end
10
-
11
- test "should save/destory main image and thumbs" do
12
- original = Rails.root.join('tmp', 'uploads', 'images', 'original', @image.filename)
13
- big = Rails.root.join('tmp', 'uploads', 'images', 'big', @image.filename)
14
- small = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
15
-
16
- assert ::File.exists?(original)
17
- assert ::File.exists?(big)
18
- assert ::File.exists?(small)
19
-
20
- @image.delete
21
-
22
- assert !::File.exists?(original)
23
- assert !::File.exists?(big)
24
- assert !::File.exists?(small)
25
- end
26
-
27
- end
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalRecordsTest < ActiveSupport::TestCase
4
-
5
- test "should save/update/destroy from the database and save/destroy the file" do
6
- record = FileAttached.create(file: fixture_file_upload('/image.jpg', 'image/jpeg'))
7
- image_filename = record.file.filename
8
- image_path = Rails.root.join('tmp', 'uploads', 'files', image_filename)
9
- assert ::File.exists?(image_path)
10
-
11
- record.update_attributes file: fixture_file_upload('/file.txt', 'text/plain')
12
- file_filename = record.file.filename
13
- assert_not_equal image_filename, file_filename
14
- file_path = Rails.root.join('tmp', 'uploads', 'files', file_filename)
15
- assert !::File.exists?(image_path)
16
- assert ::File.exists?(file_path)
17
-
18
- record.destroy
19
- assert !::File.exists?(file_path)
20
- end
21
-
22
- test "should take default file/image and shouldn't store/delete it" do
23
- record = FileAttached.create
24
- file_filename = 'file.txt'
25
- assert_equal ::File.join('uploads', 'files', file_filename), record.file.path
26
- file_realpath = Rails.root.join('public', 'uploads', 'files', file_filename)
27
- assert ::File.exists?(file_realpath)
28
-
29
- record.destroy
30
- assert record.file.exists?
31
- assert ::File.exists?(file_realpath)
32
-
33
- record = ImageAttached.create
34
- image_filename = 'image.jpg'
35
- assert_equal ::File.join('uploads', 'images', 'original', 'image.jpg'), record.image.path
36
- image_original_realpath = Rails.root.join('public', 'uploads', 'images', 'original', image_filename)
37
- assert ::File.exists?(image_original_realpath)
38
- assert_equal ::File.join('uploads', 'images', 'small', 'image.jpg'), record.image.path(:small)
39
- image_small_realpath = Rails.root.join('public', 'uploads', 'images', 'small', image_filename)
40
- assert ::File.exists?(image_small_realpath)
41
- assert_equal ::File.join('uploads', 'images', 'big', 'image.jpg'), record.image.path(:big)
42
- image_big_realpath = Rails.root.join('public', 'uploads', 'images', 'big', image_filename)
43
- assert ::File.exists?(image_big_realpath)
44
-
45
- record.destroy
46
- assert record.image.exists?
47
- assert ::File.exists?(image_original_realpath)
48
- assert ::File.exists?(image_small_realpath)
49
- assert ::File.exists?(image_big_realpath)
50
- end
51
-
52
- end
@@ -1,71 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocalValidatorsTest < ActiveSupport::TestCase
4
- include ActionView::Helpers::NumberHelper
5
-
6
- setup do
7
- @record = AllAttached.new
8
- end
9
-
10
- test "should check if file is present" do
11
- assert !@record.valid?
12
- assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
13
-
14
- @record.image_presence = fixture_file_upload('/image.jpg', 'image/jpeg')
15
- assert !@record.valid?
16
- assert_equal [], @record.errors[:image_presence]
17
- end
18
-
19
- test "should check the file content type" do
20
- @record.image_content_type = fixture_file_upload('/file.txt', 'text/plain')
21
- assert !@record.valid?
22
- assert_equal [I18n.t('errors.messages.attachment_content_type', types: 'jpg')], @record.errors[:image_content_type]
23
-
24
- @record.file_content_type = fixture_file_upload('/image.jpg', 'image/jpeg')
25
- assert !@record.valid?
26
- assert_equal [I18n.t('errors.messages.attachment_content_type', types: 'txt')], @record.errors[:file_content_type]
27
- end
28
-
29
- test "should check the file size" do
30
- @record.file_size = fixture_file_upload('/file_big.txt', 'text/plain')
31
- assert !@record.valid?
32
- assert_equal [I18n.t('errors.messages.attachment_size_less_than', count: number_to_human_size(15.kilobytes))], @record.errors[:file_size]
33
-
34
- @record.file_size = fixture_file_upload('/file_empty.txt', 'text/plain')
35
- assert !@record.valid?
36
- assert_equal [I18n.t('errors.messages.attachment_size_greater_than', count: number_to_human_size(10.bytes))], @record.errors[:file_size]
37
-
38
- @record.file_size = fixture_file_upload('/file.txt', 'text/plain')
39
- assert !@record.valid?
40
- assert_equal [], @record.errors[:file_size]
41
-
42
- @record.image_size = fixture_file_upload('/image_big.jpg', 'image/jpeg')
43
- assert !@record.valid?
44
- assert_equal [I18n.t('errors.messages.attachment_size_in', min: number_to_human_size(2.kilobytes), max: number_to_human_size(60.kilobytes))], @record.errors[:image_size]
45
-
46
- @record.image_size = fixture_file_upload('/image_empty.jpg', 'image/jpeg')
47
- assert !@record.valid?
48
- assert_equal [I18n.t('errors.messages.attachment_size_in', min: number_to_human_size(2.kilobytes), max: number_to_human_size(60.kilobytes))], @record.errors[:image_size]
49
-
50
- @record.image_size = fixture_file_upload('/image.jpg', 'image/jpeg')
51
- assert !@record.valid?
52
- assert_equal [], @record.errors[:image_size]
53
- end
54
-
55
- test "should check all the validations together" do
56
- @record.file_all = fixture_file_upload('/file.txt', 'text/plain')
57
- assert !@record.valid?
58
- assert_equal [], @record.errors[:file_all]
59
-
60
- @record.image_all = fixture_file_upload('/image.jpg', 'image/jpeg')
61
- assert !@record.valid?
62
- assert_equal [], @record.errors[:image_all]
63
-
64
- assert !@record.valid?
65
- assert_equal [I18n.t('errors.messages.blank')], @record.errors[:file_default]
66
-
67
- assert !@record.valid?
68
- assert_equal [I18n.t('errors.messages.blank')], @record.errors[:image_default]
69
- end
70
-
71
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class S3FileRecordTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- load_s3
7
- @record = FileAttached.create(file: fixture_file_upload('/file.txt', 'text/plain'))
8
- end
9
-
10
- test "should maintain properties and delete correctly" do
11
- assert @record.file.exists?
12
- assert_equal 11, @record.file.size
13
- assert_equal '.txt', @record.file.extname
14
-
15
- uploads_url = @record.file.url
16
- @record.destroy
17
- assert_not_object_s3 uploads_url
18
- assert !@record.file.exists?
19
- end
20
-
21
- end