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,48 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "stringio"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "App routes helper", :app_integration do
|
|
6
|
-
specify "Routing to actions based on their container identifiers" 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
|
-
config.logger.stream = StringIO.new
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
RUBY
|
|
17
|
-
|
|
18
|
-
write "config/routes.rb", <<~RUBY
|
|
19
|
-
module TestApp
|
|
20
|
-
class Routes < Hanami::Routes
|
|
21
|
-
root to: "home.index"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
RUBY
|
|
25
|
-
|
|
26
|
-
write "app/actions/home/index.rb", <<~RUBY
|
|
27
|
-
require "hanami/action"
|
|
28
|
-
|
|
29
|
-
module TestApp
|
|
30
|
-
module Actions
|
|
31
|
-
module Home
|
|
32
|
-
class Index < Hanami::Action
|
|
33
|
-
def handle(*, res)
|
|
34
|
-
res.body = "Hello world"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
RUBY
|
|
41
|
-
|
|
42
|
-
require "hanami/prepare"
|
|
43
|
-
|
|
44
|
-
expect(TestApp::App["routes"].path(:root)).to eq "/"
|
|
45
|
-
expect(TestApp::App["routes"].url(:root).to_s).to match /http:\/\/.*\//
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container auto-injection (aka \"Deps\") mixin", :app_integration do
|
|
4
|
-
# rubocop:disable Metrics/MethodLength
|
|
5
|
-
def with_app
|
|
6
|
-
with_tmp_directory(Dir.mktmpdir) 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 "app/some_service.rb", <<~'RUBY'
|
|
17
|
-
module TestApp
|
|
18
|
-
class SomeService
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
RUBY
|
|
22
|
-
|
|
23
|
-
write "app/some_operation.rb", <<~'RUBY'
|
|
24
|
-
module TestApp
|
|
25
|
-
class SomeOperation
|
|
26
|
-
include Deps["some_service"]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
RUBY
|
|
30
|
-
|
|
31
|
-
yield
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
# rubocop:enable Metrics/MethodLength
|
|
35
|
-
|
|
36
|
-
specify "Dependencies are auto-injected in a booted app" do
|
|
37
|
-
with_app do
|
|
38
|
-
require "hanami/boot"
|
|
39
|
-
|
|
40
|
-
op = TestApp::App["some_operation"]
|
|
41
|
-
expect(op.some_service).to be_a TestApp::SomeService
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
specify "Dependencies are lazily resolved and auto-injected in an unbooted app" do
|
|
46
|
-
with_app do
|
|
47
|
-
require "hanami/prepare"
|
|
48
|
-
|
|
49
|
-
op = TestApp::App["some_operation"]
|
|
50
|
-
expect(op.some_service).to be_a TestApp::SomeService
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container auto-registration", :app_integration do
|
|
4
|
-
specify "Auto-registering files in slice source directories" do
|
|
5
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
require "hanami"
|
|
8
|
-
|
|
9
|
-
module TestApp
|
|
10
|
-
class App < Hanami::App
|
|
11
|
-
config.inflections do |inflections|
|
|
12
|
-
inflections.acronym "NBA"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
RUBY
|
|
17
|
-
|
|
18
|
-
write "app/action.rb", <<~RUBY
|
|
19
|
-
# auto_register: false
|
|
20
|
-
require "hanami/action"
|
|
21
|
-
|
|
22
|
-
module TestApp
|
|
23
|
-
class Action < Hanami::Action
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
RUBY
|
|
27
|
-
|
|
28
|
-
write "app/actions/nba_rosters/index.rb", <<~RUBY
|
|
29
|
-
module TestApp
|
|
30
|
-
module Actions
|
|
31
|
-
module NBARosters
|
|
32
|
-
class Index < TestApp::Action
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
RUBY
|
|
38
|
-
|
|
39
|
-
write "slices/admin/lib/nba_jam/get_that_outta_here.rb", <<~RUBY
|
|
40
|
-
module Admin
|
|
41
|
-
module NBAJam
|
|
42
|
-
class GetThatOuttaHere
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
RUBY
|
|
47
|
-
|
|
48
|
-
require "hanami/setup"
|
|
49
|
-
Hanami.boot
|
|
50
|
-
|
|
51
|
-
expect(TestApp::App["actions.nba_rosters.index"]).to be_an TestApp::Actions::NBARosters::Index
|
|
52
|
-
expect(Admin::Slice["nba_jam.get_that_outta_here"]).to be_an Admin::NBAJam::GetThatOuttaHere
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "Unbooted app resolves components lazily from the lib/ directories" do
|
|
57
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
58
|
-
write "config/app.rb", <<~RUBY
|
|
59
|
-
require "hanami"
|
|
60
|
-
|
|
61
|
-
module TestApp
|
|
62
|
-
class App < Hanami::App
|
|
63
|
-
config.inflections do |inflections|
|
|
64
|
-
inflections.acronym "NBA"
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
RUBY
|
|
69
|
-
|
|
70
|
-
write "slices/admin/lib/nba_jam/get_that_outta_here.rb", <<~RUBY
|
|
71
|
-
module Admin
|
|
72
|
-
module NBAJam
|
|
73
|
-
class GetThatOuttaHere
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
RUBY
|
|
78
|
-
|
|
79
|
-
require "hanami/prepare"
|
|
80
|
-
|
|
81
|
-
expect(Admin::Slice.keys).not_to include("nba_jam.get_that_outta_here")
|
|
82
|
-
expect(Admin::Slice["nba_jam.get_that_outta_here"]).to be_an Admin::NBAJam::GetThatOuttaHere
|
|
83
|
-
expect(Admin::Slice.keys).to include("nba_jam.get_that_outta_here")
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
RSpec.describe "App autoloader", :app_integration do
|
|
2
|
-
specify "Classes are autoloaded through direct reference, including through components resolved from the container" do
|
|
3
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
4
|
-
write "config/app.rb", <<~RUBY
|
|
5
|
-
require "hanami"
|
|
6
|
-
|
|
7
|
-
module TestApp
|
|
8
|
-
class App < Hanami::App
|
|
9
|
-
# Use a custom inflection to ensure this is respected by the autoloader
|
|
10
|
-
config.inflections do |inflections|
|
|
11
|
-
inflections.acronym "NBA"
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
RUBY
|
|
16
|
-
|
|
17
|
-
write "lib/non_app/thing.rb", <<~RUBY
|
|
18
|
-
module NonApp
|
|
19
|
-
class Thing
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "lib/test_app/nba_jam/get_that_outta_here.rb", <<~RUBY
|
|
25
|
-
module TestApp
|
|
26
|
-
module NBAJam
|
|
27
|
-
class GetThatOuttaHere
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
RUBY
|
|
32
|
-
|
|
33
|
-
write "slices/admin/lib/operations/create_game.rb", <<~RUBY
|
|
34
|
-
module Admin
|
|
35
|
-
module Operations
|
|
36
|
-
class CreateGame
|
|
37
|
-
def call
|
|
38
|
-
Entities::Game.new
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
RUBY
|
|
44
|
-
|
|
45
|
-
write "slices/admin/lib/entities/game.rb", <<~RUBY
|
|
46
|
-
# auto_register: false
|
|
47
|
-
|
|
48
|
-
module Admin
|
|
49
|
-
module Entities
|
|
50
|
-
class Game
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
RUBY
|
|
55
|
-
|
|
56
|
-
write "slices/admin/lib/entities/quarter.rb", <<~RUBY
|
|
57
|
-
# auto_register: false
|
|
58
|
-
|
|
59
|
-
module Admin
|
|
60
|
-
module Entities
|
|
61
|
-
class Quarter
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
RUBY
|
|
66
|
-
|
|
67
|
-
require "hanami/prepare"
|
|
68
|
-
|
|
69
|
-
expect(require("non_app/thing")).to be true
|
|
70
|
-
expect(NonApp::Thing).to be
|
|
71
|
-
|
|
72
|
-
expect(TestApp::NBAJam::GetThatOuttaHere).to be
|
|
73
|
-
expect(TestApp::App.autoloader.tag).to eq("hanami.app.test_app")
|
|
74
|
-
|
|
75
|
-
expect(Admin::Slice["operations.create_game"]).to be_an_instance_of(Admin::Operations::CreateGame)
|
|
76
|
-
expect(Admin::Slice["operations.create_game"].call).to be_an_instance_of(Admin::Entities::Game)
|
|
77
|
-
|
|
78
|
-
expect(Admin::Entities::Quarter).to be
|
|
79
|
-
expect(Admin::Slice.autoloader.tag).to eq("hanami.slices.admin")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container imports", :app_integration do
|
|
4
|
-
xspecify "App container is imported into slice containers by default" do
|
|
5
|
-
with_tmp_directory(Dir.mktmpdir) 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 "config/slices/admin.rb", <<~RUBY
|
|
16
|
-
module Admin
|
|
17
|
-
class Slice < Hanami::Slice
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
RUBY
|
|
21
|
-
|
|
22
|
-
require "hanami/setup"
|
|
23
|
-
|
|
24
|
-
Hanami.prepare
|
|
25
|
-
|
|
26
|
-
shared_service = Object.new
|
|
27
|
-
TestApp::App.register("shared_service", shared_service)
|
|
28
|
-
|
|
29
|
-
Hanami.boot
|
|
30
|
-
|
|
31
|
-
expect(Admin::Slice["shared_service"]).to be shared_service
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
specify "Slices can import other slices" do
|
|
36
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
37
|
-
write "config/app.rb", <<~RUBY
|
|
38
|
-
require "hanami"
|
|
39
|
-
|
|
40
|
-
module TestApp
|
|
41
|
-
class App < Hanami::App
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
RUBY
|
|
45
|
-
|
|
46
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
47
|
-
module Admin
|
|
48
|
-
class Slice < Hanami::Slice
|
|
49
|
-
import from: :search
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
RUBY
|
|
53
|
-
|
|
54
|
-
write "slices/search/lib/index_entity.rb", <<~RUBY
|
|
55
|
-
module Search
|
|
56
|
-
class IndexEntity
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
RUBY
|
|
60
|
-
|
|
61
|
-
require "hanami/boot"
|
|
62
|
-
|
|
63
|
-
expect(Admin::Slice["search.index_entity"]).to be_a Search::IndexEntity
|
|
64
|
-
|
|
65
|
-
# Ensure a slice's imported components (e.g. from "app") are not then
|
|
66
|
-
# exported again when that slice is imported, which would result in redundant
|
|
67
|
-
# components
|
|
68
|
-
expect(Search::Slice.key?("logger")).to be true
|
|
69
|
-
expect(Admin::Slice.key?("logger")).to be true
|
|
70
|
-
expect(Admin::Slice.key?("search.logger")).to be false
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
specify "Slices can import specific components from other slices" do
|
|
75
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
76
|
-
write "config/app.rb", <<~RUBY
|
|
77
|
-
require "hanami"
|
|
78
|
-
|
|
79
|
-
module TestApp
|
|
80
|
-
class App < Hanami::App
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
RUBY
|
|
84
|
-
|
|
85
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
86
|
-
module Admin
|
|
87
|
-
class Slice < Hanami::Slice
|
|
88
|
-
import(
|
|
89
|
-
keys: ["query"],
|
|
90
|
-
from: :search
|
|
91
|
-
)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
RUBY
|
|
95
|
-
|
|
96
|
-
write "slices/search/lib/index_entity.rb", <<~RUBY
|
|
97
|
-
module Search
|
|
98
|
-
class IndexEntity; end
|
|
99
|
-
end
|
|
100
|
-
RUBY
|
|
101
|
-
|
|
102
|
-
write "slices/search/lib/query.rb", <<~RUBY
|
|
103
|
-
module Search
|
|
104
|
-
class Query; end
|
|
105
|
-
end
|
|
106
|
-
RUBY
|
|
107
|
-
|
|
108
|
-
require "hanami/setup"
|
|
109
|
-
Hanami.boot
|
|
110
|
-
|
|
111
|
-
expect(Admin::Slice["search.query"]).to be_a Search::Query
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
specify "Slices can import from other slices with a custom import key namespace" do
|
|
116
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
117
|
-
write "config/app.rb", <<~RUBY
|
|
118
|
-
require "hanami"
|
|
119
|
-
|
|
120
|
-
module TestApp
|
|
121
|
-
class App < Hanami::App
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
RUBY
|
|
125
|
-
|
|
126
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
127
|
-
module Admin
|
|
128
|
-
class Slice < Hanami::Slice
|
|
129
|
-
import(
|
|
130
|
-
keys: ["query"],
|
|
131
|
-
from: :search,
|
|
132
|
-
as: :search_engine
|
|
133
|
-
)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
RUBY
|
|
137
|
-
|
|
138
|
-
write "slices/search/lib/index_entity.rb", <<~RUBY
|
|
139
|
-
module Search
|
|
140
|
-
class IndexEntity; end
|
|
141
|
-
end
|
|
142
|
-
RUBY
|
|
143
|
-
|
|
144
|
-
write "slices/search/lib/query.rb", <<~RUBY
|
|
145
|
-
module Search
|
|
146
|
-
class Query; end
|
|
147
|
-
end
|
|
148
|
-
RUBY
|
|
149
|
-
|
|
150
|
-
require "hanami/boot"
|
|
151
|
-
|
|
152
|
-
expect(Admin::Slice["search_engine.query"]).to be_a Search::Query
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
specify "Imported components from another slice are lazily resolved in unbooted apps" do
|
|
157
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
158
|
-
write "config/app.rb", <<~RUBY
|
|
159
|
-
require "hanami"
|
|
160
|
-
|
|
161
|
-
module TestApp
|
|
162
|
-
class App < Hanami::App
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
RUBY
|
|
166
|
-
|
|
167
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
168
|
-
module Admin
|
|
169
|
-
class Slice < Hanami::Slice
|
|
170
|
-
import from: :search
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
RUBY
|
|
174
|
-
|
|
175
|
-
write "slices/admin/lib/admin/test_op.rb", <<~RUBY
|
|
176
|
-
module Admin
|
|
177
|
-
class TestOp
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
RUBY
|
|
181
|
-
|
|
182
|
-
write "slices/search/lib/index_entity.rb", <<~RUBY
|
|
183
|
-
module Search
|
|
184
|
-
class IndexEntity
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
RUBY
|
|
188
|
-
|
|
189
|
-
require "hanami/prepare"
|
|
190
|
-
|
|
191
|
-
expect(Hanami.app).not_to be_booted
|
|
192
|
-
|
|
193
|
-
expect(Admin::Slice.keys).not_to include "search.index_entity"
|
|
194
|
-
expect(Admin::Slice["search.index_entity"]).to be_a Search::IndexEntity
|
|
195
|
-
expect(Admin::Slice.keys).to include "search.index_entity"
|
|
196
|
-
|
|
197
|
-
expect(Admin::Slice).not_to be_booted
|
|
198
|
-
expect(Admin::Slice.container).not_to be_finalized
|
|
199
|
-
expect(Search::Slice).not_to be_booted
|
|
200
|
-
expect(Search::Slice.container).not_to be_finalized
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
specify "Slices can configure specific exports" do
|
|
205
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
206
|
-
write "config/app.rb", <<~RUBY
|
|
207
|
-
require "hanami"
|
|
208
|
-
|
|
209
|
-
module TestApp
|
|
210
|
-
class App < Hanami::App
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
RUBY
|
|
214
|
-
|
|
215
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
216
|
-
module Admin
|
|
217
|
-
class Slice < Hanami::Slice
|
|
218
|
-
import(
|
|
219
|
-
keys: %w[index_entity query],
|
|
220
|
-
from: :search
|
|
221
|
-
)
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
RUBY
|
|
225
|
-
|
|
226
|
-
write "config/slices/search.rb", <<~RUBY
|
|
227
|
-
module Search
|
|
228
|
-
class Slice < Hanami::Slice
|
|
229
|
-
export(%w[query])
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
RUBY
|
|
233
|
-
|
|
234
|
-
write "slices/search/lib/index_entity.rb", <<~RUBY
|
|
235
|
-
module Search
|
|
236
|
-
class IndexEntity; end
|
|
237
|
-
end
|
|
238
|
-
RUBY
|
|
239
|
-
|
|
240
|
-
write "slices/search/lib/query.rb", <<~RUBY
|
|
241
|
-
module Search
|
|
242
|
-
class Query; end
|
|
243
|
-
end
|
|
244
|
-
RUBY
|
|
245
|
-
|
|
246
|
-
require "hanami/setup"
|
|
247
|
-
Hanami.boot
|
|
248
|
-
|
|
249
|
-
expect(Admin::Slice.key?("search.query")).to be true
|
|
250
|
-
expect(Admin::Slice.key?("search.index_entity")).to be false
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
end
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container / prepare_container", :app_integration do
|
|
4
|
-
# (Most of) the examples below make their expectations on a `container_to_prepare`,
|
|
5
|
-
# which is the container yielded to the `Slice.prepare_container` block _at the moment
|
|
6
|
-
# it is called_.
|
|
7
|
-
#
|
|
8
|
-
# This around hook ensures the examples are run at the right time and container is
|
|
9
|
-
# available to each.
|
|
10
|
-
around(in_prepare_container: true) do |example|
|
|
11
|
-
# Eagerly capture @loaded_features here (see spec/support/app_integration.rb) since
|
|
12
|
-
# around hooks are run before any before hooks (where we ordinarily capture
|
|
13
|
-
# @loaded_features), and by invoking `example_group_instance.subject` below, we're
|
|
14
|
-
# making requires that we want to ensure are properly cleaned between examples.
|
|
15
|
-
@loaded_features = $LOADED_FEATURES.dup
|
|
16
|
-
|
|
17
|
-
slice = example.example_group_instance.subject
|
|
18
|
-
|
|
19
|
-
slice.prepare_container do |container|
|
|
20
|
-
example.example.example_group.let(:container_to_prepare) { container }
|
|
21
|
-
example.run
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# The prepare_container block is called when the slice is prepared
|
|
25
|
-
slice.prepare
|
|
26
|
-
|
|
27
|
-
autoloaders_teardown!
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "in app", :in_prepare_container do
|
|
31
|
-
before :context do
|
|
32
|
-
with_directory(@dir = make_tmp_directory) do
|
|
33
|
-
write "config/app.rb", <<~'RUBY'
|
|
34
|
-
module TestApp
|
|
35
|
-
class App < Hanami::App
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
RUBY
|
|
39
|
-
|
|
40
|
-
write "app/.keep", ""
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
subject {
|
|
45
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
46
|
-
Hanami.app
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
it "receives the container for the app" do
|
|
50
|
-
expect(container_to_prepare).to be TestApp::Container
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
specify "the container has been already configured by the app" do
|
|
54
|
-
expect(container_to_prepare.config.component_dirs.dir("app")).to be
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
specify "the container is not yet marked as configured" do
|
|
58
|
-
expect(container_to_prepare).not_to be_configured
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "after app is prepared", in_prepare_container: false do
|
|
62
|
-
before do
|
|
63
|
-
subject.prepare_container do |container|
|
|
64
|
-
container.config.name = :custom_name
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "preserves any container configuration changes made via the block" do
|
|
69
|
-
expect { subject.prepare }
|
|
70
|
-
.to change { subject.container.config.name }
|
|
71
|
-
.to :custom_name
|
|
72
|
-
|
|
73
|
-
expect(subject.container).to be_configured
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "in slice", :in_prepare_container do
|
|
79
|
-
before :context do
|
|
80
|
-
with_directory(@dir = make_tmp_directory) do
|
|
81
|
-
write "config/app.rb", <<~'RUBY'
|
|
82
|
-
module TestApp
|
|
83
|
-
class App < Hanami::App
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
RUBY
|
|
87
|
-
|
|
88
|
-
write "slices/main/.keep", ""
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
subject {
|
|
93
|
-
with_directory(@dir) { require "hanami/setup" }
|
|
94
|
-
Hanami.app.register_slice(:main)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
it "receives the container for the slice" do
|
|
98
|
-
expect(container_to_prepare).to be Main::Container
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
specify "the container has been already configured by the slice" do
|
|
102
|
-
expect(container_to_prepare.config.component_dirs.dir("")).to be
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
specify "the container is not yet marked as configured" do
|
|
106
|
-
expect(container_to_prepare).not_to be_configured
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe "after slice is prepared", in_prepare_container: false do
|
|
110
|
-
before do
|
|
111
|
-
subject.prepare_container do |container|
|
|
112
|
-
container.config.name = :custom_name
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "preserves any container configuration changes made via the block" do
|
|
117
|
-
expect { subject.prepare }
|
|
118
|
-
.to change { subject.container.config.name }
|
|
119
|
-
.to :custom_name
|
|
120
|
-
|
|
121
|
-
expect(subject.container).to be_configured
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container / Provider environment", :app_integration do
|
|
4
|
-
let!(:app) {
|
|
5
|
-
module TestApp
|
|
6
|
-
class App < Hanami::App
|
|
7
|
-
class << self
|
|
8
|
-
attr_accessor :test_provider_target
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
before_prepare if respond_to?(:before_prepare)
|
|
14
|
-
|
|
15
|
-
Hanami.app.prepare
|
|
16
|
-
Hanami.app
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
context "app provider" do
|
|
20
|
-
before do
|
|
21
|
-
Hanami.app.register_provider :test_provider, namespace: true do
|
|
22
|
-
start do
|
|
23
|
-
Hanami.app.test_provider_target = target
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "exposes the app as the provider target" do
|
|
29
|
-
Hanami.app.start :test_provider
|
|
30
|
-
expect(Hanami.app.test_provider_target).to be Hanami.app
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "slice provider" do
|
|
35
|
-
def before_prepare
|
|
36
|
-
Hanami.app.register_slice :main
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
Main::Slice.register_provider :test_provider, namespace: true do
|
|
41
|
-
start do
|
|
42
|
-
Hanami.app.test_provider_target = target
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "exposes the slice as the provider target" do
|
|
48
|
-
Main::Slice.start :test_provider
|
|
49
|
-
expect(Hanami.app.test_provider_target).to be Main::Slice
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|