hanami 2.0.0.beta1.1 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -0
- data/hanami.gemspec +1 -2
- data/lib/hanami/app.rb +76 -16
- data/lib/hanami/assets/{application_configuration.rb → app_configuration.rb} +1 -1
- data/lib/hanami/configuration/null_configuration.rb +2 -2
- data/lib/hanami/configuration.rb +36 -36
- data/lib/hanami/extensions/action/slice_configured_action.rb +44 -1
- data/lib/hanami/extensions/view/slice_configured_view.rb +47 -7
- data/lib/hanami/providers/rack.rb +2 -0
- data/lib/hanami/providers/settings.rb +81 -6
- data/lib/hanami/routes.rb +48 -21
- data/lib/hanami/settings/env_store.rb +32 -0
- data/lib/hanami/settings.rb +8 -12
- data/lib/hanami/setup.rb +1 -6
- data/lib/hanami/slice/routing/middleware/stack.rb +26 -5
- data/lib/hanami/slice.rb +38 -45
- data/lib/hanami/slice_configurable.rb +14 -1
- data/lib/hanami/slice_registrar.rb +65 -5
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami.rb +53 -2
- 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/integration/action/slice_configuration_spec.rb +287 -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/integration/code_loading/loading_from_lib_spec.rb +208 -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 +0 -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/integration/dotenv_loading_spec.rb +137 -0
- data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +9 -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_to_constants_spec.rb +169 -0
- data/spec/integration/settings/loading_from_env_spec.rb +187 -0
- data/spec/integration/settings/settings_component_loading_spec.rb +113 -0
- data/spec/integration/settings/using_types_spec.rb +87 -0
- data/spec/integration/setup_spec.rb +165 -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/integration/slices/slice_loading_spec.rb +171 -0
- data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
- data/spec/{new_integration → integration}/slices/slice_settings_spec.rb +0 -0
- 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 +5 -1
- 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/integration/view/slice_configuration_spec.rb +289 -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 +4 -5
- data/spec/unit/hanami/configuration/actions_spec.rb +4 -15
- data/spec/unit/hanami/configuration/router_spec.rb +45 -0
- data/spec/unit/hanami/configuration/slices_spec.rb +34 -0
- data/spec/unit/hanami/configuration/views_spec.rb +4 -15
- data/spec/unit/hanami/settings/env_store_spec.rb +52 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +2 -2
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +105 -250
- data/lib/hanami/server.rb +0 -29
- data/lib/hanami/settings/dotenv_store.rb +0 -58
- 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/action/configuration_spec.rb +0 -26
- data/spec/new_integration/settings_spec.rb +0 -115
- data/spec/new_integration/view/configuration_spec.rb +0 -49
- 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/routes_spec.rb +0 -25
- data/spec/unit/hanami/settings/dotenv_store_spec.rb +0 -119
@@ -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
|
@@ -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,169 @@
|
|
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
|
+
describe "Settings can access autoloadable constants" do
|
13
|
+
describe "settings for app" do
|
14
|
+
specify "constant defined in app directory" do
|
15
|
+
with_directory(make_tmp_directory) 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 ".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, constructor: Types::Params::Bool
|
33
|
+
end
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
write "app/types.rb", <<~'RUBY'
|
38
|
+
# auto_register: false
|
39
|
+
|
40
|
+
require "dry/types"
|
41
|
+
|
42
|
+
module TestApp
|
43
|
+
Types = Dry.Types()
|
44
|
+
end
|
45
|
+
RUBY
|
46
|
+
|
47
|
+
require "hanami/prepare"
|
48
|
+
|
49
|
+
expect(Hanami.app[:settings].some_flag).to be true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
specify "constant defined in root lib directory" do
|
54
|
+
with_directory(make_tmp_directory) do
|
55
|
+
write "config/app.rb", <<~'RUBY'
|
56
|
+
require "hanami"
|
57
|
+
|
58
|
+
module TestApp
|
59
|
+
class App < Hanami::App
|
60
|
+
end
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
|
64
|
+
write ".env", <<~'TEXT'
|
65
|
+
SOME_FLAG=true
|
66
|
+
TEXT
|
67
|
+
|
68
|
+
write "config/settings.rb", <<~'RUBY'
|
69
|
+
module TestApp
|
70
|
+
class Settings < Hanami::Settings
|
71
|
+
setting :some_flag, constructor: Types::Params::Bool
|
72
|
+
end
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
|
76
|
+
write "lib/test_app/types.rb", <<~'RUBY'
|
77
|
+
require "dry/types"
|
78
|
+
|
79
|
+
module TestApp
|
80
|
+
Types = Dry.Types()
|
81
|
+
end
|
82
|
+
RUBY
|
83
|
+
|
84
|
+
require "hanami/prepare"
|
85
|
+
|
86
|
+
expect(Hanami.app[:settings].some_flag).to be true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "settings for slice" do
|
92
|
+
specify "constant defined in slice directory" do
|
93
|
+
with_directory(make_tmp_directory) do
|
94
|
+
write "config/app.rb", <<~'RUBY'
|
95
|
+
require "hanami"
|
96
|
+
|
97
|
+
module TestApp
|
98
|
+
class App < Hanami::App
|
99
|
+
end
|
100
|
+
end
|
101
|
+
RUBY
|
102
|
+
|
103
|
+
write ".env", <<~'TEXT'
|
104
|
+
SOME_FLAG=true
|
105
|
+
TEXT
|
106
|
+
|
107
|
+
write "slices/main/config/settings.rb", <<~'RUBY'
|
108
|
+
module Main
|
109
|
+
class Settings < Hanami::Settings
|
110
|
+
setting :some_flag, constructor: Types::Params::Bool
|
111
|
+
end
|
112
|
+
end
|
113
|
+
RUBY
|
114
|
+
|
115
|
+
write "slices/main/types.rb", <<~'RUBY'
|
116
|
+
# auto_register: false
|
117
|
+
|
118
|
+
require "dry/types"
|
119
|
+
|
120
|
+
module Main
|
121
|
+
Types = Dry.Types()
|
122
|
+
end
|
123
|
+
RUBY
|
124
|
+
|
125
|
+
require "hanami/prepare"
|
126
|
+
|
127
|
+
expect(Main::Slice[:settings].some_flag).to be true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
specify "constant defined in root lib directory" do
|
132
|
+
with_directory(make_tmp_directory) do
|
133
|
+
write "config/app.rb", <<~'RUBY'
|
134
|
+
require "hanami"
|
135
|
+
|
136
|
+
module TestApp
|
137
|
+
class App < Hanami::App
|
138
|
+
end
|
139
|
+
end
|
140
|
+
RUBY
|
141
|
+
|
142
|
+
write ".env", <<~'TEXT'
|
143
|
+
SOME_FLAG=true
|
144
|
+
TEXT
|
145
|
+
|
146
|
+
write "slices/main/config/settings.rb", <<~'RUBY'
|
147
|
+
module Main
|
148
|
+
class Settings < Hanami::Settings
|
149
|
+
setting :some_flag, constructor: TestApp::Types::Params::Bool
|
150
|
+
end
|
151
|
+
end
|
152
|
+
RUBY
|
153
|
+
|
154
|
+
write "lib/test_app/types.rb", <<~'RUBY'
|
155
|
+
require "dry/types"
|
156
|
+
|
157
|
+
module TestApp
|
158
|
+
Types = Dry.Types()
|
159
|
+
end
|
160
|
+
RUBY
|
161
|
+
|
162
|
+
require "hanami/prepare"
|
163
|
+
|
164
|
+
expect(Main::Slice[:settings].some_flag).to be true
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,187 @@
|
|
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 are loaded from ENV" do
|
13
|
+
with_tmp_directory(Dir.mktmpdir) 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 :database_url
|
27
|
+
end
|
28
|
+
end
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
ENV["DATABASE_URL"] = "postgres://localhost/database"
|
32
|
+
|
33
|
+
require "hanami/prepare"
|
34
|
+
|
35
|
+
expect(Hanami.app["settings"].database_url).to eq "postgres://localhost/database"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "settings are loaded from .env files" do
|
40
|
+
context "hanami env is development" do
|
41
|
+
it "loads settings from .env.development.local, .env.local, .env.development and .env (in this order)" do
|
42
|
+
with_tmp_directory(Dir.mktmpdir) do
|
43
|
+
write "config/app.rb", <<~'RUBY'
|
44
|
+
require "hanami"
|
45
|
+
|
46
|
+
module TestApp
|
47
|
+
class App < Hanami::App
|
48
|
+
end
|
49
|
+
end
|
50
|
+
RUBY
|
51
|
+
|
52
|
+
write "config/settings.rb", <<~'RUBY'
|
53
|
+
module TestApp
|
54
|
+
class Settings < Hanami::Settings
|
55
|
+
setting :from_specific_env_local
|
56
|
+
setting :from_base_local
|
57
|
+
setting :from_specific_env
|
58
|
+
setting :from_base
|
59
|
+
end
|
60
|
+
end
|
61
|
+
RUBY
|
62
|
+
|
63
|
+
write ".env.development.local", <<~'TEXT'
|
64
|
+
FROM_SPECIFIC_ENV_LOCAL="from .env.development.local"
|
65
|
+
TEXT
|
66
|
+
|
67
|
+
write ".env.local", <<~'TEXT'
|
68
|
+
FROM_BASE_LOCAL="from .env.local"
|
69
|
+
|
70
|
+
FROM_SPECIFIC_ENV_LOCAL=nope
|
71
|
+
TEXT
|
72
|
+
|
73
|
+
write ".env.development", <<~'TEXT'
|
74
|
+
FROM_SPECIFIC_ENV="from .env.development"
|
75
|
+
|
76
|
+
FROM_SPECIFIC_ENV_LOCAL=nope
|
77
|
+
FROM_BASE_LOCAL=nope
|
78
|
+
TEXT
|
79
|
+
|
80
|
+
write ".env", <<~'TEXT'
|
81
|
+
FROM_BASE="from .env"
|
82
|
+
|
83
|
+
FROM_SPECIFIC_ENV_LOCAL=nope
|
84
|
+
FROM_BASE_LOCAL=nope
|
85
|
+
FROM_SPECIFIC_ENV=nope
|
86
|
+
TEXT
|
87
|
+
|
88
|
+
ENV["HANAMI_ENV"] = "development"
|
89
|
+
|
90
|
+
require "hanami/prepare"
|
91
|
+
|
92
|
+
expect(Hanami.app["settings"].from_specific_env_local).to eq "from .env.development.local"
|
93
|
+
expect(Hanami.app["settings"].from_base_local).to eq "from .env.local"
|
94
|
+
expect(Hanami.app["settings"].from_specific_env).to eq "from .env.development"
|
95
|
+
expect(Hanami.app["settings"].from_base).to eq "from .env"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "hanami env is test" do
|
100
|
+
it "loads settings from .env.development.local, .env.development and .env (in this order)" do
|
101
|
+
with_tmp_directory(Dir.mktmpdir) do
|
102
|
+
write "config/app.rb", <<~'RUBY'
|
103
|
+
require "hanami"
|
104
|
+
|
105
|
+
module TestApp
|
106
|
+
class App < Hanami::App
|
107
|
+
end
|
108
|
+
end
|
109
|
+
RUBY
|
110
|
+
|
111
|
+
write "config/settings.rb", <<~'RUBY'
|
112
|
+
module TestApp
|
113
|
+
class Settings < Hanami::Settings
|
114
|
+
setting :from_specific_env_local
|
115
|
+
setting :from_base_local
|
116
|
+
setting :from_specific_env
|
117
|
+
setting :from_base
|
118
|
+
end
|
119
|
+
end
|
120
|
+
RUBY
|
121
|
+
|
122
|
+
write ".env.test.local", <<~'TEXT'
|
123
|
+
FROM_SPECIFIC_ENV_LOCAL="from .env.test.local"
|
124
|
+
TEXT
|
125
|
+
|
126
|
+
write ".env.local", <<~'TEXT'
|
127
|
+
FROM_BASE_LOCAL="from .env.local"
|
128
|
+
TEXT
|
129
|
+
|
130
|
+
write ".env.test", <<~'TEXT'
|
131
|
+
FROM_SPECIFIC_ENV="from .env.test"
|
132
|
+
|
133
|
+
FROM_SPECIFIC_ENV_LOCAL=nope
|
134
|
+
TEXT
|
135
|
+
|
136
|
+
write ".env", <<~'TEXT'
|
137
|
+
FROM_BASE="from .env"
|
138
|
+
|
139
|
+
FROM_SPECIFIC_ENV_LOCAL=nope
|
140
|
+
FROM_SPECIFIC_ENV=nope
|
141
|
+
TEXT
|
142
|
+
|
143
|
+
ENV["HANAMI_ENV"] = "test"
|
144
|
+
|
145
|
+
require "hanami/prepare"
|
146
|
+
|
147
|
+
expect(Hanami.app["settings"].from_specific_env_local).to eq "from .env.test.local"
|
148
|
+
expect(Hanami.app["settings"].from_base_local).to be nil
|
149
|
+
expect(Hanami.app["settings"].from_specific_env).to eq "from .env.test"
|
150
|
+
expect(Hanami.app["settings"].from_base).to eq "from .env"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "prefers ENV values are preferred over .env files" do
|
158
|
+
with_tmp_directory(Dir.mktmpdir) do
|
159
|
+
write "config/app.rb", <<~'RUBY'
|
160
|
+
require "hanami"
|
161
|
+
|
162
|
+
module TestApp
|
163
|
+
class App < Hanami::App
|
164
|
+
end
|
165
|
+
end
|
166
|
+
RUBY
|
167
|
+
|
168
|
+
write "config/settings.rb", <<~'RUBY'
|
169
|
+
module TestApp
|
170
|
+
class Settings < Hanami::Settings
|
171
|
+
setting :database_url
|
172
|
+
end
|
173
|
+
end
|
174
|
+
RUBY
|
175
|
+
|
176
|
+
write ".env", <<~'TEXT'
|
177
|
+
DATABASE_URL=nope
|
178
|
+
TEXT
|
179
|
+
|
180
|
+
ENV["DATABASE_URL"] = "postgres://localhost/database"
|
181
|
+
|
182
|
+
require "hanami/prepare"
|
183
|
+
|
184
|
+
expect(Hanami.app["settings"].database_url).to eq "postgres://localhost/database"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,113 @@
|
|
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
|