hanami 2.3.2 → 3.0.0.rc1

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 (184) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -19
  3. data/LICENSE +20 -0
  4. data/README.md +18 -35
  5. data/hanami.gemspec +36 -37
  6. data/lib/hanami/config/db.rb +2 -0
  7. data/lib/hanami/config/i18n.rb +138 -0
  8. data/lib/hanami/config/logger.rb +15 -7
  9. data/lib/hanami/config/null_config.rb +1 -1
  10. data/lib/hanami/config/views.rb +17 -0
  11. data/lib/hanami/config.rb +66 -22
  12. data/lib/hanami/errors.rb +6 -0
  13. data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
  14. data/lib/hanami/extensions/action.rb +2 -2
  15. data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
  16. data/lib/hanami/extensions/mailer.rb +28 -0
  17. data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
  18. data/lib/hanami/extensions/view/context.rb +26 -4
  19. data/lib/hanami/extensions/view/part.rb +2 -0
  20. data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
  21. data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
  22. data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
  23. data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
  24. data/lib/hanami/extensions.rb +6 -1
  25. data/lib/hanami/helpers/assets_helper.rb +0 -4
  26. data/lib/hanami/helpers/form_helper.rb +1 -1
  27. data/lib/hanami/helpers/i18n_helper.rb +176 -0
  28. data/lib/hanami/logger/rack_formatter.rb +73 -0
  29. data/lib/hanami/logger/sql_formatter.rb +80 -0
  30. data/lib/hanami/logger/sql_logger.rb +48 -0
  31. data/lib/hanami/middleware/render_errors.rb +2 -2
  32. data/lib/hanami/providers/db.rb +7 -2
  33. data/lib/hanami/providers/db_logging.rb +4 -7
  34. data/lib/hanami/providers/i18n/backend.rb +369 -0
  35. data/lib/hanami/providers/i18n/locale/en.yml +57 -0
  36. data/lib/hanami/providers/i18n.rb +114 -0
  37. data/lib/hanami/providers/mailers.rb +101 -0
  38. data/lib/hanami/routes.rb +1 -0
  39. data/lib/hanami/settings/composite_store.rb +53 -0
  40. data/lib/hanami/settings.rb +4 -4
  41. data/lib/hanami/slice/router.rb +15 -10
  42. data/lib/hanami/slice.rb +71 -11
  43. data/lib/hanami/slice_registrar.rb +2 -2
  44. data/lib/hanami/universal_logger.rb +250 -0
  45. data/lib/hanami/version.rb +1 -1
  46. data/lib/hanami/web/rack_logger.rb +2 -80
  47. data/lib/hanami/web/welcome.html.erb +443 -58
  48. data/lib/hanami.rb +4 -2
  49. metadata +28 -276
  50. data/CODE_OF_CONDUCT.md +0 -74
  51. data/FEATURES.md +0 -269
  52. data/LICENSE.md +0 -22
  53. data/spec/integration/action/cookies_spec.rb +0 -58
  54. data/spec/integration/action/csrf_protection_spec.rb +0 -54
  55. data/spec/integration/action/format_config_spec.rb +0 -129
  56. data/spec/integration/action/routes_spec.rb +0 -71
  57. data/spec/integration/action/sessions_spec.rb +0 -50
  58. data/spec/integration/action/slice_configuration_spec.rb +0 -284
  59. data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
  60. data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
  61. data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
  62. data/spec/integration/action/view_rendering_spec.rb +0 -89
  63. data/spec/integration/assets/assets_spec.rb +0 -155
  64. data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
  65. data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
  66. data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
  67. data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
  68. data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
  69. data/spec/integration/container/application_routes_helper_spec.rb +0 -48
  70. data/spec/integration/container/auto_injection_spec.rb +0 -53
  71. data/spec/integration/container/auto_registration_spec.rb +0 -86
  72. data/spec/integration/container/autoloader_spec.rb +0 -82
  73. data/spec/integration/container/imports_spec.rb +0 -253
  74. data/spec/integration/container/prepare_container_spec.rb +0 -125
  75. data/spec/integration/container/provider_environment_spec.rb +0 -52
  76. data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
  77. data/spec/integration/container/shutdown_spec.rb +0 -91
  78. data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
  79. data/spec/integration/container/standard_providers_spec.rb +0 -124
  80. data/spec/integration/db/auto_registration_spec.rb +0 -39
  81. data/spec/integration/db/commands_spec.rb +0 -80
  82. data/spec/integration/db/db_inflector_spec.rb +0 -57
  83. data/spec/integration/db/db_slices_spec.rb +0 -398
  84. data/spec/integration/db/db_spec.rb +0 -245
  85. data/spec/integration/db/gateways_spec.rb +0 -361
  86. data/spec/integration/db/logging_spec.rb +0 -301
  87. data/spec/integration/db/mappers_spec.rb +0 -84
  88. data/spec/integration/db/provider_config_spec.rb +0 -88
  89. data/spec/integration/db/provider_spec.rb +0 -35
  90. data/spec/integration/db/relations_spec.rb +0 -60
  91. data/spec/integration/db/repo_spec.rb +0 -300
  92. data/spec/integration/db/slices_importing_from_parent.rb +0 -130
  93. data/spec/integration/dotenv_loading_spec.rb +0 -138
  94. data/spec/integration/logging/exception_logging_spec.rb +0 -120
  95. data/spec/integration/logging/notifications_spec.rb +0 -68
  96. data/spec/integration/logging/request_logging_spec.rb +0 -202
  97. data/spec/integration/operations/extension_spec.rb +0 -122
  98. data/spec/integration/rack_app/body_parser_spec.rb +0 -108
  99. data/spec/integration/rack_app/method_override_spec.rb +0 -97
  100. data/spec/integration/rack_app/middleware_spec.rb +0 -720
  101. data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
  102. data/spec/integration/rack_app/rack_app_spec.rb +0 -442
  103. data/spec/integration/rake_tasks_spec.rb +0 -107
  104. data/spec/integration/router/resource_routes_spec.rb +0 -281
  105. data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
  106. data/spec/integration/settings/access_to_constants_spec.rb +0 -46
  107. data/spec/integration/settings/loading_from_env_spec.rb +0 -188
  108. data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
  109. data/spec/integration/settings/slice_registration_spec.rb +0 -145
  110. data/spec/integration/settings/using_types_spec.rb +0 -80
  111. data/spec/integration/setup_spec.rb +0 -165
  112. data/spec/integration/slices/external_slice_spec.rb +0 -91
  113. data/spec/integration/slices/slice_configuration_spec.rb +0 -42
  114. data/spec/integration/slices/slice_loading_spec.rb +0 -171
  115. data/spec/integration/slices/slice_registrations_spec.rb +0 -80
  116. data/spec/integration/slices/slice_routing_spec.rb +0 -219
  117. data/spec/integration/slices_spec.rb +0 -471
  118. data/spec/integration/view/config/default_context_spec.rb +0 -149
  119. data/spec/integration/view/config/inflector_spec.rb +0 -57
  120. data/spec/integration/view/config/part_class_spec.rb +0 -147
  121. data/spec/integration/view/config/part_namespace_spec.rb +0 -103
  122. data/spec/integration/view/config/paths_spec.rb +0 -119
  123. data/spec/integration/view/config/scope_class_spec.rb +0 -147
  124. data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
  125. data/spec/integration/view/config/template_spec.rb +0 -38
  126. data/spec/integration/view/context/assets_spec.rb +0 -79
  127. data/spec/integration/view/context/inflector_spec.rb +0 -40
  128. data/spec/integration/view/context/request_spec.rb +0 -57
  129. data/spec/integration/view/context/routes_spec.rb +0 -84
  130. data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
  131. data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
  132. data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
  133. data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
  134. data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
  135. data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
  136. data/spec/integration/view/slice_configuration_spec.rb +0 -289
  137. data/spec/integration/view/views_spec.rb +0 -103
  138. data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
  139. data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
  140. data/spec/integration/web/render_errors_spec.rb +0 -242
  141. data/spec/integration/web/welcome_view_spec.rb +0 -84
  142. data/spec/spec_helper.rb +0 -28
  143. data/spec/support/app_integration.rb +0 -157
  144. data/spec/support/coverage.rb +0 -1
  145. data/spec/support/matchers.rb +0 -32
  146. data/spec/support/rspec.rb +0 -27
  147. data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
  148. data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
  149. data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
  150. data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
  151. data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
  152. data/spec/unit/hanami/config/actions_spec.rb +0 -52
  153. data/spec/unit/hanami/config/base_url_spec.rb +0 -25
  154. data/spec/unit/hanami/config/console_spec.rb +0 -22
  155. data/spec/unit/hanami/config/db_spec.rb +0 -38
  156. data/spec/unit/hanami/config/inflector_spec.rb +0 -35
  157. data/spec/unit/hanami/config/logger_spec.rb +0 -195
  158. data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
  159. data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
  160. data/spec/unit/hanami/config/router_spec.rb +0 -44
  161. data/spec/unit/hanami/config/slices_spec.rb +0 -34
  162. data/spec/unit/hanami/config/views_spec.rb +0 -80
  163. data/spec/unit/hanami/env_spec.rb +0 -37
  164. data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
  165. data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
  166. data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
  167. data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
  168. data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
  169. data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
  170. data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
  171. data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
  172. data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
  173. data/spec/unit/hanami/port_spec.rb +0 -117
  174. data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
  175. data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
  176. data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
  177. data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
  178. data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
  179. data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
  180. data/spec/unit/hanami/settings_spec.rb +0 -111
  181. data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
  182. data/spec/unit/hanami/slice_name_spec.rb +0 -47
  183. data/spec/unit/hanami/slice_spec.rb +0 -99
  184. data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript", :app_integration do
