hanami 2.3.2 → 3.0.0

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +103 -19
  3. data/LICENSE +20 -0
  4. data/README.md +18 -35
  5. data/hanami.gemspec +36 -37
  6. data/lib/hanami/app.rb +12 -2
  7. data/lib/hanami/config/db.rb +2 -0
  8. data/lib/hanami/config/i18n.rb +138 -0
  9. data/lib/hanami/config/logger.rb +15 -7
  10. data/lib/hanami/config/null_config.rb +1 -1
  11. data/lib/hanami/config/views.rb +17 -0
  12. data/lib/hanami/config.rb +66 -22
  13. data/lib/hanami/errors.rb +6 -0
  14. data/lib/hanami/extensions/action/i18n_helper.rb +64 -0
  15. data/lib/hanami/extensions/action/name_inferrer.rb +34 -0
  16. data/lib/hanami/extensions/action/slice_configured_action.rb +31 -2
  17. data/lib/hanami/extensions/action.rb +20 -7
  18. data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +134 -0
  19. data/lib/hanami/extensions/mailer.rb +28 -0
  20. data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
  21. data/lib/hanami/extensions/view/context.rb +26 -4
  22. data/lib/hanami/extensions/view/part.rb +2 -0
  23. data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
  24. data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
  25. data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
  26. data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
  27. data/lib/hanami/extensions.rb +6 -1
  28. data/lib/hanami/helpers/assets_helper.rb +0 -4
  29. data/lib/hanami/helpers/form_helper.rb +1 -1
  30. data/lib/hanami/helpers/i18n_helper.rb +241 -0
  31. data/lib/hanami/logger/rack_formatter.rb +73 -0
  32. data/lib/hanami/logger/sql_formatter.rb +80 -0
  33. data/lib/hanami/logger/sql_logger.rb +48 -0
  34. data/lib/hanami/middleware/render_errors.rb +2 -2
  35. data/lib/hanami/providers/db.rb +7 -2
  36. data/lib/hanami/providers/db_logging.rb +4 -7
  37. data/lib/hanami/providers/i18n/backend.rb +373 -0
  38. data/lib/hanami/providers/i18n/locale/en.yml +57 -0
  39. data/lib/hanami/providers/i18n.rb +114 -0
  40. data/lib/hanami/providers/logger.rb +23 -1
  41. data/lib/hanami/providers/mailers.rb +101 -0
  42. data/lib/hanami/routes.rb +1 -0
  43. data/lib/hanami/settings/composite_store.rb +53 -0
  44. data/lib/hanami/settings.rb +4 -4
  45. data/lib/hanami/slice/router.rb +15 -10
  46. data/lib/hanami/slice.rb +102 -11
  47. data/lib/hanami/slice_configurable.rb +1 -3
  48. data/lib/hanami/slice_registrar.rb +2 -2
  49. data/lib/hanami/universal_logger.rb +250 -0
  50. data/lib/hanami/version.rb +1 -1
  51. data/lib/hanami/web/rack_logger.rb +2 -80
  52. data/lib/hanami/web/welcome.html.erb +443 -58
  53. data/lib/hanami.rb +4 -2
  54. metadata +34 -280
  55. data/CODE_OF_CONDUCT.md +0 -74
  56. data/FEATURES.md +0 -269
  57. data/LICENSE.md +0 -22
  58. data/spec/integration/action/cookies_spec.rb +0 -58
  59. data/spec/integration/action/csrf_protection_spec.rb +0 -54
  60. data/spec/integration/action/format_config_spec.rb +0 -129
  61. data/spec/integration/action/routes_spec.rb +0 -71
  62. data/spec/integration/action/sessions_spec.rb +0 -50
  63. data/spec/integration/action/slice_configuration_spec.rb +0 -284
  64. data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
  65. data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
  66. data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
  67. data/spec/integration/action/view_rendering_spec.rb +0 -89
  68. data/spec/integration/assets/assets_spec.rb +0 -155
  69. data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
  70. data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
  71. data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
  72. data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
  73. data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
  74. data/spec/integration/container/application_routes_helper_spec.rb +0 -48
  75. data/spec/integration/container/auto_injection_spec.rb +0 -53
  76. data/spec/integration/container/auto_registration_spec.rb +0 -86
  77. data/spec/integration/container/autoloader_spec.rb +0 -82
  78. data/spec/integration/container/imports_spec.rb +0 -253
  79. data/spec/integration/container/prepare_container_spec.rb +0 -125
  80. data/spec/integration/container/provider_environment_spec.rb +0 -52
  81. data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
  82. data/spec/integration/container/shutdown_spec.rb +0 -91
  83. data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
  84. data/spec/integration/container/standard_providers_spec.rb +0 -124
  85. data/spec/integration/db/auto_registration_spec.rb +0 -39
  86. data/spec/integration/db/commands_spec.rb +0 -80
  87. data/spec/integration/db/db_inflector_spec.rb +0 -57
  88. data/spec/integration/db/db_slices_spec.rb +0 -398
  89. data/spec/integration/db/db_spec.rb +0 -245
  90. data/spec/integration/db/gateways_spec.rb +0 -361
  91. data/spec/integration/db/logging_spec.rb +0 -301
  92. data/spec/integration/db/mappers_spec.rb +0 -84
  93. data/spec/integration/db/provider_config_spec.rb +0 -88
  94. data/spec/integration/db/provider_spec.rb +0 -35
  95. data/spec/integration/db/relations_spec.rb +0 -60
  96. data/spec/integration/db/repo_spec.rb +0 -300
  97. data/spec/integration/db/slices_importing_from_parent.rb +0 -130
  98. data/spec/integration/dotenv_loading_spec.rb +0 -138
  99. data/spec/integration/logging/exception_logging_spec.rb +0 -120
  100. data/spec/integration/logging/notifications_spec.rb +0 -68
  101. data/spec/integration/logging/request_logging_spec.rb +0 -202
  102. data/spec/integration/operations/extension_spec.rb +0 -122
  103. data/spec/integration/rack_app/body_parser_spec.rb +0 -108
  104. data/spec/integration/rack_app/method_override_spec.rb +0 -97
  105. data/spec/integration/rack_app/middleware_spec.rb +0 -720
  106. data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
  107. data/spec/integration/rack_app/rack_app_spec.rb +0 -442
  108. data/spec/integration/rake_tasks_spec.rb +0 -107
  109. data/spec/integration/router/resource_routes_spec.rb +0 -281
  110. data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
  111. data/spec/integration/settings/access_to_constants_spec.rb +0 -46
  112. data/spec/integration/settings/loading_from_env_spec.rb +0 -188
  113. data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
  114. data/spec/integration/settings/slice_registration_spec.rb +0 -145
  115. data/spec/integration/settings/using_types_spec.rb +0 -80
  116. data/spec/integration/setup_spec.rb +0 -165
  117. data/spec/integration/slices/external_slice_spec.rb +0 -91
  118. data/spec/integration/slices/slice_configuration_spec.rb +0 -42
  119. data/spec/integration/slices/slice_loading_spec.rb +0 -171
  120. data/spec/integration/slices/slice_registrations_spec.rb +0 -80
  121. data/spec/integration/slices/slice_routing_spec.rb +0 -219
  122. data/spec/integration/slices_spec.rb +0 -471
  123. data/spec/integration/view/config/default_context_spec.rb +0 -149
  124. data/spec/integration/view/config/inflector_spec.rb +0 -57
  125. data/spec/integration/view/config/part_class_spec.rb +0 -147
  126. data/spec/integration/view/config/part_namespace_spec.rb +0 -103
  127. data/spec/integration/view/config/paths_spec.rb +0 -119
  128. data/spec/integration/view/config/scope_class_spec.rb +0 -147
  129. data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
  130. data/spec/integration/view/config/template_spec.rb +0 -38
  131. data/spec/integration/view/context/assets_spec.rb +0 -79
  132. data/spec/integration/view/context/inflector_spec.rb +0 -40
  133. data/spec/integration/view/context/request_spec.rb +0 -57
  134. data/spec/integration/view/context/routes_spec.rb +0 -84
  135. data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
  136. data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
  137. data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
  138. data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
  139. data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
  140. data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
  141. data/spec/integration/view/slice_configuration_spec.rb +0 -289
  142. data/spec/integration/view/views_spec.rb +0 -103
  143. data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
  144. data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
  145. data/spec/integration/web/render_errors_spec.rb +0 -242
  146. data/spec/integration/web/welcome_view_spec.rb +0 -84
  147. data/spec/spec_helper.rb +0 -28
  148. data/spec/support/app_integration.rb +0 -157
  149. data/spec/support/coverage.rb +0 -1
  150. data/spec/support/matchers.rb +0 -32
  151. data/spec/support/rspec.rb +0 -27
  152. data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
  153. data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
  154. data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
  155. data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
  156. data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
  157. data/spec/unit/hanami/config/actions_spec.rb +0 -52
  158. data/spec/unit/hanami/config/base_url_spec.rb +0 -25
  159. data/spec/unit/hanami/config/console_spec.rb +0 -22
  160. data/spec/unit/hanami/config/db_spec.rb +0 -38
  161. data/spec/unit/hanami/config/inflector_spec.rb +0 -35
  162. data/spec/unit/hanami/config/logger_spec.rb +0 -195
  163. data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
  164. data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
  165. data/spec/unit/hanami/config/router_spec.rb +0 -44
  166. data/spec/unit/hanami/config/slices_spec.rb +0 -34
  167. data/spec/unit/hanami/config/views_spec.rb +0 -80
  168. data/spec/unit/hanami/env_spec.rb +0 -37
  169. data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
  170. data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
  171. data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
  172. data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
  173. data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
  174. data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
  175. data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
  176. data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
  177. data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
  178. data/spec/unit/hanami/port_spec.rb +0 -117
  179. data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
  180. data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
  181. data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
  182. data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
  183. data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
  184. data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
  185. data/spec/unit/hanami/settings_spec.rb +0 -111
  186. data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
  187. data/spec/unit/hanami/slice_name_spec.rb +0 -47
  188. data/spec/unit/hanami/slice_spec.rb +0 -99
  189. data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config/actions"
