bard-file_field 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.nvmrc +1 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +98 -0
  7. data/LICENSE +21 -0
  8. data/README.md +29 -0
  9. data/Rakefile +4 -0
  10. data/app/assets/javascripts/bard-file.js +4913 -0
  11. data/app/controllers/bard/file_field/blobs_controller.rb +11 -0
  12. data/bard-file/.gitignore +1 -0
  13. data/bard-file/bun.lockb +0 -0
  14. data/bard-file/index.js +2 -0
  15. data/bard-file/package.json +20 -0
  16. data/bard-file/rollup.config.js +26 -0
  17. data/bard-file_field.gemspec +34 -0
  18. data/config/routes.rb +6 -0
  19. data/dummy/.gitattributes +7 -0
  20. data/dummy/.gitignore +36 -0
  21. data/dummy/Gemfile +29 -0
  22. data/dummy/Gemfile.lock +353 -0
  23. data/dummy/README.md +24 -0
  24. data/dummy/Rakefile +13 -0
  25. data/dummy/app/assets/config/manifest.js +3 -0
  26. data/dummy/app/assets/images/.keep +0 -0
  27. data/dummy/app/assets/stylesheets/application.css +22 -0
  28. data/dummy/app/controllers/application_controller.rb +2 -0
  29. data/dummy/app/controllers/concerns/.keep +0 -0
  30. data/dummy/app/controllers/edge_cases_controller.rb +23 -0
  31. data/dummy/app/controllers/posts_controller.rb +33 -0
  32. data/dummy/app/controllers/validations_controller.rb +18 -0
  33. data/dummy/app/helpers/application_helper.rb +2 -0
  34. data/dummy/app/javascript/application.js +2 -0
  35. data/dummy/app/javascript/controllers/application.js +9 -0
  36. data/dummy/app/javascript/controllers/index.js +11 -0
  37. data/dummy/app/models/application_record.rb +3 -0
  38. data/dummy/app/models/concerns/.keep +0 -0
  39. data/dummy/app/models/post.rb +9 -0
  40. data/dummy/app/views/edge_cases/rails_validation_error.html.erb +16 -0
  41. data/dummy/app/views/layouts/application.html.erb +18 -0
  42. data/dummy/app/views/layouts/mailer.html.erb +13 -0
  43. data/dummy/app/views/layouts/mailer.text.erb +1 -0
  44. data/dummy/app/views/posts/form.html.erb +39 -0
  45. data/dummy/app/views/posts/show.html.erb +16 -0
  46. data/dummy/app/views/validations/form.html.erb +19 -0
  47. data/dummy/app/views/validations/optional_file.html.erb +10 -0
  48. data/dummy/app/views/validations/optional_file_with_max_size.html.erb +10 -0
  49. data/dummy/app/views/validations/optional_image.html.erb +10 -0
  50. data/dummy/app/views/validations/required_file.html.erb +10 -0
  51. data/dummy/app/views/validations/required_media.html.erb +10 -0
  52. data/dummy/bin/bundle +114 -0
  53. data/dummy/bin/importmap +4 -0
  54. data/dummy/bin/rails +4 -0
  55. data/dummy/bin/rake +4 -0
  56. data/dummy/bin/setup +33 -0
  57. data/dummy/config/application.rb +22 -0
  58. data/dummy/config/boot.rb +4 -0
  59. data/dummy/config/cable.yml +10 -0
  60. data/dummy/config/credentials.yml.enc +1 -0
  61. data/dummy/config/cucumber.yml +2 -0
  62. data/dummy/config/database.yml +25 -0
  63. data/dummy/config/environment.rb +5 -0
  64. data/dummy/config/environments/development.rb +70 -0
  65. data/dummy/config/environments/production.rb +93 -0
  66. data/dummy/config/environments/test.rb +60 -0
  67. data/dummy/config/importmap.rb +4 -0
  68. data/dummy/config/initializers/assets.rb +12 -0
  69. data/dummy/config/initializers/content_security_policy.rb +25 -0
  70. data/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  71. data/dummy/config/initializers/inflections.rb +16 -0
  72. data/dummy/config/initializers/permissions_policy.rb +11 -0
  73. data/dummy/config/locales/en.yml +33 -0
  74. data/dummy/config/puma.rb +43 -0
  75. data/dummy/config/routes.rb +7 -0
  76. data/dummy/config/storage.yml +34 -0
  77. data/dummy/config.ru +6 -0
  78. data/dummy/db/migrate/20231013175203_create_posts.rb +8 -0
  79. data/dummy/db/migrate/20231013175257_create_active_storage_tables.active_storage.rb +57 -0
  80. data/dummy/db/migrate/20231102131420_add_name_to_posts.rb +5 -0
  81. data/dummy/db/schema.rb +50 -0
  82. data/dummy/db/seeds.rb +7 -0
  83. data/dummy/features/edge_cases.feature +17 -0
  84. data/dummy/features/form-persistence.feature +40 -0
  85. data/dummy/features/form_bard_file_field_helper.feature +98 -0
  86. data/dummy/features/support/env.rb +21 -0
  87. data/dummy/features/support/fixtures/empty.3gpp +0 -0
  88. data/dummy/features/support/fixtures/empty.JPEG +0 -0
  89. data/dummy/features/support/fixtures/empty.M4V +0 -0
  90. data/dummy/features/support/fixtures/empty.avi +0 -0
  91. data/dummy/features/support/fixtures/empty.bmp +0 -0
  92. data/dummy/features/support/fixtures/empty.flv +0 -0
  93. data/dummy/features/support/fixtures/empty.gif +0 -0
  94. data/dummy/features/support/fixtures/empty.heic +0 -0
  95. data/dummy/features/support/fixtures/empty.jpeg +0 -0
  96. data/dummy/features/support/fixtures/empty.jpg +0 -0
  97. data/dummy/features/support/fixtures/empty.m4v +0 -0
  98. data/dummy/features/support/fixtures/empty.mkv +0 -0
  99. data/dummy/features/support/fixtures/empty.mov +0 -0
  100. data/dummy/features/support/fixtures/empty.mp4 +0 -0
  101. data/dummy/features/support/fixtures/empty.png +0 -0
  102. data/dummy/features/support/fixtures/empty.tiff +0 -0
  103. data/dummy/features/support/fixtures/empty.webm +0 -0
  104. data/dummy/features/support/fixtures/empty.wmv +0 -0
  105. data/dummy/features/support/fixtures/image.jpg +0 -0
  106. data/dummy/features/support/fixtures/image2.jpg +0 -0
  107. data/dummy/features/support/fixtures/video.mp4 +0 -0
  108. data/dummy/features/support/selectors.rb +63 -0
  109. data/dummy/features/support/step_definitions/download_steps.rb +4 -0
  110. data/dummy/features/support/step_definitions/web_steps.rb +94 -0
  111. data/dummy/features/validations.feature +71 -0
  112. data/dummy/lib/assets/.keep +0 -0
  113. data/dummy/lib/tasks/.keep +0 -0
  114. data/dummy/log/.keep +0 -0
  115. data/dummy/public/404.html +67 -0
  116. data/dummy/public/422.html +67 -0
  117. data/dummy/public/500.html +66 -0
  118. data/dummy/public/apple-touch-icon-precomposed.png +0 -0
  119. data/dummy/public/apple-touch-icon.png +0 -0
  120. data/dummy/public/favicon.ico +0 -0
  121. data/dummy/public/robots.txt +1 -0
  122. data/dummy/storage/.keep +0 -0
  123. data/dummy/test/application_system_test_case.rb +21 -0
  124. data/dummy/test/channels/application_cable/connection_test.rb +11 -0
  125. data/dummy/test/controllers/.keep +0 -0
  126. data/dummy/test/fixtures/files/.keep +0 -0
  127. data/dummy/test/helpers/.keep +0 -0
  128. data/dummy/test/integration/.keep +0 -0
  129. data/dummy/test/mailers/.keep +0 -0
  130. data/dummy/test/models/.keep +0 -0
  131. data/dummy/test/system/.keep +0 -0
  132. data/dummy/test/system/tests_test.rb +9 -0
  133. data/dummy/test/test_helper.rb +13 -0
  134. data/dummy/tmp/.keep +0 -0
  135. data/dummy/tmp/pids/.keep +0 -0
  136. data/dummy/tmp/storage/.keep +0 -0
  137. data/lib/bard/file_field/field.rb +27 -0
  138. data/lib/bard/file_field/form_builder.rb +12 -0
  139. data/lib/bard/file_field/version.rb +7 -0
  140. data/lib/bard/file_field.rb +20 -0
  141. metadata +197 -0
