hanami 2.0.0.beta2 → 2.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -1
- data/hanami.gemspec +5 -5
- data/lib/hanami/app.rb +4 -4
- data/lib/hanami/assets/{app_configuration.rb → app_config.rb} +10 -10
- data/lib/hanami/assets/{configuration.rb → config.rb} +4 -4
- data/lib/hanami/{configuration → config}/actions/content_security_policy.rb +2 -2
- data/lib/hanami/{configuration → config}/actions/cookies.rb +6 -5
- data/lib/hanami/{configuration → config}/actions/sessions.rb +2 -2
- data/lib/hanami/{configuration → config}/actions.rb +11 -12
- data/lib/hanami/{configuration → config}/logger.rb +2 -2
- data/lib/hanami/config/null_config.rb +14 -0
- data/lib/hanami/{configuration → config}/router.rb +8 -8
- data/lib/hanami/{configuration → config}/sessions.rb +2 -2
- data/lib/hanami/{configuration → config}/views.rb +10 -10
- data/lib/hanami/{configuration.rb → config.rb} +30 -30
- data/lib/hanami/errors.rb +3 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/providers/inflector.rb +0 -2
- data/lib/hanami/providers/logger.rb +1 -3
- data/lib/hanami/providers/rack.rb +0 -2
- data/lib/hanami/providers/routes.rb +0 -2
- data/lib/hanami/routes.rb +48 -21
- data/lib/hanami/settings/env_store.rb +3 -3
- data/lib/hanami/settings.rb +87 -5
- data/lib/hanami/slice/routing/middleware/stack.rb +45 -1
- data/lib/hanami/slice.rb +52 -37
- data/lib/hanami/slice_configurable.rb +1 -1
- data/lib/hanami/slice_registrar.rb +6 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami.rb +0 -1
- data/spec/{new_integration → integration}/action/cookies_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/csrf_protection_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/routes_spec.rb +3 -5
- data/spec/{new_integration → integration}/action/sessions_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_integration_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering/automatic_rendering_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering/paired_view_inference_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_app_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_lib_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_slice_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/application_routes_helper_spec.rb +1 -3
- data/spec/{new_integration → integration}/container/auto_injection_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/auto_registration_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/autoloader_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/imports_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/prepare_container_spec.rb +2 -0
- data/spec/{new_integration → integration}/container/shutdown_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/standard_bootable_components_spec.rb +0 -0
- data/spec/{new_integration → integration}/dotenv_loading_spec.rb +0 -0
- data/spec/integration/rack_app/body_parser_spec.rb +108 -0
- data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +37 -15
- data/spec/{new_integration → integration}/rack_app/non_booted_rack_app_spec.rb +3 -5
- data/spec/{new_integration → integration}/rack_app/rack_app_spec.rb +28 -48
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +82 -0
- data/spec/integration/settings/access_to_constants_spec.rb +46 -0
- data/spec/{new_integration → integration}/settings/loading_from_env_spec.rb +0 -0
- data/spec/{new_integration → integration}/settings/settings_component_loading_spec.rb +0 -0
- data/spec/{new_integration/slices/slice_settings_spec.rb → integration/settings/slice_registration_spec.rb} +5 -1
- data/spec/{new_integration → integration}/settings/using_types_spec.rb +4 -11
- data/spec/{new_integration → integration}/setup_spec.rb +20 -0
- data/spec/{new_integration → integration}/slices/external_slice_spec.rb +2 -4
- data/spec/{new_integration → integration}/slices/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/slices/slice_loading_spec.rb +0 -0
- data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
- data/spec/{new_integration → integration}/slices_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/assets_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/inflector_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/request_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/routes_spec.rb +1 -3
- data/spec/{new_integration → integration}/view/context/settings_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/inflector_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/part_namespace_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/path_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/template_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/views_spec.rb +0 -0
- data/spec/support/app_integration.rb +18 -15
- data/spec/unit/hanami/{configuration → config}/actions/content_security_policy_spec.rb +10 -10
- data/spec/unit/hanami/{configuration → config}/actions/cookies_spec.rb +6 -6
- data/spec/unit/hanami/{configuration → config}/actions/csrf_protection_spec.rb +12 -12
- data/spec/unit/hanami/config/actions/default_values_spec.rb +54 -0
- data/spec/unit/hanami/{configuration → config}/actions/sessions_spec.rb +5 -5
- data/spec/unit/hanami/{configuration → config}/actions_spec.rb +13 -25
- data/spec/unit/hanami/{configuration → config}/base_url_spec.rb +2 -2
- data/spec/unit/hanami/{configuration → config}/inflector_spec.rb +2 -2
- data/spec/unit/hanami/{configuration → config}/logger_spec.rb +4 -4
- data/spec/unit/hanami/config/router_spec.rb +44 -0
- data/spec/unit/hanami/{configuration → config}/slices_spec.rb +2 -2
- data/spec/unit/hanami/{configuration → config}/views_spec.rb +15 -27
- data/spec/unit/hanami/{configuration_spec.rb → config_spec.rb} +3 -3
- data/spec/unit/hanami/settings_spec.rb +65 -10
- data/spec/unit/hanami/slice_configurable_spec.rb +21 -2
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +162 -294
- data/lib/hanami/configuration/null_configuration.rb +0 -14
- data/lib/hanami/providers/settings.rb +0 -98
- data/lib/hanami/server.rb +0 -29
- data/spec/integration/application_middleware_stack_spec.rb +0 -84
- data/spec/integration/assets/cdn_spec.rb +0 -48
- data/spec/integration/assets/fingerprint_spec.rb +0 -42
- data/spec/integration/assets/helpers_spec.rb +0 -50
- data/spec/integration/assets/serve_spec.rb +0 -70
- data/spec/integration/assets/subresource_integrity_spec.rb +0 -54
- data/spec/integration/body_parsers_spec.rb +0 -50
- data/spec/integration/cli/assets/precompile_spec.rb +0 -147
- data/spec/integration/cli/assets_spec.rb +0 -14
- data/spec/integration/cli/console_spec.rb +0 -105
- data/spec/integration/cli/db/apply_spec.rb +0 -74
- data/spec/integration/cli/db/console_spec.rb +0 -40
- data/spec/integration/cli/db/create_spec.rb +0 -50
- data/spec/integration/cli/db/drop_spec.rb +0 -54
- data/spec/integration/cli/db/migrate_spec.rb +0 -108
- data/spec/integration/cli/db/prepare_spec.rb +0 -36
- data/spec/integration/cli/db/rollback_spec.rb +0 -96
- data/spec/integration/cli/db/version_spec.rb +0 -38
- data/spec/integration/cli/db_spec.rb +0 -21
- data/spec/integration/cli/destroy/action_spec.rb +0 -143
- data/spec/integration/cli/destroy/app_spec.rb +0 -118
- data/spec/integration/cli/destroy/mailer_spec.rb +0 -74
- data/spec/integration/cli/destroy/migration_spec.rb +0 -70
- data/spec/integration/cli/destroy/model_spec.rb +0 -113
- data/spec/integration/cli/destroy_spec.rb +0 -18
- data/spec/integration/cli/generate/action_spec.rb +0 -469
- data/spec/integration/cli/generate/app_spec.rb +0 -215
- data/spec/integration/cli/generate/mailer_spec.rb +0 -189
- data/spec/integration/cli/generate/migration_spec.rb +0 -72
- data/spec/integration/cli/generate/model_spec.rb +0 -290
- data/spec/integration/cli/generate/secret_spec.rb +0 -56
- data/spec/integration/cli/generate_spec.rb +0 -19
- data/spec/integration/cli/new/database_spec.rb +0 -235
- data/spec/integration/cli/new/hanami_head_spec.rb +0 -27
- data/spec/integration/cli/new/template_spec.rb +0 -118
- data/spec/integration/cli/new/test_spec.rb +0 -274
- data/spec/integration/cli/new_spec.rb +0 -970
- data/spec/integration/cli/plugins_spec.rb +0 -39
- data/spec/integration/cli/routes_spec.rb +0 -49
- data/spec/integration/cli/server_spec.rb +0 -626
- data/spec/integration/cli/version_spec.rb +0 -85
- data/spec/integration/early_hints_spec.rb +0 -35
- data/spec/integration/handle_exceptions_spec.rb +0 -244
- data/spec/integration/head_spec.rb +0 -89
- data/spec/integration/http_headers_spec.rb +0 -29
- data/spec/integration/mailer_spec.rb +0 -32
- data/spec/integration/middleware_spec.rb +0 -81
- data/spec/integration/mount_applications_spec.rb +0 -88
- data/spec/integration/project_initializers_spec.rb +0 -40
- data/spec/integration/rackup_spec.rb +0 -35
- data/spec/integration/rake/with_minitest_spec.rb +0 -67
- data/spec/integration/rake/with_rspec_spec.rb +0 -69
- data/spec/integration/routing_helpers_spec.rb +0 -61
- data/spec/integration/security/content_security_policy_spec.rb +0 -46
- data/spec/integration/security/csrf_protection_spec.rb +0 -42
- data/spec/integration/security/force_ssl_spec.rb +0 -29
- data/spec/integration/security/x_content_type_options_spec.rb +0 -46
- data/spec/integration/security/x_frame_options_spec.rb +0 -46
- data/spec/integration/security/x_xss_protection_spec.rb +0 -46
- data/spec/integration/send_file_spec.rb +0 -51
- data/spec/integration/sessions_spec.rb +0 -247
- data/spec/integration/static_middleware_spec.rb +0 -21
- data/spec/integration/streaming_spec.rb +0 -41
- data/spec/integration/unsafe_send_file_spec.rb +0 -52
- data/spec/new_integration/settings/access_to_constants_spec.rb +0 -169
- data/spec/support/fixtures/hanami-plugin/Gemfile +0 -8
- data/spec/support/fixtures/hanami-plugin/README.md +0 -35
- data/spec/support/fixtures/hanami-plugin/Rakefile +0 -4
- data/spec/support/fixtures/hanami-plugin/bin/console +0 -15
- data/spec/support/fixtures/hanami-plugin/bin/setup +0 -8
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +0 -28
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +0 -19
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +0 -7
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +0 -8
- data/spec/unit/hanami/configuration/actions/default_values_spec.rb +0 -52
- data/spec/unit/hanami/routes_spec.rb +0 -25
@@ -0,0 +1,108 @@
|
|
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
|
+
specify "Setting middlewares in the config" do
|
15
|
+
write "config/app.rb", <<~RUBY
|
16
|
+
require "hanami"
|
17
|
+
|
18
|
+
module TestApp
|
19
|
+
class App < Hanami::App
|
20
|
+
config.middleware.use :body_parser, :json
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
|
25
|
+
write "config/routes.rb", <<~RUBY
|
26
|
+
module TestApp
|
27
|
+
class Routes < Hanami::Routes
|
28
|
+
post "/users", to: "users.create"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
write "app/actions/users/create.rb", <<~RUBY
|
34
|
+
module TestApp
|
35
|
+
module Actions
|
36
|
+
module Users
|
37
|
+
class Create < Hanami::Action
|
38
|
+
accept :json
|
39
|
+
|
40
|
+
def handle(req, res)
|
41
|
+
res.body = req.params[:users].join("-")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
RUBY
|
48
|
+
|
49
|
+
require "hanami/boot"
|
50
|
+
|
51
|
+
post(
|
52
|
+
"/users",
|
53
|
+
JSON.dump("users" => %w[jane john jade joe]),
|
54
|
+
"CONTENT_TYPE" => "application/json"
|
55
|
+
)
|
56
|
+
|
57
|
+
expect(last_response).to be_successful
|
58
|
+
expect(last_response.body).to eql("jane-john-jade-joe")
|
59
|
+
end
|
60
|
+
|
61
|
+
specify "Configuring custom mime-types and body parser" do
|
62
|
+
write "config/app.rb", <<~RUBY
|
63
|
+
require "hanami"
|
64
|
+
|
65
|
+
module TestApp
|
66
|
+
class App < Hanami::App
|
67
|
+
config.actions.formats["application/json+scim"] = :json
|
68
|
+
config.middleware.use :body_parser, [json: "application/json+scim"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
|
73
|
+
write "config/routes.rb", <<~RUBY
|
74
|
+
module TestApp
|
75
|
+
class Routes < Hanami::Routes
|
76
|
+
post "/users", to: "users.create"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
RUBY
|
80
|
+
|
81
|
+
write "app/actions/users/create.rb", <<~RUBY
|
82
|
+
module TestApp
|
83
|
+
module Actions
|
84
|
+
module Users
|
85
|
+
class Create < Hanami::Action
|
86
|
+
accept :json
|
87
|
+
|
88
|
+
def handle(req, res)
|
89
|
+
res.body = req.params[:users].join("-")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
RUBY
|
96
|
+
|
97
|
+
require "hanami/boot"
|
98
|
+
|
99
|
+
post(
|
100
|
+
"/users",
|
101
|
+
JSON.dump("users" => %w[jane john jade joe]),
|
102
|
+
"CONTENT_TYPE" => "application/json+scim"
|
103
|
+
)
|
104
|
+
|
105
|
+
expect(last_response).to be_successful
|
106
|
+
expect(last_response.body).to eql("jane-john-jade-joe")
|
107
|
+
end
|
108
|
+
end
|
@@ -64,10 +64,8 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
64
64
|
|
65
65
|
module TestApp
|
66
66
|
class Routes < Hanami::Routes
|
67
|
-
|
68
|
-
|
69
|
-
root to: "home.index"
|
70
|
-
end
|
67
|
+
slice :main, at: "/" do
|
68
|
+
root to: "home.index"
|
71
69
|
end
|
72
70
|
end
|
73
71
|
end
|
@@ -113,14 +111,12 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
113
111
|
|
114
112
|
module TestApp
|
115
113
|
class Routes < Hanami::Routes
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
use TestApp::Middlewares::AppendTwo, after: TestApp::Middlewares::AppendOne
|
114
|
+
slice :main, at: "/" do
|
115
|
+
use TestApp::Middlewares::AppendOne
|
116
|
+
use TestApp::Middlewares::Prepare, before: TestApp::Middlewares::AppendOne
|
117
|
+
use TestApp::Middlewares::AppendTwo, after: TestApp::Middlewares::AppendOne
|
121
118
|
|
122
|
-
|
123
|
-
end
|
119
|
+
root to: "home.index"
|
124
120
|
end
|
125
121
|
end
|
126
122
|
end
|
@@ -180,10 +176,8 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
180
176
|
|
181
177
|
module TestApp
|
182
178
|
class Routes < Hanami::Routes
|
183
|
-
|
184
|
-
|
185
|
-
root to: "home.index"
|
186
|
-
end
|
179
|
+
slice :main, at: "/" do
|
180
|
+
root to: "home.index"
|
187
181
|
end
|
188
182
|
end
|
189
183
|
end
|
@@ -212,4 +206,32 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
212
206
|
expect(last_response).to be_successful
|
213
207
|
expect(last_response.body).to eql("yes")
|
214
208
|
end
|
209
|
+
|
210
|
+
context "Using module as a middleware" do
|
211
|
+
it "sets the module as the middleware" do
|
212
|
+
mod = Module.new
|
213
|
+
app = Class.new(Hanami::App) { config.middleware.use(mod) }
|
214
|
+
|
215
|
+
expect(app.config.middleware.stack["/"][0]).to include(mod)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context "Setting an unsupported middleware" do
|
220
|
+
it "raises meaningful error when an unsupported middleware spec was passed" do
|
221
|
+
expect {
|
222
|
+
Class.new(Hanami::App) do
|
223
|
+
config.middleware.use("oops")
|
224
|
+
end
|
225
|
+
}.to raise_error(Hanami::UnsupportedMiddlewareSpecError)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "raises meaningful error when corresponding file failed to load" do
|
229
|
+
expect {
|
230
|
+
Class.new(Hanami::App) do
|
231
|
+
config.middleware.namespaces.delete(Hanami::Middleware)
|
232
|
+
config.middleware.use(:body_parser)
|
233
|
+
end
|
234
|
+
}.to raise_error(Hanami::UnsupportedMiddlewareSpecError)
|
235
|
+
end
|
236
|
+
end
|
215
237
|
end
|
@@ -24,11 +24,9 @@ RSpec.describe "Running a Rack app for a non-booted app", :app_integration do
|
|
24
24
|
|
25
25
|
module TestApp
|
26
26
|
class Routes < Hanami::Routes
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
get "/articles", to: "articles.index"
|
31
|
-
end
|
27
|
+
slice :main, at: "/" do
|
28
|
+
root to: "home.show"
|
29
|
+
get "/articles", to: "articles.index"
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -21,9 +21,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
21
21
|
write "config/routes.rb", <<~RUBY
|
22
22
|
module TestApp
|
23
23
|
class Routes < Hanami::Routes
|
24
|
-
|
25
|
-
root to: ->(env) { [200, {}, ["OK"]] }
|
26
|
-
end
|
24
|
+
root to: ->(env) { [200, {}, ["OK"]] }
|
27
25
|
end
|
28
26
|
end
|
29
27
|
RUBY
|
@@ -51,8 +49,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
51
49
|
write "config/routes.rb", <<~RUBY
|
52
50
|
module TestApp
|
53
51
|
class Routes < Hanami::Routes
|
54
|
-
|
55
|
-
end
|
52
|
+
root to: ->(env) { [200, {}, ["OK"]] }
|
56
53
|
end
|
57
54
|
end
|
58
55
|
RUBY
|
@@ -65,7 +62,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
65
62
|
|
66
63
|
logs = -> { Pathname(dir).join("test.log").realpath.read }
|
67
64
|
|
68
|
-
expect(logs.()).to match %r{GET
|
65
|
+
expect(logs.()).to match %r{GET 200 \d+ms 127.0.0.1 /}
|
69
66
|
end
|
70
67
|
end
|
71
68
|
|
@@ -89,8 +86,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
89
86
|
write "slices/main/config/routes.rb", <<~RUBY
|
90
87
|
module Main
|
91
88
|
class Routes < Hanami::Routes
|
92
|
-
|
93
|
-
end
|
89
|
+
root to: ->(env) { [200, {}, ["OK"]] }
|
94
90
|
end
|
95
91
|
end
|
96
92
|
RUBY
|
@@ -101,7 +97,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
101
97
|
|
102
98
|
logs = -> { Pathname(dir).join("test.log").realpath.read }
|
103
99
|
|
104
|
-
expect(logs.()).to match %r{GET
|
100
|
+
expect(logs.()).to match %r{GET 200 \d+ms 127.0.0.1 /}
|
105
101
|
end
|
106
102
|
end
|
107
103
|
end
|
@@ -121,20 +117,18 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
121
117
|
write "config/routes.rb", <<~RUBY
|
122
118
|
module TestApp
|
123
119
|
class Routes < Hanami::Routes
|
124
|
-
|
125
|
-
get "/health", to: "health.show"
|
120
|
+
get "/health", to: "health.show"
|
126
121
|
|
127
|
-
|
128
|
-
|
129
|
-
|
122
|
+
get "/inline" do
|
123
|
+
"Inline"
|
124
|
+
end
|
130
125
|
|
131
|
-
|
132
|
-
|
133
|
-
|
126
|
+
slice :main, at: "/" do
|
127
|
+
root to: "home.index"
|
128
|
+
end
|
134
129
|
|
135
|
-
|
136
|
-
|
137
|
-
end
|
130
|
+
slice :admin, at: "/admin" do
|
131
|
+
get "/dashboard", to: "dashboard.show"
|
138
132
|
end
|
139
133
|
end
|
140
134
|
end
|
@@ -228,12 +222,10 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
228
222
|
write "config/routes.rb", <<~RUBY
|
229
223
|
module TestApp
|
230
224
|
class Routes < Hanami::Routes
|
231
|
-
|
232
|
-
root to: "home.index"
|
225
|
+
root to: "home.index"
|
233
226
|
|
234
|
-
|
235
|
-
|
236
|
-
end
|
227
|
+
slice :main, at: "/" do
|
228
|
+
root to: "home.index"
|
237
229
|
end
|
238
230
|
end
|
239
231
|
end
|
@@ -295,12 +287,10 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
295
287
|
write "config/routes.rb", <<~RUBY
|
296
288
|
module TestApp
|
297
289
|
class Routes < Hanami::Routes
|
298
|
-
|
299
|
-
get "/feedbacks", to: "feedbacks.index"
|
290
|
+
get "/feedbacks", to: "feedbacks.index"
|
300
291
|
|
301
|
-
|
302
|
-
|
303
|
-
end
|
292
|
+
slice :api, at: "/api" do
|
293
|
+
get "/people", to: "people.index"
|
304
294
|
end
|
305
295
|
end
|
306
296
|
end
|
@@ -374,9 +364,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
374
364
|
write "config/routes.rb", <<~RUBY
|
375
365
|
module TestApp
|
376
366
|
class Routes < Hanami::Routes
|
377
|
-
|
378
|
-
get "/missing", to: "missing.action"
|
379
|
-
end
|
367
|
+
get "/missing", to: "missing.action"
|
380
368
|
end
|
381
369
|
end
|
382
370
|
RUBY
|
@@ -405,10 +393,8 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
405
393
|
write "config/routes.rb", <<~RUBY
|
406
394
|
module TestApp
|
407
395
|
class Routes < Hanami::Routes
|
408
|
-
|
409
|
-
|
410
|
-
get "/missing", to: "missing.action"
|
411
|
-
end
|
396
|
+
slice :admin, at: "/admin" do
|
397
|
+
get "/missing", to: "missing.action"
|
412
398
|
end
|
413
399
|
end
|
414
400
|
end
|
@@ -437,9 +423,7 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
437
423
|
write "config/routes.rb", <<~RUBY
|
438
424
|
module TestApp
|
439
425
|
class Routes < Hanami::Routes
|
440
|
-
|
441
|
-
get "/missing", to: "missing.action"
|
442
|
-
end
|
426
|
+
get "/missing", to: "missing.action"
|
443
427
|
end
|
444
428
|
end
|
445
429
|
RUBY
|
@@ -470,10 +454,8 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
470
454
|
write "config/routes.rb", <<~RUBY
|
471
455
|
module TestApp
|
472
456
|
class Routes < Hanami::Routes
|
473
|
-
|
474
|
-
|
475
|
-
get "/missing", to: "missing.action"
|
476
|
-
end
|
457
|
+
slice :admin, at: "/admin" do
|
458
|
+
get "/missing", to: "missing.action"
|
477
459
|
end
|
478
460
|
end
|
479
461
|
end
|
@@ -504,10 +486,8 @@ RSpec.describe "Hanami web app", :app_integration do
|
|
504
486
|
write "config/routes.rb", <<~RUBY
|
505
487
|
module TestApp
|
506
488
|
class Routes < Hanami::Routes
|
507
|
-
|
508
|
-
|
509
|
-
get "/bar", to: "bar.index"
|
510
|
-
end
|
489
|
+
slice :foo, at: "/foo" do
|
490
|
+
get "/bar", to: "bar.index"
|
511
491
|
end
|
512
492
|
end
|
513
493
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Settings / Access within slice class bodies", :app_integration do
|
4
|
+
before do
|
5
|
+
@env = ENV.to_h
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
ENV.replace(@env)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "app class" do
|
13
|
+
it "provides access to the settings inside the class body" do
|
14
|
+
with_directory(make_tmp_directory) do
|
15
|
+
write "config/app.rb", <<~'RUBY'
|
16
|
+
require "hanami"
|
17
|
+
|
18
|
+
module TestApp
|
19
|
+
class App < Hanami::App
|
20
|
+
@some_flag = settings.some_flag
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
|
25
|
+
write ".env", <<~'TEXT'
|
26
|
+
SOME_FLAG=true
|
27
|
+
TEXT
|
28
|
+
|
29
|
+
write "config/settings.rb", <<~'RUBY'
|
30
|
+
module TestApp
|
31
|
+
class Settings < Hanami::Settings
|
32
|
+
setting :some_flag
|
33
|
+
end
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
require "hanami/setup"
|
38
|
+
|
39
|
+
expect(Hanami.app.instance_variable_get(:@some_flag)).to eq "true"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "slice class" do
|
45
|
+
it "provides access to the settings inside the class body" do
|
46
|
+
with_directory(make_tmp_directory) do
|
47
|
+
write "config/app.rb", <<~'RUBY'
|
48
|
+
require "hanami"
|
49
|
+
|
50
|
+
module TestApp
|
51
|
+
class App < Hanami::App
|
52
|
+
end
|
53
|
+
end
|
54
|
+
RUBY
|
55
|
+
|
56
|
+
write "config/slices/main.rb", <<~'RUBY'
|
57
|
+
module Main
|
58
|
+
class Slice < Hanami::Slice
|
59
|
+
@some_flag = settings.some_flag
|
60
|
+
end
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
|
64
|
+
write ".env", <<~'TEXT'
|
65
|
+
SOME_FLAG=true
|
66
|
+
TEXT
|
67
|
+
|
68
|
+
write "slices/main/config/settings.rb", <<~'RUBY'
|
69
|
+
module Main
|
70
|
+
class Settings < Hanami::Settings
|
71
|
+
setting :some_flag
|
72
|
+
end
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
|
76
|
+
require "hanami/prepare"
|
77
|
+
|
78
|
+
expect(Main::Slice.instance_variable_get(:@some_flag)).to eq "true"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Settings / Access to constants", :app_integration do
|
4
|
+
before do
|
5
|
+
@env = ENV.to_h
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
ENV.replace(@env)
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "Settings can not access autoloadable constants" do
|
13
|
+
with_directory(make_tmp_directory) do
|
14
|
+
write "config/app.rb", <<~'RUBY'
|
15
|
+
require "hanami"
|
16
|
+
|
17
|
+
module TestApp
|
18
|
+
class App < Hanami::App
|
19
|
+
end
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
|
23
|
+
write "config/settings.rb", <<~'RUBY'
|
24
|
+
module TestApp
|
25
|
+
class Settings < Hanami::Settings
|
26
|
+
setting :some_flag, constructor: TestApp::Types::Params::Bool
|
27
|
+
end
|
28
|
+
end
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
write "app/types.rb", <<~'RUBY'
|
32
|
+
# auto_register: false
|
33
|
+
|
34
|
+
require "dry/types"
|
35
|
+
|
36
|
+
module TestApp
|
37
|
+
Types = Dry.Types()
|
38
|
+
end
|
39
|
+
RUBY
|
40
|
+
|
41
|
+
require "hanami/setup"
|
42
|
+
|
43
|
+
expect { Hanami.app.settings }.to raise_error(NameError, /TestApp::Types/)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
File without changes
|
File without changes
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Settings / Slice registration", :app_integration do
|
2
4
|
specify "Settings are registered for each slice with a settings file" do
|
3
5
|
with_tmp_directory(Dir.mktmpdir) do
|
4
6
|
write "config/app.rb", <<~RUBY
|
@@ -10,6 +12,8 @@ RSpec.describe "Slices / Slice settings", :app_integration do
|
|
10
12
|
end
|
11
13
|
RUBY
|
12
14
|
|
15
|
+
# n.b. no app-level settings file
|
16
|
+
|
13
17
|
# The main slice has settings
|
14
18
|
write "slices/main/config/settings.rb", <<~RUBY
|
15
19
|
# frozen_string_literal: true
|
@@ -11,7 +11,7 @@ RSpec.describe "Settings / Using types", :app_integration do
|
|
11
11
|
ENV.replace(@env)
|
12
12
|
end
|
13
13
|
|
14
|
-
specify "
|
14
|
+
specify "types from a provided types module can be used as setting constructors to coerce values" do
|
15
15
|
with_tmp_directory(Dir.mktmpdir) do
|
16
16
|
write "config/app.rb", <<~RUBY
|
17
17
|
require "hanami"
|
@@ -23,14 +23,12 @@ RSpec.describe "Settings / Using types", :app_integration do
|
|
23
23
|
RUBY
|
24
24
|
|
25
25
|
write "config/settings.rb", <<~RUBY
|
26
|
-
require "dry/types"
|
27
|
-
|
28
26
|
module TestApp
|
29
27
|
class Settings < Hanami::Settings
|
30
|
-
|
28
|
+
Bool = Types::Params::Bool
|
31
29
|
|
32
30
|
setting :numeric, constructor: Types::Params::Integer
|
33
|
-
setting :flag, constructor:
|
31
|
+
setting :flag, constructor: Bool
|
34
32
|
end
|
35
33
|
end
|
36
34
|
RUBY
|
@@ -45,7 +43,7 @@ RSpec.describe "Settings / Using types", :app_integration do
|
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
specify "errors raised from setting constructors are collected and re-raised in aggregate" do
|
46
|
+
specify "errors raised from setting constructors are collected and re-raised in aggregate, and will prevent the app from booting" do
|
49
47
|
with_tmp_directory(Dir.mktmpdir) do
|
50
48
|
write "config/app.rb", <<~RUBY
|
51
49
|
require "hanami"
|
@@ -57,12 +55,8 @@ RSpec.describe "Settings / Using types", :app_integration do
|
|
57
55
|
RUBY
|
58
56
|
|
59
57
|
write "config/settings.rb", <<~RUBY
|
60
|
-
require "dry/types"
|
61
|
-
|
62
58
|
module TestApp
|
63
59
|
class Settings < Hanami::Settings
|
64
|
-
Types = Dry.Types()
|
65
|
-
|
66
60
|
setting :numeric, constructor: Types::Params::Integer
|
67
61
|
setting :flag, constructor: Types::Params::Bool
|
68
62
|
end
|
@@ -83,5 +77,4 @@ RSpec.describe "Settings / Using types", :app_integration do
|
|
83
77
|
)
|
84
78
|
end
|
85
79
|
end
|
86
|
-
|
87
80
|
end
|
@@ -55,6 +55,26 @@ RSpec.describe "Hanami setup", :app_integration do
|
|
55
55
|
|
56
56
|
expect { setup }.not_to raise_error
|
57
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
|
58
78
|
end
|
59
79
|
|
60
80
|
describe "using hanami/setup require" do
|
@@ -27,10 +27,8 @@ RSpec.describe "Slices / External slices", :app_integration do
|
|
27
27
|
|
28
28
|
module TestApp
|
29
29
|
class Routes < Hanami::Routes
|
30
|
-
|
31
|
-
|
32
|
-
root to: "test_action"
|
33
|
-
end
|
30
|
+
slice :external, at: "/" do
|
31
|
+
root to: "test_action"
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
File without changes
|
File without changes
|
@@ -44,9 +44,7 @@ RSpec.describe "Slices / Slice routing", :app_integration do
|
|
44
44
|
|
45
45
|
module TestApp
|
46
46
|
class Routes < Hanami::Routes
|
47
|
-
|
48
|
-
get "home", to: "home.show", as: :home
|
49
|
-
end
|
47
|
+
get "home", to: "home.show", as: :home
|
50
48
|
end
|
51
49
|
end
|
52
50
|
RUBY
|
@@ -79,9 +77,7 @@ RSpec.describe "Slices / Slice routing", :app_integration do
|
|
79
77
|
|
80
78
|
module Main
|
81
79
|
class Routes < Hanami::Routes
|
82
|
-
|
83
|
-
get "home", to: "home.show", as: :home
|
84
|
-
end
|
80
|
+
get "home", to: "home.show", as: :home
|
85
81
|
end
|
86
82
|
end
|
87
83
|
RUBY
|
@@ -130,11 +126,9 @@ RSpec.describe "Slices / Slice routing", :app_integration do
|
|
130
126
|
write "config/routes.rb", <<~'RUBY'
|
131
127
|
module TestApp
|
132
128
|
class Routes < Hanami::Routes
|
133
|
-
|
134
|
-
root to: "home.show"
|
129
|
+
root to: "home.show"
|
135
130
|
|
136
|
-
|
137
|
-
end
|
131
|
+
slice :main, at: "/main"
|
138
132
|
end
|
139
133
|
end
|
140
134
|
RUBY
|
@@ -158,9 +152,7 @@ RSpec.describe "Slices / Slice routing", :app_integration do
|
|
158
152
|
write "slices/main/config/routes.rb", <<~'RUBY'
|
159
153
|
module Main
|
160
154
|
class Routes < Hanami::Routes
|
161
|
-
|
162
|
-
root to: "home.show"
|
163
|
-
end
|
155
|
+
root to: "home.show"
|
164
156
|
end
|
165
157
|
end
|
166
158
|
RUBY
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|