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,471 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Slices", :app_integration do
4
- specify "Loading a slice from a slice class in the app's config dir" do
5
- with_tmp_directory(Dir.mktmpdir) do
6
- write "config/app.rb", <<~RUBY
7
- require "hanami"
8
-
9
- module TestApp
10
- class App < Hanami::App
11
- end
12
- end
13
- RUBY
14
-
15
- write "config/slices/main.rb", <<~RUBY
16
- module Main
17
- class Slice < Hanami::Slice
18
- end
19
- end
20
- RUBY
21
-
22
- write "slices/main/lib/foo.rb", <<~RUBY
23
- module Main
24
- class Foo; end
25
- end
26
- RUBY
27
-
28
- require "hanami/prepare"
29
-
30
- expect(Hanami.app.slices[:main]).to be Main::Slice
31
- end
32
- end
33
-
34
- specify "Loading a slice from a slice class in the app's config dir, even when no slice dir exists" do
35
- with_tmp_directory(Dir.mktmpdir) do
36
- write "config/app.rb", <<~RUBY
37
- require "hanami"
38
-
39
- module TestApp
40
- class App < Hanami::App
41
- end
42
- end
43
- RUBY
44
-
45
- write "config/slices/main.rb", <<~RUBY
46
- module Main
47
- class Slice < Hanami::Slice
48
- end
49
- end
50
- RUBY
51
-
52
- require "hanami/prepare"
53
-
54
- expect(Hanami.app.slices[:main]).to be Main::Slice
55
- end
56
- end
57
-
58
- specify "Loading a nested slice from a slice class in its parent's config dir" do
59
- with_tmp_directory(Dir.mktmpdir) do
60
- write "config/app.rb", <<~RUBY
61
- require "hanami"
62
-
63
- module TestApp
64
- class App < Hanami::App
65
- end
66
- end
67
- RUBY
68
-
69
- write "slices/main/config/slices/nested.rb", <<~RUBY
70
- module Main
71
- module Nested
72
- class Slice < Hanami::Slice
73
- end
74
- end
75
- end
76
- RUBY
77
-
78
- require "hanami/prepare"
79
-
80
- expect(Hanami.app.slices[:main].slices[:nested]).to be Main::Nested::Slice
81
- end
82
- end
83
-
84
- specify "Loading a slice from a slice class in its own config dir" do
85
- with_tmp_directory(Dir.mktmpdir) do
86
- write "config/app.rb", <<~RUBY
87
- require "hanami"
88
-
89
- module TestApp
90
- class App < Hanami::App
91
- end
92
- end
93
- RUBY
94
-
95
- write "slices/main/config/slice.rb", <<~RUBY
96
- module Main
97
- class Slice < Hanami::Slice
98
- def self.loaded_from = "own config dir"
99
- end
100
- end
101
- RUBY
102
-
103
- require "hanami/prepare"
104
-
105
- expect(Hanami.app.slices[:main]).to be Main::Slice
106
- expect(Hanami.app.slices[:main].loaded_from).to eq "own config dir"
107
- end
108
- end
109
-
110
- specify "Loading a slice from a slice class in the app's config dir, in preference to a slice class in its own config dir" do
111
- with_tmp_directory(Dir.mktmpdir) do
112
- write "config/app.rb", <<~RUBY
113
- require "hanami"
114
-
115
- module TestApp
116
- class App < Hanami::App
117
- end
118
- end
119
- RUBY
120
-
121
- write "config/slices/main.rb", <<~RUBY
122
- require "hanami"
123
-
124
- module Main
125
- class Slice < Hanami::Slice
126
- def self.loaded_from = "app config dir"
127
- end
128
- end
129
- RUBY
130
-
131
- write "slices/main/config/slice.rb", <<~RUBY
132
- raise "This should not be loaded"
133
- RUBY
134
-
135
- require "hanami/prepare"
136
-
137
- expect(Hanami.app.slices[:main]).to be Main::Slice
138
- expect(Hanami.app.slices[:main].loaded_from).to eq "app config dir"
139
- end
140
- end
141
-
142
- specify "Loading a nested slice from a slice class in its own config dir" do
143
- with_tmp_directory(Dir.mktmpdir) do
144
- write "config/app.rb", <<~RUBY
145
- require "hanami"
146
-
147
- module TestApp
148
- class App < Hanami::App
149
- end
150
- end
151
- RUBY
152
-
153
- write "slices/main/slices/nested/config/slice.rb", <<~RUBY
154
- module Main
155
- module Nested
156
- class Slice < Hanami::Slice
157
- def self.loaded_from = "own config dir"
158
- end
159
- end
160
- end
161
- RUBY
162
-
163
- require "hanami/prepare"
164
-
165
- expect(Hanami.app.slices[:main]).to be Main::Slice
166
- expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "own config dir"
167
- end
168
- end
169
-
170
- specify "Loading a deeply nested slice from a slice class in its own config dir" do
171
- with_tmp_directory(Dir.mktmpdir) do
172
- write "config/app.rb", <<~RUBY
173
- require "hanami"
174
-
175
- module TestApp
176
- class App < Hanami::App
177
- end
178
- end
179
- RUBY
180
-
181
- # It does NOT look up "grandparent" (or above) configs; only the parent and the app
182
- write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
183
- raise "This should not be loaded"
184
- RUBY
185
-
186
- write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
187
- module Main
188
- module Deeply
189
- module Nested
190
- class Slice < Hanami::Slice
191
- def self.loaded_from = "own config dir"
192
- end
193
- end
194
- end
195
- end
196
- RUBY
197
-
198
- require "hanami/prepare"
199
-
200
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
201
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "own config dir"
202
- end
203
- end
204
-
205
- specify "Loading a nested slice from a slice class in its parent's config dir, in preference to a slice class in its own config dir" do
206
- with_tmp_directory(Dir.mktmpdir) do
207
- write "config/app.rb", <<~RUBY
208
- require "hanami"
209
-
210
- module TestApp
211
- class App < Hanami::App
212
- end
213
- end
214
- RUBY
215
-
216
- write "slices/main/config/slices/nested.rb", <<~RUBY
217
- require "hanami"
218
-
219
- module Main
220
- module Nested
221
- class Slice < Hanami::Slice
222
- def self.loaded_from = "parent config dir"
223
- end
224
- end
225
- end
226
- RUBY
227
-
228
- write "slices/main/slices/nested/config/slice.rb", <<~RUBY
229
- raise "This should not be loaded"
230
- RUBY
231
-
232
- require "hanami/prepare"
233
-
234
- expect(Hanami.app.slices[:main]).to be Main::Slice
235
- expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "parent config dir"
236
- end
237
- end
238
-
239
- specify "Loading a deeply nested slice from a slice class in its parent's config dir, in preference to a slice class in its own config dir" do
240
- with_tmp_directory(Dir.mktmpdir) do
241
- write "config/app.rb", <<~RUBY
242
- require "hanami"
243
-
244
- module TestApp
245
- class App < Hanami::App
246
- end
247
- end
248
- RUBY
249
-
250
- # It does NOT look up "grandparent" (or above) configs; only the parent and the app
251
- write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
252
- raise "This should not be loaded"
253
- RUBY
254
-
255
- write "slices/main/slices/deeply/config/slices/nested.rb", <<~RUBY
256
- module Main
257
- module Deeply
258
- module Nested
259
- class Slice < Hanami::Slice
260
- def self.loaded_from = "parent config dir"
261
- end
262
- end
263
- end
264
- end
265
- RUBY
266
-
267
- write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
268
- raise "This should not be loaded"
269
- RUBY
270
-
271
- require "hanami/prepare"
272
-
273
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
274
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "parent config dir"
275
- end
276
- end
277
-
278
- specify "Loading a nested slice from a slice class in the app's config dir, in preference to a slice class in the slice's parent config dir or the slice's own config dir" do
279
- with_tmp_directory(Dir.mktmpdir) do
280
- write "config/app.rb", <<~RUBY
281
- require "hanami"
282
-
283
- module TestApp
284
- class App < Hanami::App
285
- end
286
- end
287
- RUBY
288
-
289
- write "config/slices/main/nested.rb", <<~RUBY
290
- require "hanami"
291
-
292
- module Main
293
- module Nested
294
- class Slice < Hanami::Slice
295
- def self.loaded_from = "app config dir"
296
- end
297
- end
298
- end
299
- RUBY
300
-
301
- write "slices/main/config/slices/nested.rb", <<~RUBY
302
- raise "This should not be loaded"
303
- RUBY
304
-
305
- write "slices/main/slices/nested/config/slice.rb", <<~RUBY
306
- raise "This should not be loaded"
307
- RUBY
308
-
309
- require "hanami/prepare"
310
-
311
- expect(Hanami.app.slices[:main]).to be Main::Slice
312
- expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "app config dir"
313
- end
314
- end
315
-
316
- specify "Loading a deeply nested slice from a slice class in the app's config dir, in preference to a slice class in the slice's parent config dir or the slice's own config dir" do
317
- with_tmp_directory(Dir.mktmpdir) do
318
- write "config/app.rb", <<~RUBY
319
- require "hanami"
320
-
321
- module TestApp
322
- class App < Hanami::App
323
- end
324
- end
325
- RUBY
326
-
327
- write "config/slices/main/deeply/nested.rb", <<~RUBY
328
- module Main
329
- module Deeply
330
- module Nested
331
- class Slice < Hanami::Slice
332
- def self.loaded_from = "app config dir"
333
- end
334
- end
335
- end
336
- end
337
- RUBY
338
-
339
- write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
340
- raise "This should not be loaded"
341
- RUBY
342
-
343
- write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
344
- raise "This should not be loaded"
345
- RUBY
346
-
347
- require "hanami/prepare"
348
-
349
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
350
- expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "app config dir"
351
- end
352
- end
353
-
354
- specify "Loading a slice generates a slice class if none is defined" do
355
- with_tmp_directory(Dir.mktmpdir) do
356
- write "config/app.rb", <<~RUBY
357
- require "hanami"
358
-
359
- module TestApp
360
- class App < Hanami::App
361
- end
362
- end
363
- RUBY
364
-
365
- write "slices/main/lib/foo.rb", <<~RUBY
366
- module Main
367
- class Foo; end
368
- end
369
- RUBY
370
-
371
- require "hanami/prepare"
372
-
373
- expect(Hanami.app.slices[:main]).to be Main::Slice
374
- end
375
- end
376
-
377
- specify "Registering a slice on the app creates a slice class with a top-level namespace" do
378
- with_tmp_directory(Dir.mktmpdir) do
379
- write "config/app.rb", <<~RUBY
380
- require "hanami"
381
-
382
- module TestApp
383
- class App < Hanami::App
384
- register_slice :main
385
- end
386
- end
387
- RUBY
388
-
389
- require "hanami/prepare"
390
-
391
- expect(Hanami.app.slices[:main]).to be Main::Slice
392
- expect(Main::Slice.ancestors).to include(Hanami::Slice)
393
- end
394
- end
395
-
396
- specify "Registering a nested slice creates a slice class within the parent's namespace" do
397
- with_tmp_directory(Dir.mktmpdir) do
398
- write "config/app.rb", <<~RUBY
399
- require "hanami"
400
-
401
- module TestApp
402
- class App < Hanami::App
403
- end
404
- end
405
- RUBY
406
-
407
- write "config/slices/main.rb", <<~RUBY
408
- module Main
409
- class Slice < Hanami::Slice
410
- register_slice :nested
411
- end
412
- end
413
- RUBY
414
-
415
- require "hanami/prepare"
416
-
417
- expect(Hanami.app.slices[:main].slices[:nested]).to be Main::Nested::Slice
418
- end
419
- end
420
-
421
- specify "Registering a nested slice with an existing class uses that class' own namespace" do
422
- with_tmp_directory(Dir.mktmpdir) do
423
- write "config/app.rb", <<~RUBY
424
- require "hanami"
425
-
426
- module TestApp
427
- class App < Hanami::App
428
- end
429
- end
430
- RUBY
431
-
432
- write "config/slices/main.rb", <<~RUBY
433
- module Admin
434
- class Slice < Hanami::Slice
435
- end
436
- end
437
-
438
- module Main
439
- class Slice < Hanami::Slice
440
- register_slice :nested, Admin::Slice
441
- end
442
- end
443
- RUBY
444
-
445
- require "hanami/prepare"
446
-
447
- expect(Hanami.app.slices[:main].slices[:nested]).to be Admin::Slice
448
- end
449
- end
450
-
451
- specify "Registering a slice with a block creates a slice class and evals the block" do
452
- with_tmp_directory(Dir.mktmpdir) do
453
- write "config/app.rb", <<~RUBY
454
- require "hanami"
455
-
456
- module TestApp
457
- class App < Hanami::App
458
- register_slice :main do
459
- register "greeting", "hello world"
460
- end
461
- end
462
- end
463
- RUBY
464
-
465
- require "hanami/prepare"
466
-
467
- expect(Hanami.app.slices[:main]).to be Main::Slice
468
- expect(Main::Slice["greeting"]).to eq "hello world"
469
- end
470
- end
471
- end
@@ -1,149 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "App view / Config / Default context", :app_integration do
4
- before do
5
- with_directory(@dir = make_tmp_directory) do
6
- write "config/app.rb", <<~RUBY
7
- module TestApp
8
- class App < Hanami::App
9
- end
10
- end
11
- RUBY
12
-
13
- write "app/view.rb", <<~RUBY
14
- # auto_register: false
15
-
16
- require "hanami/view"
17
-
18
- module TestApp
19
- class View < Hanami::View
20
- end
21
- end
22
- RUBY
23
-
24
- before_prepare if respond_to?(:before_prepare)
25
- require "hanami/prepare"
26
- end
27
- end
28
-
29
- subject(:default_context) { view_class.config.default_context }
30
-
31
- describe "app view" do
32
- let(:view_class) { TestApp::View }
33
-
34
- describe "no concrete context class defined" do
35
- it "generates an app context class and configures it as the view's default_context" do
36
- expect(default_context).to be_an_instance_of TestApp::Views::Context
37
- expect(default_context.class.superclass).to be Hanami::View::Context
38
- end
39
- end
40
-
41
- describe "concrete context class defined" do
42
- def before_prepare
43
- write "app/views/context.rb", <<~RUBY
44
- # auto_register: false
45
-
46
- module TestApp
47
- module Views
48
- class Context < Hanami::View::Context
49
- def concrete?
50
- true
51
- end
52
- end
53
- end
54
- end
55
- RUBY
56
- end
57
-
58
- it "configures the app scope class as the view's scope_class" do
59
- expect(default_context).to be_an_instance_of TestApp::Views::Context
60
- expect(default_context).to be_concrete
61
- end
62
- end
63
- end
64
-
65
- describe "slice view" do
66
- let(:view_class) { Main::View }
67
-
68
- def before_prepare
69
- write "slices/main/view.rb", <<~RUBY
70
- # auto_register: false
71
-
72
- module Main
73
- class View < TestApp::View
74
- end
75
- end
76
- RUBY
77
- end
78
-
79
- describe "no concrete slice context class defined" do
80
- it "generates an app context class and configures it as the view's default_context" do
81
- expect(default_context).to be_an_instance_of Main::Views::Context
82
- expect(default_context.class.superclass).to be TestApp::Views::Context
83
- end
84
- end
85
-
86
- describe "concrete slice context class defined" do
87
- def before_prepare
88
- super
89
-
90
- write "slices/main/views/context.rb", <<~RUBY
91
- # auto_register: false
92
-
93
- module Main
94
- module Views
95
- class Context < Hanami::View::Context
96
- def concrete?
97
- true
98
- end
99
- end
100
- end
101
- end
102
- RUBY
103
- end
104
-
105
- it "configures the slice context as the view's default_context" do
106
- expect(default_context).to be_an_instance_of Main::Views::Context
107
- expect(default_context).to be_concrete
108
- end
109
- end
110
-
111
- describe "view not inheriting from app view, no concrete context class defined" do
112
- def before_prepare
113
- write "slices/main/view.rb", <<~RUBY
114
- # auto_register: false
115
-
116
- module Main
117
- class View < Hanami::View
118
- end
119
- end
120
- RUBY
121
- end
122
-
123
- it "generates a slice context class, inheriting from the app context class, and configures it as the view's default_context" do
124
- expect(default_context).to be_an_instance_of Main::Views::Context
125
- expect(default_context.class.superclass).to be TestApp::Views::Context
126
- end
127
- end
128
-
129
- describe "no app view class defined" do
130
- def before_prepare
131
- FileUtils.rm "app/view.rb"
132
-
133
- write "slices/main/view.rb", <<~RUBY
134
- # auto_register: false
135
-
136
- module Main
137
- class View < Hanami::View
138
- end
139
- end
140
- RUBY
141
- end
142
-
143
- it "generates a slice context class, inheriting from the app context class, and configures it as the view's default_context" do
144
- expect(default_context).to be_an_instance_of Main::Views::Context
145
- expect(default_context.class.superclass).to be Hanami::View::Context
146
- end
147
- end
148
- end
149
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Config / Inflector", :app_integration do
6
- before do
7
- module TestApp
8
- class App < Hanami::App
9
- config.root = "/test_app"
10
- end
11
- end
12
-
13
- Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
14
- Hanami.app.register_slice :main
15
- Hanami.app.prepare
16
-
17
- module TestApp
18
- class View < Hanami::View
19
- end
20
- end
21
- end
22
-
23
- subject(:view_class) { TestApp::View }
24
-
25
- context "default app inflector" do
26
- it "configures the view with the default app inflector" do
27
- expect(view_class.config.inflector).to be TestApp::App.config.inflector
28
- end
29
- end
30
-
31
- context "custom inflections configured" do
32
- let(:app_hook) {
33
- proc do
34
- config.inflections do |inflections|
35
- inflections.acronym "NBA"
36
- end
37
- end
38
- }
39
-
40
- it "configures the view with the customized app inflector" do
41
- expect(view_class.config.inflector).to be TestApp::App.config.inflector
42
- expect(view_class.config.inflector.camelize("nba_jam")).to eq "NBAJam"
43
- end
44
- end
45
-
46
- context "custom inflector configured on view class" do
47
- let(:custom_inflector) { Object.new }
48
-
49
- before do
50
- view_class.config.inflector = custom_inflector
51
- end
52
-
53
- it "overrides the default app inflector" do
54
- expect(view_class.config.inflector).to be custom_inflector
55
- end
56
- end
57
- end