hanami 2.0.2 → 2.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +25 -9
  5. data/hanami.gemspec +2 -2
  6. data/lib/hanami/config/actions.rb +0 -4
  7. data/lib/hanami/config/logger.rb +1 -1
  8. data/lib/hanami/config/views.rb +0 -4
  9. data/lib/hanami/config.rb +54 -0
  10. data/lib/hanami/extensions/action/slice_configured_action.rb +15 -7
  11. data/lib/hanami/extensions/action.rb +4 -4
  12. data/lib/hanami/extensions/router/errors.rb +58 -0
  13. data/lib/hanami/extensions/view/context.rb +129 -60
  14. data/lib/hanami/extensions/view/part.rb +26 -0
  15. data/lib/hanami/extensions/view/scope.rb +26 -0
  16. data/lib/hanami/extensions/view/slice_configured_context.rb +0 -2
  17. data/lib/hanami/extensions/view/slice_configured_helpers.rb +44 -0
  18. data/lib/hanami/extensions/view/slice_configured_view.rb +106 -21
  19. data/lib/hanami/extensions/view/standard_helpers.rb +14 -0
  20. data/lib/hanami/extensions.rb +10 -3
  21. data/lib/hanami/helpers/form_helper/form_builder.rb +1391 -0
  22. data/lib/hanami/helpers/form_helper/values.rb +75 -0
  23. data/lib/hanami/helpers/form_helper.rb +213 -0
  24. data/lib/hanami/middleware/public_errors_app.rb +75 -0
  25. data/lib/hanami/middleware/render_errors.rb +93 -0
  26. data/lib/hanami/slice.rb +28 -2
  27. data/lib/hanami/slice_configurable.rb +3 -2
  28. data/lib/hanami/version.rb +1 -1
  29. data/lib/hanami/web/rack_logger.rb +8 -20
  30. data/lib/hanami.rb +1 -1
  31. data/spec/integration/action/view_rendering/view_context_spec.rb +221 -0
  32. data/spec/integration/action/view_rendering_spec.rb +0 -18
  33. data/spec/integration/rack_app/middleware_spec.rb +23 -23
  34. data/spec/integration/rack_app/rack_app_spec.rb +5 -1
  35. data/spec/integration/slices/slice_registrations_spec.rb +80 -0
  36. data/spec/integration/view/config/default_context_spec.rb +149 -0
  37. data/spec/integration/view/{inflector_spec.rb → config/inflector_spec.rb} +1 -1
  38. data/spec/integration/view/config/part_class_spec.rb +147 -0
  39. data/spec/integration/view/config/part_namespace_spec.rb +103 -0
  40. data/spec/integration/view/config/paths_spec.rb +119 -0
  41. data/spec/integration/view/config/scope_class_spec.rb +147 -0
  42. data/spec/integration/view/config/scope_namespace_spec.rb +103 -0
  43. data/spec/integration/view/config/template_spec.rb +38 -0
  44. data/spec/integration/view/context/request_spec.rb +3 -7
  45. data/spec/integration/view/helpers/form_helper_spec.rb +174 -0
  46. data/spec/integration/view/helpers/part_helpers_spec.rb +124 -0
  47. data/spec/integration/view/helpers/scope_helpers_spec.rb +84 -0
  48. data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +162 -0
  49. data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +119 -0
  50. data/spec/integration/view/slice_configuration_spec.rb +9 -9
  51. data/spec/integration/web/render_detailed_errors_spec.rb +90 -0
  52. data/spec/integration/web/render_errors_spec.rb +240 -0
  53. data/spec/spec_helper.rb +1 -1
  54. data/spec/support/matchers.rb +32 -0
  55. data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -4
  56. data/spec/unit/hanami/config/logger_spec.rb +9 -0
  57. data/spec/unit/hanami/config/render_detailed_errors_spec.rb +25 -0
  58. data/spec/unit/hanami/config/render_errors_spec.rb +25 -0
  59. data/spec/unit/hanami/config/views_spec.rb +0 -18
  60. data/spec/unit/hanami/extensions/view/context_spec.rb +59 -0
  61. data/spec/unit/hanami/helpers/form_helper_spec.rb +2826 -0
  62. data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +27 -0
  63. data/spec/unit/hanami/router/errors/not_found_error_spec.rb +22 -0
  64. data/spec/unit/hanami/slice_configurable_spec.rb +18 -0
  65. data/spec/unit/hanami/version_spec.rb +1 -1
  66. data/spec/unit/hanami/web/rack_logger_spec.rb +1 -1
  67. metadata +67 -33
  68. data/spec/integration/action/view_integration_spec.rb +0 -165
  69. data/spec/integration/view/part_namespace_spec.rb +0 -96
  70. data/spec/integration/view/path_spec.rb +0 -56
  71. data/spec/integration/view/template_spec.rb +0 -68
  72. data/spec/isolation/hanami/application/already_configured_spec.rb +0 -19
  73. data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +0 -10
  74. data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +0 -14
  75. data/spec/isolation/hanami/application/not_configured_spec.rb +0 -9
  76. data/spec/isolation/hanami/application/routes/configured_spec.rb +0 -44
  77. data/spec/isolation/hanami/application/routes/not_configured_spec.rb +0 -16
  78. data/spec/isolation/hanami/boot/success_spec.rb +0 -50
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/router"
4
+ require "hanami/extensions/router/errors"
5
+
6
+ RSpec.describe(Hanami::Router::NotAllowedError) do
7
+ subject(:error) { described_class.new(env, allowed_methods) }
8
+
9
+ let(:env) { Rack::MockRequest.env_for("http://example.com/example", method: "POST") }
10
+ let(:allowed_methods) { ["GET", "HEAD"] }
11
+
12
+ it "is a Hanami::Router::Error" do
13
+ expect(error.class).to be < Hanami::Router::Error
14
+ end
15
+
16
+ it "returns a relevant message" do
17
+ expect(error.to_s).to eq "Only GET, HEAD requests are allowed at /example"
18
+ end
19
+
20
+ it "returns the env" do
21
+ expect(error.env).to be env
22
+ end
23
+
24
+ it "returns the allowed methods" do
25
+ expect(error.allowed_methods).to be allowed_methods
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/router"
4
+ require "hanami/extensions/router/errors"
5
+
6
+ RSpec.describe(Hanami::Router::NotFoundError) do
7
+ subject(:error) { described_class.new(env) }
8
+
9
+ let(:env) { Rack::MockRequest.env_for("http://example.com/example", method: "GET") }
10
+
11
+ it "is a Hanami::Router::Error" do
12
+ expect(error.class).to be < Hanami::Router::Error
13
+ end
14
+
15
+ it "returns a relevant message" do
16
+ expect(error.to_s).to eq "No route found for GET /example"
17
+ end
18
+
19
+ it "returns the env" do
20
+ expect(error.env).to be env
21
+ end
22
+ end
@@ -72,6 +72,24 @@ RSpec.describe Hanami::SliceConfigurable, :app_integration do
72
72
  end
