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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -19
- data/LICENSE +20 -0
- data/README.md +18 -35
- data/hanami.gemspec +36 -37
- data/lib/hanami/config/db.rb +2 -0
- data/lib/hanami/config/i18n.rb +138 -0
- data/lib/hanami/config/logger.rb +15 -7
- data/lib/hanami/config/null_config.rb +1 -1
- data/lib/hanami/config/views.rb +17 -0
- data/lib/hanami/config.rb +66 -22
- data/lib/hanami/errors.rb +6 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/extensions/action.rb +2 -2
- data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
- data/lib/hanami/extensions/mailer.rb +28 -0
- data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
- data/lib/hanami/extensions/view/context.rb +26 -4
- data/lib/hanami/extensions/view/part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions.rb +6 -1
- data/lib/hanami/helpers/assets_helper.rb +0 -4
- data/lib/hanami/helpers/form_helper.rb +1 -1
- data/lib/hanami/helpers/i18n_helper.rb +176 -0
- data/lib/hanami/logger/rack_formatter.rb +73 -0
- data/lib/hanami/logger/sql_formatter.rb +80 -0
- data/lib/hanami/logger/sql_logger.rb +48 -0
- data/lib/hanami/middleware/render_errors.rb +2 -2
- data/lib/hanami/providers/db.rb +7 -2
- data/lib/hanami/providers/db_logging.rb +4 -7
- data/lib/hanami/providers/i18n/backend.rb +369 -0
- data/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/lib/hanami/providers/i18n.rb +114 -0
- data/lib/hanami/providers/mailers.rb +101 -0
- data/lib/hanami/routes.rb +1 -0
- data/lib/hanami/settings/composite_store.rb +53 -0
- data/lib/hanami/settings.rb +4 -4
- data/lib/hanami/slice/router.rb +15 -10
- data/lib/hanami/slice.rb +71 -11
- data/lib/hanami/slice_registrar.rb +2 -2
- data/lib/hanami/universal_logger.rb +250 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +2 -80
- data/lib/hanami/web/welcome.html.erb +443 -58
- data/lib/hanami.rb +4 -2
- metadata +28 -276
- data/CODE_OF_CONDUCT.md +0 -74
- data/FEATURES.md +0 -269
- data/LICENSE.md +0 -22
- data/spec/integration/action/cookies_spec.rb +0 -58
- data/spec/integration/action/csrf_protection_spec.rb +0 -54
- data/spec/integration/action/format_config_spec.rb +0 -129
- data/spec/integration/action/routes_spec.rb +0 -71
- data/spec/integration/action/sessions_spec.rb +0 -50
- data/spec/integration/action/slice_configuration_spec.rb +0 -284
- data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
- data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
- data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
- data/spec/integration/action/view_rendering_spec.rb +0 -89
- data/spec/integration/assets/assets_spec.rb +0 -155
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
- data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
- data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
- data/spec/integration/container/application_routes_helper_spec.rb +0 -48
- data/spec/integration/container/auto_injection_spec.rb +0 -53
- data/spec/integration/container/auto_registration_spec.rb +0 -86
- data/spec/integration/container/autoloader_spec.rb +0 -82
- data/spec/integration/container/imports_spec.rb +0 -253
- data/spec/integration/container/prepare_container_spec.rb +0 -125
- data/spec/integration/container/provider_environment_spec.rb +0 -52
- data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
- data/spec/integration/container/shutdown_spec.rb +0 -91
- data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
- data/spec/integration/container/standard_providers_spec.rb +0 -124
- data/spec/integration/db/auto_registration_spec.rb +0 -39
- data/spec/integration/db/commands_spec.rb +0 -80
- data/spec/integration/db/db_inflector_spec.rb +0 -57
- data/spec/integration/db/db_slices_spec.rb +0 -398
- data/spec/integration/db/db_spec.rb +0 -245
- data/spec/integration/db/gateways_spec.rb +0 -361
- data/spec/integration/db/logging_spec.rb +0 -301
- data/spec/integration/db/mappers_spec.rb +0 -84
- data/spec/integration/db/provider_config_spec.rb +0 -88
- data/spec/integration/db/provider_spec.rb +0 -35
- data/spec/integration/db/relations_spec.rb +0 -60
- data/spec/integration/db/repo_spec.rb +0 -300
- data/spec/integration/db/slices_importing_from_parent.rb +0 -130
- data/spec/integration/dotenv_loading_spec.rb +0 -138
- data/spec/integration/logging/exception_logging_spec.rb +0 -120
- data/spec/integration/logging/notifications_spec.rb +0 -68
- data/spec/integration/logging/request_logging_spec.rb +0 -202
- data/spec/integration/operations/extension_spec.rb +0 -122
- data/spec/integration/rack_app/body_parser_spec.rb +0 -108
- data/spec/integration/rack_app/method_override_spec.rb +0 -97
- data/spec/integration/rack_app/middleware_spec.rb +0 -720
- data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
- data/spec/integration/rack_app/rack_app_spec.rb +0 -442
- data/spec/integration/rake_tasks_spec.rb +0 -107
- data/spec/integration/router/resource_routes_spec.rb +0 -281
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
- data/spec/integration/settings/access_to_constants_spec.rb +0 -46
- data/spec/integration/settings/loading_from_env_spec.rb +0 -188
- data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
- data/spec/integration/settings/slice_registration_spec.rb +0 -145
- data/spec/integration/settings/using_types_spec.rb +0 -80
- data/spec/integration/setup_spec.rb +0 -165
- data/spec/integration/slices/external_slice_spec.rb +0 -91
- data/spec/integration/slices/slice_configuration_spec.rb +0 -42
- data/spec/integration/slices/slice_loading_spec.rb +0 -171
- data/spec/integration/slices/slice_registrations_spec.rb +0 -80
- data/spec/integration/slices/slice_routing_spec.rb +0 -219
- data/spec/integration/slices_spec.rb +0 -471
- data/spec/integration/view/config/default_context_spec.rb +0 -149
- data/spec/integration/view/config/inflector_spec.rb +0 -57
- data/spec/integration/view/config/part_class_spec.rb +0 -147
- data/spec/integration/view/config/part_namespace_spec.rb +0 -103
- data/spec/integration/view/config/paths_spec.rb +0 -119
- data/spec/integration/view/config/scope_class_spec.rb +0 -147
- data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
- data/spec/integration/view/config/template_spec.rb +0 -38
- data/spec/integration/view/context/assets_spec.rb +0 -79
- data/spec/integration/view/context/inflector_spec.rb +0 -40
- data/spec/integration/view/context/request_spec.rb +0 -57
- data/spec/integration/view/context/routes_spec.rb +0 -84
- data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
- data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
- data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
- data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
- data/spec/integration/view/slice_configuration_spec.rb +0 -289
- data/spec/integration/view/views_spec.rb +0 -103
- data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
- data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
- data/spec/integration/web/render_errors_spec.rb +0 -242
- data/spec/integration/web/welcome_view_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -28
- data/spec/support/app_integration.rb +0 -157
- data/spec/support/coverage.rb +0 -1
- data/spec/support/matchers.rb +0 -32
- data/spec/support/rspec.rb +0 -27
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
- data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
- data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
- data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
- data/spec/unit/hanami/config/actions_spec.rb +0 -52
- data/spec/unit/hanami/config/base_url_spec.rb +0 -25
- data/spec/unit/hanami/config/console_spec.rb +0 -22
- data/spec/unit/hanami/config/db_spec.rb +0 -38
- data/spec/unit/hanami/config/inflector_spec.rb +0 -35
- data/spec/unit/hanami/config/logger_spec.rb +0 -195
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/router_spec.rb +0 -44
- data/spec/unit/hanami/config/slices_spec.rb +0 -34
- data/spec/unit/hanami/config/views_spec.rb +0 -80
- data/spec/unit/hanami/env_spec.rb +0 -37
- data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
- data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
- data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
- data/spec/unit/hanami/port_spec.rb +0 -117
- data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
- data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
- data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
- data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
- data/spec/unit/hanami/settings_spec.rb +0 -111
- data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
- data/spec/unit/hanami/slice_name_spec.rb +0 -47
- data/spec/unit/hanami/slice_spec.rb +0 -99
- data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "Slices / Slice loading", :app_integration, :aggregate_failures do
|
|
6
|
-
let(:app_modules) { %i[TestApp Admin Main] }
|
|
7
|
-
|
|
8
|
-
describe "loading specific slices with config.slices" do
|
|
9
|
-
describe "setup app" do
|
|
10
|
-
it "ignores any explicitly registered slices not included in load_slices" do
|
|
11
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
12
|
-
write "config/app.rb", <<~'RUBY'
|
|
13
|
-
require "hanami"
|
|
14
|
-
|
|
15
|
-
module TestApp
|
|
16
|
-
class App < Hanami::App
|
|
17
|
-
config.slices = %w[admin]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
RUBY
|
|
21
|
-
|
|
22
|
-
require "hanami/setup"
|
|
23
|
-
|
|
24
|
-
expect { Hanami.app.register_slice :main }.not_to(change { Hanami.app.slices.keys })
|
|
25
|
-
expect { Main }.to raise_error(NameError)
|
|
26
|
-
|
|
27
|
-
expect { Hanami.app.register_slice :admin }.to change { Hanami.app.slices.keys }.to [:admin]
|
|
28
|
-
expect(Admin::Slice).to be
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "nested slices" do
|
|
33
|
-
it "ignores any explicitly registered slices not included in load_slices" do
|
|
34
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
35
|
-
write "config/app.rb", <<~'RUBY'
|
|
36
|
-
require "hanami"
|
|
37
|
-
|
|
38
|
-
module TestApp
|
|
39
|
-
class App < Hanami::App
|
|
40
|
-
config.slices = %w[admin.shop]
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
RUBY
|
|
44
|
-
|
|
45
|
-
require "hanami/setup"
|
|
46
|
-
|
|
47
|
-
expect { Hanami.app.register_slice :admin }.to change { Hanami.app.slices.keys }.to [:admin]
|
|
48
|
-
|
|
49
|
-
expect { Admin::Slice.register_slice :editorial }.not_to(change { Admin::Slice.slices.keys })
|
|
50
|
-
expect { Admin::Slice.register_slice :shop }.to change { Admin::Slice.slices.keys }.to [:shop]
|
|
51
|
-
expect(Admin::Shop::Slice).to be
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe "prepared app" do
|
|
58
|
-
it "loads only the slices included in load_slices" do
|
|
59
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
60
|
-
write "config/app.rb", <<~'RUBY'
|
|
61
|
-
require "hanami"
|
|
62
|
-
|
|
63
|
-
module TestApp
|
|
64
|
-
class App < Hanami::App
|
|
65
|
-
config.slices = %w[admin]
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
RUBY
|
|
69
|
-
|
|
70
|
-
write "slices/admin/.keep"
|
|
71
|
-
write "slices/main/.keep"
|
|
72
|
-
|
|
73
|
-
require "hanami/prepare"
|
|
74
|
-
|
|
75
|
-
expect(Hanami.app.slices.keys).to eq [:admin]
|
|
76
|
-
expect(Admin::Slice).to be
|
|
77
|
-
expect { Main }.to raise_error(NameError)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "ignores unknown slices in load_slices" do
|
|
82
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
83
|
-
write "config/app.rb", <<~'RUBY'
|
|
84
|
-
require "hanami"
|
|
85
|
-
|
|
86
|
-
module TestApp
|
|
87
|
-
class App < Hanami::App
|
|
88
|
-
config.slices = %w[admin meep morp]
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
RUBY
|
|
92
|
-
|
|
93
|
-
write "slices/admin/.keep"
|
|
94
|
-
write "slices/main/.keep"
|
|
95
|
-
|
|
96
|
-
require "hanami/prepare"
|
|
97
|
-
|
|
98
|
-
expect(Hanami.app.slices.keys).to eq [:admin]
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "nested slices" do
|
|
103
|
-
it "loads only the dot-delimited nested slices (and their parents) included in load_slices" do
|
|
104
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
105
|
-
write "config/app.rb", <<~'RUBY'
|
|
106
|
-
require "hanami"
|
|
107
|
-
|
|
108
|
-
module TestApp
|
|
109
|
-
class App < Hanami::App
|
|
110
|
-
config.slices = %w[admin.shop]
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
RUBY
|
|
114
|
-
|
|
115
|
-
write "slices/admin/.keep"
|
|
116
|
-
write "slices/admin/slices/shop/.keep"
|
|
117
|
-
write "slices/admin/slices/editorial/.keep"
|
|
118
|
-
write "slices/main/.keep"
|
|
119
|
-
|
|
120
|
-
require "hanami/prepare"
|
|
121
|
-
|
|
122
|
-
expect(Hanami.app.slices.keys).to eq [:admin]
|
|
123
|
-
expect(Admin::Slice.slices.keys).to eq [:shop]
|
|
124
|
-
|
|
125
|
-
expect(Admin::Slice).to be
|
|
126
|
-
expect(Admin::Shop::Slice).to be
|
|
127
|
-
|
|
128
|
-
expect { Admin::Editorial }.to raise_error(NameError)
|
|
129
|
-
expect { Main }.to raise_error(NameError)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
describe "using ENV vars" do
|
|
137
|
-
before do
|
|
138
|
-
@orig_env = ENV.to_h
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
after do
|
|
142
|
-
ENV.replace(@orig_env)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "uses HANAMI_SLICES" do
|
|
146
|
-
ENV["HANAMI_SLICES"] = "admin"
|
|
147
|
-
|
|
148
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
149
|
-
write "config/app.rb", <<~'RUBY'
|
|
150
|
-
require "hanami"
|
|
151
|
-
|
|
152
|
-
module TestApp
|
|
153
|
-
class App < Hanami::App
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
RUBY
|
|
157
|
-
|
|
158
|
-
write "slices/admin/.keep"
|
|
159
|
-
write "slices/main/.keep"
|
|
160
|
-
|
|
161
|
-
require "hanami/setup"
|
|
162
|
-
|
|
163
|
-
expect(Hanami.app.config.slices).to eq %w[admin]
|
|
164
|
-
|
|
165
|
-
require "hanami/prepare"
|
|
166
|
-
|
|
167
|
-
expect(Hanami.app.slices.keys).to eq [:admin]
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Slice Registrations", :app_integration do
|
|
4
|
-
matcher :have_key do |name, value|
|
|
5
|
-
match do |slice|
|
|
6
|
-
slice.resolve(name) == value
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
specify "Registrations are loaded" do
|
|
11
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
12
|
-
write "config/app.rb", <<~RUBY
|
|
13
|
-
require "hanami"
|
|
14
|
-
|
|
15
|
-
module TestApp
|
|
16
|
-
class App < Hanami::App
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
RUBY
|
|
20
|
-
|
|
21
|
-
write "config/registrations/foo.rb", <<~RUBY
|
|
22
|
-
TestApp::App.register("foo") { "bar" }
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
require "hanami/prepare"
|
|
26
|
-
|
|
27
|
-
expect(Hanami.app).to have_key(:foo, "bar")
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
specify "Slices load their own registrations" do
|
|
32
|
-
with_tmp_directory(Dir.mktmpdir) 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 "config/slices/main.rb", <<~RUBY
|
|
43
|
-
module Admin
|
|
44
|
-
class Slice < Hanami::Slice
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
RUBY
|
|
48
|
-
|
|
49
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
50
|
-
module Main
|
|
51
|
-
class Slice < Hanami::Slice
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
RUBY
|
|
55
|
-
|
|
56
|
-
write "config/registrations/foo.rb", <<~RUBY
|
|
57
|
-
TestApp::App.register("foo") { "bar" }
|
|
58
|
-
RUBY
|
|
59
|
-
|
|
60
|
-
write "slices/admin/config/registrations/bar.rb", <<~RUBY
|
|
61
|
-
Admin::Slice.register("bar") { "baz" }
|
|
62
|
-
RUBY
|
|
63
|
-
|
|
64
|
-
write "slices/main/config/registrations/baz.rb", <<~RUBY
|
|
65
|
-
Main::Slice.register("baz") { "quux" }
|
|
66
|
-
RUBY
|
|
67
|
-
|
|
68
|
-
require "hanami/prepare"
|
|
69
|
-
|
|
70
|
-
admin_slice = Hanami.app.slices[:admin]
|
|
71
|
-
main_slice = Hanami.app.slices[:main]
|
|
72
|
-
|
|
73
|
-
aggregate_failures do
|
|
74
|
-
expect(Hanami.app).to have_key(:foo, "bar")
|
|
75
|
-
expect(admin_slice).to have_key(:bar, "baz")
|
|
76
|
-
expect(main_slice).to have_key(:baz, "quux")
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
require "stringio"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Slices / Slice routing", :app_integration do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
|
|
9
|
-
let(:app) { Main::Slice.rack_app }
|
|
10
|
-
|
|
11
|
-
specify "Slices have a nil router when no routes are defined" 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
|
-
end
|
|
19
|
-
end
|
|
20
|
-
RUBY
|
|
21
|
-
|
|
22
|
-
write "slices/main/.keep", ""
|
|
23
|
-
|
|
24
|
-
require "hanami/prepare"
|
|
25
|
-
|
|
26
|
-
expect(Main::Slice.routes).to be nil
|
|
27
|
-
expect(Main::Slice.router).to be nil
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
specify "Slices have the app 'routes' component registered when app routes are defined but not their own" do
|
|
32
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
33
|
-
write "config/app.rb", <<~'RUBY'
|
|
34
|
-
require "hanami"
|
|
35
|
-
|
|
36
|
-
module TestApp
|
|
37
|
-
class App < Hanami::App
|
|
38
|
-
config.logger.stream = StringIO.new
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
RUBY
|
|
42
|
-
|
|
43
|
-
write "config/routes.rb", <<~'RUBY'
|
|
44
|
-
require "hanami/routes"
|
|
45
|
-
|
|
46
|
-
module TestApp
|
|
47
|
-
class Routes < Hanami::Routes
|
|
48
|
-
get "home", to: "home.show", as: :home
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
RUBY
|
|
52
|
-
|
|
53
|
-
write "slices/main/.keep", ""
|
|
54
|
-
|
|
55
|
-
require "hanami/prepare"
|
|
56
|
-
|
|
57
|
-
expect(Main::Slice["routes"].path(:home)).to eq "/home"
|
|
58
|
-
|
|
59
|
-
expect(Main::Slice.router).to be nil
|
|
60
|
-
expect(TestApp::App.router).not_to be nil
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
specify "Slices use their own router and registered 'routes' component when their own routes are defined" do
|
|
65
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
66
|
-
write "config/app.rb", <<~'RUBY'
|
|
67
|
-
require "hanami"
|
|
68
|
-
|
|
69
|
-
module TestApp
|
|
70
|
-
class App < Hanami::App
|
|
71
|
-
config.logger.stream = StringIO.new
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
RUBY
|
|
75
|
-
|
|
76
|
-
write "slices/main/config/routes.rb", <<~'RUBY'
|
|
77
|
-
require "hanami/routes"
|
|
78
|
-
|
|
79
|
-
module Main
|
|
80
|
-
class Routes < Hanami::Routes
|
|
81
|
-
get "home", to: "home.show", as: :home
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
RUBY
|
|
85
|
-
|
|
86
|
-
write "slices/main/actions/home/show.rb", <<~'RUBY'
|
|
87
|
-
require "hanami/action"
|
|
88
|
-
|
|
89
|
-
module Main
|
|
90
|
-
module Actions
|
|
91
|
-
module Home
|
|
92
|
-
class Show < Hanami::Action
|
|
93
|
-
def handle(*, res)
|
|
94
|
-
res.body = "Hello world"
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
RUBY
|
|
101
|
-
|
|
102
|
-
require "hanami/prepare"
|
|
103
|
-
Main::Slice.boot
|
|
104
|
-
|
|
105
|
-
expect(Main::Slice["routes"].path(:home)).to eq "/home"
|
|
106
|
-
|
|
107
|
-
get "/home"
|
|
108
|
-
|
|
109
|
-
expect(last_response.status).to eq 200
|
|
110
|
-
expect(last_response.body).to eq "Hello world"
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe "Mounting slice routes" do
|
|
115
|
-
before :context do
|
|
116
|
-
with_directory(@dir = make_tmp_directory) do
|
|
117
|
-
write "config/app.rb", <<~'RUBY'
|
|
118
|
-
require "hanami"
|
|
119
|
-
|
|
120
|
-
module TestApp
|
|
121
|
-
class App < Hanami::App
|
|
122
|
-
config.logger.stream = StringIO.new
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
RUBY
|
|
126
|
-
|
|
127
|
-
write "config/routes.rb", <<~'RUBY'
|
|
128
|
-
module TestApp
|
|
129
|
-
class Routes < Hanami::Routes
|
|
130
|
-
root to: "home.show"
|
|
131
|
-
|
|
132
|
-
slice :main, at: "/main"
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
RUBY
|
|
136
|
-
|
|
137
|
-
write "app/actions/home/show.rb", <<~'RUBY'
|
|
138
|
-
require "hanami/action"
|
|
139
|
-
|
|
140
|
-
module TestApp
|
|
141
|
-
module Actions
|
|
142
|
-
module Home
|
|
143
|
-
class Show < Hanami::Action
|
|
144
|
-
def handle(*, res)
|
|
145
|
-
res.body = "Hello from app"
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
RUBY
|
|
152
|
-
|
|
153
|
-
write "slices/main/config/routes.rb", <<~'RUBY'
|
|
154
|
-
module Main
|
|
155
|
-
class Routes < Hanami::Routes
|
|
156
|
-
root to: "home.show"
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
RUBY
|
|
160
|
-
|
|
161
|
-
write "slices/main/actions/home/show.rb", <<~'RUBY'
|
|
162
|
-
require "hanami/action"
|
|
163
|
-
|
|
164
|
-
module Main
|
|
165
|
-
module Actions
|
|
166
|
-
module Home
|
|
167
|
-
class Show < Hanami::Action
|
|
168
|
-
def handle(*, res)
|
|
169
|
-
res.body = "Hello from slice"
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
RUBY
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
let(:app) { TestApp::App.app }
|
|
180
|
-
|
|
181
|
-
describe "A slice with its own router can be mounted in its parent's routes" do
|
|
182
|
-
context "prepared" do
|
|
183
|
-
before do
|
|
184
|
-
with_directory(@dir) { require "hanami/prepare" }
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
specify do
|
|
188
|
-
get "/"
|
|
189
|
-
|
|
190
|
-
expect(last_response.status).to eq 200
|
|
191
|
-
expect(last_response.body).to eq "Hello from app"
|
|
192
|
-
|
|
193
|
-
get "/main"
|
|
194
|
-
|
|
195
|
-
expect(last_response.status).to eq 200
|
|
196
|
-
expect(last_response.body).to eq "Hello from slice"
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
context "booted" do
|
|
201
|
-
before do
|
|
202
|
-
with_directory(@dir) { require "hanami/boot" }
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
specify do
|
|
206
|
-
get "/"
|
|
207
|
-
|
|
208
|
-
expect(last_response.status).to eq 200
|
|
209
|
-
expect(last_response.body).to eq "Hello from app"
|
|
210
|
-
|
|
211
|
-
get "/main"
|
|
212
|
-
|
|
213
|
-
expect(last_response.status).to eq 200
|
|
214
|
-
expect(last_response.body).to eq "Hello from slice"
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|