hanami 2.0.0.beta1.1 → 2.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -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.rb +20 -20
- 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/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/action/slice_configuration_spec.rb +287 -0
- data/spec/new_integration/code_loading/loading_from_lib_spec.rb +208 -0
- data/spec/new_integration/dotenv_loading_spec.rb +137 -0
- data/spec/new_integration/settings/access_to_constants_spec.rb +169 -0
- data/spec/new_integration/settings/loading_from_env_spec.rb +187 -0
- data/spec/new_integration/settings/settings_component_loading_spec.rb +113 -0
- data/spec/new_integration/settings/using_types_spec.rb +87 -0
- data/spec/new_integration/setup_spec.rb +145 -0
- data/spec/new_integration/slices/slice_loading_spec.rb +171 -0
- data/spec/new_integration/view/context/settings_spec.rb +5 -1
- data/spec/new_integration/view/slice_configuration_spec.rb +289 -0
- data/spec/support/app_integration.rb +4 -5
- data/spec/unit/hanami/configuration/slices_spec.rb +34 -0
- 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 +30 -28
- data/lib/hanami/settings/dotenv_store.rb +0 -58
- 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/unit/hanami/settings/dotenv_store_spec.rb +0 -119
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,20 +58,6 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0.7'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: dry-types
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.5'
|
68
|
-
type: :runtime
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '1.5'
|
75
61
|
- !ruby/object:Gem::Dependency
|
76
62
|
name: dry-inflector
|
77
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +107,7 @@ dependencies:
|
|
121
107
|
version: '0.6'
|
122
108
|
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.6.
|
110
|
+
version: 0.6.3
|
125
111
|
type: :runtime
|
126
112
|
prerelease: false
|
127
113
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -131,7 +117,7 @@ dependencies:
|
|
131
117
|
version: '0.6'
|
132
118
|
- - ">="
|
133
119
|
- !ruby/object:Gem::Version
|
134
|
-
version: 0.6.
|
120
|
+
version: 0.6.3
|
135
121
|
- !ruby/object:Gem::Dependency
|
136
122
|
name: hanami-cli
|
137
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -231,7 +217,7 @@ files:
|
|
231
217
|
- hanami.gemspec
|
232
218
|
- lib/hanami.rb
|
233
219
|
- lib/hanami/app.rb
|
234
|
-
- lib/hanami/assets/
|
220
|
+
- lib/hanami/assets/app_configuration.rb
|
235
221
|
- lib/hanami/assets/configuration.rb
|
236
222
|
- lib/hanami/boot.rb
|
237
223
|
- lib/hanami/configuration.rb
|
@@ -263,7 +249,7 @@ files:
|
|
263
249
|
- lib/hanami/routes.rb
|
264
250
|
- lib/hanami/server.rb
|
265
251
|
- lib/hanami/settings.rb
|
266
|
-
- lib/hanami/settings/
|
252
|
+
- lib/hanami/settings/env_store.rb
|
267
253
|
- lib/hanami/setup.rb
|
268
254
|
- lib/hanami/slice.rb
|
269
255
|
- lib/hanami/slice/router.rb
|
@@ -347,16 +333,17 @@ files:
|
|
347
333
|
- spec/isolation/hanami/application/routes/configured_spec.rb
|
348
334
|
- spec/isolation/hanami/application/routes/not_configured_spec.rb
|
349
335
|
- spec/isolation/hanami/boot/success_spec.rb
|
350
|
-
- spec/new_integration/action/configuration_spec.rb
|
351
336
|
- spec/new_integration/action/cookies_spec.rb
|
352
337
|
- spec/new_integration/action/csrf_protection_spec.rb
|
353
338
|
- spec/new_integration/action/routes_spec.rb
|
354
339
|
- spec/new_integration/action/sessions_spec.rb
|
340
|
+
- spec/new_integration/action/slice_configuration_spec.rb
|
355
341
|
- spec/new_integration/action/view_integration_spec.rb
|
356
342
|
- spec/new_integration/action/view_rendering/automatic_rendering_spec.rb
|
357
343
|
- spec/new_integration/action/view_rendering/paired_view_inference_spec.rb
|
358
344
|
- spec/new_integration/action/view_rendering_spec.rb
|
359
345
|
- spec/new_integration/code_loading/loading_from_app_spec.rb
|
346
|
+
- spec/new_integration/code_loading/loading_from_lib_spec.rb
|
360
347
|
- spec/new_integration/code_loading/loading_from_slice_spec.rb
|
361
348
|
- spec/new_integration/container/application_routes_helper_spec.rb
|
362
349
|
- spec/new_integration/container/auto_injection_spec.rb
|
@@ -366,16 +353,21 @@ files:
|
|
366
353
|
- spec/new_integration/container/prepare_container_spec.rb
|
367
354
|
- spec/new_integration/container/shutdown_spec.rb
|
368
355
|
- spec/new_integration/container/standard_bootable_components_spec.rb
|
356
|
+
- spec/new_integration/dotenv_loading_spec.rb
|
369
357
|
- spec/new_integration/rack_app/middleware_spec.rb
|
370
358
|
- spec/new_integration/rack_app/non_booted_rack_app_spec.rb
|
371
359
|
- spec/new_integration/rack_app/rack_app_spec.rb
|
372
|
-
- spec/new_integration/
|
360
|
+
- spec/new_integration/settings/access_to_constants_spec.rb
|
361
|
+
- spec/new_integration/settings/loading_from_env_spec.rb
|
362
|
+
- spec/new_integration/settings/settings_component_loading_spec.rb
|
363
|
+
- spec/new_integration/settings/using_types_spec.rb
|
364
|
+
- spec/new_integration/setup_spec.rb
|
373
365
|
- spec/new_integration/slices/external_slice_spec.rb
|
374
366
|
- spec/new_integration/slices/slice_configuration_spec.rb
|
367
|
+
- spec/new_integration/slices/slice_loading_spec.rb
|
375
368
|
- spec/new_integration/slices/slice_routing_spec.rb
|
376
369
|
- spec/new_integration/slices/slice_settings_spec.rb
|
377
370
|
- spec/new_integration/slices_spec.rb
|
378
|
-
- spec/new_integration/view/configuration_spec.rb
|
379
371
|
- spec/new_integration/view/context/assets_spec.rb
|
380
372
|
- spec/new_integration/view/context/inflector_spec.rb
|
381
373
|
- spec/new_integration/view/context/request_spec.rb
|
@@ -384,6 +376,7 @@ files:
|
|
384
376
|
- spec/new_integration/view/inflector_spec.rb
|
385
377
|
- spec/new_integration/view/part_namespace_spec.rb
|
386
378
|
- spec/new_integration/view/path_spec.rb
|
379
|
+
- spec/new_integration/view/slice_configuration_spec.rb
|
387
380
|
- spec/new_integration/view/template_spec.rb
|
388
381
|
- spec/new_integration/view/views_spec.rb
|
389
382
|
- spec/spec_helper.rb
|
@@ -412,11 +405,12 @@ files:
|
|
412
405
|
- spec/unit/hanami/configuration/base_url_spec.rb
|
413
406
|
- spec/unit/hanami/configuration/inflector_spec.rb
|
414
407
|
- spec/unit/hanami/configuration/logger_spec.rb
|
408
|
+
- spec/unit/hanami/configuration/slices_spec.rb
|
415
409
|
- spec/unit/hanami/configuration/views_spec.rb
|
416
410
|
- spec/unit/hanami/configuration_spec.rb
|
417
411
|
- spec/unit/hanami/env_spec.rb
|
418
412
|
- spec/unit/hanami/routes_spec.rb
|
419
|
-
- spec/unit/hanami/settings/
|
413
|
+
- spec/unit/hanami/settings/env_store_spec.rb
|
420
414
|
- spec/unit/hanami/settings_spec.rb
|
421
415
|
- spec/unit/hanami/slice_configurable_spec.rb
|
422
416
|
- spec/unit/hanami/slice_name_spec.rb
|
@@ -520,16 +514,17 @@ test_files:
|
|
520
514
|
- spec/isolation/hanami/application/routes/configured_spec.rb
|
521
515
|
- spec/isolation/hanami/application/routes/not_configured_spec.rb
|
522
516
|
- spec/isolation/hanami/boot/success_spec.rb
|
523
|
-
- spec/new_integration/action/configuration_spec.rb
|
524
517
|
- spec/new_integration/action/cookies_spec.rb
|
525
518
|
- spec/new_integration/action/csrf_protection_spec.rb
|
526
519
|
- spec/new_integration/action/routes_spec.rb
|
527
520
|
- spec/new_integration/action/sessions_spec.rb
|
521
|
+
- spec/new_integration/action/slice_configuration_spec.rb
|
528
522
|
- spec/new_integration/action/view_integration_spec.rb
|
529
523
|
- spec/new_integration/action/view_rendering/automatic_rendering_spec.rb
|
530
524
|
- spec/new_integration/action/view_rendering/paired_view_inference_spec.rb
|
531
525
|
- spec/new_integration/action/view_rendering_spec.rb
|
532
526
|
- spec/new_integration/code_loading/loading_from_app_spec.rb
|
527
|
+
- spec/new_integration/code_loading/loading_from_lib_spec.rb
|
533
528
|
- spec/new_integration/code_loading/loading_from_slice_spec.rb
|
534
529
|
- spec/new_integration/container/application_routes_helper_spec.rb
|
535
530
|
- spec/new_integration/container/auto_injection_spec.rb
|
@@ -539,16 +534,21 @@ test_files:
|
|
539
534
|
- spec/new_integration/container/prepare_container_spec.rb
|
540
535
|
- spec/new_integration/container/shutdown_spec.rb
|
541
536
|
- spec/new_integration/container/standard_bootable_components_spec.rb
|
537
|
+
- spec/new_integration/dotenv_loading_spec.rb
|
542
538
|
- spec/new_integration/rack_app/middleware_spec.rb
|
543
539
|
- spec/new_integration/rack_app/non_booted_rack_app_spec.rb
|
544
540
|
- spec/new_integration/rack_app/rack_app_spec.rb
|
545
|
-
- spec/new_integration/
|
541
|
+
- spec/new_integration/settings/access_to_constants_spec.rb
|
542
|
+
- spec/new_integration/settings/loading_from_env_spec.rb
|
543
|
+
- spec/new_integration/settings/settings_component_loading_spec.rb
|
544
|
+
- spec/new_integration/settings/using_types_spec.rb
|
545
|
+
- spec/new_integration/setup_spec.rb
|
546
546
|
- spec/new_integration/slices/external_slice_spec.rb
|
547
547
|
- spec/new_integration/slices/slice_configuration_spec.rb
|
548
|
+
- spec/new_integration/slices/slice_loading_spec.rb
|
548
549
|
- spec/new_integration/slices/slice_routing_spec.rb
|
549
550
|
- spec/new_integration/slices/slice_settings_spec.rb
|
550
551
|
- spec/new_integration/slices_spec.rb
|
551
|
-
- spec/new_integration/view/configuration_spec.rb
|
552
552
|
- spec/new_integration/view/context/assets_spec.rb
|
553
553
|
- spec/new_integration/view/context/inflector_spec.rb
|
554
554
|
- spec/new_integration/view/context/request_spec.rb
|
@@ -557,6 +557,7 @@ test_files:
|
|
557
557
|
- spec/new_integration/view/inflector_spec.rb
|
558
558
|
- spec/new_integration/view/part_namespace_spec.rb
|
559
559
|
- spec/new_integration/view/path_spec.rb
|
560
|
+
- spec/new_integration/view/slice_configuration_spec.rb
|
560
561
|
- spec/new_integration/view/template_spec.rb
|
561
562
|
- spec/new_integration/view/views_spec.rb
|
562
563
|
- spec/spec_helper.rb
|
@@ -585,11 +586,12 @@ test_files:
|
|
585
586
|
- spec/unit/hanami/configuration/base_url_spec.rb
|
586
587
|
- spec/unit/hanami/configuration/inflector_spec.rb
|
587
588
|
- spec/unit/hanami/configuration/logger_spec.rb
|
589
|
+
- spec/unit/hanami/configuration/slices_spec.rb
|
588
590
|
- spec/unit/hanami/configuration/views_spec.rb
|
589
591
|
- spec/unit/hanami/configuration_spec.rb
|
590
592
|
- spec/unit/hanami/env_spec.rb
|
591
593
|
- spec/unit/hanami/routes_spec.rb
|
592
|
-
- spec/unit/hanami/settings/
|
594
|
+
- spec/unit/hanami/settings/env_store_spec.rb
|
593
595
|
- spec/unit/hanami/settings_spec.rb
|
594
596
|
- spec/unit/hanami/slice_configurable_spec.rb
|
595
597
|
- spec/unit/hanami/slice_name_spec.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "dry/core/constants"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
class Settings
|
7
|
-
# Default app settings store.
|
8
|
-
#
|
9
|
-
# Uses [dotenv](https://github.com/bkeepers/dotenv) (if available) to load
|
10
|
-
# .env files and then loads settings from ENV. For a given `HANAMI_ENV`
|
11
|
-
# environment, the following `.env` files are looked up in the following order:
|
12
|
-
#
|
13
|
-
# - .env.{environment}.local
|
14
|
-
# - .env.local (except if the environment is `test`)
|
15
|
-
# - .env.{environment}
|
16
|
-
# - .env
|
17
|
-
#
|
18
|
-
# @since 2.0.0
|
19
|
-
# @api private
|
20
|
-
class DotenvStore
|
21
|
-
Undefined = Dry::Core::Constants::Undefined
|
22
|
-
|
23
|
-
attr_reader :store,
|
24
|
-
:hanami_env
|
25
|
-
|
26
|
-
def initialize(store: ENV, hanami_env: Hanami.env)
|
27
|
-
@store = store
|
28
|
-
@hanami_env = hanami_env
|
29
|
-
end
|
30
|
-
|
31
|
-
def fetch(name, default_value = Undefined, &block)
|
32
|
-
name = name.to_s.upcase
|
33
|
-
args = (default_value == Undefined) ? [name] : [name, default_value]
|
34
|
-
|
35
|
-
store.fetch(*args, &block)
|
36
|
-
end
|
37
|
-
|
38
|
-
def with_dotenv_loaded
|
39
|
-
require "dotenv"
|
40
|
-
Dotenv.load(*dotenv_files) if defined?(Dotenv)
|
41
|
-
self
|
42
|
-
rescue LoadError
|
43
|
-
self
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def dotenv_files
|
49
|
-
[
|
50
|
-
".env.#{hanami_env}.local",
|
51
|
-
(".env.local" unless hanami_env == :test),
|
52
|
-
".env.#{hanami_env}",
|
53
|
-
".env"
|
54
|
-
].compact
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "App action / Configuration", :app_integration do
|
4
|
-
before do
|
5
|
-
module TestApp
|
6
|
-
class App < Hanami::App
|
7
|
-
config.actions.default_response_format = :json
|
8
|
-
register_slice :main
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Hanami.app.prepare
|
13
|
-
|
14
|
-
module TestApp
|
15
|
-
class Action < Hanami::Action
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:action_class) { TestApp::Action }
|
21
|
-
subject(:configuration) { action_class.config }
|
22
|
-
|
23
|
-
it "applies 'config.actions' configuration from the app" do
|
24
|
-
expect(configuration.default_response_format).to eq :json
|
25
|
-
end
|
26
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/settings"
|
4
|
-
|
5
|
-
RSpec.describe "App settings", :app_integration do
|
6
|
-
before do
|
7
|
-
@env = ENV.to_h
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
ENV.replace(@env)
|
12
|
-
end
|
13
|
-
|
14
|
-
specify "Settings defined in config/settings.rb are loaded from .env" do
|
15
|
-
with_tmp_directory(Dir.mktmpdir) do
|
16
|
-
write "config/app.rb", <<~RUBY
|
17
|
-
require "hanami"
|
18
|
-
|
19
|
-
module TestApp
|
20
|
-
class App < Hanami::App
|
21
|
-
end
|
22
|
-
end
|
23
|
-
RUBY
|
24
|
-
|
25
|
-
write "config/settings.rb", <<~RUBY
|
26
|
-
require "hanami/settings"
|
27
|
-
require "test_app/types"
|
28
|
-
|
29
|
-
module TestApp
|
30
|
-
class Settings < Hanami::Settings
|
31
|
-
setting :database_url
|
32
|
-
setting :redis_url
|
33
|
-
setting :feature_flag, constructor: TestApp::Types::Params::Bool
|
34
|
-
setting :feature_flag_with_default, default: false, constructor: TestApp::Types::Params::Bool
|
35
|
-
end
|
36
|
-
end
|
37
|
-
RUBY
|
38
|
-
|
39
|
-
write ".env", <<~RUBY
|
40
|
-
DATABASE_URL=postgres://localhost/test_app_development
|
41
|
-
REDIS_URL=redis://localhost:6379
|
42
|
-
FEATURE_FLAG=true
|
43
|
-
RUBY
|
44
|
-
|
45
|
-
write "lib/test_app/types.rb", <<~RUBY
|
46
|
-
require "dry/types"
|
47
|
-
|
48
|
-
module TestApp
|
49
|
-
module Types
|
50
|
-
include Dry.Types()
|
51
|
-
end
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
|
55
|
-
require "hanami/prepare"
|
56
|
-
|
57
|
-
expect(Hanami.app.settings.database_url).to eq "postgres://localhost/test_app_development"
|
58
|
-
expect(Hanami.app.settings.redis_url).to eq "redis://localhost:6379"
|
59
|
-
expect(Hanami.app.settings.feature_flag).to be true
|
60
|
-
expect(Hanami.app.settings.feature_flag_with_default).to be false
|
61
|
-
|
62
|
-
expect(Hanami.app[:settings]).to eql Hanami.app.settings
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
specify "Errors raised from setting constructors are collected" do
|
67
|
-
with_tmp_directory(Dir.mktmpdir) do
|
68
|
-
write "config/app.rb", <<~RUBY
|
69
|
-
require "hanami"
|
70
|
-
|
71
|
-
module TestApp
|
72
|
-
class App < Hanami::App
|
73
|
-
end
|
74
|
-
end
|
75
|
-
RUBY
|
76
|
-
|
77
|
-
write "config/settings.rb", <<~RUBY
|
78
|
-
require "hanami/settings"
|
79
|
-
require "test_app/types"
|
80
|
-
|
81
|
-
module TestApp
|
82
|
-
class Settings < Hanami::Settings
|
83
|
-
setting :numeric_setting, constructor: TestApp::Types::Params::Integer
|
84
|
-
setting :feature_flag, constructor: TestApp::Types::Params::Bool
|
85
|
-
end
|
86
|
-
end
|
87
|
-
RUBY
|
88
|
-
|
89
|
-
write ".env", <<~RUBY
|
90
|
-
NUMERIC_SETTING=hello
|
91
|
-
FEATURE_FLAG=maybe
|
92
|
-
RUBY
|
93
|
-
|
94
|
-
write "lib/test_app/types.rb", <<~RUBY
|
95
|
-
require "dry/types"
|
96
|
-
|
97
|
-
module TestApp
|
98
|
-
module Types
|
99
|
-
include Dry.Types()
|
100
|
-
end
|
101
|
-
end
|
102
|
-
RUBY
|
103
|
-
|
104
|
-
numeric_setting_error = "numeric_setting: invalid value for Integer"
|
105
|
-
feature_flag_error = "feature_flag: maybe cannot be coerced"
|
106
|
-
|
107
|
-
expect {
|
108
|
-
require "hanami/prepare"
|
109
|
-
}.to raise_error(
|
110
|
-
Hanami::Settings::InvalidSettingsError,
|
111
|
-
/#{numeric_setting_error}.+#{feature_flag_error}|#{feature_flag_error}.+#{numeric_setting_error}/m
|
112
|
-
)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami"
|
4
|
-
|
5
|
-
RSpec.describe "App view / Configuration", :app_integration do
|
6
|
-
before do
|
7
|
-
module TestApp
|
8
|
-
class App < Hanami::App
|
9
|
-
config.root = "/test_app"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
|
14
|
-
Hanami.app.register_slice :main
|
15
|
-
Hanami.app.prepare
|
16
|
-
|
17
|
-
module TestApp
|
18
|
-
class View < Hanami::View
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:view_class) { TestApp::View }
|
24
|
-
|
25
|
-
subject(:config) { view_class.config }
|
26
|
-
|
27
|
-
it "applies default view configuration from the app" do
|
28
|
-
aggregate_failures do
|
29
|
-
expect(config.layouts_dir).to eq "layouts"
|
30
|
-
expect(config.layout).to eq "app"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "custom views configuration on app" do
|
35
|
-
let(:app_hook) {
|
36
|
-
proc do
|
37
|
-
config.views.layouts_dir = "custom_layouts"
|
38
|
-
config.views.layout = "my_layout"
|
39
|
-
end
|
40
|
-
}
|
41
|
-
|
42
|
-
it "applies the custom configuration" do
|
43
|
-
aggregate_failures do
|
44
|
-
expect(config.layouts_dir).to eq "custom_layouts"
|
45
|
-
expect(config.layout).to eq "my_layout"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/settings/dotenv_store"
|
4
|
-
require "dotenv"
|
5
|
-
|
6
|
-
RSpec.describe Hanami::Settings::DotenvStore do
|
7
|
-
def mock_dotenv(store)
|
8
|
-
dotenv = spy(:dotenv)
|
9
|
-
allow(store).to receive(:require).and_call_original
|
10
|
-
stub_const "Dotenv", dotenv
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#with_dotenv_loaded" do
|
14
|
-
context "dotenv available and environment other than test" do
|
15
|
-
it "requires and loads a range of dotenv files, specific to the current environment" do
|
16
|
-
store = described_class.new(store: {}, hanami_env: :development)
|
17
|
-
dotenv = mock_dotenv(store)
|
18
|
-
|
19
|
-
store.with_dotenv_loaded
|
20
|
-
|
21
|
-
expect(store).to have_received(:require).with("dotenv").ordered
|
22
|
-
expect(dotenv).to have_received(:load).ordered.with(
|
23
|
-
".env.development.local",
|
24
|
-
".env.local",
|
25
|
-
".env.development",
|
26
|
-
".env"
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns self" do
|
31
|
-
store = described_class.new(store: {}, hanami_env: :development)
|
32
|
-
|
33
|
-
expect(store.with_dotenv_loaded).to be(store)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "dotenv available and test environment" do
|
38
|
-
it "does not load .env.local (which is intended for non-test settings only)" do
|
39
|
-
store = described_class.new(store: {}, hanami_env: :test)
|
40
|
-
dotenv = mock_dotenv(store)
|
41
|
-
|
42
|
-
store.with_dotenv_loaded
|
43
|
-
|
44
|
-
expect(store).to have_received(:require).with("dotenv").ordered
|
45
|
-
expect(dotenv).to have_received(:load).ordered.with(
|
46
|
-
".env.test.local",
|
47
|
-
".env.test",
|
48
|
-
".env"
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns self" do
|
53
|
-
store = described_class.new(store: {}, hanami_env: :test)
|
54
|
-
|
55
|
-
expect(store.with_dotenv_loaded).to be(store)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "dotenv unavailable" do
|
60
|
-
let(:store) { described_class.new(store: {}) }
|
61
|
-
|
62
|
-
before do
|
63
|
-
allow(store).to receive(:require).with("dotenv").and_raise LoadError
|
64
|
-
end
|
65
|
-
|
66
|
-
it "attempts to require dotenv" do
|
67
|
-
store.with_dotenv_loaded
|
68
|
-
|
69
|
-
expect(store).to have_received(:require).with("dotenv")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "gracefully ignores load errors" do
|
73
|
-
expect { store.with_dotenv_loaded }.not_to raise_error
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns self" do
|
77
|
-
expect(store.with_dotenv_loaded).to be(store)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#fetch" do
|
83
|
-
it "fetches from ENV" do
|
84
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
85
|
-
|
86
|
-
expect(store.fetch("FOO")).to eq("bar")
|
87
|
-
end
|
88
|
-
|
89
|
-
it "capitalizes name" do
|
90
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
91
|
-
|
92
|
-
expect(store.fetch("foo")).to eq("bar")
|
93
|
-
end
|
94
|
-
|
95
|
-
it "coerces name to string" do
|
96
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
97
|
-
|
98
|
-
expect(store.fetch(:foo)).to eq("bar")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns default when value is not found" do
|
102
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
103
|
-
|
104
|
-
expect(store.fetch("BAZ", "qux")).to eq("qux")
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns the block execution when value is not found" do
|
108
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
109
|
-
|
110
|
-
expect(store.fetch("BAZ") { "qux" }).to eq("qux")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "raises KeyError when value is not found and no default is given" do
|
114
|
-
store = described_class.new(store: { "FOO" => "bar" })
|
115
|
-
|
116
|
-
expect{ store.fetch("BAZ") }.to raise_error(KeyError)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|