73
73
  end
74
74
 
75
+ context "subclass inside slice with name overlapping another slice" do
76
+ let(:app_modules) { super() << :ExternalAdmin }
77
+
78
+ before do
79
+ TestApp::App.register_slice :external_admin
80
+
81
+ module ExternalAdmin
82
+ class MySubclass < TestApp::BaseClass; end
83
+ end
84
+ end
85
+
86
+ subject(:subclass) { ExternalAdmin::MySubclass }
87
+
88
+ it "calls `configure_for_slice` with the correct matching slice" do
89
+ expect(subclass.traces).to eq [ExternalAdmin::Slice]
90
+ end
91
+ end
92
+
75
93
  context "class inside app" do
76
94
  before do
77
95
  module TestApp
@@ -2,6 +2,6 @@
2
2
 
3
3
  RSpec.describe "Hanami::VERSION" do
4
4
  it "returns current version" do
5
- expect(Hanami::VERSION).to eq("2.0.2")
5
+ expect(Hanami::VERSION).to eq("2.1.0.beta1")
6
6
  end
7
7
  end
@@ -42,7 +42,7 @@ RSpec.describe Hanami::Web::RackLogger do
42
42
  verb = "POST"
43
43
 
44
44
  env = Rack::MockRequest.env_for(path, method: verb)
