attachs 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +98 -0
  4. data/Rakefile +34 -0
  5. data/app/controllers/attachs/presets_controller.rb +17 -0
  6. data/config/locales/en.yml +8 -0
  7. data/config/locales/es.yml +8 -0
  8. data/config/routes.rb +5 -0
  9. data/lib/attachs.rb +16 -0
  10. data/lib/attachs/active_record/base.rb +145 -0
  11. data/lib/attachs/engine.rb +7 -0
  12. data/lib/attachs/magick/image.rb +85 -0
  13. data/lib/attachs/railtie.rb +20 -0
  14. data/lib/attachs/storages/local.rb +61 -0
  15. data/lib/attachs/storages/s3.rb +77 -0
  16. data/lib/attachs/types/file.rb +113 -0
  17. data/lib/attachs/types/image.rb +40 -0
  18. data/lib/attachs/validators/attachment_content_type_validator.rb +11 -0
  19. data/lib/attachs/validators/attachment_presence_validator.rb +9 -0
  20. data/lib/attachs/validators/attachment_size_validator.rb +27 -0
  21. data/lib/attachs/validators/base.rb +13 -0
  22. data/lib/attachs/version.rb +5 -0
  23. data/lib/generators/attachs/s3/config_generator.rb +13 -0
  24. data/lib/generators/attachs/s3/templates/s3.yml +16 -0
  25. data/lib/tasks/attachs_tasks.rake +71 -0
  26. data/test/dummy/README.rdoc +28 -0
  27. data/test/dummy/Rakefile +6 -0
  28. data/test/dummy/app/assets/javascripts/application.js +13 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +5 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/models/all_attached.rb +16 -0
  33. data/test/dummy/app/models/file_attached.rb +3 -0
  34. data/test/dummy/app/models/image_attached.rb +3 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/bin/bundle +3 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/bin/rake +4 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +29 -0
  41. data/test/dummy/config/boot.rb +5 -0
  42. data/test/dummy/config/database.yml +25 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +29 -0
  45. data/test/dummy/config/environments/production.rb +80 -0
  46. data/test/dummy/config/environments/test.rb +36 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/test/dummy/config/initializers/inflections.rb +16 -0
  50. data/test/dummy/config/initializers/mime_types.rb +5 -0
  51. data/test/dummy/config/initializers/secret_token.rb +12 -0
  52. data/test/dummy/config/initializers/session_store.rb +3 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +3 -0
  56. data/test/dummy/db/development.sqlite3 +0 -0
  57. data/test/dummy/db/migrate/20130820222342_create_file_attacheds.rb +9 -0
  58. data/test/dummy/db/migrate/20130820222355_create_image_attacheds.rb +9 -0
  59. data/test/dummy/db/migrate/20130820222534_create_all_attacheds.rb +19 -0
  60. data/test/dummy/db/schema.rb +44 -0
  61. data/test/dummy/db/test.sqlite3 +0 -0
  62. data/test/dummy/log/development.log +28 -0
  63. data/test/dummy/log/test.log +8545 -0
  64. data/test/dummy/public/404.html +58 -0
  65. data/test/dummy/public/422.html +58 -0
  66. data/test/dummy/public/500.html +57 -0
  67. data/test/dummy/public/favicon.ico +0 -0
  68. data/test/dummy/public/uploads/files/file.txt +1 -0
  69. data/test/dummy/public/uploads/images/big/image.jpg +0 -0
  70. data/test/dummy/public/uploads/images/original/image.jpg +0 -0
  71. data/test/dummy/public/uploads/images/small/image.jpg +0 -0
  72. data/test/dummy/test/fixtures/file.txt +1 -0
  73. data/test/dummy/test/fixtures/file_big.txt +1 -0
  74. data/test/dummy/test/fixtures/file_empty.txt +1 -0
  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/local_file_record_test.rb +20 -0
  79. data/test/local_file_string_test.rb +23 -0
  80. data/test/local_file_upload_test.rb +30 -0
  81. data/test/local_generate_test.rb +25 -0
  82. data/test/local_image_record_test.rb +25 -0
  83. data/test/local_image_string_test.rb +34 -0
  84. data/test/local_image_upload_test.rb +27 -0
  85. data/test/local_records_test.rb +52 -0
  86. data/test/local_validators_test.rb +71 -0
  87. data/test/s3_file_record_tes.rb +21 -0
  88. data/test/s3_file_string_tes.rb +24 -0
  89. data/test/s3_file_upload_tes.rb +31 -0
  90. data/test/s3_image_record_tes.rb +26 -0
  91. data/test/s3_image_string_tes.rb +31 -0
  92. data/test/s3_image_upload_tes.rb +28 -0
  93. data/test/s3_records_tes.rb +56 -0
  94. data/test/s3_validators_tes.rb +72 -0
  95. data/test/test_helper.rb +49 -0
  96. metadata +250 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1 @@
1
+ 1234567890
@@ -0,0 +1 @@
1
+ 1234567890
@@ -0,0 +1 @@
1
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
@@ -0,0 +1,20 @@
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
+ end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,52 @@
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