hanami 2.3.2 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -19
- data/LICENSE +20 -0
- data/README.md +18 -35
- data/hanami.gemspec +36 -37
- data/lib/hanami/config/db.rb +2 -0
- data/lib/hanami/config/i18n.rb +138 -0
- data/lib/hanami/config/logger.rb +15 -7
- data/lib/hanami/config/null_config.rb +1 -1
- data/lib/hanami/config/views.rb +17 -0
- data/lib/hanami/config.rb +66 -22
- data/lib/hanami/errors.rb +6 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/extensions/action.rb +2 -2
- data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
- data/lib/hanami/extensions/mailer.rb +28 -0
- data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
- data/lib/hanami/extensions/view/context.rb +26 -4
- data/lib/hanami/extensions/view/part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions.rb +6 -1
- data/lib/hanami/helpers/assets_helper.rb +0 -4
- data/lib/hanami/helpers/form_helper.rb +1 -1
- data/lib/hanami/helpers/i18n_helper.rb +176 -0
- data/lib/hanami/logger/rack_formatter.rb +73 -0
- data/lib/hanami/logger/sql_formatter.rb +80 -0
- data/lib/hanami/logger/sql_logger.rb +48 -0
- data/lib/hanami/middleware/render_errors.rb +2 -2
- data/lib/hanami/providers/db.rb +7 -2
- data/lib/hanami/providers/db_logging.rb +4 -7
- data/lib/hanami/providers/i18n/backend.rb +369 -0
- data/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/lib/hanami/providers/i18n.rb +114 -0
- data/lib/hanami/providers/mailers.rb +101 -0
- data/lib/hanami/routes.rb +1 -0
- data/lib/hanami/settings/composite_store.rb +53 -0
- data/lib/hanami/settings.rb +4 -4
- data/lib/hanami/slice/router.rb +15 -10
- data/lib/hanami/slice.rb +71 -11
- data/lib/hanami/slice_registrar.rb +2 -2
- data/lib/hanami/universal_logger.rb +250 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +2 -80
- data/lib/hanami/web/welcome.html.erb +443 -58
- data/lib/hanami.rb +4 -2
- metadata +28 -276
- data/CODE_OF_CONDUCT.md +0 -74
- data/FEATURES.md +0 -269
- data/LICENSE.md +0 -22
- data/spec/integration/action/cookies_spec.rb +0 -58
- data/spec/integration/action/csrf_protection_spec.rb +0 -54
- data/spec/integration/action/format_config_spec.rb +0 -129
- data/spec/integration/action/routes_spec.rb +0 -71
- data/spec/integration/action/sessions_spec.rb +0 -50
- data/spec/integration/action/slice_configuration_spec.rb +0 -284
- data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
- data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
- data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
- data/spec/integration/action/view_rendering_spec.rb +0 -89
- data/spec/integration/assets/assets_spec.rb +0 -155
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
- data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
- data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
- data/spec/integration/container/application_routes_helper_spec.rb +0 -48
- data/spec/integration/container/auto_injection_spec.rb +0 -53
- data/spec/integration/container/auto_registration_spec.rb +0 -86
- data/spec/integration/container/autoloader_spec.rb +0 -82
- data/spec/integration/container/imports_spec.rb +0 -253
- data/spec/integration/container/prepare_container_spec.rb +0 -125
- data/spec/integration/container/provider_environment_spec.rb +0 -52
- data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
- data/spec/integration/container/shutdown_spec.rb +0 -91
- data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
- data/spec/integration/container/standard_providers_spec.rb +0 -124
- data/spec/integration/db/auto_registration_spec.rb +0 -39
- data/spec/integration/db/commands_spec.rb +0 -80
- data/spec/integration/db/db_inflector_spec.rb +0 -57
- data/spec/integration/db/db_slices_spec.rb +0 -398
- data/spec/integration/db/db_spec.rb +0 -245
- data/spec/integration/db/gateways_spec.rb +0 -361
- data/spec/integration/db/logging_spec.rb +0 -301
- data/spec/integration/db/mappers_spec.rb +0 -84
- data/spec/integration/db/provider_config_spec.rb +0 -88
- data/spec/integration/db/provider_spec.rb +0 -35
- data/spec/integration/db/relations_spec.rb +0 -60
- data/spec/integration/db/repo_spec.rb +0 -300
- data/spec/integration/db/slices_importing_from_parent.rb +0 -130
- data/spec/integration/dotenv_loading_spec.rb +0 -138
- data/spec/integration/logging/exception_logging_spec.rb +0 -120
- data/spec/integration/logging/notifications_spec.rb +0 -68
- data/spec/integration/logging/request_logging_spec.rb +0 -202
- data/spec/integration/operations/extension_spec.rb +0 -122
- data/spec/integration/rack_app/body_parser_spec.rb +0 -108
- data/spec/integration/rack_app/method_override_spec.rb +0 -97
- data/spec/integration/rack_app/middleware_spec.rb +0 -720
- data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
- data/spec/integration/rack_app/rack_app_spec.rb +0 -442
- data/spec/integration/rake_tasks_spec.rb +0 -107
- data/spec/integration/router/resource_routes_spec.rb +0 -281
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
- data/spec/integration/settings/access_to_constants_spec.rb +0 -46
- data/spec/integration/settings/loading_from_env_spec.rb +0 -188
- data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
- data/spec/integration/settings/slice_registration_spec.rb +0 -145
- data/spec/integration/settings/using_types_spec.rb +0 -80
- data/spec/integration/setup_spec.rb +0 -165
- data/spec/integration/slices/external_slice_spec.rb +0 -91
- data/spec/integration/slices/slice_configuration_spec.rb +0 -42
- data/spec/integration/slices/slice_loading_spec.rb +0 -171
- data/spec/integration/slices/slice_registrations_spec.rb +0 -80
- data/spec/integration/slices/slice_routing_spec.rb +0 -219
- data/spec/integration/slices_spec.rb +0 -471
- data/spec/integration/view/config/default_context_spec.rb +0 -149
- data/spec/integration/view/config/inflector_spec.rb +0 -57
- data/spec/integration/view/config/part_class_spec.rb +0 -147
- data/spec/integration/view/config/part_namespace_spec.rb +0 -103
- data/spec/integration/view/config/paths_spec.rb +0 -119
- data/spec/integration/view/config/scope_class_spec.rb +0 -147
- data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
- data/spec/integration/view/config/template_spec.rb +0 -38
- data/spec/integration/view/context/assets_spec.rb +0 -79
- data/spec/integration/view/context/inflector_spec.rb +0 -40
- data/spec/integration/view/context/request_spec.rb +0 -57
- data/spec/integration/view/context/routes_spec.rb +0 -84
- data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
- data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
- data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
- data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
- data/spec/integration/view/slice_configuration_spec.rb +0 -289
- data/spec/integration/view/views_spec.rb +0 -103
- data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
- data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
- data/spec/integration/web/render_errors_spec.rb +0 -242
- data/spec/integration/web/welcome_view_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -28
- data/spec/support/app_integration.rb +0 -157
- data/spec/support/coverage.rb +0 -1
- data/spec/support/matchers.rb +0 -32
- data/spec/support/rspec.rb +0 -27
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
- data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
- data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
- data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
- data/spec/unit/hanami/config/actions_spec.rb +0 -52
- data/spec/unit/hanami/config/base_url_spec.rb +0 -25
- data/spec/unit/hanami/config/console_spec.rb +0 -22
- data/spec/unit/hanami/config/db_spec.rb +0 -38
- data/spec/unit/hanami/config/inflector_spec.rb +0 -35
- data/spec/unit/hanami/config/logger_spec.rb +0 -195
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/router_spec.rb +0 -44
- data/spec/unit/hanami/config/slices_spec.rb +0 -34
- data/spec/unit/hanami/config/views_spec.rb +0 -80
- data/spec/unit/hanami/env_spec.rb +0 -37
- data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
- data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
- data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
- data/spec/unit/hanami/port_spec.rb +0 -117
- data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
- data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
- data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
- data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
- data/spec/unit/hanami/settings_spec.rb +0 -111
- data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
- data/spec/unit/hanami/slice_name_spec.rb +0 -47
- data/spec/unit/hanami/slice_spec.rb +0 -99
- data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
require "stringio"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Serve Static Assets", :app_integration do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
let(:app) { Hanami.app }
|
|
9
|
-
let(:root) { make_tmp_directory }
|
|
10
|
-
let!(:env) { ENV.to_h }
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
with_directory(root) do
|
|
14
|
-
write "config/app.rb", <<~RUBY
|
|
15
|
-
module TestApp
|
|
16
|
-
class App < Hanami::App
|
|
17
|
-
config.logger.stream = StringIO.new
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
RUBY
|
|
21
|
-
|
|
22
|
-
write "config/routes.rb", <<~RUBY
|
|
23
|
-
module TestApp
|
|
24
|
-
class Routes < Hanami::Routes
|
|
25
|
-
root to: ->(env) { [200, {}, ["Hello from root"]] }
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
RUBY
|
|
29
|
-
|
|
30
|
-
write "public/assets/app.js", <<~JS
|
|
31
|
-
console.log("Hello from app.js");
|
|
32
|
-
JS
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
after do
|
|
37
|
-
ENV.replace(env)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "with default configuration" do
|
|
41
|
-
before do
|
|
42
|
-
with_directory(root) do
|
|
43
|
-
require "hanami/prepare"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "serves static assets" do
|
|
48
|
-
get "/assets/app.js"
|
|
49
|
-
|
|
50
|
-
expect(last_response.status).to eq(200)
|
|
51
|
-
expect(last_response.body).to match(/Hello/)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "returns 404 for missing asset" do
|
|
55
|
-
get "/assets/missing.js"
|
|
56
|
-
|
|
57
|
-
expect(last_response.status).to eq(404)
|
|
58
|
-
expect(last_response.body).to match(/Not Found/i)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "doesn't escape from root directory" do
|
|
62
|
-
get "/assets/../../config/app.rb"
|
|
63
|
-
|
|
64
|
-
expect(last_response.status).to eq(404)
|
|
65
|
-
expect(last_response.body).to match("Hanami::Router::NotFoundError")
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context "when configuration is set to false" do
|
|
70
|
-
before do
|
|
71
|
-
with_directory(root) do
|
|
72
|
-
write "config/app.rb", <<~RUBY
|
|
73
|
-
module TestApp
|
|
74
|
-
class App < Hanami::App
|
|
75
|
-
config.logger.stream = StringIO.new
|
|
76
|
-
config.assets.serve = false
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
RUBY
|
|
80
|
-
|
|
81
|
-
require "hanami/boot"
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "doesn't serve static assets" do
|
|
86
|
-
get "/assets/app.js"
|
|
87
|
-
|
|
88
|
-
expect(last_response.status).to eq(404)
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "when env var is set to true" do
|
|
93
|
-
before do
|
|
94
|
-
with_directory(root) do
|
|
95
|
-
ENV["HANAMI_SERVE_ASSETS"] = "true"
|
|
96
|
-
require "hanami/boot"
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "serves static assets" do
|
|
101
|
-
get "/assets/app.js"
|
|
102
|
-
|
|
103
|
-
expect(last_response.status).to eq(200)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context "when env var is set to false" do
|
|
108
|
-
before do
|
|
109
|
-
with_directory(root) do
|
|
110
|
-
ENV["HANAMI_SERVE_ASSETS"] = "false"
|
|
111
|
-
require "hanami/boot"
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "doesn't serve static assets" do
|
|
116
|
-
get "/assets/app.js"
|
|
117
|
-
|
|
118
|
-
expect(last_response.status).to eq(404)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
context "when Hanami.env is not :development or :test" do
|
|
123
|
-
before do
|
|
124
|
-
with_directory(root) do
|
|
125
|
-
ENV["HANAMI_ENV"] = "production"
|
|
126
|
-
require "hanami/boot"
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "doesn't serve static assets" do
|
|
131
|
-
get "/assets/app.js"
|
|
132
|
-
|
|
133
|
-
expect(last_response.status).to eq(404)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "when Hanami.env is not :development or :test, but env var is set to true" do
|
|
138
|
-
before do
|
|
139
|
-
with_directory(root) do
|
|
140
|
-
ENV["HANAMI_ENV"] = "production"
|
|
141
|
-
ENV["HANAMI_SERVE_ASSETS"] = "true"
|
|
142
|
-
require "hanami/boot"
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it "serves static assets" do
|
|
147
|
-
get "/assets/app.js"
|
|
148
|
-
|
|
149
|
-
expect(last_response.status).to eq(200)
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
end
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Code loading / Loading from app directory", :app_integration do
|
|
4
|
-
before :context do
|
|
5
|
-
with_directory(@dir = make_tmp_directory) do
|
|
6
|
-
write "config/app.rb", <<~'RUBY'
|
|
7
|
-
require "hanami"
|
|
8
|
-
|
|
9
|
-
module TestApp
|
|
10
|
-
class App < Hanami::App
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
RUBY
|
|
14
|
-
|
|
15
|
-
write "app/test_class.rb", <<~'RUBY'
|
|
16
|
-
module TestApp
|
|
17
|
-
class TestClass
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
RUBY
|
|
21
|
-
|
|
22
|
-
write "app/action.rb", <<~'RUBY'
|
|
23
|
-
# auto_register: false
|
|
24
|
-
|
|
25
|
-
module TestApp
|
|
26
|
-
class Action < Hanami::Action
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
RUBY
|
|
30
|
-
|
|
31
|
-
write "app/actions/home/show.rb", <<~'RUBY'
|
|
32
|
-
module TestApp
|
|
33
|
-
module Actions
|
|
34
|
-
module Home
|
|
35
|
-
class Show < TestApp::Action
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
RUBY
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
before do
|
|
45
|
-
with_directory(@dir) do
|
|
46
|
-
require "hanami/prepare"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
specify "Classes in app/ directory are autoloaded with the app namespace" do
|
|
51
|
-
expect(TestApp::TestClass).to be
|
|
52
|
-
expect(TestApp::Action).to be
|
|
53
|
-
expect(TestApp::Actions::Home::Show).to be
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
specify "Classes in app directory are auto-registered" do
|
|
57
|
-
expect(TestApp::App["test_class"]).to be_an_instance_of TestApp::TestClass
|
|
58
|
-
expect(TestApp::App["actions.home.show"]).to be_an_instance_of TestApp::Actions::Home::Show
|
|
59
|
-
|
|
60
|
-
# Files with "auto_register: false" magic comments are not auto-registered
|
|
61
|
-
expect(TestApp::App.key?("action")).to be false
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "app/lib/ directory" do
|
|
65
|
-
before :context do
|
|
66
|
-
with_directory(@dir = make_tmp_directory) do
|
|
67
|
-
write "config/app.rb", <<~'RUBY'
|
|
68
|
-
require "hanami"
|
|
69
|
-
|
|
70
|
-
module TestApp
|
|
71
|
-
class App < Hanami::App
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
RUBY
|
|
75
|
-
|
|
76
|
-
write "app/lib/test_class.rb", <<~'RUBY'
|
|
77
|
-
module TestApp
|
|
78
|
-
class TestClass
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
RUBY
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
specify "Classes in app/lib/ directory are autoloaded with the app namespace" do
|
|
86
|
-
expect(TestApp::TestClass).to be
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
specify "Classes in app/lib/ directory are auto-registered" do
|
|
90
|
-
expect(TestApp::App["test_class"]).to be_an_instance_of TestApp::TestClass
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
specify "Classes in app/lib/ directory are not redundantly auto-registered under 'lib' key namespace" do
|
|
94
|
-
expect(TestApp::App.key?("lib.test_class")).to be false
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# rubocop:disable Style/GlobalVars
|
|
99
|
-
describe "same-named class defined in both app/ and app/lib/ directories" do
|
|
100
|
-
before :context do
|
|
101
|
-
with_directory(@dir = make_tmp_directory) 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 "app/test_class.rb", <<~'RUBY'
|
|
112
|
-
$app_class_loaded = true
|
|
113
|
-
|
|
114
|
-
module TestApp
|
|
115
|
-
class TestClass
|
|
116
|
-
(@loaded_from ||= []) << "app"
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
RUBY
|
|
120
|
-
|
|
121
|
-
write "app/lib/test_class.rb", <<~'RUBY'
|
|
122
|
-
$app_lib_class_loaded = true
|
|
123
|
-
|
|
124
|
-
module TestApp
|
|
125
|
-
class TestClass
|
|
126
|
-
(@loaded_from ||= []) << "app/lib"
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
RUBY
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
after do
|
|
134
|
-
$app_class_loaded = $app_lib_class_loaded = nil
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
specify "Classes in app/lib/ directory are preferred for autoloading" do
|
|
138
|
-
expect(TestApp::TestClass).to be
|
|
139
|
-
expect(TestApp::TestClass.instance_variable_get(:@loaded_from)).to eq ["app/lib"]
|
|
140
|
-
expect($app_lib_class_loaded).to be true
|
|
141
|
-
expect($app_class_loaded).to be nil
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
specify "Classes in app/lib/ directory are preferred for auto-registration" do
|
|
145
|
-
expect(TestApp::App["test_class"]).to be
|
|
146
|
-
expect(TestApp::TestClass.instance_variable_get(:@loaded_from)).to eq ["app/lib"]
|
|
147
|
-
expect($app_lib_class_loaded).to be true
|
|
148
|
-
expect($app_class_loaded).to be nil
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
# rubocop:enable Style/GlobalVars
|
|
152
|
-
end
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Code loading / Loading from lib directory", :app_integration do
|
|
4
|
-
describe "default root" do
|
|
5
|
-
before :context do
|
|
6
|
-
with_directory(@dir = make_tmp_directory.realpath) 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 "lib/external_class.rb", <<~'RUBY'
|
|
17
|
-
class ExternalClass
|
|
18
|
-
end
|
|
19
|
-
RUBY
|
|
20
|
-
|
|
21
|
-
write "lib/test_app/test_class.rb", <<~'RUBY'
|
|
22
|
-
module TestApp
|
|
23
|
-
class TestClass
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
RUBY
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "setup app" do
|
|
31
|
-
before do
|
|
32
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "adds the lib directory to the load path" do
|
|
36
|
-
expect($LOAD_PATH).to include(@dir.join("lib").to_s)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
specify "classes in lib/ can be required directly" do
|
|
40
|
-
expect(require("external_class")).to be true
|
|
41
|
-
expect(ExternalClass).to be
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
specify "classes in lib/[app_namespace]/ cannot yet be autoloaded" do
|
|
45
|
-
expect { TestApp::TestClass }.to raise_error(NameError)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "prepared app" do
|
|
50
|
-
before do
|
|
51
|
-
with_directory(@dir) { require "hanami/prepare" }
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "leaves the lib directory already in the load path" do
|
|
55
|
-
expect($LOAD_PATH).to include(@dir.join("lib").to_s).exactly(1).times
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
specify "classes in lib/[app_namespace]/ can be autoloaded" do
|
|
59
|
-
expect(TestApp::TestClass).to be
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context "lib dir missing" do
|
|
64
|
-
before do
|
|
65
|
-
with_directory(@dir = make_tmp_directory.realpath) do
|
|
66
|
-
write "config/app.rb", <<~'RUBY'
|
|
67
|
-
require "hanami"
|
|
68
|
-
|
|
69
|
-
module TestApp
|
|
70
|
-
class App < Hanami::App
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
RUBY
|
|
74
|
-
|
|
75
|
-
require "hanami/setup"
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "does not add the lib directory to the load path" do
|
|
80
|
-
expect($LOAD_PATH).not_to include(@dir.join("lib").to_s)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe "default root with requires at top of app file" do
|
|
86
|
-
before :context do
|
|
87
|
-
with_directory(@dir = make_tmp_directory.realpath) do
|
|
88
|
-
write "config/app.rb", <<~'RUBY'
|
|
89
|
-
require "hanami"
|
|
90
|
-
require "external_class"
|
|
91
|
-
|
|
92
|
-
module TestApp
|
|
93
|
-
class App < Hanami::App
|
|
94
|
-
@class_from_lib = ExternalClass
|
|
95
|
-
|
|
96
|
-
def self.class_from_lib
|
|
97
|
-
@class_from_lib
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
RUBY
|
|
102
|
-
|
|
103
|
-
write "lib/external_class.rb", <<~'RUBY'
|
|
104
|
-
class ExternalClass
|
|
105
|
-
end
|
|
106
|
-
RUBY
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
before do
|
|
111
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
specify "classes in lib/ can be required directly from the top of the app file" do
|
|
115
|
-
expect(Hanami.app.class_from_lib).to be ExternalClass
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context "app root reconfigured" do
|
|
120
|
-
before :context do
|
|
121
|
-
with_directory(@dir = make_tmp_directory.realpath) do
|
|
122
|
-
write "config/app.rb", <<~'RUBY'
|
|
123
|
-
require "hanami"
|
|
124
|
-
|
|
125
|
-
module TestApp
|
|
126
|
-
class App < Hanami::App
|
|
127
|
-
config.root = Pathname(__dir__).join("..", "src").realpath
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
RUBY
|
|
131
|
-
|
|
132
|
-
write "src/lib/external_class.rb", <<~'RUBY'
|
|
133
|
-
class ExternalClass
|
|
134
|
-
end
|
|
135
|
-
RUBY
|
|
136
|
-
|
|
137
|
-
write "src/lib/test_app/test_class.rb", <<~'RUBY'
|
|
138
|
-
module TestApp
|
|
139
|
-
class TestClass
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
RUBY
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context "setup app" do
|
|
147
|
-
before do
|
|
148
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "does not add the lib directory to the load path (already done at time of subclassing)" do
|
|
152
|
-
expect($LOAD_PATH).not_to include(@dir.join("src", "lib").to_s)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "adds the lib directory under the new root with `prepare_load_path`" do
|
|
156
|
-
expect { Hanami.app.prepare_load_path }
|
|
157
|
-
.to change { $LOAD_PATH }
|
|
158
|
-
.to include(@dir.join("src", "lib").to_s)
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
context "prepared app" do
|
|
163
|
-
before do
|
|
164
|
-
with_directory(@dir) { require "hanami/prepare" }
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "adds the lib directory to the load path" do
|
|
168
|
-
expect($LOAD_PATH).to include(@dir.join("src", "lib").to_s)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
specify "classes in lib/ can be required directly" do
|
|
172
|
-
expect(require("external_class")).to be true
|
|
173
|
-
expect(ExternalClass).to be
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
specify "classes in lib/[app_namespace]/ can be autoloaded" do
|
|
177
|
-
expect(TestApp::TestClass).to be
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
context "app root reconfigured and load path immediately prepared" do
|
|
183
|
-
before :context do
|
|
184
|
-
with_directory(@dir = make_tmp_directory.realpath) do
|
|
185
|
-
write "config/app.rb", <<~'RUBY'
|
|
186
|
-
require "hanami"
|
|
187
|
-
|
|
188
|
-
module TestApp
|
|
189
|
-
class App < Hanami::App
|
|
190
|
-
config.root = Pathname(__dir__).join("..", "src").realpath and prepare_load_path
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
RUBY
|
|
194
|
-
|
|
195
|
-
write "src/lib/external_class.rb", <<~'RUBY'
|
|
196
|
-
class ExternalClass
|
|
197
|
-
end
|
|
198
|
-
RUBY
|
|
199
|
-
|
|
200
|
-
write "src/lib/test_app/test_class.rb", <<~'RUBY'
|
|
201
|
-
module TestApp
|
|
202
|
-
class TestClass
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
RUBY
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context "setup app" do
|
|
210
|
-
before do
|
|
211
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
it "adds the lib directory to the load path" do
|
|
215
|
-
expect($LOAD_PATH).to include(@dir.join("src", "lib").to_s)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
specify "classes in lib/ can be required directly" do
|
|
219
|
-
expect(require("external_class")).to be true
|
|
220
|
-
expect(ExternalClass).to be
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
specify "classes in lib/[app_namespace]/ cannot yet be autoloaded" do
|
|
224
|
-
expect { TestApp::TestClass }.to raise_error(NameError)
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
context "prepared app" do
|
|
229
|
-
before do
|
|
230
|
-
with_directory(@dir) { require "hanami/prepare" }
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it "leaves the lib directory to the load path" do
|
|
234
|
-
expect($LOAD_PATH).to include(@dir.join("src", "lib").to_s).exactly(1).times
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
specify "classes in lib/[app_namespace]/ can be autoloaded" do
|
|
238
|
-
expect(TestApp::TestClass).to be
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
end
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Code loading / Loading from slice directory", :app_integration do
|
|
4
|
-
before :context do
|
|
5
|
-
with_directory(@dir = make_tmp_directory) do
|
|
6
|
-
write "config/app.rb", <<~'RUBY'
|
|
7
|
-
require "hanami"
|
|
8
|
-
|
|
9
|
-
module TestApp
|
|
10
|
-
class App < Hanami::App
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
RUBY
|
|
14
|
-
|
|
15
|
-
write "slices/main/config/not_loadable.rb", <<~'RUBY'
|
|
16
|
-
raise "This file should never be loaded"
|
|
17
|
-
RUBY
|
|
18
|
-
|
|
19
|
-
write "slices/main/test_class.rb", <<~'RUBY'
|
|
20
|
-
module Main
|
|
21
|
-
class TestClass
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
RUBY
|
|
25
|
-
|
|
26
|
-
write "slices/main/action.rb", <<~'RUBY'
|
|
27
|
-
# auto_register: false
|
|
28
|
-
|
|
29
|
-
module Main
|
|
30
|
-
class Action < Hanami::Action
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
RUBY
|
|
34
|
-
|
|
35
|
-
write "slices/main/actions/home/show.rb", <<~'RUBY'
|
|
36
|
-
module Main
|
|
37
|
-
module Actions
|
|
38
|
-
module Home
|
|
39
|
-
class Show < Main::Action
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
RUBY
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
before do
|
|
49
|
-
with_directory(@dir) do
|
|
50
|
-
require "hanami/prepare"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
specify "Classes in slice directory are autoloaded with the slice namespace" do
|
|
55
|
-
expect(Main::TestClass).to be
|
|
56
|
-
expect(Main::Action).to be
|
|
57
|
-
expect(Main::Actions::Home::Show).to be
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
specify "Files in slice config/ directory are not autoloaded" do
|
|
61
|
-
expect { Main::NotLoadable }.to raise_error NameError
|
|
62
|
-
expect { Main::Config::NotLoadable }.to raise_error NameError
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
specify "Classes in slice directory are auto-registered" do
|
|
66
|
-
expect(Main::Slice["test_class"]).to be_an_instance_of Main::TestClass
|
|
67
|
-
expect(Main::Slice["actions.home.show"]).to be_an_instance_of Main::Actions::Home::Show
|
|
68
|
-
|
|
69
|
-
# Files with "auto_register: false" magic comments are not auto-registered
|
|
70
|
-
expect(Main::Slice.key?("action")).to be false
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
specify "Files in slice config/ directory are not auto-registered" do
|
|
74
|
-
expect(Main::Slice.key?("config.settings")).to be false
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "slice lib/ directory" do
|
|
78
|
-
before :context do
|
|
79
|
-
with_directory(@dir = make_tmp_directory) do
|
|
80
|
-
write "config/app.rb", <<~'RUBY'
|
|
81
|
-
require "hanami"
|
|
82
|
-
|
|
83
|
-
module TestApp
|
|
84
|
-
class App < Hanami::App
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
RUBY
|
|
88
|
-
|
|
89
|
-
write "slices/main/lib/test_class.rb", <<~'RUBY'
|
|
90
|
-
module Main
|
|
91
|
-
class TestClass
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
RUBY
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
specify "Classes in slice lib/ directory are autoloaded with the slice namespace" do
|
|
99
|
-
expect(Main::TestClass).to be
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
specify "Classes in slice lib/ directory are auto-registered" do
|
|
103
|
-
expect(Main::Slice["test_class"]).to be_an_instance_of Main::TestClass
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
specify "Classes in slice lib/ directory are not redundantly auto-registered under 'lib' key namespace" do
|
|
107
|
-
expect(Main::Slice.key?("lib.test_class")).to be false
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# rubocop:disable Style/GlobalVars
|
|
112
|
-
describe "same-named class defined in both slice and lib/ directories" do
|
|
113
|
-
before :context do
|
|
114
|
-
with_directory(@dir = make_tmp_directory) do
|
|
115
|
-
write "config/app.rb", <<~'RUBY'
|
|
116
|
-
require "hanami"
|
|
117
|
-
|
|
118
|
-
module TestApp
|
|
119
|
-
class App < Hanami::App
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
RUBY
|
|
123
|
-
|
|
124
|
-
write "slices/main/test_class.rb", <<~'RUBY'
|
|
125
|
-
$slice_class_loaded = true
|
|
126
|
-
|
|
127
|
-
module Main
|
|
128
|
-
class TestClass
|
|
129
|
-
(@loaded_from ||= []) << "slice"
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
RUBY
|
|
133
|
-
|
|
134
|
-
write "slices/main/lib/test_class.rb", <<~'RUBY'
|
|
135
|
-
$slice_lib_class_loaded = true
|
|
136
|
-
|
|
137
|
-
module Main
|
|
138
|
-
class TestClass
|
|
139
|
-
(@loaded_from ||= []) << "slice/lib"
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
RUBY
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
after do
|
|
147
|
-
$slice_class_loaded = $slice_lib_class_loaded = nil
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
specify "Classes in slice lib/ directory are preferred for autoloading" do
|
|
151
|
-
expect(Main::TestClass).to be
|
|
152
|
-
expect(Main::TestClass.instance_variable_get(:@loaded_from)).to eq ["slice/lib"]
|
|
153
|
-
expect($slice_lib_class_loaded).to be true
|
|
154
|
-
expect($slice_class_loaded).to be nil
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
specify "Classes in slice lib/ directory are preferred for auto-registration" do
|
|
158
|
-
expect(Main::Slice["test_class"]).to be
|
|
159
|
-
expect(Main::TestClass.instance_variable_get(:@loaded_from)).to eq ["slice/lib"]
|
|
160
|
-
expect($slice_lib_class_loaded).to be true
|
|
161
|
-
expect($slice_class_loaded).to be nil
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
# rubocop:enable Style/GlobalVars
|
|
165
|
-
end
|