45
- env["Content-Length"] = content_length
45
+ env["CONTENT_LENGTH"] = content_length
46
46
  env["REMOTE_ADDR"] = ip
47
47
 
48
48
  params = {"user" => {"password" => "secret"}}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-25 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,28 +162,28 @@ dependencies:
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '2.0'
165
+ version: 2.1.beta
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '2.0'
172
+ version: 2.1.beta
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: hanami-utils
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '2.0'
179
+ version: 2.1.beta
180
180
  type: :runtime
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: '2.0'
186
+ version: 2.1.beta
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: zeitwerk
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -273,10 +273,20 @@ files:
273
273
  - lib/hanami/extensions.rb
274
274
  - lib/hanami/extensions/action.rb
275
275
  - lib/hanami/extensions/action/slice_configured_action.rb
276
+ - lib/hanami/extensions/router/errors.rb
276
277
  - lib/hanami/extensions/view.rb
277
278
  - lib/hanami/extensions/view/context.rb
279
+ - lib/hanami/extensions/view/part.rb
280
+ - lib/hanami/extensions/view/scope.rb
278
281
  - lib/hanami/extensions/view/slice_configured_context.rb
282
+ - lib/hanami/extensions/view/slice_configured_helpers.rb
279
283
  - lib/hanami/extensions/view/slice_configured_view.rb
284
+ - lib/hanami/extensions/view/standard_helpers.rb
285
+ - lib/hanami/helpers/form_helper.rb
286
+ - lib/hanami/helpers/form_helper/form_builder.rb
287
+ - lib/hanami/helpers/form_helper/values.rb
288
+ - lib/hanami/middleware/public_errors_app.rb
289
+ - lib/hanami/middleware/render_errors.rb
280
290
  - lib/hanami/port.rb
281
291
  - lib/hanami/prepare.rb
282
292
  - lib/hanami/providers/inflector.rb
@@ -305,9 +315,9 @@ files:
305
315
  - spec/integration/action/routes_spec.rb
306
316
  - spec/integration/action/sessions_spec.rb
307
317
  - spec/integration/action/slice_configuration_spec.rb
308
- - spec/integration/action/view_integration_spec.rb
309
318
  - spec/integration/action/view_rendering/automatic_rendering_spec.rb
310
319
  - spec/integration/action/view_rendering/paired_view_inference_spec.rb
320
+ - spec/integration/action/view_rendering/view_context_spec.rb
311
321
  - spec/integration/action/view_rendering_spec.rb
312
322
  - spec/integration/code_loading/loading_from_app_spec.rb
313
323
  - spec/integration/code_loading/loading_from_lib_spec.rb
@@ -337,29 +347,35 @@ files:
337
347
  - spec/integration/slices/external_slice_spec.rb
338
348
  - spec/integration/slices/slice_configuration_spec.rb
339
349
  - spec/integration/slices/slice_loading_spec.rb
350
+ - spec/integration/slices/slice_registrations_spec.rb
340
351
  - spec/integration/slices/slice_routing_spec.rb
341
352
  - spec/integration/slices_spec.rb
353
+ - spec/integration/view/config/default_context_spec.rb
354
+ - spec/integration/view/config/inflector_spec.rb
355
+ - spec/integration/view/config/part_class_spec.rb
356
+ - spec/integration/view/config/part_namespace_spec.rb
357
+ - spec/integration/view/config/paths_spec.rb
358
+ - spec/integration/view/config/scope_class_spec.rb
359
+ - spec/integration/view/config/scope_namespace_spec.rb
360
+ - spec/integration/view/config/template_spec.rb
342
361
  - spec/integration/view/context/assets_spec.rb
