attachs 0.4.5 → 4.0.0.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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +83 -218
  4. data/Rakefile +1 -14
  5. data/lib/attachs.rb +98 -31
  6. data/lib/attachs/attachment.rb +301 -72
  7. data/lib/attachs/builder.rb +78 -0
  8. data/lib/attachs/collection.rb +84 -0
  9. data/lib/attachs/concern.rb +47 -0
  10. data/lib/attachs/configuration.rb +11 -0
  11. data/lib/attachs/console.rb +40 -0
  12. data/lib/attachs/extensions/active_record/base.rb +24 -0
  13. data/lib/attachs/extensions/active_record/validations/attachment_content_type_validator.rb +37 -0
  14. data/lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb +27 -0
  15. data/lib/attachs/extensions/active_record/validations/attachment_size_validator.rb +55 -0
  16. data/lib/attachs/extensions/active_record/validations/attachment_validator.rb +24 -0
  17. data/lib/attachs/interpolations.rb +27 -0
  18. data/lib/attachs/jobs/base.rb +14 -0
  19. data/lib/attachs/jobs/delete_job.rb +15 -0
  20. data/lib/attachs/jobs/update_job.rb +11 -0
  21. data/lib/attachs/locales/en.yml +2 -6
  22. data/lib/attachs/locales/es.yml +2 -6
  23. data/lib/attachs/processors/base.rb +4 -14
  24. data/lib/attachs/processors/image.rb +45 -0
  25. data/lib/attachs/railtie.rb +7 -27
  26. data/lib/attachs/storages/base.rb +10 -59
  27. data/lib/attachs/storages/s3.rb +68 -63
  28. data/lib/attachs/version.rb +1 -1
  29. data/lib/generators/attachs/install/install_generator.rb +15 -0
  30. data/lib/generators/attachs/install/templates/initializer.rb +7 -0
  31. data/lib/generators/attachs/upload/templates/migration.rb +11 -0
  32. data/lib/generators/attachs/upload/templates/model.rb +19 -0
  33. data/lib/generators/attachs/upload/upload_generator.rb +24 -0
  34. data/lib/tasks/attachs.rake +12 -26
  35. data/test/attachment_test.rb +175 -12
  36. data/test/collection_test.rb +52 -0
  37. data/test/concern_test.rb +10 -0
  38. data/test/dummy/Rakefile +1 -2
  39. data/test/dummy/app/assets/javascripts/application.js +2 -2
  40. data/test/dummy/app/assets/stylesheets/application.css +6 -4
  41. data/test/dummy/app/models/product.rb +16 -0
  42. data/test/dummy/app/models/shop.rb +14 -0
  43. data/test/dummy/app/models/upload.rb +19 -0
  44. data/test/dummy/app/views/layouts/application.html.erb +9 -11
  45. data/test/dummy/bin/bundle +1 -0
  46. data/test/dummy/bin/rails +2 -1
  47. data/test/dummy/bin/rake +1 -0
  48. data/test/dummy/bin/setup +30 -0
  49. data/test/dummy/config.ru +1 -1
  50. data/test/dummy/config/application.rb +3 -2
  51. data/test/dummy/config/boot.rb +1 -1
  52. data/test/dummy/config/database.yml +4 -22
  53. data/test/dummy/config/database.yml.travis +3 -0
  54. data/test/dummy/config/environment.rb +1 -1
  55. data/test/dummy/config/environments/development.rb +15 -3
  56. data/test/dummy/config/environments/production.rb +21 -26
  57. data/test/dummy/config/environments/test.rb +10 -12
  58. data/test/dummy/config/initializers/assets.rb +11 -0
  59. data/test/dummy/config/initializers/attachs.rb +7 -21
  60. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  61. data/test/dummy/config/initializers/mime_types.rb +1 -2
  62. data/test/dummy/config/initializers/session_store.rb +1 -1
  63. data/test/dummy/config/routes.rb +54 -0
  64. data/test/dummy/config/secrets.yml +24 -0
  65. data/test/dummy/db/migrate/20161024234003_create_shops.rb +11 -0
  66. data/test/dummy/db/migrate/20161024234029_create_products.rb +12 -0
  67. data/test/dummy/db/migrate/20161031135453_create_uploads.rb +11 -0
  68. data/test/dummy/db/schema.rb +27 -16
  69. data/test/dummy/log/development.log +61 -0
  70. data/test/dummy/log/test.log +5873 -0
  71. data/test/dummy/public/404.html +58 -55
  72. data/test/dummy/public/422.html +58 -55
  73. data/test/dummy/public/500.html +57 -54
  74. data/test/fixtures/big_file.txt +50 -0
  75. data/test/fixtures/big_image.jpg +0 -0
  76. data/test/fixtures/file.txt +1 -0
  77. data/test/fixtures/image.jpg +0 -0
  78. data/test/{dummy/test/fixtures/file.txt → fixtures/small_file.txt} +0 -0
  79. data/test/fixtures/small_image.jpg +0 -0
  80. data/test/generator_test.rb +14 -6
  81. data/test/helper_test.rb +28 -0
  82. data/test/query_test.rb +26 -0
  83. data/test/support/storage_helper.rb +65 -0
  84. data/test/task_test.rb +69 -0
  85. data/test/test_helper.rb +6 -45
  86. data/test/upload_test.rb +27 -0
  87. data/test/validator_test.rb +160 -0
  88. metadata +114 -68
  89. data/lib/attachs/active_record/base.rb +0 -103
  90. data/lib/attachs/active_record/connection_adapters.rb +0 -40
  91. data/lib/attachs/active_record/migration.rb +0 -17
  92. data/lib/attachs/active_record/validators.rb +0 -7
  93. data/lib/attachs/active_record/validators/attachment_content_type_validator.rb +0 -30
  94. data/lib/attachs/active_record/validators/attachment_presence_validator.rb +0 -22
  95. data/lib/attachs/active_record/validators/attachment_size_validator.rb +0 -47
  96. data/lib/attachs/processors/thumbnail.rb +0 -69
  97. data/lib/attachs/storages/local.rb +0 -95
  98. data/lib/attachs/types/base.rb +0 -22
  99. data/lib/attachs/types/default.rb +0 -29
  100. data/lib/attachs/types/regular.rb +0 -21
  101. data/lib/generators/attachs/install_generator.rb +0 -13
  102. data/lib/generators/attachs/templates/attachs.rb +0 -2
  103. data/test/dummy/README.rdoc +0 -28
  104. data/test/dummy/app/models/medium.rb +0 -5
  105. data/test/dummy/app/models/picture.rb +0 -2
  106. data/test/dummy/config/initializers/secret_token.rb +0 -13
  107. data/test/dummy/config/s3.yml +0 -15
  108. data/test/dummy/db/migrate/20140808012639_create_media.rb +0 -11
  109. data/test/dummy/test/fixtures/image.gif +0 -0
  110. data/test/local_storage_test.rb +0 -72
  111. data/test/migration_test.rb +0 -65
  112. data/test/processor_test.rb +0 -49
  113. data/test/s3_storage_tes.rb +0 -66
  114. data/test/tasks_test.rb +0 -57
  115. data/test/validators_test.rb +0 -100
