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
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/settings"
|
4
|
+
|
5
|
+
RSpec.describe "Settings / Using types", :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 "dry-types can be used as setting constructors to coerce values" 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 "dry/types"
|
27
|
+
|
28
|
+
module TestApp
|
29
|
+
class Settings < Hanami::Settings
|
30
|
+
Types = Dry.Types()
|
31
|
+
|
32
|
+
setting :numeric, constructor: Types::Params::Integer
|
33
|
+
setting :flag, constructor: Types::Params::Bool
|
34
|
+
end
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
|
38
|
+
ENV["NUMERIC"] = "42"
|
39
|
+
ENV["FLAG"] = "true"
|
40
|
+
|
41
|
+
require "hanami/prepare"
|
42
|
+
|
43
|
+
expect(Hanami.app["settings"].numeric).to eq 42
|
44
|
+
expect(Hanami.app["settings"].flag).to be true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
specify "errors raised from setting constructors are collected and re-raised in aggregate" do
|
49
|
+
with_tmp_directory(Dir.mktmpdir) do
|
50
|
+
write "config/app.rb", <<~RUBY
|
51
|
+
require "hanami"
|
52
|
+
|
53
|
+
module TestApp
|
54
|
+
class App < Hanami::App
|
55
|
+
end
|
56
|
+
end
|
57
|
+
RUBY
|
58
|
+
|
59
|
+
write "config/settings.rb", <<~RUBY
|
60
|
+
require "dry/types"
|
61
|
+
|
62
|
+
module TestApp
|
63
|
+
class Settings < Hanami::Settings
|
64
|
+
Types = Dry.Types()
|
65
|
+
|
66
|
+
setting :numeric, constructor: Types::Params::Integer
|
67
|
+
setting :flag, constructor: Types::Params::Bool
|
68
|
+
end
|
69
|
+
end
|
70
|
+
RUBY
|
71
|
+
|
72
|
+
ENV["NUMERIC"] = "never gonna"
|
73
|
+
ENV["FLAG"] = "give you up"
|
74
|
+
|
75
|
+
numeric_error = "numeric: invalid value for Integer"
|
76
|
+
flag_error = "flag: give you up cannot be coerced"
|
77
|
+
|
78
|
+
expect {
|
79
|
+
require "hanami/prepare"
|
80
|
+
}.to raise_error(
|
81
|
+
Hanami::Settings::InvalidSettingsError,
|
82
|
+
/#{numeric_error}.+#{flag_error}|#{flag_error}.+#{numeric_error}/m
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "Hanami setup", :app_integration do
|
4
|
+
describe "Hanami.setup" do
|
5
|
+
shared_examples "hanami setup" do
|
6
|
+
it "requires the app file when found" do
|
7
|
+
with_tmp_directory(Dir.mktmpdir) do
|
8
|
+
write "config/app.rb", <<~RUBY
|
9
|
+
require "hanami"
|
10
|
+
|
11
|
+
module TestApp
|
12
|
+
class App < Hanami::App
|
13
|
+
end
|
14
|
+
end
|
15
|
+
RUBY
|
16
|
+
|
17
|
+
expect { setup }.to change { Hanami.app? }.to true
|
18
|
+
expect(Hanami.app).to be TestApp::App
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "requires the app file when found in a parent directory" do
|
23
|
+
with_tmp_directory(Dir.mktmpdir) do
|
24
|
+
write "config/app.rb", <<~RUBY
|
25
|
+
require "hanami"
|
26
|
+
|
27
|
+
module TestApp
|
28
|
+
class App < Hanami::App
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
write "lib/foo/bar/.keep"
|
34
|
+
|
35
|
+
Dir.chdir("lib/foo/bar") do
|
36
|
+
expect { setup }.to change { Hanami.app? }.to true
|
37
|
+
expect(Hanami.app).to be TestApp::App
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises when the app file is not found" do
|
43
|
+
with_tmp_directory(Dir.mktmpdir) do
|
44
|
+
expect { setup }.to raise_error Hanami::AppLoadError, /Could not locate your Hanami app file/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "doesn't raise when the app file is not found but the app is already set" do
|
49
|
+
require "hanami"
|
50
|
+
|
51
|
+
module TestApp
|
52
|
+
class App < Hanami::App
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
expect { setup }.not_to raise_error
|
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
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "using hanami/setup require" do
|
81
|
+
def setup
|
82
|
+
require "hanami/setup"
|
83
|
+
end
|
84
|
+
|
85
|
+
it_behaves_like "hanami setup"
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "using Hanami.setup method" do
|
89
|
+
def setup(...)
|
90
|
+
require "hanami"
|
91
|
+
Hanami.setup(...)
|
92
|
+
end
|
93
|
+
|
94
|
+
it_behaves_like "hanami setup"
|
95
|
+
|
96
|
+
it "returns the loaded app when the app file is found" do
|
97
|
+
with_tmp_directory(Dir.mktmpdir) do
|
98
|
+
write "config/app.rb", <<~RUBY
|
99
|
+
require "hanami"
|
100
|
+
|
101
|
+
module TestApp
|
102
|
+
class App < Hanami::App
|
103
|
+
end
|
104
|
+
end
|
105
|
+
RUBY
|
106
|
+
|
107
|
+
# Multiple calls return the same app
|
108
|
+
expect(setup).to be(Hanami.app)
|
109
|
+
expect(setup).to be(Hanami.app)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns nil when given `raise_exception: false` and the app file is not found" do
|
114
|
+
with_tmp_directory(Dir.mktmpdir) do
|
115
|
+
expect(setup(raise_exception: false)).to be nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "Hanami.app_path" do
|
122
|
+
subject(:app_path) { Hanami.app_path }
|
123
|
+
|
124
|
+
context "config/app.rb exists in current directory" do
|
125
|
+
it "returns its absolute path" do
|
126
|
+
with_tmp_directory(Dir.mktmpdir) do
|
127
|
+
write "config/app.rb"
|
128
|
+
|
129
|
+
expect(app_path).to match(%r{^/.*/config/app.rb$})
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "config/app.rb exists in a parent directory" do
|
135
|
+
it "returns its absolute path" do
|
136
|
+
with_tmp_directory(Dir.mktmpdir) do
|
137
|
+
write "config/app.rb"
|
138
|
+
write "lib/foo/bar/.keep"
|
139
|
+
|
140
|
+
Dir.chdir("lib/foo/bar") do
|
141
|
+
expect(app_path).to match(%r{^/.*/config/app.rb$})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "no app file in any directory" do
|
148
|
+
it "returns nil" do
|
149
|
+
with_tmp_directory(Dir.mktmpdir) do
|
150
|
+
expect(app_path).to be(nil)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "directory exists with same name as the app file" do
|
156
|
+
it "returns nil" do
|
157
|
+
with_tmp_directory(Dir.mktmpdir) do
|
158
|
+
write "config/app.rb/.keep"
|
159
|
+
|
160
|
+
expect(app_path).to be(nil)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -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
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
RSpec.describe "Slices / Slice loading", :app_integration, :aggregate_failures do
|
6
|
+
let(:app_modules) { %i[TestApp Admin Editorial Main Shop] }
|
7
|
+
|
8
|
+
describe "loading specific slices with config.slices" do
|
9
|
+
describe "setup app" do
|
10
|
+
it "ignores any explicitly registered slices not included in load_slices" do
|
11
|
+
with_tmp_directory(Dir.mktmpdir) do
|
12
|
+
write "config/app.rb", <<~'RUBY'
|
13
|
+
require "hanami"
|
14
|
+
|
15
|
+
module TestApp
|
16
|
+
class App < Hanami::App
|
17
|
+
config.slices = %w[admin]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
|
22
|
+
require "hanami/setup"
|
23
|
+
|
24
|
+
expect { Hanami.app.register_slice :main }.not_to(change { Hanami.app.slices.keys })
|
25
|
+
expect { Main }.to raise_error(NameError)
|
26
|
+
|
27
|
+
expect { Hanami.app.register_slice :admin }.to change { Hanami.app.slices.keys }.to [:admin]
|
28
|
+
expect(Admin::Slice).to be
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "nested slices" do
|
33
|
+
it "ignores any explicitly registered slices not included in load_slices" do
|
34
|
+
with_tmp_directory(Dir.mktmpdir) do
|
35
|
+
write "config/app.rb", <<~'RUBY'
|
36
|
+
require "hanami"
|
37
|
+
|
38
|
+
module TestApp
|
39
|
+
class App < Hanami::App
|
40
|
+
config.slices = %w[admin.shop]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
|
45
|
+
require "hanami/setup"
|
46
|
+
|
47
|
+
expect { Hanami.app.register_slice :admin }.to change { Hanami.app.slices.keys }.to [:admin]
|
48
|
+
|
49
|
+
expect { Admin::Slice.register_slice :editorial }.not_to(change { Admin::Slice.slices.keys })
|
50
|
+
expect { Admin::Slice.register_slice :shop }.to change { Admin::Slice.slices.keys }.to [:shop]
|
51
|
+
expect(Shop::Slice).to be
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "prepared app" do
|
58
|
+
it "loads only the slices included in load_slices" do
|
59
|
+
with_tmp_directory(Dir.mktmpdir) do
|
60
|
+
write "config/app.rb", <<~'RUBY'
|
61
|
+
require "hanami"
|
62
|
+
|
63
|
+
module TestApp
|
64
|
+
class App < Hanami::App
|
65
|
+
config.slices = %w[admin]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
RUBY
|
69
|
+
|
70
|
+
write "slices/admin/.keep"
|
71
|
+
write "slices/main/.keep"
|
72
|
+
|
73
|
+
require "hanami/prepare"
|
74
|
+
|
75
|
+
expect(Hanami.app.slices.keys).to eq [:admin]
|
76
|
+
expect(Admin::Slice).to be
|
77
|
+
expect { Main }.to raise_error(NameError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "ignores unknown slices in load_slices" do
|
82
|
+
with_tmp_directory(Dir.mktmpdir) do
|
83
|
+
write "config/app.rb", <<~'RUBY'
|
84
|
+
require "hanami"
|
85
|
+
|
86
|
+
module TestApp
|
87
|
+
class App < Hanami::App
|
88
|
+
config.slices = %w[admin meep morp]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
RUBY
|
92
|
+
|
93
|
+
write "slices/admin/.keep"
|
94
|
+
write "slices/main/.keep"
|
95
|
+
|
96
|
+
require "hanami/prepare"
|
97
|
+
|
98
|
+
expect(Hanami.app.slices.keys).to eq [:admin]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "nested slices" do
|
103
|
+
it "loads only the dot-delimited nested slices (and their parents) included in load_slices" do
|
104
|
+
with_tmp_directory(Dir.mktmpdir) do
|
105
|
+
write "config/app.rb", <<~'RUBY'
|
106
|
+
require "hanami"
|
107
|
+
|
108
|
+
module TestApp
|
109
|
+
class App < Hanami::App
|
110
|
+
config.slices = %w[admin.shop]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
RUBY
|
114
|
+
|
115
|
+
write "slices/admin/.keep"
|
116
|
+
write "slices/admin/slices/shop/.keep"
|
117
|
+
write "slices/admin/slices/editorial/.keep"
|
118
|
+
write "slices/main/.keep"
|
119
|
+
|
120
|
+
require "hanami/prepare"
|
121
|
+
|
122
|
+
expect(Hanami.app.slices.keys).to eq [:admin]
|
123
|
+
expect(Admin::Slice.slices.keys).to eq [:shop]
|
124
|
+
|
125
|
+
expect(Admin::Slice).to be
|
126
|
+
expect(Shop::Slice).to be
|
127
|
+
|
128
|
+
expect { Editorial }.to raise_error(NameError)
|
129
|
+
expect { Main }.to raise_error(NameError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "using ENV vars" do
|
137
|
+
before do
|
138
|
+
@orig_env = ENV.to_h
|
139
|
+
end
|
140
|
+
|
141
|
+
after do
|
142
|
+
ENV.replace(@orig_env)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "uses HANAMI_SLICES" do
|
146
|
+
ENV["HANAMI_SLICES"] = "admin"
|
147
|
+
|
148
|
+
with_tmp_directory(Dir.mktmpdir) do
|
149
|
+
write "config/app.rb", <<~'RUBY'
|
150
|
+
require "hanami"
|
151
|
+
|
152
|
+
module TestApp
|
153
|
+
class App < Hanami::App
|
154
|
+
end
|
155
|
+
end
|
156
|
+
RUBY
|
157
|
+
|
158
|
+
write "slices/admin/.keep"
|
159
|
+
write "slices/main/.keep"
|
160
|
+
|
161
|
+
require "hanami/setup"
|
162
|
+
|
163
|
+
expect(Hanami.app.config.slices).to eq %w[admin]
|
164
|
+
|
165
|
+
require "hanami/prepare"
|
166
|
+
|
167
|
+
expect(Hanami.app.slices.keys).to eq [:admin]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -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
|
File without changes
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "hanami"
|
4
|
+
require "hanami/settings"
|
4
5
|
|
5
6
|
RSpec.describe "App view / Context / Settings", :app_integration do
|
6
7
|
before do
|
7
8
|
module TestApp
|
8
9
|
class App < Hanami::App
|
9
10
|
end
|
11
|
+
|
12
|
+
class Settings < Hanami::Settings
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
Hanami.prepare
|
@@ -24,7 +28,7 @@ RSpec.describe "App view / Context / Settings", :app_integration do
|
|
24
28
|
|
25
29
|
describe "#settings" do
|
26
30
|
it "is the app settings by default" do
|
27
|
-
expect(context.settings).to be TestApp::App
|
31
|
+
expect(context.settings).to be TestApp::App["settings"]
|
28
32
|
end
|
29
33
|
|
30
34
|
context "injected settings" do
|
File without changes
|
File without changes
|
File without changes
|