343
362
  - spec/integration/view/context/inflector_spec.rb
344
363
  - spec/integration/view/context/request_spec.rb
345
364
  - spec/integration/view/context/routes_spec.rb
346
365
  - spec/integration/view/context/settings_spec.rb
347
- - spec/integration/view/inflector_spec.rb
348
- - spec/integration/view/part_namespace_spec.rb
349
- - spec/integration/view/path_spec.rb
366
+ - spec/integration/view/helpers/form_helper_spec.rb
367
+ - spec/integration/view/helpers/part_helpers_spec.rb
368
+ - spec/integration/view/helpers/scope_helpers_spec.rb
369
+ - spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb
370
+ - spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb
350
371
  - spec/integration/view/slice_configuration_spec.rb
351
- - spec/integration/view/template_spec.rb
352
372
  - spec/integration/view/views_spec.rb
353
- - spec/isolation/hanami/application/already_configured_spec.rb
354
- - spec/isolation/hanami/application/inherit_anonymous_class_spec.rb
355
- - spec/isolation/hanami/application/inherit_concrete_class_spec.rb
356
- - spec/isolation/hanami/application/not_configured_spec.rb
357
- - spec/isolation/hanami/application/routes/configured_spec.rb
358
- - spec/isolation/hanami/application/routes/not_configured_spec.rb
359
- - spec/isolation/hanami/boot/success_spec.rb
373
+ - spec/integration/web/render_detailed_errors_spec.rb
374
+ - spec/integration/web/render_errors_spec.rb
360
375
  - spec/spec_helper.rb
361
376
  - spec/support/app_integration.rb
362
377
  - spec/support/coverage.rb
378
+ - spec/support/matchers.rb
363
379
  - spec/support/rspec.rb
364
380
  - spec/support/shared_examples/cli/generate/app.rb
365
381
  - spec/support/shared_examples/cli/generate/migration.rb
@@ -374,11 +390,17 @@ files:
374
390
  - spec/unit/hanami/config/base_url_spec.rb
375
391
  - spec/unit/hanami/config/inflector_spec.rb
376
392
  - spec/unit/hanami/config/logger_spec.rb
393
+ - spec/unit/hanami/config/render_detailed_errors_spec.rb
394
+ - spec/unit/hanami/config/render_errors_spec.rb
377
395
  - spec/unit/hanami/config/router_spec.rb
378
396
  - spec/unit/hanami/config/slices_spec.rb
379
397
  - spec/unit/hanami/config/views_spec.rb
380
398
  - spec/unit/hanami/env_spec.rb
399
+ - spec/unit/hanami/extensions/view/context_spec.rb
400
+ - spec/unit/hanami/helpers/form_helper_spec.rb
381
401
  - spec/unit/hanami/port_spec.rb
402
+ - spec/unit/hanami/router/errors/not_allowed_error_spec.rb
403
+ - spec/unit/hanami/router/errors/not_found_error_spec.rb
382
404
  - spec/unit/hanami/settings/env_store_spec.rb
383
405
  - spec/unit/hanami/settings_spec.rb
384
406
  - spec/unit/hanami/slice_configurable_spec.rb
@@ -403,11 +425,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
403
425
  version: '3.0'
404
426
  required_rubygems_version: !ruby/object:Gem::Requirement
405
427
  requirements:
406
- - - ">="
428
+ - - ">"
407
429
  - !ruby/object:Gem::Version
408
- version: '0'
430
+ version: 1.3.1
409
431
  requirements: []
410
- rubygems_version: 3.4.1
432
+ rubygems_version: 3.4.13
411
433
  signing_key:
412
434
  specification_version: 4
413
435
  summary: The web, with simplicity
@@ -418,9 +440,9 @@ test_files:
418
440
  - spec/integration/action/routes_spec.rb
419
441
  - spec/integration/action/sessions_spec.rb
420
442
  - spec/integration/action/slice_configuration_spec.rb
421
- - spec/integration/action/view_integration_spec.rb
422
443
  - spec/integration/action/view_rendering/automatic_rendering_spec.rb
