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,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Context / Assets", :app_integration do
6
- subject(:context) { context_class.new }
7
- let(:context_class) { TestApp::Views::Context }
8
-
9
- before do
10
- with_directory(make_tmp_directory) do
11
- write "config/app.rb", <<~RUBY
12
- module TestApp
13
- class App < Hanami::App
14
- config.logger.stream = File::NULL
15
- end
16
- end
17
- RUBY
18
-
19
- write "app/views/context.rb", <<~RUBY
20
- # auto_register: false
21
-
22
- require "hanami/view/context"
23
-
24
- module TestApp
25
- module Views
26
- class Context < Hanami::View::Context
27
- end
28
- end
29
- end
30
- RUBY
31
-
32
- before_prepare if respond_to?(:before_prepare)
33
- require "hanami/prepare"
34
- end
35
- end
36
-
37
- context "assets present and hanami-assets bundled" do
38
- def before_prepare
39
- write "app/assets/.keep", ""
40
- end
41
-
42
- it "is the app assets by default" do
43
- expect(context.assets).to be TestApp::App[:assets]
44
- end
45
- end
46
-
47
- context "assets not present" do
48
- it "raises error" do
49
- expect { context.assets }.to raise_error(Hanami::ComponentLoadError, /assets directory\?/)
50
- end
51
- end
52
-
53
- context "hanami-assets not bundled" do
54
- def before_prepare
55
- # These must be here instead of an ordinary before hook because the Hanami.bundled? check for
56
- # assets is done as part of requiring "hanami/prepare" above.
57
- allow(Hanami).to receive(:bundled?).and_call_original
58
- allow(Hanami).to receive(:bundled?).with("hanami-assets").and_return(false)
59
-
60
- write "app/assets/.keep", ""
61
- end
62
-
63
- it "raises error" do
64
- expect { context.assets }.to raise_error(Hanami::ComponentLoadError, /hanami-assets gem/)
65
- end
66
- end
67
-
68
- context "injected assets" do
69
- subject(:context) {
70
- context_class.new(assets: assets)
71
- }
72
-
73
- let(:assets) { double(:assets) }
74
-
75
- it "is the injected assets" do
76
- expect(context.assets).to be assets
77
- end
78
- end
79
- end
@@ -1,40 +0,0 @@
1
- require "hanami"
2
-
3
- RSpec.describe "App view / Context / Inflector", :app_integration do
4
- before do
5
- module TestApp
6
- class App < Hanami::App
7
- end
8
- end
9
-
10
- Hanami.prepare
11
-
12
- module TestApp
13
- module Views
14
- class Context < Hanami::View::Context
15
- end
16
- end
17
- end
18
- end
19
-
20
- let(:context_class) { TestApp::Views::Context }
21
- subject(:context) { context_class.new }
22
-
23
- describe "#inflector" do
24
- it "is the app inflector by default" do
25
- expect(context.inflector).to be TestApp::App.inflector
26
- end
27
-
28
- context "injected inflector" do
29
- subject(:context) {
30
- context_class.new(inflector: inflector)
31
- }
32
-
33
- let(:inflector) { double(:inflector) }
34
-
35
- it "is the injected inflector" do
36
- expect(context.inflector).to be inflector
37
- end
38
- end
39
- end
40
- end
@@ -1,57 +0,0 @@
1
- require "hanami"
2
-
3
- RSpec.describe "App view / Context / Request", :app_integration do
4
- before do
5
- module TestApp
6
- class App < Hanami::App
7
- end
8
- end
9
-
10
- Hanami.prepare
11
-
12
- module TestApp
13
- module Views
14
- class Context < Hanami::View::Context
15
- end
16
- end
17
- end
18
- end
19
-
20
- let(:context_class) { TestApp::Views::Context }
21
-
22
- subject(:context) {
23
- context_class.new(request: request)
24
- }
25
-
26
- let(:request) { double(:request) }
27
-
28
- describe "#request" do
29
- it "is the provided request" do
30
- expect(context.request).to be request
31
- end
32
- end
33
-
34
- describe "#session" do
35
- let(:session) { double(:session) }
36
-
37
- before do
38
- allow(request).to receive(:session) { session }
39
- end
40
-
41
- it "is the request's session" do
42
- expect(context.session).to be session
43
- end
44
- end
45
-
46
- describe "#flash" do
47
- let(:flash) { double(:flash) }
48
-
49
- before do
50
- allow(request).to receive(:flash) { flash }
51
- end
52
-
53
- it "is the request's flash" do
54
- expect(context.flash).to be flash
55
- end
56
- end
57
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Context / Routes", :app_integration do
6
- it "accesses app routes" do
7
- with_tmp_directory(Dir.mktmpdir) do
8
- write "config/app.rb", <<~RUBY
9
- require "hanami"
10
-
11
- module TestApp
12
- class App < Hanami::App
13
- end
14
- end
15
- RUBY
16
-
17
- write "config/routes.rb", <<~RUBY
18
- module TestApp
19
- class Routes < Hanami::Routes
20
- root to: "home.index"
21
- end
22
- end
23
- RUBY
24
-
25
- write "app/action.rb", <<~RUBY
26
- require "hanami/action"
27
-
28
- module TestApp
29
- class Action < Hanami::Action
30
- end
31
- end
32
- RUBY
33
-
34
- write "app/actions/home/index.rb", <<~RUBY
35
- module TestApp
36
- module Actions
37
- module Home
38
- class Index < Hanami::Action
39
- end
40
- end
41
- end
42
- end
43
- RUBY
44
-
45
- write "app/views/context.rb", <<~RUBY
46
- require "hanami/view/context"
47
-
48
- module TestApp
49
- module Views
50
- class Context < Hanami::View::Context
51
- end
52
- end
53
- end
54
- RUBY
55
-
56
- require "hanami/prepare"
57
-
58
- context = TestApp::Views::Context.new
59
- expect(context.routes.path(:root)).to eq "/"
60
- end
61
- end
62
-
63
- it "can inject routes" do
64
- module TestApp
65
- class App < Hanami::App
66
- end
67
- end
68
-
69
- Hanami.prepare
70
-
71
- module TestApp
72
- module Views
73
- class Context < Hanami::View::Context
74
- end
75
- end
76
- end
77
-
78
- routes = double(:routes)
79
-
80
- context = TestApp::Views::Context.new(routes: routes)
81
-
82
- expect(context.routes).to be(routes)
83
- end
84
- end
@@ -1,174 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rack/test"
4
- require "stringio"
5
-
6
- RSpec.describe "Helpers / FormHelper", :app_integration do
7
- include Rack::Test::Methods
8
- let(:app) { Hanami.app }
9
-
10
- before do
11
- with_directory(make_tmp_directory) do
12
- write "config/app.rb", <<~RUBY
13
- module TestApp
14
- class App < Hanami::App
15
- config.logger.stream = StringIO.new
16
- end
17
- end
18
- RUBY
19
-
20
- write "config/routes.rb", <<~RUBY
21
- module TestApp
22
- class Routes < Hanami::Routes
23
- get "posts/:id/edit", to: "posts.edit"
24
- put "posts/:id", to: "posts.update"
25
- end
26
- end
27
- RUBY
28
-
29
- write "app/action.rb", <<~RUBY
30
- # auto_register: false
31
-
32
- require "hanami/action"
33
-
34
- module TestApp
35
- class Action < Hanami::Action
36
- end
37
- end
38
- RUBY
39
-
40
- write "app/view.rb", <<~RUBY
41
- # auto_register: false
42
-
43
- require "hanami/view"
44
-
45
- module TestApp
46
- class View < Hanami::View
47
- config.layout = nil
48
- end
49
- end
50
- RUBY
51
-
52
- write "app/actions/posts/edit.rb", <<~RUBY
53
- module TestApp
54
- module Actions
55
- module Posts
56
- class Edit < TestApp::Action
57
- end
58
- end
59
- end
60
- end
61
- RUBY
62
-
63
- write "app/actions/posts/update.rb", <<~RUBY
64
- module TestApp
65
- module Actions
66
- module Posts
67
- class Update < TestApp::Action
68
- def handle(request, response)
69
- if valid?(request.params[:post])
70
- response.redirect_to "/posts/x/edit"
71
- else
72
- response.render view
73
- end
74
- end
75
-
76
- private
77
-
78
- def valid?(post)
79
- post.to_h[:title].to_s.length > 0
80
- end
81
- end
82
- end
83
- end
84
- end
85
- RUBY
86
-
87
- write "app/views/posts/edit.rb", <<~RUBY
88
- module TestApp
89
- module Views
90
- module Posts
91
- class Edit < TestApp::View
92
- expose :post do
93
- Struct.new(:title, :body).new("Hello <world>", "This is the post.")
94
- end
95
- end
96
- end
97
- end
98
- end
99
- RUBY
100
-
101
- write "app/templates/posts/edit.html.erb", <<~ERB
102
- <h1>Edit post</h1>
103
-
104
- <%= form_for("/posts") do |f| %>
105
- <div>
106
- Title:
107
- <%= f.text_field "post.title" %>
108
- </div>
109
- <div>
110
- Body:
111
- <%= f.text_area "post.body" %>
112
- </div>
113
- <% end %>
114
- ERB
115
-
116
- before_prepare if respond_to?(:before_prepare)
117
- require "hanami/prepare"
118
- end
119
- end
120
-
121
- it "does not have a _csrf_token field when no sessions are configured" do
122
- get "/posts/123/edit"
123
-
124
- html = Capybara.string(last_response.body)
125
-
126
- expect(html).to have_no_selector("input[type='hidden'][name='_csrf_token']")
127
- end
128
-
129
- it "uses the value from the view's locals" do
130
- get "/posts/123/edit"
131
-
132
- html = Capybara.string(last_response.body)
133
-
134
- title_field = html.find("input[name='post[title]']")
135
- expect(title_field.value).to eq "Hello <world>"
136
-
137
- body_field = html.find("textarea[name='post[body]']")
138
- expect(body_field.value).to eq "This is the post."
139
- end
140
-
141
- it "prefers the values from the request params" do
142
- put "/posts/123", post: {title: "", body: "This is the UPDATED post."}
143
-
144
- html = Capybara.string(last_response.body)
145
-
146
- title_field = html.find("input[name='post[title]']")
147
- expect(title_field.value).to eq ""
148
-
149
- body_field = html.find("textarea[name='post[body]']")
150
- expect(body_field.value).to eq "This is the UPDATED post."
151
- end
152
-
153
- context "sessions enabled" do
154
- def before_prepare
155
- write "config/app.rb", <<~RUBY
156
- module TestApp
157
- class App < Hanami::App
158
- config.logger.stream = StringIO.new
159
- config.actions.sessions = :cookie, {secret: "wxyz"*16} # Rack demands >=64 characters
160
- end
161
- end
162
- RUBY
163
- end
164
-
165
- it "inserts a CSRF token field" do
166
- get "/posts/123/edit"
167
-
168
- html = Capybara.string(last_response.body)
169
-
170
- csrf_field = html.find("input[type='hidden'][name='_csrf_token']", visible: false)
171
- expect(csrf_field.value).to match(/[a-z0-9]{10,}/i)
172
- end
173
- end
174
- end
@@ -1,124 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ostruct"
4
-
5
- # rubocop:disable Style/OpenStructUse
6
-
7
- RSpec.describe "App view / Helpers / Part helpers", :app_integration do
8
- before do
9
- with_directory(make_tmp_directory) do
10
- write "config/app.rb", <<~RUBY
11
- module TestApp
12
- class App < Hanami::App
13
- end
14
- end
15
- RUBY
16
-
17
- write "app/view.rb", <<~RUBY
18
- # auto_register: false
19
-
20
- require "hanami/view"
21
-
22
- module TestApp
23
- class View < Hanami::View
24
- config.layout = nil
25
- end
26
- end
27
- RUBY
28
-
29
- before_prepare if respond_to?(:before_prepare)
30
- require "hanami/prepare"
31
- end
32
- end
33
-
34
- describe "app view and parts" do
35
- def before_prepare
36
- write "app/views/posts/show.rb", <<~RUBY
37
- module TestApp
38
- module Views
39
- module Posts
40
- class Show < TestApp::View
41
- expose :post
42
- end
43
- end
44
- end
45
- end
46
- RUBY
47
-
48
- write "app/views/parts/post.rb", <<~RUBY
49
- module TestApp
50
- module Views
51
- module Parts
52
- class Post < TestApp::Views::Part
53
- def number
54
- helpers.format_number(value.number)
55
- end
56
- end
57
- end
58
- end
59
- end
60
- RUBY
61
-
62
- write "app/templates/posts/show.html.erb", <<~ERB
63
- <h1><%= post.number %></h1>
64
- ERB
65
- end
66
-
67
- it "makes default helpers available in parts" do
68
- post = OpenStruct.new(number: 12_345)
69
- output = TestApp::App["views.posts.show"].call(post: post).to_s.strip
70
-
71
- expect(output).to eq "<h1>12,345</h1>"
72
- end
73
- end
74
-
75
- describe "slice view and parts" do
76
- def before_prepare
77
- write "slices/main/view.rb", <<~RUBY
78
- module Main
79
- class View < TestApp::View
80
- end
81
- end
82
- RUBY
83
-
84
- write "slices/main/views/posts/show.rb", <<~RUBY
85
- module Main
86
- module Views
87
- module Posts
88
- class Show < Main::View
89
- expose :post
90
- end
91
- end
92
- end
93
- end
94
- RUBY
95
-
96
- write "slices/main/views/parts/post.rb", <<~RUBY
97
- module Main
98
- module Views
99
- module Parts
100
- class Post < Main::Views::Part
101
- def number
102
- helpers.format_number(value.number)
103
- end
104
- end
105
- end
106
- end
107
- end
108
- RUBY
109
-
110
- write "slices/main/templates/posts/show.html.erb", <<~ERB
111
- <h1><%= post.number %></h1>
112
- ERB
113
- end
114
-
115
- it "makes default helpers available in parts" do
116
- post = OpenStruct.new(number: 12_345)
117
- output = Main::Slice["views.posts.show"].call(post: post).to_s.strip
118
-
119
- expect(output).to eq "<h1>12,345</h1>"
120
- end
121
- end
122
- end
123
-
124
- # rubocop:enable Style/OpenStructUse
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "App view / Helpers / Scope helpers", :app_integration do
4
- before do
5
- with_directory(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
- config.layout = nil
21
- end
22
- end
23
- RUBY
24
-
25
- before_prepare if respond_to?(:before_prepare)
26
- require "hanami/prepare"
27
- end
28
- end
29
-
30
- describe "app view" do
31
- def before_prepare
32
- write "app/views/posts/show.rb", <<~RUBY
33
- module TestApp
34
- module Views
35
- module Posts
36
- class Show < TestApp::View
37
- end
38
- end
39
- end
40
- end
41
- RUBY
42
-
43
- write "app/templates/posts/show.html.erb", <<~ERB
44
- <h1><%= format_number(12_345) %></h1>
45
- ERB
46
- end
47
-
48
- it "makes default helpers available in templates" do
49
- output = TestApp::App["views.posts.show"].call.to_s.strip
50
- expect(output).to eq "<h1>12,345</h1>"
51
- end
52
- end
53
-
54
- describe "slice view" do
55
- def before_prepare
56
- write "slices/main/view.rb", <<~RUBY
57
- module Main
58
- class View < TestApp::View
59
- end
60
- end
61
- RUBY
62
-
63
- write "slices/main/views/posts/show.rb", <<~RUBY
64
- module Main
65
- module Views
66
- module Posts
67
- class Show < Main::View
68
- end
69
- end
70
- end
71
- end
72
- RUBY
73
-
74
- write "slices/main/templates/posts/show.html.erb", <<~ERB
75
- <h1><%= format_number(12_345) %></h1>
76
- ERB
77
- end
78
-
79
- it "makes default helpers available in templates" do
80
- output = Main::Slice["views.posts.show"].call.to_s.strip
81
- expect(output).to eq "<h1>12,345</h1>"
82
- end
83
- end
84
- end