hanami 2.0.0.alpha8 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +442 -241
- data/FEATURES.md +30 -9
- data/README.md +1 -3
- data/hanami.gemspec +21 -11
- data/lib/hanami/app.rb +141 -0
- data/lib/hanami/assets/application_configuration.rb +10 -4
- data/lib/hanami/configuration/actions/content_security_policy.rb +5 -5
- data/lib/hanami/configuration/actions/cookies.rb +2 -2
- data/lib/hanami/configuration/actions.rb +10 -4
- data/lib/hanami/configuration/logger.rb +4 -4
- data/lib/hanami/configuration/router.rb +2 -6
- data/lib/hanami/configuration/sessions.rb +1 -1
- data/lib/hanami/configuration/views.rb +9 -4
- data/lib/hanami/configuration.rb +118 -46
- data/lib/hanami/constants.rb +24 -2
- data/lib/hanami/errors.rb +1 -1
- data/lib/hanami/{application → extensions}/action/slice_configured_action.rb +9 -9
- data/lib/hanami/extensions/action.rb +79 -0
- data/lib/hanami/extensions/view/context.rb +106 -0
- data/lib/hanami/{application → extensions}/view/slice_configured_context.rb +10 -10
- data/lib/hanami/{application → extensions}/view/slice_configured_view.rb +12 -6
- data/lib/hanami/extensions/view.rb +33 -0
- data/lib/hanami/extensions.rb +10 -0
- data/lib/hanami/providers/inflector.rb +13 -0
- data/lib/hanami/providers/logger.rb +13 -0
- data/lib/hanami/providers/rack.rb +27 -0
- data/lib/hanami/providers/routes.rb +33 -0
- data/lib/hanami/providers/settings.rb +23 -0
- data/lib/hanami/rake_tasks.rb +61 -0
- data/lib/hanami/routes.rb +51 -0
- data/lib/hanami/server.rb +1 -1
- data/lib/hanami/settings/dotenv_store.rb +58 -0
- data/lib/hanami/settings.rb +90 -0
- data/lib/hanami/setup.rb +4 -2
- data/lib/hanami/{application → slice}/router.rb +18 -13
- data/lib/hanami/slice/routes_helper.rb +37 -0
- data/lib/hanami/{application → slice}/routing/middleware/stack.rb +43 -5
- data/lib/hanami/slice/routing/resolver.rb +97 -0
- data/lib/hanami/{application → slice}/view_name_inferrer.rb +3 -3
- data/lib/hanami/slice.rb +246 -73
- data/lib/hanami/slice_configurable.rb +4 -17
- data/lib/hanami/slice_name.rb +6 -6
- data/lib/hanami/slice_registrar.rb +119 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +1 -1
- data/lib/hanami.rb +34 -26
- data/spec/integration/application_middleware_stack_spec.rb +84 -0
- data/spec/integration/assets/cdn_spec.rb +48 -0
- data/spec/integration/assets/fingerprint_spec.rb +42 -0
- data/spec/integration/assets/helpers_spec.rb +50 -0
- data/spec/integration/assets/serve_spec.rb +70 -0
- data/spec/integration/assets/subresource_integrity_spec.rb +54 -0
- data/spec/integration/body_parsers_spec.rb +50 -0
- data/spec/integration/cli/assets/precompile_spec.rb +147 -0
- data/spec/integration/cli/assets_spec.rb +14 -0
- data/spec/integration/cli/console_spec.rb +105 -0
- data/spec/integration/cli/db/apply_spec.rb +74 -0
- data/spec/integration/cli/db/console_spec.rb +40 -0
- data/spec/integration/cli/db/create_spec.rb +50 -0
- data/spec/integration/cli/db/drop_spec.rb +54 -0
- data/spec/integration/cli/db/migrate_spec.rb +108 -0
- data/spec/integration/cli/db/prepare_spec.rb +36 -0
- data/spec/integration/cli/db/rollback_spec.rb +96 -0
- data/spec/integration/cli/db/version_spec.rb +38 -0
- data/spec/integration/cli/db_spec.rb +21 -0
- data/spec/integration/cli/destroy/action_spec.rb +143 -0
- data/spec/integration/cli/destroy/app_spec.rb +118 -0
- data/spec/integration/cli/destroy/mailer_spec.rb +74 -0
- data/spec/integration/cli/destroy/migration_spec.rb +70 -0
- data/spec/integration/cli/destroy/model_spec.rb +113 -0
- data/spec/integration/cli/destroy_spec.rb +18 -0
- data/spec/integration/cli/generate/action_spec.rb +469 -0
- data/spec/integration/cli/generate/app_spec.rb +215 -0
- data/spec/integration/cli/generate/mailer_spec.rb +189 -0
- data/spec/integration/cli/generate/migration_spec.rb +72 -0
- data/spec/integration/cli/generate/model_spec.rb +290 -0
- data/spec/integration/cli/generate/secret_spec.rb +56 -0
- data/spec/integration/cli/generate_spec.rb +19 -0
- data/spec/integration/cli/new/database_spec.rb +235 -0
- data/spec/integration/cli/new/hanami_head_spec.rb +27 -0
- data/spec/integration/cli/new/template_spec.rb +118 -0
- data/spec/integration/cli/new/test_spec.rb +274 -0
- data/spec/integration/cli/new_spec.rb +970 -0
- data/spec/integration/cli/plugins_spec.rb +39 -0
- data/spec/integration/cli/routes_spec.rb +49 -0
- data/spec/integration/cli/server_spec.rb +626 -0
- data/spec/integration/cli/version_spec.rb +85 -0
- data/spec/integration/early_hints_spec.rb +35 -0
- data/spec/integration/handle_exceptions_spec.rb +244 -0
- data/spec/integration/head_spec.rb +89 -0
- data/spec/integration/http_headers_spec.rb +29 -0
- data/spec/integration/mailer_spec.rb +32 -0
- data/spec/integration/middleware_spec.rb +81 -0
- data/spec/integration/mount_applications_spec.rb +88 -0
- data/spec/integration/project_initializers_spec.rb +40 -0
- data/spec/integration/rackup_spec.rb +35 -0
- data/spec/integration/rake/with_minitest_spec.rb +67 -0
- data/spec/integration/rake/with_rspec_spec.rb +69 -0
- data/spec/integration/routing_helpers_spec.rb +61 -0
- data/spec/integration/security/content_security_policy_spec.rb +46 -0
- data/spec/integration/security/csrf_protection_spec.rb +42 -0
- data/spec/integration/security/force_ssl_spec.rb +29 -0
- data/spec/integration/security/x_content_type_options_spec.rb +46 -0
- data/spec/integration/security/x_frame_options_spec.rb +46 -0
- data/spec/integration/security/x_xss_protection_spec.rb +46 -0
- data/spec/integration/send_file_spec.rb +51 -0
- data/spec/integration/sessions_spec.rb +247 -0
- data/spec/integration/static_middleware_spec.rb +21 -0
- data/spec/integration/streaming_spec.rb +41 -0
- data/spec/integration/unsafe_send_file_spec.rb +52 -0
- data/spec/isolation/hanami/application/already_configured_spec.rb +19 -0
- data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +10 -0
- data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +14 -0
- data/spec/isolation/hanami/application/not_configured_spec.rb +9 -0
- data/spec/isolation/hanami/application/routes/configured_spec.rb +44 -0
- data/spec/isolation/hanami/application/routes/not_configured_spec.rb +16 -0
- data/spec/isolation/hanami/boot/success_spec.rb +50 -0
- data/spec/new_integration/action/configuration_spec.rb +26 -0
- data/spec/new_integration/action/cookies_spec.rb +58 -0
- data/spec/new_integration/action/csrf_protection_spec.rb +54 -0
- data/spec/new_integration/action/routes_spec.rb +73 -0
- data/spec/new_integration/action/sessions_spec.rb +50 -0
- data/spec/new_integration/action/view_integration_spec.rb +165 -0
- data/spec/new_integration/action/view_rendering/automatic_rendering_spec.rb +247 -0
- data/spec/new_integration/action/view_rendering/paired_view_inference_spec.rb +115 -0
- data/spec/new_integration/action/view_rendering_spec.rb +107 -0
- data/spec/new_integration/code_loading/loading_from_app_spec.rb +152 -0
- data/spec/new_integration/code_loading/loading_from_slice_spec.rb +165 -0
- data/spec/new_integration/container/application_routes_helper_spec.rb +48 -0
- data/spec/new_integration/container/auto_injection_spec.rb +53 -0
- data/spec/new_integration/container/auto_registration_spec.rb +86 -0
- data/spec/new_integration/container/autoloader_spec.rb +80 -0
- data/spec/new_integration/container/imports_spec.rb +253 -0
- data/spec/new_integration/container/prepare_container_spec.rb +123 -0
- data/spec/new_integration/container/shutdown_spec.rb +91 -0
- data/spec/new_integration/container/standard_bootable_components_spec.rb +124 -0
- data/spec/new_integration/rack_app/middleware_spec.rb +215 -0
- data/spec/new_integration/rack_app/non_booted_rack_app_spec.rb +105 -0
- data/spec/new_integration/rack_app/rack_app_spec.rb +524 -0
- data/spec/new_integration/settings_spec.rb +115 -0
- data/spec/new_integration/slices/external_slice_spec.rb +92 -0
- data/spec/new_integration/slices/slice_configuration_spec.rb +40 -0
- data/spec/new_integration/slices/slice_routing_spec.rb +226 -0
- data/spec/new_integration/slices/slice_settings_spec.rb +141 -0
- data/spec/new_integration/slices_spec.rb +101 -0
- data/spec/new_integration/view/configuration_spec.rb +49 -0
- data/spec/new_integration/view/context/assets_spec.rb +67 -0
- data/spec/new_integration/view/context/inflector_spec.rb +48 -0
- data/spec/new_integration/view/context/request_spec.rb +61 -0
- data/spec/new_integration/view/context/routes_spec.rb +86 -0
- data/spec/new_integration/view/context/settings_spec.rb +50 -0
- data/spec/new_integration/view/inflector_spec.rb +57 -0
- data/spec/new_integration/view/part_namespace_spec.rb +96 -0
- data/spec/new_integration/view/path_spec.rb +56 -0
- data/spec/new_integration/view/template_spec.rb +68 -0
- data/spec/new_integration/view/views_spec.rb +103 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/app_integration.rb +91 -0
- data/spec/support/coverage.rb +1 -0
- data/spec/support/fixtures/hanami-plugin/Gemfile +8 -0
- data/spec/support/fixtures/hanami-plugin/README.md +35 -0
- data/spec/support/fixtures/hanami-plugin/Rakefile +4 -0
- data/spec/support/fixtures/hanami-plugin/bin/console +15 -0
- data/spec/support/fixtures/hanami-plugin/bin/setup +8 -0
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +28 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +19 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +7 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +8 -0
- data/spec/support/rspec.rb +27 -0
- data/spec/support/shared_examples/cli/generate/app.rb +494 -0
- data/spec/support/shared_examples/cli/generate/migration.rb +32 -0
- data/spec/support/shared_examples/cli/generate/model.rb +81 -0
- data/spec/support/shared_examples/cli/new.rb +97 -0
- data/spec/unit/hanami/configuration/actions/content_security_policy_spec.rb +102 -0
- data/spec/unit/hanami/configuration/actions/cookies_spec.rb +46 -0
- data/spec/unit/hanami/configuration/actions/csrf_protection_spec.rb +57 -0
- data/spec/unit/hanami/configuration/actions/default_values_spec.rb +52 -0
- data/spec/unit/hanami/configuration/actions/sessions_spec.rb +50 -0
- data/spec/unit/hanami/configuration/actions_spec.rb +78 -0
- data/spec/unit/hanami/configuration/base_url_spec.rb +25 -0
- data/spec/unit/hanami/configuration/inflector_spec.rb +35 -0
- data/spec/unit/hanami/configuration/logger_spec.rb +203 -0
- data/spec/unit/hanami/configuration/views_spec.rb +120 -0
- data/spec/unit/hanami/configuration_spec.rb +43 -0
- data/spec/unit/hanami/env_spec.rb +54 -0
- data/spec/unit/hanami/routes_spec.rb +25 -0
- data/spec/unit/hanami/settings/dotenv_store_spec.rb +119 -0
- data/spec/unit/hanami/settings_spec.rb +56 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +104 -0
- data/spec/unit/hanami/slice_name_spec.rb +47 -0
- data/spec/unit/hanami/slice_spec.rb +17 -0
- data/spec/unit/hanami/version_spec.rb +7 -0
- data/spec/unit/hanami/web/rack_logger_spec.rb +78 -0
- metadata +353 -57
- data/lib/hanami/application/action.rb +0 -72
- data/lib/hanami/application/container/providers/inflector.rb +0 -7
- data/lib/hanami/application/container/providers/logger.rb +0 -7
- data/lib/hanami/application/container/providers/rack_logger.rb +0 -15
- data/lib/hanami/application/container/providers/rack_monitor.rb +0 -12
- data/lib/hanami/application/container/providers/routes_helper.rb +0 -9
- data/lib/hanami/application/container/providers/settings.rb +0 -7
- data/lib/hanami/application/routes.rb +0 -55
- data/lib/hanami/application/routes_helper.rb +0 -34
- data/lib/hanami/application/routing/resolver/node.rb +0 -50
- data/lib/hanami/application/routing/resolver/trie.rb +0 -59
- data/lib/hanami/application/routing/resolver.rb +0 -87
- data/lib/hanami/application/routing/router.rb +0 -36
- data/lib/hanami/application/settings/dotenv_store.rb +0 -60
- data/lib/hanami/application/settings.rb +0 -93
- data/lib/hanami/application/slice_registrar.rb +0 -106
- data/lib/hanami/application/view/context.rb +0 -95
- data/lib/hanami/application/view.rb +0 -24
- data/lib/hanami/application.rb +0 -273
- data/lib/hanami/cli/application/cli.rb +0 -40
- data/lib/hanami/cli/application/command.rb +0 -47
- data/lib/hanami/cli/application/commands/console.rb +0 -81
- data/lib/hanami/cli/application/commands.rb +0 -16
- data/lib/hanami/cli/base_command.rb +0 -48
- data/lib/hanami/cli/commands/command.rb +0 -171
- data/lib/hanami/cli/commands/server.rb +0 -88
- data/lib/hanami/cli/commands.rb +0 -65
- data/lib/hanami/configuration/middleware.rb +0 -20
- data/lib/hanami/configuration/source_dirs.rb +0 -42
@@ -0,0 +1,215 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
RSpec.describe "Hanami web app", :app_integration do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
let(:app) { Hanami.app }
|
9
|
+
|
10
|
+
around do |example|
|
11
|
+
with_tmp_directory(Dir.mktmpdir, &example)
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
module TestApp
|
16
|
+
module Middlewares
|
17
|
+
class Core
|
18
|
+
def initialize(app)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Prepare < Core
|
24
|
+
def call(env)
|
25
|
+
env["tested"] = []
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class AppendOne < Core
|
31
|
+
def call(env)
|
32
|
+
env["tested"] << "one"
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class AppendTwo < Core
|
38
|
+
def call(env)
|
39
|
+
env["tested"] << "two"
|
40
|
+
@app.call(env)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "Setting middlewares in the config" do
|
48
|
+
write "config/app.rb", <<~RUBY
|
49
|
+
require "hanami"
|
50
|
+
|
51
|
+
module TestApp
|
52
|
+
class App < Hanami::App
|
53
|
+
config.logger.stream = File.new("/dev/null", "w")
|
54
|
+
|
55
|
+
config.middleware.use Middlewares::AppendOne
|
56
|
+
config.middleware.use Middlewares::Prepare, before: Middlewares::AppendOne
|
57
|
+
config.middleware.use Middlewares::AppendTwo, after: Middlewares::AppendOne
|
58
|
+
end
|
59
|
+
end
|
60
|
+
RUBY
|
61
|
+
|
62
|
+
write "config/routes.rb", <<~RUBY
|
63
|
+
require "hanami/router"
|
64
|
+
|
65
|
+
module TestApp
|
66
|
+
class Routes < Hanami::Routes
|
67
|
+
define do
|
68
|
+
slice :main, at: "/" do
|
69
|
+
root to: "home.index"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
|
76
|
+
write "slices/main/actions/home/index.rb", <<~RUBY
|
77
|
+
require "hanami/action"
|
78
|
+
|
79
|
+
module Main
|
80
|
+
module Actions
|
81
|
+
module Home
|
82
|
+
class Index < Hanami::Action
|
83
|
+
def handle(req, res)
|
84
|
+
res.body = req.env["tested"].join(".")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
RUBY
|
91
|
+
|
92
|
+
require "hanami/boot"
|
93
|
+
|
94
|
+
get "/"
|
95
|
+
|
96
|
+
expect(last_response).to be_successful
|
97
|
+
expect(last_response.body).to eql("one.two")
|
98
|
+
end
|
99
|
+
|
100
|
+
specify "Setting middlewares in the router" do
|
101
|
+
write "config/app.rb", <<~RUBY
|
102
|
+
require "hanami"
|
103
|
+
|
104
|
+
module TestApp
|
105
|
+
class App < Hanami::App
|
106
|
+
config.logger.stream = File.new("/dev/null", "w")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
RUBY
|
110
|
+
|
111
|
+
write "config/routes.rb", <<~RUBY
|
112
|
+
require "hanami/router"
|
113
|
+
|
114
|
+
module TestApp
|
115
|
+
class Routes < Hanami::Routes
|
116
|
+
define do
|
117
|
+
slice :main, at: "/" do
|
118
|
+
use TestApp::Middlewares::AppendOne
|
119
|
+
use TestApp::Middlewares::Prepare, before: TestApp::Middlewares::AppendOne
|
120
|
+
use TestApp::Middlewares::AppendTwo, after: TestApp::Middlewares::AppendOne
|
121
|
+
|
122
|
+
root to: "home.index"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
RUBY
|
128
|
+
|
129
|
+
write "slices/main/actions/home/index.rb", <<~RUBY
|
130
|
+
require "hanami/action"
|
131
|
+
|
132
|
+
module Main
|
133
|
+
module Actions
|
134
|
+
module Home
|
135
|
+
class Index < Hanami::Action
|
136
|
+
def handle(req, res)
|
137
|
+
res.body = req.env["tested"].join(".")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
RUBY
|
144
|
+
|
145
|
+
require "hanami/boot"
|
146
|
+
|
147
|
+
get "/"
|
148
|
+
|
149
|
+
expect(last_response).to be_successful
|
150
|
+
expect(last_response.body).to eql("one.two")
|
151
|
+
end
|
152
|
+
|
153
|
+
specify "Setting a middleware that requires a block" do
|
154
|
+
write "config/app.rb", <<~RUBY
|
155
|
+
require "hanami"
|
156
|
+
|
157
|
+
module TestApp
|
158
|
+
class TestMiddleware
|
159
|
+
def initialize(app, &block)
|
160
|
+
@app = app
|
161
|
+
@block = block
|
162
|
+
end
|
163
|
+
|
164
|
+
def call(env)
|
165
|
+
@block.call(env)
|
166
|
+
@app.call(env)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class App < Hanami::App
|
171
|
+
config.logger.stream = File.new("/dev/null", "w")
|
172
|
+
|
173
|
+
config.middleware.use(TestApp::TestMiddleware) { |env| env["tested"] = "yes" }
|
174
|
+
end
|
175
|
+
end
|
176
|
+
RUBY
|
177
|
+
|
178
|
+
write "config/routes.rb", <<~RUBY
|
179
|
+
require "hanami/router"
|
180
|
+
|
181
|
+
module TestApp
|
182
|
+
class Routes < Hanami::Routes
|
183
|
+
define do
|
184
|
+
slice :main, at: "/" do
|
185
|
+
root to: "home.index"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
RUBY
|
191
|
+
|
192
|
+
write "slices/main/actions/home/index.rb", <<~RUBY
|
193
|
+
require "hanami/action"
|
194
|
+
|
195
|
+
module Main
|
196
|
+
module Actions
|
197
|
+
module Home
|
198
|
+
class Index < Hanami::Action
|
199
|
+
def handle(req, res)
|
200
|
+
res.body = req.env["tested"]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
RUBY
|
207
|
+
|
208
|
+
require "hanami/boot"
|
209
|
+
|
210
|
+
get "/"
|
211
|
+
|
212
|
+
expect(last_response).to be_successful
|
213
|
+
expect(last_response.body).to eql("yes")
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
RSpec.describe "Running a Rack app for a non-booted app", :app_integration do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
let(:app) { Hanami.app }
|
9
|
+
|
10
|
+
it "lazy loads only the components required for any accessed routes" 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.logger.stream = File.new("/dev/null", "w")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
|
22
|
+
write "config/routes.rb", <<~RUBY
|
23
|
+
require "hanami/routes"
|
24
|
+
|
25
|
+
module TestApp
|
26
|
+
class Routes < Hanami::Routes
|
27
|
+
define do
|
28
|
+
slice :main, at: "/" do
|
29
|
+
root to: "home.show"
|
30
|
+
get "/articles", to: "articles.index"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
write "slices/main/lib/action.rb", <<~RUBY
|
38
|
+
# auto_register: false
|
39
|
+
|
40
|
+
require "hanami/action"
|
41
|
+
|
42
|
+
module Main
|
43
|
+
class Action < Hanami::Action
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
|
48
|
+
write "slices/main/lib/article_repo.rb", <<~RUBY
|
49
|
+
module Main
|
50
|
+
class ArticleRepo < Hanami::Action
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
|
55
|
+
write "slices/main/lib/greeter.rb", <<~RUBY
|
56
|
+
module Main
|
57
|
+
class Greeter
|
58
|
+
def greeting
|
59
|
+
"Hello world"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
|
65
|
+
write "slices/main/actions/home/show.rb", <<~RUBY
|
66
|
+
module Main
|
67
|
+
module Actions
|
68
|
+
module Home
|
69
|
+
class Show < Main::Action
|
70
|
+
include Deps["greeter"]
|
71
|
+
|
72
|
+
def handle(req, res)
|
73
|
+
res.body = greeter.greeting
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
RUBY
|
80
|
+
|
81
|
+
write "slices/main/actions/articles/index.rb", <<~RUBY
|
82
|
+
module Main
|
83
|
+
module Actions
|
84
|
+
module Articles
|
85
|
+
class Index < Main::Action
|
86
|
+
include Deps["article_repo"]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
RUBY
|
92
|
+
|
93
|
+
require "hanami/prepare"
|
94
|
+
|
95
|
+
get "/"
|
96
|
+
|
97
|
+
expect(last_response.status).to eq 200
|
98
|
+
expect(last_response.body).to eq "Hello world"
|
99
|
+
|
100
|
+
expect(Hanami.app).not_to be_booted
|
101
|
+
expect(Main::Slice.keys).to include(*%w[actions.home.show greeter])
|
102
|
+
expect(Main::Slice.keys).not_to include(*%w[actions.articles.index article_repo])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|