423
444
  - spec/integration/action/view_rendering/paired_view_inference_spec.rb
445
+ - spec/integration/action/view_rendering/view_context_spec.rb
424
446
  - spec/integration/action/view_rendering_spec.rb
425
447
  - spec/integration/code_loading/loading_from_app_spec.rb
426
448
  - spec/integration/code_loading/loading_from_lib_spec.rb
@@ -450,29 +472,35 @@ test_files:
450
472
  - spec/integration/slices/external_slice_spec.rb
451
473
  - spec/integration/slices/slice_configuration_spec.rb
452
474
  - spec/integration/slices/slice_loading_spec.rb
475
+ - spec/integration/slices/slice_registrations_spec.rb
453
476
  - spec/integration/slices/slice_routing_spec.rb
454
477
  - spec/integration/slices_spec.rb
478
+ - spec/integration/view/config/default_context_spec.rb
479
+ - spec/integration/view/config/inflector_spec.rb
480
+ - spec/integration/view/config/part_class_spec.rb
481
+ - spec/integration/view/config/part_namespace_spec.rb
482
+ - spec/integration/view/config/paths_spec.rb
483
+ - spec/integration/view/config/scope_class_spec.rb
484
+ - spec/integration/view/config/scope_namespace_spec.rb
485
+ - spec/integration/view/config/template_spec.rb
455
486
  - spec/integration/view/context/assets_spec.rb
456
487
  - spec/integration/view/context/inflector_spec.rb
457
488
  - spec/integration/view/context/request_spec.rb
458
489
  - spec/integration/view/context/routes_spec.rb
459
490
  - spec/integration/view/context/settings_spec.rb
460
- - spec/integration/view/inflector_spec.rb
461
- - spec/integration/view/part_namespace_spec.rb
462
- - spec/integration/view/path_spec.rb
491
+ - spec/integration/view/helpers/form_helper_spec.rb
492
+ - spec/integration/view/helpers/part_helpers_spec.rb
493
+ - spec/integration/view/helpers/scope_helpers_spec.rb
494
+ - spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb
495
+ - spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb
463
496
  - spec/integration/view/slice_configuration_spec.rb
464
- - spec/integration/view/template_spec.rb
465
497
  - spec/integration/view/views_spec.rb
466
- - spec/isolation/hanami/application/already_configured_spec.rb
467
- - spec/isolation/hanami/application/inherit_anonymous_class_spec.rb
468
- - spec/isolation/hanami/application/inherit_concrete_class_spec.rb
469
- - spec/isolation/hanami/application/not_configured_spec.rb
470
- - spec/isolation/hanami/application/routes/configured_spec.rb
471
- - spec/isolation/hanami/application/routes/not_configured_spec.rb
472
- - spec/isolation/hanami/boot/success_spec.rb
498
+ - spec/integration/web/render_detailed_errors_spec.rb
499
+ - spec/integration/web/render_errors_spec.rb
473
500
  - spec/spec_helper.rb
474
501
  - spec/support/app_integration.rb
475
502
  - spec/support/coverage.rb
503
+ - spec/support/matchers.rb
476
504
  - spec/support/rspec.rb
477
505
  - spec/support/shared_examples/cli/generate/app.rb
478
506
  - spec/support/shared_examples/cli/generate/migration.rb
@@ -487,11 +515,17 @@ test_files:
487
515
  - spec/unit/hanami/config/base_url_spec.rb
488
516
  - spec/unit/hanami/config/inflector_spec.rb
489
517
  - spec/unit/hanami/config/logger_spec.rb
518
+ - spec/unit/hanami/config/render_detailed_errors_spec.rb
519
+ - spec/unit/hanami/config/render_errors_spec.rb
490
520
  - spec/unit/hanami/config/router_spec.rb
491
521
  - spec/unit/hanami/config/slices_spec.rb
492
522
  - spec/unit/hanami/config/views_spec.rb
493
523
  - spec/unit/hanami/env_spec.rb