@@ -0,0 +1,63 @@
1
+ module WithinHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+
11
+ when /the "(.+)" bard-file/
12
+ field = find_field($1)
13
+ bard_file = field.find(:xpath, "..")
14
+
15
+ when /the "(.+)" uploaded-file/
16
+ page.document.synchronize 5, errors: [Capybara::ElementNotFound, Ferrum::JavaScriptError] do
17
+ find("uploaded-file[filename='#{$1}']").shadow_root.find("figure")
18
+ end
19
+
20
+ # Add more mappings here.
21
+ # Here is an example that pulls values out of the Regexp:
22
+ #
23
+ # when /^the (notice|error|info) flash$/
24
+ # ".flash.#{$1}"
25
+
26
+ # You can also return an array to use a different selector
27
+ # type, like:
28
+ #
29
+ # when /the header/
30
+ # [:xpath, "//header"]
31
+
32
+ # This allows you to provide a quoted selector as the scope
33
+ # for "within" steps as was previously the default for the
34
+ # web steps:
35
+
36
+ else
37
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
38
+ "Now, go and add a mapping in #{__FILE__}"
39
+ end
40
+ end
41
+
42
+ def element_for(locator)
43
+ args = Array(selector_for(locator))
44
+ find(args.shift, **(args.shift || {}))
45
+ end
46
+
47
+ def with_scope(locator)
48
+ args = Array(selector_for(locator))
49
+ within(args.shift, **(args.shift || {})) { yield }
50
+ end
51
+ end
52
+ World(WithinHelpers)
53
+
54
+ # Single-line step scoper
55
+ When /^(.*) within (.*[^:])$/ do |step_fragment, parent|
56
+ with_scope(parent) { step step_fragment }
57
+ end
58
+
59
+ # Multi-line step scoper
60
+ When /^(.*) within (.*[^:]):$/ do |step_fragment, parent, table_or_string|
61
+ with_scope(parent) { step "#{step_fragment}:", table_or_string }
62
+ end
63
+
@@ -0,0 +1,4 @@
1
+ Then "I should download a file named {string}" do |filename|
2
+ page.driver.downloads[filename]
3
+ end
4
+
@@ -0,0 +1,94 @@
1
+ Given "I am on the homepage" do
2
+ visit "/"
3
+ end
4
+
5
+ Given "I am on {string}" do |path|
6
+ visit path
7
+ end
8
+
9
+ When "I reload the page" do
10
+ visit page.current_path
11
+ end
12
+
13
+ When "I fill in {string} with {string}" do |field, value|
14
+ fill_in field, with: value
15
+ end
16
+
17
+ When "I attach the file {string} to {string}" do |path, field|
18
+ attach_file field, Rails.root.join("features/support/fixtures/#{path}")
19
+ end
20
+
21
+ When "I attach a file of type {string} to {string}" do |extension, field|
22
+ path = Rails.root.join("features/support/fixtures/empty.#{extension}")
23
+ FileUtils.touch(path)
24
+ attach_file field, path
25
+ end
26
+
27
+ When "I attach the following files to {string}:" do |field, table|
28
+ files = table.raw.map(&:first).map { |path| Rails.root.join("features/support/fixtures/#{path}") }
29
+ attach_file field, files
30
+ end
31
+
32
+ When "I follow {string}" do |link|
33
+ find_link(link).trigger "click"
34
+ end
35
+
36
+ When "I press {string}" do |button|
37
+ click_button button
38
+ end
39
+
40
+ Then "I should see {string} filled in with {string}" do |field, value|
41
+ expect(find_field(field).value).to eq(value)
42
+ end
43
+
44
+ Then /^I should see "(.*?)"$/ do |text|
45
+ expect(page).to have_content(text)
46
+ end
47
+
48
+ Then /^I should not see "(.*?)"$/ do |text|
49
+ expect(page).to_not have_content(text)
50
+ end
51
+
52
+ Then "I should see the {string} image" do |filename|
53
+ expect(page).to have_css("img[src$='/#{filename}']")
54
+ end
55
+
56
+ Then "I should not see the {string} image" do |filename|
57
+ expect(page).to_not have_css("img[src$='/#{filename}']")
58
+ end
59
+
60
+ Then "I should see a preview of {string}" do |filename|
61
+ expect(find("uploaded-file")[:filename]).to eq(filename)
62
+ end
63
+
64
+ Then "I should not see a preview" do
65
+ expect(page).to_not have_css("figure")
66
+ end
67
+
68
+ Then "I should see an upload progress bar at 100%" do
69
+ page.document.synchronize 5, errors: [Capybara::ElementNotFound, Ferrum::JavaScriptError] do
70
+ expect(page).to have_css("progress-bar[percent='100']")
71
+ end
72
+ end
73
+
74
+ Then "the {string} bard-file should have a validation error containing {string}" do |field, message|
75
+ messages = bard_file_validation_messages(field)
76
+ expect(messages).to include message
77
+ end
78
+
79
+ Then "the {string} bard-file should have no validation errors" do |field|
80
+ messages = bard_file_validation_messages(field)
81
+ expect(messages).to be_empty
82
+ end
83
+
84
+ def bard_file_validation_messages field
85
+ field = find_field(field)
86
+ bard_file = field.find(:xpath, "..")
87
+ [bard_file, *bard_file.all("uploaded-file input")].map do |e|
88
+ e.evaluate_script("this.validationMessage")
89
+ end.select(&:present?)
90
+ end
91
+
92
+ Then "debugger" do
93
+ debugger
94
+ end
@@ -0,0 +1,71 @@
1
+ Feature: form.bard_file_field has validation options
2
+ Scenario: It supports required validation
3
+ Given I am on "/validations/required_file"
4
+
5
+ When I press "Submit"
6
+ Then I should not see "Post created!"
7
+ And the "Required file" bard-file should have a validation error containing "Please select a file."
8
+
9
+ When I attach the file "image.jpg" to "Required file"
10
+ And I press "Submit"
11
+ Then I should see "Post created!"
12
+ And I should see a preview of "image.jpg" within the "Required file" bard-file
13
+
14
+ Scenario: It supports file type validation
15
+ Given I am on "/validations/optional_image"
16
+
17
+ When I attach the file "video.mp4" to "Optional image"
18
+ Then the "Optional image" bard-file should have a validation error containing "Must be a image."
19
+ Then I should not see a preview within the "Optional image" bard-file
20
+
21
+ When I press "Submit"
22
+ Then I should not see "Post created!"
23
+ And I should not see "video.mp4"
24
+
25
+ When I attach the file "image.jpg" to "Optional image"
26
+ And I press "Submit"
27
+ Then I should see "Post created!"
28
+ And I should see a preview of "image.jpg" within the "Optional image" bard-file
29
+
30
+ Scenario: It supports file size validation
31
+ Given I am on "/validations/optional_file_with_max_size"
32
+ When I attach the file "video.mp4" to "File"
33
+ Then the "File" bard-file should have a validation error containing "Must be smaller than 100KB, and \"video.mp4\" is 119.59KB. Please attach a smaller file."
34
+ Then I should not see a preview within the "File" bard-file
35
+
36
+ When I press "Submit"
37
+ Then I should not see "Post created!"
38
+ And I should not see "video.mp4"
39
+
40
+ When I attach the file "image.jpg" to "File"
41
+ And I press "Submit"
42
+ Then I should see "Post created!"
43
+ And I should see a preview of "image.jpg" within the "File" bard-file
44
+
45
+ Scenario Outline: It supports many file extensions
46
+ Given I am on "/validations/required_media"
47
+ When I attach a file of type "<extension>" to "Required media"
48
+ Then the "Required media" bard-file should have no validation errors
49
+
50
+ Examples:
51
+ | extension |
52
+ # Images
53
+ | JPEG |
54
+ | jpeg |
55
+ | jpg |
56
+ | png |
57
+ | gif |
58
+ | bmp |
59
+ | tiff |
60
+ | heic |
61
+ # Videos
62
+ | mp4 |
63
+ | avi |
64
+ | mov |
65
+ | wmv |
66
+ | 3gpp |
67
+ | webm |
68
+ | m4v |
69
+ | mkv |
70
+ | flv |
71
+
File without changes
File without changes
data/dummy/log/.keep ADDED
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
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
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
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
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
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
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
File without changes
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+ require "capybara/cuprite"
3
+
4
+ Capybara.register_driver(:cuprite) do |app|
5
+ Capybara::Cuprite::Driver.new(
6
+ app, **{
7
+ window_size: [1200, 800],
8
+ browser_options: {},
9
+ process_timeout: 10,
10
+ inspector: true,
11
+ headless: false # !ENV["HEADLESS"].in?(%w[n 0 no false])
12
+ }
13
+ )
14
+ end
15
+ Capybara.default_driver = Capybara.javascript_driver = :cuprite
16
+
17
+ Capybara.server = :puma, { Silent: true }
18
+
19
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
20
+ driven_by :cuprite, using: :chromium
21
+ end
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
+ # test "connects with cookies" do
5
+ # cookies.signed[:user_id] = 42
6
+ #
7
+ # connect
8
+ #
9
+ # assert_equal connection.user_id, "42"
10
+ # end
11
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ require "application_system_test_case"
2
+
3
+ class TestsTest < ApplicationSystemTestCase
4
+ test "visiting the index" do
5
+ visit root_url
6
+
7
+ click_button "Submit"
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+ require_relative "../config/environment"
3
+ require "rails/test_help"
4
+
5
+ class ActiveSupport::TestCase
6
+ # Run tests in parallel with specified workers
7
+ parallelize(workers: :number_of_processors)
8
+
9
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
data/dummy/tmp/.keep ADDED
File without changes
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ module Bard
2
+ module FileField
3
+ class Field < ActionView::Helpers::Tags::TextField
4
+ def render &block
5
+ options = @options.stringify_keys.reverse_merge({
6
+ "directupload" => "/rails/active_storage/direct_uploads",
7
+ "preview" => true,
8
+ })
9
+ add_default_name_and_id(options)
10
+
11
+ content_tag("bard-file", options) do
12
+ next block.call(options) if block
13
+ Array(object.try(@method_name)).map do |attachment|
14
+ content_tag("uploaded-file", nil, {
15
+ name: options["name"],
16
+ src: @template_object.url_for(attachment),
17
+ filename: attachment.filename,
18
+ value: attachment.signed_id,
19
+ preview: options["preview"],
20
+ })
21
+ end.join("\n").html_safe
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,12 @@
1
+ require_relative "field"
2
+
3
+ module Bard
4
+ module FileField
5
+ module FormBuilder
6
+ def bard_file_field method, options={}, &block
7
+ self.multipart = true
8
+ Field.new(@object_name, method, @template, objectify_options(options)).render(&block)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bard
4
+ module FileField
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "file_field/version"
4
+ require_relative "file_field/form_builder"
5
+
6
+ module Bard
7
+ module FileField
8
+ class Engine < ::Rails::Engine
9
+ initializer "bard-file_field.assets" do
10
+ if Rails.application.config.respond_to?(:assets)
11
+ Rails.application.config.assets.precompile += ["bard-file.js"]
12
+ end
13
+ end
14
+
15
+ config.after_initialize do
16
+ ActionView::Base.default_form_builder.include FormBuilder
17
+ end
18
+ end
19
+ end
20
+ end