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,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Settings / Component loading", :app_integration do
4
- describe "Settings are loaded from a class defined in config/settings.rb" do
5
- specify "in app" do
6
- with_directory(make_tmp_directory) do
7
- write "config/app.rb", <<~'RUBY'
8
- require "hanami"
9
-
10
- module TestApp
11
- class App < Hanami::App
12
- end
13
- end
14
- RUBY
15
-
16
- write "config/settings.rb", <<~'RUBY'
17
- module TestApp
18
- class Settings < Hanami::Settings
19
- setting :foo
20
- end
21
- end
22
- RUBY
23
-
24
- require "hanami/prepare"
25
-
26
- expect(Hanami.app["settings"]).to be_an_instance_of TestApp::Settings
27
- expect(Hanami.app["settings"]).to respond_to :foo
28
- end
29
- end
30
-
31
- specify "in slice" do
32
- with_directory(make_tmp_directory) do
33
- write "config/app.rb", <<~'RUBY'
34
- require "hanami"
35
-
36
- module TestApp
37
- class App < Hanami::App
38
- end
39
- end
40
- RUBY
41
-
42
- write "slices/main/config/settings.rb", <<~'RUBY'
43
- module Main
44
- class Settings < Hanami::Settings
45
- setting :foo
46
- end
47
- end
48
- RUBY
49
-
50
- require "hanami/prepare"
51
-
52
- expect(Main::Slice["settings"]).to be_an_instance_of Main::Settings
53
- expect(Main::Slice["settings"]).to respond_to :foo
54
- end
55
- end
56
- end
57
-
58
- describe "Settings are loaded from a `Settings` class if already defined" do
59
- specify "in app" do
60
- with_directory(make_tmp_directory) do
61
- write "config/app.rb", <<~'RUBY'
62
- require "hanami"
63
- require "hanami/settings"
64
-
65
- module TestApp
66
- class App < Hanami::App
67
- end
68
-
69
- class Settings < Hanami::Settings
70
- setting :foo
71
- end
72
- end
73
- RUBY
74
-
75
- require "hanami/prepare"
76
-
77
- expect(Hanami.app["settings"]).to be_an_instance_of TestApp::Settings
78
- expect(Hanami.app["settings"]).to respond_to :foo
79
- end
80
- end
81
-
82
- specify "in slice" do
83
- with_directory(make_tmp_directory) do
84
- write "config/app.rb", <<~'RUBY'
85
- require "hanami"
86
-
87
- module TestApp
88
- class App < Hanami::App
89
- end
90
- end
91
- RUBY
92
-
93
- write "config/slices/main.rb", <<~'RUBY'
94
- require "hanami/settings"
95
-
96
- module Main
97
- class Slice < Hanami::Slice
98
- end
99
-
100
- class Settings < Hanami::Settings
101
- setting :foo
102
- end
103
- end
104
- RUBY
105
-
106
- require "hanami/prepare"
107
-
108
- expect(Main::Slice["settings"]).to be_an_instance_of Main::Settings
109
- expect(Main::Slice["settings"]).to respond_to :foo
110
- end
111
- end
112
- end
113
- end
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Settings / Slice registration", :app_integration do
4
- specify "Settings are registered for each slice with a settings file" 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
- # n.b. no app-level settings file
16
-
17
- # The main slice has settings
18
- write "slices/main/config/settings.rb", <<~RUBY
19
- # frozen_string_literal: true
20
-
21
- require "hanami/settings"
22
-
23
- module Main
24
- class Settings < Hanami::Settings
25
- setting :main_session_secret
26
- end
27
- end
28
- RUBY
29
-
30
- # The admin slice has none
31
- write "slices/admin/.keep", ""
32
-
33
- require "hanami/prepare"
34
-
35
- expect(Main::Slice.key?("settings")).to be true
36
- expect(Main::Slice["settings"]).to respond_to :main_session_secret
37
-
38
- expect(Admin::Slice.key?("settings")).to be false
39
- end
40
- end
41
-
42
- describe "App settings are shared with slices if no local settings are defined" do
43
- context "prepared" do
44
- specify do
45
- with_tmp_directory(Dir.mktmpdir) do
46
- write "config/app.rb", <<~RUBY
47
- require "hanami"
48
-
49
- module TestApp
50
- class App < Hanami::App
51
- end
52
- end
53
- RUBY
54
-
55
- write "config/settings.rb", <<~'RUBY'
56
- # frozen_string_literal: true
57
-
58
- require "hanami/settings"
59
-
60
- module TestApp
61
- class Settings < Hanami::Settings
62
- setting :app_session_secret
63
- end
64
- end
65
- RUBY
66
-
67
- write "slices/main/config/settings.rb", <<~RUBY
68
- # frozen_string_literal: true
69
-
70
- require "hanami/settings"
71
-
72
- module Main
73
- class Settings < Hanami::Settings
74
- setting :main_session_secret
75
- end
76
- end
77
- RUBY
78
-
79
- write "slices/admin/.keep", ""
80
-
81
- require "hanami/prepare"
82
-
83
- expect(TestApp::App.key?("settings")).to be true
84
- expect(Main::Slice.key?("settings")).to be true
85
- expect(Admin::Slice.key?("settings")).to be true
86
-
87
- expect(TestApp::App["settings"]).to respond_to :app_session_secret
88
- expect(Main::Slice["settings"]).to respond_to :main_session_secret
89
- expect(Admin::Slice["settings"]).to respond_to :app_session_secret
90
- end
91
- end
92
- end
93
-
94
- context "booted" do
95
- specify do
96
- with_tmp_directory(Dir.mktmpdir) do
97
- write "config/app.rb", <<~RUBY
98
- require "hanami"
99
-
100
- module TestApp
101
- class App < Hanami::App
102
- end
103
- end
104
- RUBY
105
-
106
- write "config/settings.rb", <<~'RUBY'
107
- # frozen_string_literal: true
108
-
109
- require "hanami/settings"
110
-
111
- module TestApp
112
- class Settings < Hanami::Settings
113
- setting :app_session_secret
114
- end
115
- end
116
- RUBY
117
-
118
- write "slices/main/config/settings.rb", <<~RUBY
119
- # frozen_string_literal: true
120
-
121
- require "hanami/settings"
122
-
123
- module Main
124
- class Settings < Hanami::Settings
125
- setting :main_session_secret
126
- end
127
- end
128
- RUBY
129
-
130
- write "slices/admin/.keep", ""
131
-
132
- require "hanami/boot"
133
-
134
- expect(TestApp::App.key?("settings")).to be true
135
- expect(Main::Slice.key?("settings")).to be true
136
- expect(Admin::Slice.key?("settings")).to be true
137
-
138
- expect(TestApp::App["settings"]).to respond_to :app_session_secret
139
- expect(Main::Slice["settings"]).to respond_to :main_session_secret
140
- expect(Admin::Slice["settings"]).to respond_to :app_session_secret
141
- end
142
- end
143
- end
144
- end
145
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/settings"
4
-
5
- RSpec.describe "Settings / Using types", :app_integration do
6
- before do
7
- @env = ENV.to_h
8
- end
9
-
10
- after do
11
- ENV.replace(@env)
12
- end
13
-
14
- specify "types from a provided types module can be used as setting constructors to coerce values" do
15
- with_tmp_directory(Dir.mktmpdir) do
16
- write "config/app.rb", <<~RUBY
17
- require "hanami"
18
-
19
- module TestApp
20
- class App < Hanami::App
21
- end
22
- end
23
- RUBY
24
-
25
- write "config/settings.rb", <<~RUBY
26
- module TestApp
27
- class Settings < Hanami::Settings
28
- Bool = Types::Params::Bool
29
-
30
- setting :numeric, constructor: Types::Params::Integer
31
- setting :flag, constructor: Bool
32
- end
33
- end
34
- RUBY
35
-
36
- ENV["NUMERIC"] = "42"
37
- ENV["FLAG"] = "true"
38
-
39
- require "hanami/prepare"
40
-
41
- expect(Hanami.app["settings"].numeric).to eq 42
42
- expect(Hanami.app["settings"].flag).to be true
43
- end
44
- end
45
-
46
- specify "errors raised from setting constructors are collected and re-raised in aggregate, and will prevent the app from booting" do
47
- with_tmp_directory(Dir.mktmpdir) do
48
- write "config/app.rb", <<~RUBY
49
- require "hanami"
50
-
51
- module TestApp
52
- class App < Hanami::App
53
- end
54
- end
55
- RUBY
56
-
57
- write "config/settings.rb", <<~RUBY
58
- module TestApp
59
- class Settings < Hanami::Settings
60
- setting :numeric, constructor: Types::Params::Integer
61
- setting :flag, constructor: Types::Params::Bool
62
- end
63
- end
64
- RUBY
65
-
66
- ENV["NUMERIC"] = "never gonna"
67
- ENV["FLAG"] = "give you up"
68
-
69
- numeric_error = "numeric: invalid value for Integer"
70
- flag_error = "flag: give you up cannot be coerced"
71
-
72
- expect {
73
- require "hanami/prepare"
74
- }.to raise_error(
75
- Hanami::Settings::InvalidSettingsError,
76
- /#{numeric_error}.+#{flag_error}|#{flag_error}.+#{numeric_error}/m
77
- )
78
- end
79
- end
80
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Hanami setup", :app_integration do
4
- describe "Hanami.setup" do
5
- shared_examples "hanami setup" do
6
- it "requires the app file when found" 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
- expect { setup }.to change { Hanami.app? }.to true
18
- expect(Hanami.app).to be TestApp::App
19
- end
20
- end
21
-
22
- it "requires the app file when found in a parent directory" do
23
- with_tmp_directory(Dir.mktmpdir) do
24
- write "config/app.rb", <<~RUBY
25
- require "hanami"
26
-
27
- module TestApp
28
- class App < Hanami::App
29
- end
30
- end
31
- RUBY
32
-
33
- write "lib/foo/bar/.keep"
34
-
35
- Dir.chdir("lib/foo/bar") do
36
- expect { setup }.to change { Hanami.app? }.to true
37
- expect(Hanami.app).to be TestApp::App
38
- end
39
- end
40
- end
41
-
42
- it "raises when the app file is not found" do
43
- with_tmp_directory(Dir.mktmpdir) do
44
- expect { setup }.to raise_error Hanami::AppLoadError, /Could not locate your Hanami app file/
45
- end
46
- end
47
-
48
- it "doesn't raise when the app file is not found but the app is already set" do
49
- require "hanami"
50
-
51
- module TestApp
52
- class App < Hanami::App
53
- end
54
- end
55
-
56
- expect { setup }.not_to raise_error
57
- end
58
-
59
- %w[hanami-view hanami-actions hanami-router].each do |gem_name|
60
- it "works when #{gem_name} gem is not bundled" do
61
- allow(Hanami).to receive(:bundled?).and_call_original
62
- expect(Hanami).to receive(:bundled?).with("hanami-router").and_return(false)
63
-
64
- with_tmp_directory(Dir.mktmpdir) do
65
- write "config/app.rb", <<~RUBY
66
- require "hanami"
67
-
68
- module TestApp
69
- class App < Hanami::App
70
- end
71
- end
72
- RUBY
73
-
74
- expect { setup }.to change { Hanami.app? }.to true
75
- end
76
- end
77
- end
78
- end
79
-
80
- describe "using hanami/setup require" do
81
- def setup
82
- require "hanami/setup"
83
- end
84
-
85
- it_behaves_like "hanami setup"
86
- end
87
-
88
- describe "using Hanami.setup method" do
89
- def setup(...)
90
- require "hanami"
91
- Hanami.setup(...)
92
- end
93
-
94
- it_behaves_like "hanami setup"
95
-
96
- it "returns the loaded app when the app file is found" do
97
- with_tmp_directory(Dir.mktmpdir) do
98
- write "config/app.rb", <<~RUBY
99
- require "hanami"
100
-
101
- module TestApp
102
- class App < Hanami::App
103
- end
104
- end
105
- RUBY
106
-
107
- # Multiple calls return the same app
108
- expect(setup).to be(Hanami.app)
109
- expect(setup).to be(Hanami.app)
110
- end
111
- end
112
-
113
- it "returns nil when given `raise_exception: false` and the app file is not found" do
114
- with_tmp_directory(Dir.mktmpdir) do
115
- expect(setup(raise_exception: false)).to be nil
116
- end
117
- end
118
- end
119
- end
120
-
121
- describe "Hanami.app_path" do
122
- subject(:app_path) { Hanami.app_path }
123
-
124
- context "config/app.rb exists in current directory" do
125
- it "returns its absolute path" do
126
- with_tmp_directory(Dir.mktmpdir) do
127
- write "config/app.rb"
128
-
129
- expect(app_path.to_s).to match(%r{^/.*/config/app.rb$})
130
- end
131
- end
132
- end
133
-
134
- context "config/app.rb exists in a parent directory" do
135
- it "returns its absolute path" do
136
- with_tmp_directory(Dir.mktmpdir) do
137
- write "config/app.rb"
138
- write "lib/foo/bar/.keep"
139
-
140
- Dir.chdir("lib/foo/bar") do
141
- expect(app_path.to_s).to match(%r{^/.*/config/app.rb$})
142
- end
143
- end
144
- end
145
- end
146
-
147
- context "no app file in any directory" do
148
- it "returns nil" do
149
- with_tmp_directory(Dir.mktmpdir) do
150
- expect(app_path).to be(nil)
151
- end
152
- end
153
- end
154
-
155
- context "directory exists with same name as the app file" do
156
- it "returns nil" do
157
- with_tmp_directory(Dir.mktmpdir) do
158
- write "config/app.rb/.keep"
159
-
160
- expect(app_path).to be(nil)
161
- end
162
- end
163
- end
164
- end
165
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rack/test"
4
- require "stringio"
5
-
6
- RSpec.describe "Slices / External slices", :app_integration do
7
- include Rack::Test::Methods
8
-
9
- let(:app) { TestApp::App.app }
10
-
11
- specify "External slices can be registered and used" do
12
- with_tmp_directory(Dir.mktmpdir) do
13
- write "config/app.rb", <<~'RUBY'
14
- require "hanami"
15
-
16
- module TestApp
17
- class App < Hanami::App
18
- config.logger.stream = StringIO.new
19
-
20
- require "external/slice"
21
- register_slice(:external, External::Slice)
22
- end
23
- end
24
- RUBY
25
-
26
- write "config/routes.rb", <<~'RUBY'
27
- require "hanami/routes"
28
-
29
- module TestApp
30
- class Routes < Hanami::Routes
31
- slice :external, at: "/" do
32
- root to: "test_action"
33
- end
34
- end
35
- end
36
- RUBY
37
-
38
- # Put a slice and its components in `lib/external/`, as if it were an external gem
39
-
40
- write "lib/external/slice.rb", <<~'RUBY'
41
- # auto_register: false
42
-
43
- require "hanami/slice"
44
-
45
- module External
46
- class Slice < Hanami::Slice
47
- config.root = __dir__
48
- end
49
- end
50
- RUBY
51
-
52
- # FIXME: Remove redundant `lib/` dir once hanami/hanami#1174 is merged
53
- write "lib/external/lib/test_repo.rb", <<~'RUBY'
54
- require "hanami/slice"
55
-
56
- module External
57
- class TestRepo
58
- def things
59
- %w[foo bar baz]
60
- end
61
- end
62
- end
63
- RUBY
64
-
65
- write "lib/external/actions/test_action.rb", <<~'RUBY'
66
- require "hanami/action"
67
-
68
- module External
69
- module Actions
70
- class TestAction < Hanami::Action
71
- include Deps["test_repo"]
72
-
73
- def handle(req, res)
74
- res.body = test_repo.things.join(", ")
75
- end
76
- end
77
- end
78
- end
79
- RUBY
80
-
81
- require "hanami/prepare"
82
-
83
- expect(Hanami.app.slices[:external]).to be External::Slice
84
-
85
- get "/"
86
-
87
- expect(last_response.status).to eq 200
88
- expect(last_response.body).to eq "foo, bar, baz"
89
- end
90
- end
91
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "stringio"
4
-
5
- RSpec.describe "Slices / Slice configuration", :app_integration do
6
- specify "Slices receive a copy of the app configuration, and can make distinct modifications" 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
- config.logger.stream = StringIO.new
14
-
15
- config.no_auto_register_paths = ["structs"]
16
- end
17
- end
18
- RUBY
19
-
20
- write "config/slices/main.rb", <<~'RUBY'
21
- module Main
22
- class Slice < Hanami::Slice
23
- config.no_auto_register_paths << "schemas"
24
- end
25
- end
26
- RUBY
27
-
28
- write "config/slices/search.rb", <<~'RUBY'
29
- module Search
30
- class Slice < Hanami::Slice
31
- end
32
- end
33
- RUBY
34
-
35
- require "hanami/prepare"
36
-
37
- expect(TestApp::App.config.no_auto_register_paths).to eq %w[structs]
38
- expect(Main::Slice.config.no_auto_register_paths).to eq %w[structs schemas]
39
- expect(Search::Slice.config.no_auto_register_paths).to eq %w[structs]
40
- end
41
- end
42
- end