4
- subject(:obj) {
5
- helpers = described_class
6
- Class.new {
7
- include helpers
8
-
9
- attr_reader :_context
10
-
11
- def initialize(context)
12
- @_context = context
13
- end
14
- }.new(context)
15
- }
16
-
17
- def javascript_tag(...)
18
- subject.javascript_tag(...)
19
- end
20
-
21
- let(:context) { TestApp::Views::Context.new }
22
- let(:root) { make_tmp_directory }
23
-
24
- before do
25
- with_directory(root) do
26
- write "config/app.rb", <<~RUBY
27
- module TestApp
28
- class App < Hanami::App
29
- config.logger.stream = StringIO.new
30
- end
31
- end
32
- RUBY
33
-
34
- write "app/views/context.rb", <<~RUBY
35
- # auto_register: false
36
-
37
- require "hanami/view/context"
38
-
39
- module TestApp
40
- module Views
41
- class Context < Hanami::View::Context
42
- end
43
- end
44
- end
45
- RUBY
46
-
47
- write "app/assets/js/app.ts", <<~JS
48
- import "../css/app.css";
49
-
50
- console.log("Hello from index.ts");
51
- JS
52
-
53
- write "app/assets/css/app.css", <<~CSS
54
- .btn {
55
- background: #f00;
56
- }
57
- CSS
58
-
59
- stub_assets("feature-a.js")
60
-
61
- require "hanami/setup"
62
- before_prepare if respond_to?(:before_prepare)
63
- require "hanami/prepare"
64
- end
65
- end
66
-
67
- it "returns an instance of SafeString" do
68
- actual = javascript_tag("feature-a")
69
- expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
70
- end
71
-
72
- it "is aliased as #javascript_tag" do
73
- expect(subject.javascript_tag("feature-a")).to eq javascript_tag("feature-a")
74
- end
75
-
76
- it "renders <script> tag" do
77
- actual = javascript_tag("feature-a")
78
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
79
- end
80
-
81
- xit "renders <script> tag without appending ext after query string" do
82
- actual = javascript_tag("feature-x?callback=init")
83
- expect(actual).to eq(%(<script src="/assets/feature-x?callback=init" type="text/javascript"></script>))
84
- end
85
-
86
- it "renders <script> tag with a defer attribute" do
87
- actual = javascript_tag("feature-a", defer: true)
88
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" defer="defer"></script>))
89
- end
90
-
91
- it "renders <script> tag with an integrity attribute" do
92
- actual = javascript_tag("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
93
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous"></script>))
94
- end
95
-
96
- it "renders <script> tag with a crossorigin attribute" do
97
- actual = javascript_tag("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
98
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials"></script>))
99
- end
100
-
101
- it "ignores src passed as an option" do
102
- actual = javascript_tag("feature-a", src: "wrong")
103
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
104
- end
105
-
106
- describe "async option" do
107
- it "renders <script> tag with an async=true if async option is true" do
108
- actual = javascript_tag("feature-a", async: true)
109
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" async="async"></script>))
110
- end
111
-
112
- it "renders <script> tag without an async=true if async option is false" do
113
- actual = javascript_tag("feature-a", async: false)
114
- expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
115
- end
116
- end
117
-
118
- describe "subresource_integrity mode" do
119
- def before_prepare
120
- Hanami.app.config.assets.subresource_integrity = [:sha384]
121
- end
122
-
123
- before { compile_assets! }
124
-
125
- it "includes subresource_integrity and crossorigin attributes" do
126
- actual = javascript_tag("app")
127
- expect(actual).to match(%r{<script src="/assets/app-[A-Z0-9]{8}.js" type="text/javascript" integrity="sha384-[A-Za-z0-9+/]{64}" crossorigin="anonymous"></script>})
128
- end
129
- end
130
-
131
- describe "cdn mode" do
132
- let(:base_url) { "https://hanami.test" }
133
-
134
- def before_prepare
135
- Hanami.app.config.assets.base_url = "https://hanami.test"
136
- end
137
-
138
- it "returns absolute url for src attribute" do
139
- actual = javascript_tag("feature-a")
140
- expect(actual).to eq(%(<script src="#{base_url}/assets/feature-a.js" type="text/javascript"></script>))
141
- end
142
- end
143
- end
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet", :app_integration do
4
- subject(:obj) {
5
- helpers = described_class
6
- Class.new {
7
- include helpers
8
-
9
- attr_reader :_context
10
-
11
- def initialize(context)
12
- @_context = context
13
- end
14
- }.new(context)
15
- }
16
-
17
- def stylesheet_tag(...)
18
- subject.stylesheet_tag(...)
19
- end
20
-
21
- let(:context) { TestApp::Views::Context.new }
22
- let(:root) { make_tmp_directory }
23
-
24
- before do
25
- with_directory(root) do
26
- write "config/app.rb", <<~RUBY
27
- module TestApp
28
- class App < Hanami::App
29
- config.logger.stream = StringIO.new
30
- end
31
- end
32
- RUBY
33
-
34
- write "app/views/context.rb", <<~RUBY
35
- # auto_register: false
36
-
37
- require "hanami/view/context"
38
-
39
- module TestApp
40
- module Views
41
- class Context < Hanami::View::Context
42
- end
43
- end
44
- end
45
- RUBY
46
-
47
- write "app/assets/js/app.ts", <<~JS
48
- import "../css/app.css";
49
-
50
- console.log("Hello from index.ts");
51
- JS
52
-
53
- write "app/assets/css/app.css", <<~CSS
54
- .btn {
55
- background: #f00;
56
- }
57
- CSS
58
-
59
- stub_assets("main.css")
60
-
61
- require "hanami/setup"
62
- before_prepare if respond_to?(:before_prepare)
63
- require "hanami/prepare"
64
- end
65
- end
66
-
67
- it "returns an instance of SafeString" do
68
- actual = stylesheet_tag("main")
69
- expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
70
- end
71
-
72
- it "is aliased as #stylesheet_tag" do
73
- expect(subject.stylesheet_tag("main")).to eq stylesheet_tag("main")
74
- end
75
-
76
- it "renders <link> tag" do
77
- actual = stylesheet_tag("main")
78
- expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet">))
79
- end
80
-
81
- xit "renders <link> tag without appending ext after query string" do
82
- actual = stylesheet_tag("fonts?font=Helvetica")
83
- expect(actual).to eq(%(<link href="/assets/fonts?font=Helvetica" type="text/css" rel="stylesheet">))
84
- end
85
-
86
- it "renders <link> tag with an integrity attribute" do
87
- actual = stylesheet_tag("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
88
- expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous">))
89
- end
90
-
91
- it "renders <link> tag with a crossorigin attribute" do
92
- actual = stylesheet_tag("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
93
- expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials">))
94
- end
95
-
96
- it "ignores href passed as an option" do
97
- actual = stylesheet_tag("main", href: "wrong")
98
- expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet">))
99
- end
100
-
101
- describe "subresource_integrity mode" do
102
- def before_prepare
103
- Hanami.app.config.assets.subresource_integrity = [:sha384]
104
- end
105
-
106
- before { compile_assets! }
107
-
108
- it "includes subresource_integrity and crossorigin attributes" do
109
- actual = stylesheet_tag("app")
110
- expect(actual).to match(%r{<link href="/assets/app-[A-Z0-9]{8}.css" type="text/css" rel="stylesheet" integrity="sha384-[A-Za-z0-9+/]{64}" crossorigin="anonymous">})
111
- end
112
- end
113
-
114
- describe "cdn mode" do
115
- let(:base_url) { "https://hanami.test" }
116
-
117
- def before_prepare
118
- Hanami.app.config.assets.base_url = base_url
119
- end
120
-
121
- it "returns absolute url for href attribute" do
122
- actual = stylesheet_tag("main")
123
- expect(actual).to eq(%(<link href="#{base_url}/assets/main.css" type="text/css" rel="stylesheet">))
124
- end
125
- end
126
- end
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#video", :app_integration do
4
- subject(:obj) {
5
- helpers = described_class
6
- Class.new {
7
- include helpers
8
-
9
- attr_reader :_context
10
-
11
- def initialize(context)
12
- @_context = context
13
- end
14
- }.new(context)
15
- }
16
-
17
- def video_tag(...)
18
- subject.video_tag(...)
19
- end
20
-
21
- let(:context) { TestApp::Views::Context.new }
22
- let(:root) { make_tmp_directory }
23
-
24
- before do
25
- with_directory(root) do
26
- write "config/app.rb", <<~RUBY
27
- module TestApp
28
- class App < Hanami::App
29
- config.logger.stream = StringIO.new
30
- end
31
- end
32
- RUBY
33
-
34
- write "app/views/context.rb", <<~RUBY
35
- # auto_register: false
36
-
37
- require "hanami/view/context"
38
-
39
- module TestApp
40
- module Views
41
- class Context < Hanami::View::Context
42
- end
43
- end
44
- end
45
- RUBY
46
-
47
- stub_assets("movie.mp4", "movie.en.vtt")
48
-
49
- require "hanami/setup"
50
- before_prepare if respond_to?(:before_prepare)
51
- require "hanami/prepare"
52
- end
53
- end
54
-
55
- it "returns an instance of HtmlBuilder" do
56
- actual = video_tag("movie.mp4")
57
- expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
58
- end
59
-
60
- it "renders <video> tag" do
61
- actual = video_tag("movie.mp4").to_s
62
- expect(actual).to eq(%(<video src="/assets/movie.mp4"></video>))
63
- end
64
-
65
- it "is aliased as #video_tag" do
66
- expect(video_tag("movie.mp4")).to eq(subject.video_tag("movie.mp4"))
67
- end
68
-
69
- it "renders with html attributes" do
70
- actual = video_tag("movie.mp4", autoplay: true, controls: true).to_s
71
- expect(actual).to eq(%(<video autoplay="autoplay" controls="controls" src="/assets/movie.mp4"></video>))
72
- end
73
-
74
- it "renders with fallback content" do
75
- actual = video_tag("movie.mp4") do
76
- "Your browser does not support the video tag"
77
- end.to_s
78
-
79
- expect(actual).to eq(%(<video src="/assets/movie.mp4">Your browser does not support the video tag</video>))
80
- end
81
-
82
- it "renders with tracks" do
83
- actual = video_tag("movie.mp4") do
84
- tag.track kind: "captions", src: subject.asset_url("movie.en.vtt"), srclang: "en", label: "English"
85
- end.to_s
86
-
87
- expect(actual).to eq(%(<video src="/assets/movie.mp4"><track kind="captions" src="/assets/movie.en.vtt" srclang="en" label="English"></video>))
88
- end
89
-
90
- xit "renders with sources" do
91
- actual = subject.video do
92
- tag.text "Your browser does not support the video tag"
93
- tag.source src: subject.asset_url("movie.mp4"), type: "video/mp4"
94
- tag.source src: subject.asset_url("movie.ogg"), type: "video/ogg"
95
- end.to_s
96
-
97
- expect(actual).to eq(%(<video>Your browser does not support the video tag<source src="/assets/movie.mp4" type="video/mp4"><source src="/assets/movie.ogg" type="video/ogg"></video>))
98
- end
99
-
100
- it "raises an exception when no arguments" do
101
- expect do
102
- video_tag
103
- end.to raise_error(
104
- ArgumentError,
105
- "You should provide a source via `src` option or with a `source` HTML tag"
106
- )
107
- end
108
-
109
- it "raises an exception when no src and no block" do
110
- expect do
111
- video_tag(content: true)
112
- end.to raise_error(
113
- ArgumentError,
114
- "You should provide a source via `src` option or with a `source` HTML tag"
115
- )
116
- end
117
-
118
- describe "cdn mode" do
119
- let(:base_url) { "https://hanami.test" }
120
-
121
- def before_prepare
122
- Hanami.app.config.assets.base_url = "https://hanami.test"
123
- end
124
-
125
- it "returns absolute url for src attribute" do
126
- actual = video_tag("movie.mp4").to_s
127
- expect(actual).to eq(%(<video src="#{base_url}/assets/movie.mp4"></video>))
128
- end
129
- end
130
-
131
- private
132
-
133
- def tag(...)
134
- subject.__send__(:tag, ...)
135
- end
136
- end