524
+ - spec/unit/hanami/extensions/view/context_spec.rb
525
+ - spec/unit/hanami/helpers/form_helper_spec.rb
494
526
  - spec/unit/hanami/port_spec.rb
527
+ - spec/unit/hanami/router/errors/not_allowed_error_spec.rb
528
+ - spec/unit/hanami/router/errors/not_found_error_spec.rb
495
529
  - spec/unit/hanami/settings/env_store_spec.rb
496
530
  - spec/unit/hanami/settings_spec.rb
497
531
  - spec/unit/hanami/slice_configurable_spec.rb
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "App action / View integration", :app_integration do
4
- before do
5
- module TestApp
6
- class App < Hanami::App
7
- end
8
- end
9
-
10
- Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
11
- Hanami.app.prepare
12
-
13
- module TestApp
14
- class Action < Hanami::Action; end
15
- end
16
-
17
- module TestApp
18
- module Actions
19
- module Articles
20
- class Index < TestApp::Action; end
21
- end
22
- end
23
- end
24
- end
25
-
26
- let(:action_class) { TestApp::Actions::Articles::Index }
27
- subject(:action) { action_class.new(**action_args) }
28
- let(:action_args) { {} }
29
-
30
- describe "#view_context" do
31
- subject(:view_context) { action.view_context }
32
-
33
- context "Explicitly injected view context" do
34
- let(:view_context) { double(:view_context) }
35
- let(:action_args) { {view_context: view_context} }
36
-
37
- it "returns the injected object" do
38
- is_expected.to eql view_context
39
- end
40
- end
41
-
42
- context "No view context registered" do
43
- it "is nil" do
44
- is_expected.to be_nil
45
- end
46
- end
47
-
48
- context "Default view context identifier" do
49
- context "View context registered in slice" do
50
- before do
51
- TestApp::App.register "views.context", slice_view_context
52
- end
53
-
54
- let(:slice_view_context) { double(:slice_view_context) }
55
-
56
- it "is the slice's view context" do
57
- is_expected.to eql slice_view_context
58
- end
59
- end
60
-
61
- context "View context registered in app" do
62
- before do
63
- Hanami.app.register "views.context", app_view_context
64
- end
65
-
66
- let(:app_view_context) { double(:app_view_context) }
67
-
68
- it "is the apps's view context" do
69
- is_expected.to eql app_view_context
70
- end
71
- end
72
- end
73
-
74
- context "custom view context identifier" do
75
- let(:app_hook) {
76
- proc do |app|
77
- app.config.actions.view_context_identifier = "view.custom_context"
78
- end
79
- }
80
-
81
- before do
82
- TestApp::App.register "view.custom_context", custom_view_context
83
- end
84
-
85
- let(:custom_view_context) { double(:custom_view_context) }
86
-
87
- it "is the context registered with the custom identifier" do
88
- is_expected.to eql custom_view_context
89
- end
90
- end
91
- end
92
-
93
- describe "#view_options" do
94
- subject(:view_options) { action.send(:view_options, req, res) }
95
- let(:req) { double(:req) }
96
- let(:res) { double(:res) }
97
-
98
- context "without view context" do
99
- it "is an empty hash" do
100
- is_expected.to eq({})
101
- end
102
- end
103
-
104
- context "with view context" do
105
- let(:initial_view_context) { double(:initial_view_context) }
106
- let(:action_args) { {view_context: initial_view_context} }
107
-
108
- context "default #view_context_options" do
109
- let(:request_view_context) { double(:request_view_context) }
110
-
111
- before do
112
- allow(initial_view_context).to receive(:with).with(
113
- request: req,
114
- response: res,
115
- ) { request_view_context }
116
- end
117
-
118
- it "is the view context with the request and response provided" do
119
- is_expected.to eq(context: request_view_context)
120
- end
121
- end
122
-
123
- context "custom #view_context_options" do
124
- let(:custom_view_context) { double(:custom_view_context)}
125
-
126
- before do
127
- action_class.class_eval do
128
- def view_context_options(req, res)
129
- {custom_option: "custom option"}
130
- end
131
- end
132
-
133
- allow(initial_view_context).to receive(:with).with(
134
- custom_option: "custom option"
135
- ) { custom_view_context }
136
- end
137
-
138
- it "is the view context with the custom options provided" do
139
- is_expected.to eq(context: custom_view_context)
140
- end
141
- end
142
-
143
- context "specialized method (calling super) defined in action class" do
144
- let(:request_view_context) { double(:request_view_context) }
145
-
146
- before do
147
- allow(initial_view_context).to receive(:with).with(
148
- request: req,
149
- response: res,
150
- ) { request_view_context }
151
-
152
- action_class.class_eval do
153
- def view_options(req, res)
154
- super.merge(extra_option: "extra option")
155
- end
156
- end
157
- end
158
-
159
- it "includes the options provided by the specialized method" do
160
- is_expected.to eq(context: request_view_context, extra_option: "extra option")
161
- end
162
- end
163
- end
164
- end
165
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Part namespace", :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
- # The parts module (or any related setup) must exist _before_ we subclass
18
- # Hanami::View, because the parts_namespace is configured at the time of
19
- # subclassing (which happens right below)
20
- parts_module! if respond_to?(:parts_module!)
21
-
22
- module TestApp
23
- class View < Hanami::View
24
- end
25
- end
26
-
27
- module TestApp
28
- module Views
29
- module Article
30
- class Index < TestApp::View
31
- end
32
- end
33
- end
34
- end
35
- end
36
-
37
- subject(:part_namespace) { view_class.config.part_namespace }
38
-
39
- let(:view_class) { TestApp::Views::Article::Index }
40
-
41
- context "default parts_path" do
42
- let(:parts_module!) do
43
- module TestApp
44
- module Views
45
- module Parts
46
- end
47
- end
48
- end
49
- end
50
-
51
- it "is View::Parts" do
52
- is_expected.to eq TestApp::Views::Parts
53
- end
54
- end
55
-
56
- context "custom parts_path configured" do
57
- let(:app_hook) {
58
- proc do
59
- config.views.parts_path = "views/custom_parts"
60
- end
61
- }
62
-
63
- context "parts module exists" do
64
- let(:parts_module!) do
65
- module TestApp
66
- module Views
67
- module CustomParts
68
- end
69
- end
70
- end
71
- end
72
-
73
- it "is the matching module within the slice" do
74
- is_expected.to eq TestApp::Views::CustomParts
75
- end
76
- end
77
-
78
- context "namespace does not exist" do
79
- it "is nil" do
80
- is_expected.to be_nil
81
- end
82
- end
83
- end
84
-
85
- context "nil parts_path configured" do
86
- let(:app_hook) {
87
- proc do
88
- config.views.parts_path = nil
89
- end
90
- }
91
-
92
- it "is nil" do
93
- is_expected.to be_nil
94
- end
95
- end
96
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Path", :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
- let(:view_class) { TestApp::View }
24
-
25
- subject(:paths) { view_class.config.paths }
26
-
27
- context "default path" do
28
- it "is 'templates' appended to the slice's root path" do
29
- expect(paths.map { |path| path.dir.to_s }).to eq ["/test_app/app/templates"]
30
- end
31
- end
32
-
33
- context "relative path provided in app config" do
34
- let(:app_hook) {
35
- proc do
36
- config.views.paths = ["my_templates"]
37
- end
38
- }
39
-
40
- it "configures the path as the relative path appended to the slice's root path" do
41
- expect(paths.map { |path| path.dir.to_s }).to eq ["/test_app/app/my_templates"]
42
- end
43
- end
44
-
45
- context "absolute path provided in app config" do
46
- let(:app_hook) {
47
- proc do
48
- config.views.paths = ["/absolute/path"]
49
- end
50
- }
51
-
52
- it "leaves the absolute path in place" do
53
- expect(paths.map { |path| path.dir.to_s }).to eq ["/absolute/path"]
54
- end
55
- end
56
- end