4
-
5
- RSpec.describe Hanami::Config::Actions, "#cookies" do
6
- let(:config) { described_class.new }
7
- subject(:cookies) { config.cookies }
8
-
9
- context "default config" do
10
- it "is enabled" do
11
- expect(cookies).to be_enabled
12
- end
13
-
14
- it "is an empty hash" do
15
- expect(cookies.to_h).to eq({})
16
- end
17
- end
18
-
19
- context "options given" do
20
- before do
21
- config.cookies = {max_age: 300}
22
- end
23
-
24
- it "is enabled" do
25
- expect(cookies).to be_enabled
26
- end
27
-
28
- it "returns the given options" do
29
- expect(cookies.to_h).to eq(max_age: 300)
30
- end
31
- end
32
-
33
- context "nil value given" do
34
- before do
35
- config.cookies = nil
36
- end
37
-
38
- it "is not enabled" do
39
- expect(cookies).not_to be_enabled
40
- end
41
-
42
- it "returns an empty hash" do
43
- expect(cookies.to_h).to eq({})
44
- end
45
- end
46
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config/actions"
4
-
5
- RSpec.describe Hanami::Config::Actions, "#csrf_protection" do
6
- let(:app_config) { Hanami::Config.new(app_name: "MyApp::App", env: :development) }
7
- let(:config) { app_config.actions }
8
- subject(:value) { config.csrf_protection }
9
-
10
- context "non-finalized config" do
11
- it "returns a default of nil" do
12
- is_expected.to be_nil
13
- end
14
-
15
- it "can be explicitly enabled" do
16
- config.csrf_protection = true
17
- is_expected.to be true
18
- end
19
-
20
- it "can be explicitly disabled" do
21
- config.csrf_protection = false
22
- is_expected.to be false
23
- end
24
- end
25
-
26
- context "finalized config" do
27
- context "sessions enabled" do
28
- before do
29
- config.sessions = :cookie, {secret: "abc"}
30
- app_config.finalize!
31
- end
32
-
33
- it "is true" do
34
- is_expected.to be true
35
- end
36
-
37
- context "explicitly disabled" do
38
- before do
39
- config.csrf_protection = false
40
- end
41
-
42
- it "is false" do
43
- is_expected.to be false
44
- end
45
- end
46
- end
47
-
48
- context "sessions not enabled" do
49
- before do
50
- app_config.finalize!
51
- end
52
-
53
- it "is true" do
54
- is_expected.to be false
55
- end
56
- end
57
- end
58
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config/actions"
4
-
5
- RSpec.describe Hanami::Config::Actions, "default values" do
6
- let(:app_config) { Hanami::Config.new(app_name: "MyApp::App", env: :development) }
7
- subject(:config) { app_config.actions }
8
-
9
- describe "sessions" do
10
- specify { expect(config.sessions).not_to be_enabled }
11
- end
12
-
13
- describe "name_inference_base" do
14
- specify { expect(config.name_inference_base).to eq "actions" }
15
- end
16
-
17
- describe "view_name_inferrer" do
18
- specify { expect(config.view_name_inferrer).to eq Hanami::Slice::ViewNameInferrer }
19
- end
20
-
21
- describe "view_name_inference_base" do
22
- specify { expect(config.view_name_inference_base).to eq "views" }
23
- end
24
-
25
- describe "new default values applied to base action settings" do
26
- describe "content_security_policy" do
27
- specify { expect(config.content_security_policy).to be_kind_of(Hanami::Config::Actions::ContentSecurityPolicy) }
28
- end
29
-
30
- describe "default_headers" do
31
- specify {
32
- app_config.finalize!
33
-
34
- expect(config.default_headers).to eq(
35
- "X-Frame-Options" => "DENY",
36
- "X-Content-Type-Options" => "nosniff",
37
- "X-XSS-Protection" => "1; mode=block",
38
- "Content-Security-Policy" => config.content_security_policy.to_s
39
- )
40
- }
41
- end
42
- end
43
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config/actions"
4
-
5
- RSpec.describe Hanami::Config::Actions, "#sessions" do
6
- let(:config) { described_class.new }
7
- subject(:sessions) { config.sessions }
8
-
9
- context "no session config specified" do
10
- it "is not enabled" do
11
- expect(sessions).not_to be_enabled
12
- end
13
-
14
- it "returns nil storage" do
15
- expect(sessions.storage).to be_nil
16
- end
17
-
18
- it "returns empty options" do
19
- expect(sessions.options).to eq []
20
- end
21
-
22
- it "returns no session middleware" do
23
- expect(sessions.middleware).to eq []
24
- end
25
- end
26
-
27
- context "valid session config provided" do
28
- before do
29
- config.sessions = :cookie, {secret: "abc"}
30
- end
31
-
32
- it "is enabled" do
33
- expect(sessions).to be_enabled
34
- end
35
-
36
- it "returns the given storage" do
37
- expect(sessions.storage).to eq :cookie
38
- end
39
-
40
- it "returns the given options" do
41
- expect(sessions.options).to eq [secret: "abc"]
42
- end
43
-
44
- it "returns an array of middleware classes and options" do
45
- expect(sessions.middleware).to eq [Rack::Session::Cookie, {secret: "abc"}]
46
- end
47
- end
48
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
- require "hanami/action"
5
-
6
- RSpec.describe Hanami::Config, "#actions" do
7
- let(:config) { described_class.new(app_name: app_name, env: :development) }
8
- let(:app_name) { "MyApp::app" }
9
-
10
- subject(:actions) { config.actions }
11
-
12
- context "hanami-controller is bundled" do
13
- it "is a full actions config" do
14
- is_expected.to be_an_instance_of(Hanami::Config::Actions)
15
-
16
- is_expected.to respond_to(:format)
17
- end
18
-
19
- it "configures base action settings" do
20
- expect { actions.public_directory = "pub" }
21
- .to change { actions.public_directory }
22
- .to end_with("pub")
23
- end
24
-
25
- it "configures base actions settings using custom methods" do
26
- expect { actions.formats.register(:json, "app/json") }
27
- .to change { actions.formats.mapping }
28
- .to include(json: have_attributes(media_type: "app/json"))
29
- end
30
-
31
- it "can be finalized" do
32
- is_expected.to respond_to(:finalize!)
33
- end
34
- end
35
-
36
- context "hanami-controller is not bundled" do
37
- before do
38
- allow(Hanami).to receive(:bundled?).and_call_original
39
- expect(Hanami).to receive(:bundled?).with("hanami-controller").and_return(false)
40
- end
41
-
42
- it "does not expose any settings" do
43
- is_expected.to be_an_instance_of(Hanami::Config::NullConfig)
44
- is_expected.not_to respond_to(:default_response_format)
45
- is_expected.not_to respond_to(:default_response_format=)
46
- end
47
-
48
- it "can be finalized" do
49
- is_expected.to respond_to(:finalize!)
50
- end
51
- end
52
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
- require "uri"
5
-
6
- RSpec.describe Hanami::Config, "base_url" do
7
- subject(:config) { described_class.new(app_name: app_name, env: :development) }
8
- let(:app_name) { "MyApp::app" }
9
-
10
- it "defaults to a URI of 'http://0.0.0.0:2300'" do
11
- expect(config.base_url).to eq URI("http://0.0.0.0:2300")
12
- end
13
-
14
- it "can be changed to another URI via a string" do
15
- expect { config.base_url = "http://example.com" }
16
- .to change { config.base_url }
17
- .to(URI("http://example.com"))
18
- end
19
-
20
- it "can be changed to another URI object" do
21
- expect { config.base_url = URI("http://example.com") }
22
- .to change { config.base_url }
23
- .to(URI("http://example.com"))
24
- end
25
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
-
5
- RSpec.describe Hanami::Config, "#console" do
6
- let(:config) { described_class.new(app_name: app_name, env: :development) }
7
- let(:app_name) { "MyApp::App" }
8
-
9
- subject(:console) { config.console }
10
-
11
- it "is a full console configuration" do
12
- is_expected.to be_an_instance_of(Hanami::Config::Console)
13
-
14
- is_expected.to respond_to(:engine)
15
- is_expected.to respond_to(:include)
16
- is_expected.to respond_to(:extensions)
17
- end
18
-
19
- it "can be finalized" do
20
- is_expected.to respond_to(:finalize!)
21
- end
22
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
-
5
- RSpec.describe Hanami::Config, "#db" do
6
- let(:config) { described_class.new(app_name: app_name, env: :development) }
7
- let(:app_name) { "MyApp::App" }
8
-
9
- subject(:db) { config.db }
10
-
11
- context "hanami-router is bundled" do
12
- it "is a full router configuration" do
13
- is_expected.to be_an_instance_of(Hanami::Config::DB)
14
-
15
- is_expected.to respond_to(:import_from_parent)
16
- end
17
-
18
- it "can be finalized" do
19
- is_expected.to respond_to(:finalize!)
20
- end
21
- end
22
-
23
- context "hanami-db is not bundled" do
24
- before do
25
- allow(Hanami).to receive(:bundled?).and_call_original
26
- allow(Hanami).to receive(:bundled?).with("hanami-db").and_return(false)
27
- end
28
-
29
- it "does not expose any settings" do
30
- is_expected.to be_an_instance_of(Hanami::Config::NullConfig)
31
- is_expected.not_to respond_to(:import_from_parent)
32
- end
33
-
34
- it "can be finalized" do
35
- is_expected.to respond_to(:finalize!)
36
- end
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
-
5
- RSpec.describe Hanami::Config do
6
- subject(:config) { described_class.new(app_name: app_name, env: :development) }
7
- let(:app_name) { "MyApp::app" }
8
-
9
- describe "inflector" do
10
- it "defaults to a Dry::Inflector instance" do
11
- expect(config.inflector).to be_kind_of(Dry::Inflector)
12
- end
13
-
14
- it "can be replaced with another inflector" do
15
- new_inflector = double(:inflector)
16
-
17
- expect { config.inflector = new_inflector }
18
- .to change { config.inflector }
19
- .to new_inflector
20
- end
21
- end
22
-
23
- describe "inflections" do
24
- it "configures a new inflector with the given inflections" do
25
- expect(config.inflector.pluralize("hanami")).to eq("hanamis")
26
-
27
- config.inflections do |i|
28
- i.uncountable("hanami")
29
- end
30
-
31
- expect(config.inflector).to be_kind_of(Dry::Inflector)
32
- expect(config.inflector.pluralize("hanami")).to eq("hanami")
33
- end
34
- end
35
- end
@@ -1,195 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config/logger"
4
- require "hanami/slice_name"
5
- require "dry/inflector"
6
- require "logger"
7
- require "stringio"
8
-
9
- RSpec.describe Hanami::Config::Logger do
10
- subject do
11
- described_class.new(app_name: app_name, env: env)
12
- end
13
-
14
- let(:app_name) do
15
- Hanami::SliceName.new(double(name: "MyApp::app"), inflector: -> { Dry::Inflector.new })
16
- end
17
-
18
- let(:env) { :development }
19
-
20
- describe "#level" do
21
- it "defaults to :debug" do
22
- expect(subject.level).to eq(:debug)
23
- end
24
-
25
- context "when :production environment" do
26
- let(:env) { :production }
27
-
28
- it "returns :info" do
29
- expect(subject.level).to eq(:info)
30
- end
31
- end
32
- end
33
-
34
- describe "#level=" do
35
- it "a value" do
36
- expect { subject.level = :warn }
37
- .to change { subject.level }
38
- .to(:warn)
39
- end
40
- end
41
-
42
- describe "#stream" do
43
- it "defaults to $stdout" do
44
- expect(subject.stream).to eq($stdout)
45
- end
46
-
47
- context "when :test environment" do
48
- let(:env) { :test }
49
-
50
- it "returns a file" do
51
- expected = File.join("log", "test.log")
52
-
53
- expect(subject.stream).to eq(expected)
54
- end
55
- end
56
- end
57
-
58
- describe "#stream=" do
59
- it "accepts a path to a file" do
60
- expect { subject.stream = File::NULL }
61
- .to change { subject.stream }
62
- .to(File::NULL)
63
- end
64
-
65
- it "accepts a IO object" do
66
- stream = StringIO.new
67
-
68
- expect { subject.stream = stream }
69
- .to change { subject.stream }
70
- .to(stream)
71
- end
72
- end
73
-
74
- describe "#formatter" do
75
- it "defaults to :string" do
76
- expect(subject.formatter).to eq(:string)
77
- end
78
-
79
- context "when :production environment" do
80
- let(:env) { :production }
81
-
82
- it "returns :json" do
83
- expect(subject.formatter).to eq(:json)
84
- end
85
- end
86
- end
87
-
88
- describe "#formatter=" do
89
- it "accepts a formatter" do
90
- expect { subject.formatter = :json }
91
- .to change { subject.formatter }
92
- .to(:json)
93
- end
94
- end
95
-
96
- describe "#template" do
97
- it "defaults to :details" do
98
- expect(subject.template).to be(:details)
99
- end
100
- end
101
-
102
- describe "#template=" do
103
- it "accepts a value" do
104
- expect { subject.template = "%<message>s" }
105
- .to change { subject.template }
106
- .to("%<message>s")
107
- end
108
- end
109
-
110
- describe "#filters" do
111
- it "defaults to a standard array of sensitive param names" do
112
- expect(subject.filters).to include(*%w[_csrf password password_confirmation])
113
- end
114
-
115
- it "can have other params names added" do
116
- expect { subject.filters << "secret" }
117
- .to change { subject.filters }
118
- .to array_including("secret")
119
-
120
- expect { subject.filters += ["yet", "another"] }
121
- .to change { subject.filters }
122
- .to array_including(["yet", "another"])
123
- end
124
-
125
- it "can be changed to another array" do
126
- expect { subject.filters = ["secret"] }
127
- .to change { subject.filters }
128
- .to ["secret"]
129
- end
130
- end
131
-
132
- describe "#options" do
133
- it "defaults to empty hash" do
134
- expect(subject.options).to eq({})
135
- end
136
- end
137
-
138
- describe "#options=" do
139
- it "accepts value" do
140
- subject.options = expected = {rotate: "daily"}
141
-
142
- expect(subject.options).to eq(expected)
143
- end
144
- end
145
- end
146
-
147
- RSpec.describe Hanami::Config do
148
- subject(:config) { described_class.new(app_name: app_name, env: env) }
149
-
150
- let(:app_name) do
151
- Hanami::SliceName.new(double(name: "SOS::app"), inflector: -> { Dry::Inflector.new })
152
- end
153
-
154
- let(:env) { :development }
155
-
156
- describe "#logger" do
157
- before do
158
- config.inflections do |inflections|
159
- inflections.acronym "SOS"
160
- end
161
-
162
- config.logger.finalize!
163
- end
164
-
165
- describe "#app_name" do
166
- it "defaults to Hanami::Config#app_name" do
167
- expect(config.logger.app_name).to eq(config.app_name)
168
- end
169
- end
170
- end
171
-
172
- describe "#logger_instance" do
173
- it "defaults to using Dry::Logger, based on the default logger settings" do
174
- expect(config.logger_instance).to be_a(Dry::Logger::Dispatcher)
175
- expect(config.logger_instance.level).to eq Logger::DEBUG
176
- end
177
-
178
- it "can be changed to a pre-initialized instance via #logger=" do
179
- logger_instance = Object.new
180
-
181
- expect { config.logger = logger_instance }
182
- .to change { config.logger_instance }
183
- .to logger_instance
184
- end
185
-
186
- context "unrecognized :env" do
187
- let(:env) { :staging }
188
-
189
- it "provides a fail-safe configuration" do
190
- expect { config.logger_instance }.to_not raise_error
191
- expect(config.logger_instance).to be_a(Dry::Logger::Dispatcher)
192
- end
193
- end
194
- end
195
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dry/inflector"
4
-
5
- RSpec.describe Hanami::Config, "#render_detailed_errors" do
6
- let(:config) { described_class.new(app_name: app_name, env: env) }
7
- let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::App"), inflector: Dry::Inflector.new) }
8
-
9
- subject(:render_detailed_errors) { config.render_detailed_errors }
10
-
11
- context "development mode" do
12
- let(:env) { :development }
13
- it { is_expected.to be true }
14
- end
15
-
16
- context "test mode" do
17
- let(:env) { :test }
18
- it { is_expected.to be false }
19
- end
20
-
21
- context "production mode" do
22
- let(:env) { :production }
23
- it { is_expected.to be false }
24
- end
25
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dry/inflector"
4
-
5
- RSpec.describe Hanami::Config, "#render_errors" do
6
- let(:config) { described_class.new(app_name: app_name, env: env) }
7
- let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::App"), inflector: Dry::Inflector.new) }
8
-
9
- subject(:render_errors) { config.render_errors }
10
-
11
- context "development mode" do
12
- let(:env) { :development }
13
- it { is_expected.to be false }
14
- end
15
-
16
- context "test mode" do
17
- let(:env) { :test }
18
- it { is_expected.to be false }
19
- end
20
-
21
- context "production mode" do
22
- let(:env) { :production }
23
- it { is_expected.to be true }
24
- end
25
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/config"
4
-
5
- RSpec.describe Hanami::Config, "#router" do
6
- let(:config) { described_class.new(app_name: app_name, env: :development) }
7
- let(:app_name) { "MyApp::app" }
8
-
9
- subject(:router) { config.router }
10
-
11
- context "hanami-router is bundled" do
12
- it "is a full router configuration" do
13
- is_expected.to be_an_instance_of(Hanami::Config::Router)
14
-
15
- is_expected.to respond_to(:resolver)
16
- end
17
-
18
- it "loads the middleware stack" do
19
- subject
20
-
21
- expect(config.middleware_stack).not_to be_nil
22
- end
23
-
24
- it "can be finalized" do
25
- is_expected.to respond_to(:finalize!)
26
- end
27
- end
28
-
29
- context "hanami-router is not bundled" do
30
- before do
31
- allow(Hanami).to receive(:bundled?).and_call_original
32
- allow(Hanami).to receive(:bundled?).with("hanami-router").and_return(false)
33
- end
34
-
35
- it "does not expose any settings" do
36
- is_expected.to be_an_instance_of(Hanami::Config::NullConfig)
37
- is_expected.not_to respond_to(:resolver)
38
- end
39
-
40
- it "can be finalized" do
41
- is_expected.to respond_to(:finalize!)
42
- end
43
- end
44
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dry/inflector"
4
- require "hanami/config"
5
- require "hanami/slice_name"
6
-
7
- RSpec.describe Hanami::Config, "#slices" do
8
- subject(:config) { described_class.new(app_name: app_name, env: :development) }
9
- let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::App"), inflector: Dry::Inflector.new) }
10
-
11
- subject(:slices) { config.slices }
12
-
13
- before do
14
- @orig_env = ENV.to_h
15
- end
16
-
17
- after do
18
- ENV.replace(@orig_env)
19
- end
20
-
21
- it "is nil by default" do
22
- is_expected.to be nil
23
- end
24
-
25
- it "defaults to the HANAMI_LOAD_SLICES env var, separated by commas" do
26
- ENV["HANAMI_SLICES"] = "main,admin"
27
- is_expected.to eq %w[main admin]
28
- end
29
-
30
- it "strips spaces from HANAMI_LOAD_SLICES env var entries" do
31
- ENV["HANAMI_SLICES"] = "main, admin"
32
- is_expected.to eq %w[main admin]
33
- end
34
- end