@@ -1,58 +1,61 @@
1
1
  <!DOCTYPE html>
2
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>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The page you were looking for doesn't exist.</h1>
56
+ <p>You may have mistyped the address or the page may have moved.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
59
+ </div>
60
+ </body>
58
61
  </html>
@@ -1,58 +1,61 @@
1
1
  <!DOCTYPE html>
2
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>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The change you wanted was rejected.</h1>
56
+ <p>Maybe you tried to change something you didn't have access to.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
59
+ </div>
60
+ </body>
58
61
  </html>
@@ -1,57 +1,60 @@
1
1
  <!DOCTYPE html>
2
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>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>We're sorry, but something went wrong.</h1>
56
+ </div>
57
+ <p>If you are the application owner check the logs for more information.</p>
58
+ </div>
59
+ </body>
57
60
  </html>
@@ -0,0 +1,50 @@
1
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
2
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
3
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
4
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
5
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
6
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
7
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
8
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
9
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
10
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
11
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
12
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
13
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
14
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
15
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
16
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
17
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
18
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
19
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
20
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
21
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
22
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
23
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
24
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
25
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
26
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
27
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
28
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
29
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
30
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
31
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
32
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
33
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
34
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
35
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
36
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
37
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
38
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
39
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
40
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
41
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
42
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
43
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
44
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
45
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
46
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
47
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
48
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
49
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
50
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
@@ -0,0 +1 @@
1
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Binary file
@@ -1,18 +1,26 @@
1
1
  require 'test_helper'
2
2
  require 'rails/generators'
3
- require 'generators/attachs/install_generator'
3
+ require 'generators/attachs/install/install_generator'
4
+ require 'generators/attachs/upload/upload_generator'
4
5
 
5
- class GeneratorsTest < Rails::Generators::TestCase
6
- tests Attachs::InstallGenerator
7
- destination File.expand_path('../tmp', File.dirname(__FILE__))
6
+ class GeneratorTest < Rails::Generators::TestCase
7
+ destination Rails.root.join('tmp')
8
8
 
9
9
  teardown do
10
- FileUtils.rm_rf self.destination_root
10
+ FileUtils.rm_rf destination_root
11
11
  end
12
12
 
13
- test 'initializer generator' do
13
+ test 'install' do
14
+ self.class.tests Attachs::Generators::InstallGenerator
14
15
  run_generator
15
16
  assert_file 'config/initializers/attachs.rb'
16
17
  end
17
18
 
19
+ test 'upload' do
20
+ self.class.tests Attachs::Generators::UploadGenerator
21
+ run_generator
22
+ assert_file 'app/models/upload.rb'
23
+ assert_migration 'db/migrate/create_uploads.rb'
24
+ end
25
+
18
26
  end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class HelperTest < ActionView::TestCase
4
+ include StorageHelper
5
+
6
+ test 'fields for' do
7
+ product = Product.create(pictures: [image])
8
+ product.run_callbacks :commit
9
+ product.pictures.build
10
+
11
+ html = form_for(product, url: 'test') do |f|
12
+ f.fields_for(:pictures) do |ff|
13
+ ff.file_field(:value) +
14
+ ff.number_field(:position)
15
+ end
16
+ end
17
+
18
+ assert html.include?('[pictures_attributes][0][id]')
19
+ assert html.include?('[pictures_attributes][0][value]')
20
+ assert html.include?('[pictures_attributes][0][position]')
21
+ assert html.exclude?('[pictures_attributes][1][id]')
22
+ assert html.include?('[pictures_attributes][1][value]')
23
+ assert html.include?('[pictures_attributes][1][position]')
24
+
25
+ product.pictures.destroy
26
+ end
27
+
28
+ end