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,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Container / Provider lifecycle", :app_integration do
|
|
4
|
-
let!(:slice) {
|
|
5
|
-
module TestApp
|
|
6
|
-
class App < Hanami::App
|
|
7
|
-
register_provider :connection do
|
|
8
|
-
prepare do
|
|
9
|
-
module ::TestApp
|
|
10
|
-
class Connection
|
|
11
|
-
def initialize
|
|
12
|
-
@connected = true
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def disconnect
|
|
16
|
-
@connected = false
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def connected?
|
|
20
|
-
@connected
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
start do
|
|
27
|
-
register("connection", TestApp::Connection.new)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
stop do
|
|
31
|
-
container["connection"].disconnect
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
TestApp::App
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
require "hanami/setup"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
specify "individual providers can be prepared, started and stopped" do
|
|
45
|
-
expect { TestApp::Connection }.to raise_error NameError
|
|
46
|
-
|
|
47
|
-
slice.prepare :connection
|
|
48
|
-
|
|
49
|
-
expect(TestApp::Connection).to be
|
|
50
|
-
expect(slice.container.registered?("connection")).to be false
|
|
51
|
-
|
|
52
|
-
slice.start :connection
|
|
53
|
-
|
|
54
|
-
expect(slice.container.registered?("connection")).to be true
|
|
55
|
-
expect(slice["connection"]).to be_connected
|
|
56
|
-
|
|
57
|
-
slice.stop :connection
|
|
58
|
-
|
|
59
|
-
expect(slice["connection"]).not_to be_connected
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "App shutdown", :app_integration do
|
|
4
|
-
specify "App shutdown stops providers in both the app and slices" do
|
|
5
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
# frozen_string_literal: true
|
|
8
|
-
|
|
9
|
-
require "hanami"
|
|
10
|
-
|
|
11
|
-
module TestApp
|
|
12
|
-
class App < Hanami::App
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
RUBY
|
|
16
|
-
|
|
17
|
-
write "config/providers/connection.rb", <<~RUBY
|
|
18
|
-
# frozen_string_literal: true
|
|
19
|
-
|
|
20
|
-
Hanami.app.register_provider :connection do
|
|
21
|
-
prepare do
|
|
22
|
-
module TestApp
|
|
23
|
-
class Connection
|
|
24
|
-
attr_reader :connected
|
|
25
|
-
|
|
26
|
-
def initialize
|
|
27
|
-
@connected = true
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def disconnect
|
|
31
|
-
@connected = false
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
start do
|
|
38
|
-
register("connection", TestApp::Connection.new)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
stop do
|
|
42
|
-
container["connection"].disconnect
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
write "slices/main/config/providers/connection.rb", <<~RUBY
|
|
48
|
-
# frozen_string_literal: true
|
|
49
|
-
|
|
50
|
-
Main::Slice.register_provider :connection do
|
|
51
|
-
prepare do
|
|
52
|
-
module Main
|
|
53
|
-
class Connection
|
|
54
|
-
attr_reader :connected
|
|
55
|
-
|
|
56
|
-
def initialize
|
|
57
|
-
@connected = true
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def disconnect
|
|
61
|
-
@connected = false
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
start do
|
|
68
|
-
register "connection", Main::Connection.new
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
stop do
|
|
72
|
-
container["connection"].disconnect
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
RUBY
|
|
76
|
-
|
|
77
|
-
require "hanami/boot"
|
|
78
|
-
|
|
79
|
-
app_connection = Hanami.app["connection"]
|
|
80
|
-
slice_connection = Main::Slice["connection"]
|
|
81
|
-
|
|
82
|
-
expect(app_connection.connected).to be true
|
|
83
|
-
expect(slice_connection.connected).to be true
|
|
84
|
-
|
|
85
|
-
Hanami.shutdown
|
|
86
|
-
|
|
87
|
-
expect(app_connection.connected).to be false
|
|
88
|
-
expect(slice_connection.connected).to be false
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
RSpec.describe "Container / Standard providers / Rack", :app_integration do
|
|
2
|
-
specify "Rack provider is loaded when rack is bundled" 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
|
-
end
|
|
10
|
-
end
|
|
11
|
-
RUBY
|
|
12
|
-
|
|
13
|
-
write "slices/main/.keep", ""
|
|
14
|
-
|
|
15
|
-
require "hanami/prepare"
|
|
16
|
-
|
|
17
|
-
expect(Hanami.app["rack.monitor"]).to be_a_kind_of(Dry::Monitor::Rack::Middleware)
|
|
18
|
-
expect(Main::Slice["rack.monitor"]).to be_a_kind_of(Dry::Monitor::Rack::Middleware)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
specify "Rack provider is not loaded when rack is not bundled" do
|
|
23
|
-
allow(Hanami).to receive(:bundled?).and_call_original
|
|
24
|
-
allow(Hanami).to receive(:bundled?).with("rack").and_return false
|
|
25
|
-
|
|
26
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
27
|
-
write "config/app.rb", <<~RUBY
|
|
28
|
-
require "hanami"
|
|
29
|
-
|
|
30
|
-
module TestApp
|
|
31
|
-
class App < Hanami::App
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
RUBY
|
|
35
|
-
|
|
36
|
-
write "slices/main/.keep", ""
|
|
37
|
-
|
|
38
|
-
require "hanami/prepare"
|
|
39
|
-
|
|
40
|
-
expect(Hanami.app.key?("rack.monitor")).to be false
|
|
41
|
-
expect(Main::Slice.key?("rack.monitor")).to be false
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
RSpec.describe "Container / Standard providers", :app_integration do
|
|
2
|
-
specify "Standard components are available on booted 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
|
-
end
|
|
10
|
-
end
|
|
11
|
-
RUBY
|
|
12
|
-
|
|
13
|
-
require "hanami/setup"
|
|
14
|
-
Hanami.boot
|
|
15
|
-
|
|
16
|
-
expect(Hanami.app.key?(:settings)).to be false
|
|
17
|
-
expect(Hanami.app["inflector"]).to eql Hanami.app.inflector
|
|
18
|
-
expect(Hanami.app["logger"]).to be_a_kind_of(Dry::Logger::Dispatcher)
|
|
19
|
-
expect(Hanami.app["rack.monitor"]).to be_a_kind_of(Dry::Monitor::Rack::Middleware)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
specify "Standard components are resolved lazily on non-booted container" do
|
|
24
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
25
|
-
write "config/app.rb", <<~RUBY
|
|
26
|
-
require "hanami"
|
|
27
|
-
|
|
28
|
-
module TestApp
|
|
29
|
-
class App < Hanami::App
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
require "hanami/setup"
|
|
35
|
-
Hanami.prepare
|
|
36
|
-
|
|
37
|
-
expect(Hanami.app.key?(:settings)).to be false
|
|
38
|
-
expect(Hanami.app["inflector"]).to eql Hanami.app.inflector
|
|
39
|
-
expect(Hanami.app["logger"]).to be_a_kind_of(Dry::Logger::Dispatcher)
|
|
40
|
-
expect(Hanami.app["rack.monitor"]).to be_a_kind_of(Dry::Monitor::Rack::Middleware)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
specify "Settings component is available when settings are defined" do
|
|
45
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
46
|
-
write "config/app.rb", <<~RUBY
|
|
47
|
-
require "hanami"
|
|
48
|
-
|
|
49
|
-
module TestApp
|
|
50
|
-
class App < Hanami::App
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
RUBY
|
|
54
|
-
|
|
55
|
-
write "config/settings.rb", <<~RUBY
|
|
56
|
-
require "hanami/settings"
|
|
57
|
-
|
|
58
|
-
module TestApp
|
|
59
|
-
class Settings < Hanami::Settings
|
|
60
|
-
setting :session_secret
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
RUBY
|
|
64
|
-
|
|
65
|
-
require "hanami/setup"
|
|
66
|
-
Hanami.boot
|
|
67
|
-
|
|
68
|
-
expect(Hanami.app.key?(:settings)).to be true
|
|
69
|
-
expect(Hanami.app[:settings]).to respond_to :session_secret
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
specify "Standard components can be replaced by custom bootable components (on booted container)" do
|
|
74
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
75
|
-
write "config/app.rb", <<~RUBY
|
|
76
|
-
require "hanami"
|
|
77
|
-
|
|
78
|
-
module TestApp
|
|
79
|
-
class App < Hanami::App
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
RUBY
|
|
83
|
-
|
|
84
|
-
write "config/providers/logger.rb", <<~RUBY
|
|
85
|
-
Hanami.app.register_provider :logger do
|
|
86
|
-
start do
|
|
87
|
-
register :logger, "custom logger"
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
RUBY
|
|
91
|
-
|
|
92
|
-
require "hanami/setup"
|
|
93
|
-
Hanami.boot
|
|
94
|
-
|
|
95
|
-
expect(Hanami.app[:logger]).to eq "custom logger"
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
specify "Standard components can be replaced by custom bootable components resolved lazily (on non-booted container)" do
|
|
100
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
101
|
-
write "config/app.rb", <<~RUBY
|
|
102
|
-
require "hanami"
|
|
103
|
-
|
|
104
|
-
module TestApp
|
|
105
|
-
class App < Hanami::App
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
RUBY
|
|
109
|
-
|
|
110
|
-
write "config/providers/logger.rb", <<~RUBY
|
|
111
|
-
Hanami.app.register_provider :logger do
|
|
112
|
-
start do
|
|
113
|
-
register :logger, "custom logger"
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
RUBY
|
|
117
|
-
|
|
118
|
-
require "hanami/setup"
|
|
119
|
-
Hanami.prepare
|
|
120
|
-
|
|
121
|
-
expect(Hanami.app[:logger]).to eq "custom logger"
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / auto-registration", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "does not auto-register files in entities/, structs/, or db/" do
|
|
14
|
-
with_tmp_directory(@dir = Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "app/db/changesets/update_posts.rb", ""
|
|
25
|
-
write "app/entities/post.rb", ""
|
|
26
|
-
write "app/structs/post.rb", ""
|
|
27
|
-
|
|
28
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
29
|
-
|
|
30
|
-
require "hanami/boot"
|
|
31
|
-
|
|
32
|
-
expect(Hanami.app.keys).not_to include(*[
|
|
33
|
-
"db.changesets.update_posts",
|
|
34
|
-
"entities.post",
|
|
35
|
-
"structs.post"
|
|
36
|
-
])
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Commands", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "registers custom commands" do
|
|
14
|
-
with_tmp_directory(@dir = Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
config.logger.stream = File::NULL
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
26
|
-
module TestApp
|
|
27
|
-
module Relations
|
|
28
|
-
class Posts < Hanami::DB::Relation
|
|
29
|
-
schema :posts, infer: true
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
RUBY
|
|
34
|
-
|
|
35
|
-
write "app/db/commands/nested/create_post_with_default_title.rb", <<~RUBY
|
|
36
|
-
module TestApp
|
|
37
|
-
module DB
|
|
38
|
-
module Commands
|
|
39
|
-
module Nested
|
|
40
|
-
class CreatePostWithDefaultTitle < ROM::SQL::Commands::Create
|
|
41
|
-
relation :posts
|
|
42
|
-
register_as :create_with_default_title
|
|
43
|
-
result :one
|
|
44
|
-
|
|
45
|
-
before :set_title
|
|
46
|
-
|
|
47
|
-
def set_title(tuple, *)
|
|
48
|
-
tuple[:title] ||= "Default title from command"
|
|
49
|
-
tuple
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
RUBY
|
|
57
|
-
|
|
58
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
59
|
-
|
|
60
|
-
require "hanami/prepare"
|
|
61
|
-
|
|
62
|
-
Hanami.app.prepare :db
|
|
63
|
-
|
|
64
|
-
# Manually run a migration and add a test record
|
|
65
|
-
gateway = TestApp::App["db.gateway"]
|
|
66
|
-
migration = gateway.migration do
|
|
67
|
-
change do
|
|
68
|
-
create_table :posts do
|
|
69
|
-
primary_key :id
|
|
70
|
-
column :title, :text, null: false
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
migration.apply(gateway, :up)
|
|
75
|
-
|
|
76
|
-
post = TestApp::App["relations.posts"].command(:create_with_default_title).call({})
|
|
77
|
-
expect(post[:title]).to eq "Default title from command"
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/system"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "ROM::Inflector", :app_integration do
|
|
6
|
-
before do
|
|
7
|
-
@env = ENV.to_h
|
|
8
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
after do
|
|
12
|
-
ENV.replace(@env)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
around :each do |example|
|
|
16
|
-
inflector = ROM::Inflector
|
|
17
|
-
ROM.instance_eval {
|
|
18
|
-
remove_const :Inflector
|
|
19
|
-
const_set :Inflector, Dry::Inflector.new
|
|
20
|
-
}
|
|
21
|
-
example.run
|
|
22
|
-
ensure
|
|
23
|
-
ROM.instance_eval {
|
|
24
|
-
remove_const :Inflector
|
|
25
|
-
const_set :Inflector, inflector
|
|
26
|
-
}
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "replaces ROM::Inflector with the Hanami inflector" do
|
|
30
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
31
|
-
write "config/app.rb", <<~RUBY
|
|
32
|
-
require "hanami"
|
|
33
|
-
|
|
34
|
-
module TestApp
|
|
35
|
-
class App < Hanami::App
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
RUBY
|
|
39
|
-
|
|
40
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
41
|
-
module TestApp
|
|
42
|
-
module Relations
|
|
43
|
-
class Posts < Hanami::DB::Relation
|
|
44
|
-
schema :posts, infer: true
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
RUBY
|
|
49
|
-
|
|
50
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
51
|
-
|
|
52
|
-
require "hanami/prepare"
|
|
53
|
-
|
|
54
|
-
expect { Hanami.app.prepare :db }.to change { ROM::Inflector == Hanami.app["inflector"] }.from(false).to(true)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|