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,104 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
require "stringio"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Running a Rack app for a non-booted app", :app_integration do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
|
|
9
|
-
let(:app) { Hanami.app }
|
|
10
|
-
|
|
11
|
-
it "lazy loads only the components required for any accessed routes" do
|
|
12
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
13
|
-
write "config/app.rb", <<~RUBY
|
|
14
|
-
require "hanami"
|
|
15
|
-
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
18
|
-
config.logger.stream = StringIO.new
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
RUBY
|
|
22
|
-
|
|
23
|
-
write "config/routes.rb", <<~RUBY
|
|
24
|
-
require "hanami/routes"
|
|
25
|
-
|
|
26
|
-
module TestApp
|
|
27
|
-
class Routes < Hanami::Routes
|
|
28
|
-
slice :main, at: "/" do
|
|
29
|
-
root to: "home.show"
|
|
30
|
-
get "/articles", to: "articles.index"
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
RUBY
|
|
35
|
-
|
|
36
|
-
write "slices/main/lib/action.rb", <<~RUBY
|
|
37
|
-
# auto_register: false
|
|
38
|
-
|
|
39
|
-
require "hanami/action"
|
|
40
|
-
|
|
41
|
-
module Main
|
|
42
|
-
class Action < Hanami::Action
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
write "slices/main/lib/article_repo.rb", <<~RUBY
|
|
48
|
-
module Main
|
|
49
|
-
class ArticleRepo < Hanami::Action
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
RUBY
|
|
53
|
-
|
|
54
|
-
write "slices/main/lib/greeter.rb", <<~RUBY
|
|
55
|
-
module Main
|
|
56
|
-
class Greeter
|
|
57
|
-
def greeting
|
|
58
|
-
"Hello world"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
RUBY
|
|
63
|
-
|
|
64
|
-
write "slices/main/actions/home/show.rb", <<~RUBY
|
|
65
|
-
module Main
|
|
66
|
-
module Actions
|
|
67
|
-
module Home
|
|
68
|
-
class Show < Main::Action
|
|
69
|
-
include Deps["greeter"]
|
|
70
|
-
|
|
71
|
-
def handle(req, res)
|
|
72
|
-
res.body = greeter.greeting
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
RUBY
|
|
79
|
-
|
|
80
|
-
write "slices/main/actions/articles/index.rb", <<~RUBY
|
|
81
|
-
module Main
|
|
82
|
-
module Actions
|
|
83
|
-
module Articles
|
|
84
|
-
class Index < Main::Action
|
|
85
|
-
include Deps["article_repo"]
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
RUBY
|
|
91
|
-
|
|
92
|
-
require "hanami/prepare"
|
|
93
|
-
|
|
94
|
-
get "/"
|
|
95
|
-
|
|
96
|
-
expect(last_response.status).to eq 200
|
|
97
|
-
expect(last_response.body).to eq "Hello world"
|
|
98
|
-
|
|
99
|
-
expect(Hanami.app).not_to be_booted
|
|
100
|
-
expect(Main::Slice.keys).to include(*%w[actions.home.show greeter])
|
|
101
|
-
expect(Main::Slice.keys).not_to include(*%w[actions.articles.index article_repo])
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rack/test"
|
|
4
|
-
require "stringio"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Hanami web app", :app_integration do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
|
|
9
|
-
let(:app) { Hanami.app }
|
|
10
|
-
|
|
11
|
-
specify "Hanami.app returns a rack builder" do
|
|
12
|
-
with_tmp_directory do
|
|
13
|
-
write "config/app.rb", <<~RUBY
|
|
14
|
-
require "hanami"
|
|
15
|
-
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
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, {}, ["OK"]] }
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
RUBY
|
|
29
|
-
|
|
30
|
-
require "hanami/boot"
|
|
31
|
-
|
|
32
|
-
expect(app).to be(TestApp::App)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
specify "Routing to actions based on their container identifiers" do
|
|
37
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
38
|
-
write "config/app.rb", <<~RUBY
|
|
39
|
-
require "hanami"
|
|
40
|
-
|
|
41
|
-
module TestApp
|
|
42
|
-
class App < Hanami::App
|
|
43
|
-
config.logger.stream = StringIO.new
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
RUBY
|
|
47
|
-
|
|
48
|
-
write "config/routes.rb", <<~RUBY
|
|
49
|
-
module TestApp
|
|
50
|
-
class Routes < Hanami::Routes
|
|
51
|
-
get "/health", to: "health.show"
|
|
52
|
-
|
|
53
|
-
get "/inline" do
|
|
54
|
-
"Inline"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
slice :main, at: "/" do
|
|
58
|
-
root to: "home.index"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
slice :admin, at: "/admin" do
|
|
62
|
-
get "/dashboard", to: "dashboard.show"
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
RUBY
|
|
67
|
-
|
|
68
|
-
write "app/actions/health/show.rb", <<~RUBY
|
|
69
|
-
require "hanami/action"
|
|
70
|
-
|
|
71
|
-
module TestApp
|
|
72
|
-
module Actions
|
|
73
|
-
module Health
|
|
74
|
-
class Show < Hanami::Action
|
|
75
|
-
def handle(*, res)
|
|
76
|
-
res.body = "Health, OK"
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
RUBY
|
|
83
|
-
|
|
84
|
-
write "slices/main/actions/home/index.rb", <<~RUBY
|
|
85
|
-
require "hanami/action"
|
|
86
|
-
|
|
87
|
-
module Main
|
|
88
|
-
module Actions
|
|
89
|
-
module Home
|
|
90
|
-
class Index < Hanami::Action
|
|
91
|
-
def handle(*, res)
|
|
92
|
-
res.body = "Hello world"
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
RUBY
|
|
99
|
-
|
|
100
|
-
write "slices/admin/actions/dashboard/show.rb", <<~RUBY
|
|
101
|
-
require "hanami/action"
|
|
102
|
-
|
|
103
|
-
module Admin
|
|
104
|
-
module Actions
|
|
105
|
-
module Dashboard
|
|
106
|
-
class Show < Hanami::Action
|
|
107
|
-
def handle(*, res)
|
|
108
|
-
res.body = "Admin dashboard here"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
RUBY
|
|
115
|
-
|
|
116
|
-
require "hanami/boot"
|
|
117
|
-
|
|
118
|
-
get "/"
|
|
119
|
-
|
|
120
|
-
expect(last_response.status).to eq 200
|
|
121
|
-
expect(last_response.body).to eq "Hello world"
|
|
122
|
-
|
|
123
|
-
get "/inline"
|
|
124
|
-
|
|
125
|
-
expect(last_response.status).to eq 200
|
|
126
|
-
expect(last_response.body).to eq "Inline"
|
|
127
|
-
|
|
128
|
-
get "/health"
|
|
129
|
-
|
|
130
|
-
expect(last_response.status).to eq 200
|
|
131
|
-
expect(last_response.body).to eq "Health, OK"
|
|
132
|
-
|
|
133
|
-
get "/admin/dashboard"
|
|
134
|
-
|
|
135
|
-
expect(last_response.status).to eq 200
|
|
136
|
-
expect(last_response.body).to eq "Admin dashboard here"
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# TODO: is this test even needed, given this is standard hanami-router behavior?
|
|
141
|
-
specify "It gives priority to the last declared route" do
|
|
142
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
143
|
-
write "config/app.rb", <<~RUBY
|
|
144
|
-
require "hanami"
|
|
145
|
-
|
|
146
|
-
module TestApp
|
|
147
|
-
class App < Hanami::App
|
|
148
|
-
config.logger.stream = StringIO.new
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
RUBY
|
|
152
|
-
|
|
153
|
-
write "config/routes.rb", <<~RUBY
|
|
154
|
-
module TestApp
|
|
155
|
-
class Routes < Hanami::Routes
|
|
156
|
-
root to: "home.index"
|
|
157
|
-
|
|
158
|
-
slice :main, at: "/" do
|
|
159
|
-
root to: "home.index"
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
RUBY
|
|
164
|
-
|
|
165
|
-
write "app/actions/home/index.rb", <<~RUBY
|
|
166
|
-
require "hanami/action"
|
|
167
|
-
|
|
168
|
-
module TestApp
|
|
169
|
-
module Actions
|
|
170
|
-
module Home
|
|
171
|
-
class Index < Hanami::Action
|
|
172
|
-
def handle(*, res)
|
|
173
|
-
res.body = "Hello from App"
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
RUBY
|
|
180
|
-
|
|
181
|
-
write "slices/main/actions/home/index.rb", <<~RUBY
|
|
182
|
-
require "hanami/action"
|
|
183
|
-
|
|
184
|
-
module Main
|
|
185
|
-
module Actions
|
|
186
|
-
module Home
|
|
187
|
-
class Index < Hanami::Action
|
|
188
|
-
def handle(*, res)
|
|
189
|
-
res.body = "Hello from Slice"
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
RUBY
|
|
196
|
-
|
|
197
|
-
require "hanami/boot"
|
|
198
|
-
|
|
199
|
-
get "/"
|
|
200
|
-
|
|
201
|
-
expect(last_response.status).to eq 200
|
|
202
|
-
expect(last_response.body).to eq "Hello from Slice"
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
specify "It does not choose actions from slice to route in app" do
|
|
207
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
208
|
-
write "config/app.rb", <<~RUBY
|
|
209
|
-
require "hanami"
|
|
210
|
-
|
|
211
|
-
module TestApp
|
|
212
|
-
class App < Hanami::App
|
|
213
|
-
config.logger.stream = StringIO.new
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
RUBY
|
|
217
|
-
|
|
218
|
-
write "config/routes.rb", <<~RUBY
|
|
219
|
-
module TestApp
|
|
220
|
-
class Routes < Hanami::Routes
|
|
221
|
-
get "/feedbacks", to: "feedbacks.index"
|
|
222
|
-
|
|
223
|
-
slice :api, at: "/api" do
|
|
224
|
-
get "/people", to: "people.index"
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
RUBY
|
|
229
|
-
|
|
230
|
-
write "app/action.rb", <<~RUBY
|
|
231
|
-
# auto_register: false
|
|
232
|
-
require "hanami/action"
|
|
233
|
-
|
|
234
|
-
module TestApp
|
|
235
|
-
class Action < Hanami::Action
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
RUBY
|
|
239
|
-
|
|
240
|
-
write "app/actions/feedbacks/index.rb", <<~RUBY
|
|
241
|
-
module TestApp
|
|
242
|
-
module Actions
|
|
243
|
-
module Feedbacks
|
|
244
|
-
class Index < TestApp::Action
|
|
245
|
-
def handle(*, res)
|
|
246
|
-
res.body = "Feedbacks"
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
RUBY
|
|
253
|
-
|
|
254
|
-
write "slices/api/action.rb", <<~RUBY
|
|
255
|
-
module API
|
|
256
|
-
class Action < TestApp::Action
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
RUBY
|
|
260
|
-
|
|
261
|
-
write "slices/api/actions/people/index.rb", <<~RUBY
|
|
262
|
-
module API
|
|
263
|
-
module Actions
|
|
264
|
-
module People
|
|
265
|
-
class Index < API::Action
|
|
266
|
-
def handle(*, res)
|
|
267
|
-
res.body = "People"
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
RUBY
|
|
274
|
-
|
|
275
|
-
require "hanami/boot"
|
|
276
|
-
|
|
277
|
-
get "/api/people"
|
|
278
|
-
|
|
279
|
-
expect(last_response.status).to eq 200
|
|
280
|
-
expect(last_response.body).to eq "People"
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
specify "For a booted app, rack_app raises an exception if a referenced action isn't registered in the app" do
|
|
285
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
286
|
-
write "config/app.rb", <<~RUBY
|
|
287
|
-
require "hanami"
|
|
288
|
-
|
|
289
|
-
module TestApp
|
|
290
|
-
class App < Hanami::App
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
RUBY
|
|
294
|
-
|
|
295
|
-
write "config/routes.rb", <<~RUBY
|
|
296
|
-
module TestApp
|
|
297
|
-
class Routes < Hanami::Routes
|
|
298
|
-
get "/missing", to: "missing.action"
|
|
299
|
-
end
|
|
300
|
-
end
|
|
301
|
-
RUBY
|
|
302
|
-
|
|
303
|
-
require "hanami/boot"
|
|
304
|
-
|
|
305
|
-
expect { Hanami.app.rack_app }.to raise_error do |exception|
|
|
306
|
-
expect(exception).to be_kind_of(Hanami::Routes::MissingActionError)
|
|
307
|
-
expect(exception.message).to include("Could not find action with key \"actions.missing.action\" in TestApp::App")
|
|
308
|
-
expect(exception.message).to include("define the action class TestApp::Actions::Missing::Action in app/actions/missing/action.rb")
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
specify "For a booted app, rack_app raises an error if a referenced action isn't registered in a slice" do
|
|
314
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
315
|
-
write "config/app.rb", <<~RUBY
|
|
316
|
-
require "hanami"
|
|
317
|
-
|
|
318
|
-
module TestApp
|
|
319
|
-
class App < Hanami::App
|
|
320
|
-
register_slice :admin
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
RUBY
|
|
324
|
-
|
|
325
|
-
write "config/routes.rb", <<~RUBY
|
|
326
|
-
module TestApp
|
|
327
|
-
class Routes < Hanami::Routes
|
|
328
|
-
slice :admin, at: "/admin" do
|
|
329
|
-
get "/missing", to: "missing.action"
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
RUBY
|
|
334
|
-
|
|
335
|
-
require "hanami/boot"
|
|
336
|
-
|
|
337
|
-
expect { Hanami.app.rack_app }.to raise_error do |exception|
|
|
338
|
-
expect(exception).to be_kind_of(Hanami::Routes::MissingActionError)
|
|
339
|
-
expect(exception.message).to include("Could not find action with key \"actions.missing.action\" in Admin::Slice")
|
|
340
|
-
expect(exception.message).to include("define the action class Admin::Actions::Missing::Action in slices/admin/actions/missing/action.rb")
|
|
341
|
-
end
|
|
342
|
-
end
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
specify "For a non-booted app, rack_app does not raise an error if a referenced action isn't registered in the app" do
|
|
346
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
347
|
-
write "config/app.rb", <<~RUBY
|
|
348
|
-
require "hanami"
|
|
349
|
-
|
|
350
|
-
module TestApp
|
|
351
|
-
class App < Hanami::App
|
|
352
|
-
config.render_detailed_errors = false
|
|
353
|
-
end
|
|
354
|
-
end
|
|
355
|
-
RUBY
|
|
356
|
-
|
|
357
|
-
write "config/routes.rb", <<~RUBY
|
|
358
|
-
module TestApp
|
|
359
|
-
class Routes < Hanami::Routes
|
|
360
|
-
get "/missing", to: "missing.action"
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
RUBY
|
|
364
|
-
|
|
365
|
-
require "hanami/prepare"
|
|
366
|
-
|
|
367
|
-
expect { Hanami.app.rack_app }.not_to raise_error
|
|
368
|
-
|
|
369
|
-
expect { get "/missing" }.to raise_error do |exception|
|
|
370
|
-
expect(exception).to be_kind_of(Hanami::Routes::MissingActionError)
|
|
371
|
-
expect(exception.message).to include("Could not find action with key \"actions.missing.action\" in TestApp::App")
|
|
372
|
-
expect(exception.message).to match(%r{define the action class TestApp::Actions::Missing::Action.+actions/missing/action.rb})
|
|
373
|
-
end
|
|
374
|
-
end
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
specify "For a non-booted app, rack_app does not raise an error if a referenced action isn't registered in a slice" do
|
|
378
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
379
|
-
write "config/app.rb", <<~RUBY
|
|
380
|
-
require "hanami"
|
|
381
|
-
|
|
382
|
-
module TestApp
|
|
383
|
-
class App < Hanami::App
|
|
384
|
-
config.render_detailed_errors = false
|
|
385
|
-
|
|
386
|
-
register_slice :admin
|
|
387
|
-
end
|
|
388
|
-
end
|
|
389
|
-
RUBY
|
|
390
|
-
|
|
391
|
-
write "config/routes.rb", <<~RUBY
|
|
392
|
-
module TestApp
|
|
393
|
-
class Routes < Hanami::Routes
|
|
394
|
-
slice :admin, at: "/admin" do
|
|
395
|
-
get "/missing", to: "missing.action"
|
|
396
|
-
end
|
|
397
|
-
end
|
|
398
|
-
end
|
|
399
|
-
RUBY
|
|
400
|
-
|
|
401
|
-
require "hanami/prepare"
|
|
402
|
-
|
|
403
|
-
expect { Hanami.app.rack_app }.not_to raise_error
|
|
404
|
-
|
|
405
|
-
expect { get "/admin/missing" }.to raise_error do |exception|
|
|
406
|
-
expect(exception).to be_kind_of(Hanami::Routes::MissingActionError)
|
|
407
|
-
expect(exception.message).to include("Could not find action with key \"actions.missing.action\" in Admin::Slice")
|
|
408
|
-
expect(exception.message).to match(%r{define the action class Admin::Actions::Missing::Action.+slices/admin/actions/missing/action.rb})
|
|
409
|
-
end
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
specify "rack_app raises an error if a referenced slice is not registered" do
|
|
414
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
415
|
-
write "config/app.rb", <<~RUBY
|
|
416
|
-
require "hanami"
|
|
417
|
-
|
|
418
|
-
module TestApp
|
|
419
|
-
class App < Hanami::App
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
RUBY
|
|
423
|
-
|
|
424
|
-
write "config/routes.rb", <<~RUBY
|
|
425
|
-
module TestApp
|
|
426
|
-
class Routes < Hanami::Routes
|
|
427
|
-
slice :foo, at: "/foo" do
|
|
428
|
-
get "/bar", to: "bar.index"
|
|
429
|
-
end
|
|
430
|
-
end
|
|
431
|
-
end
|
|
432
|
-
RUBY
|
|
433
|
-
|
|
434
|
-
require "hanami/prepare"
|
|
435
|
-
|
|
436
|
-
expect { Hanami.app.rack_app }.to raise_error do |exception|
|
|
437
|
-
expect(exception).to be_kind_of(Hanami::SliceLoadError)
|
|
438
|
-
expect(exception.message).to include("Slice 'foo' not found")
|
|
439
|
-
end
|
|
440
|
-
end
|
|
441
|
-
end
|
|
442
|
-
end
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rake"
|
|
4
|
-
require "hanami/cli/bundler"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Rake tasks", :app_integration do
|
|
7
|
-
describe "assets:precompile" do
|
|
8
|
-
before do
|
|
9
|
-
allow(Hanami).to receive(:bundled?)
|
|
10
|
-
allow(Hanami).to receive(:bundled?).with("hanami-assets").and_return(hanami_assets_bundled)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context "when hanami-assets is bundled" do
|
|
14
|
-
let(:hanami_assets_bundled) { true }
|
|
15
|
-
|
|
16
|
-
xit "compiles assets" do
|
|
17
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
18
|
-
write "config/app.rb", <<~'RUBY'
|
|
19
|
-
require "hanami"
|
|
20
|
-
|
|
21
|
-
module TestApp
|
|
22
|
-
class App < Hanami::App
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
RUBY
|
|
26
|
-
|
|
27
|
-
write "Rakefile", <<~RUBY
|
|
28
|
-
# frozen_string_literal: true
|
|
29
|
-
|
|
30
|
-
require "hanami/rake_tasks"
|
|
31
|
-
RUBY
|
|
32
|
-
|
|
33
|
-
write "app/assets/js/app.js", <<~JS
|
|
34
|
-
console.log("Hello from index.js");
|
|
35
|
-
JS
|
|
36
|
-
|
|
37
|
-
before_prepare if respond_to?(:before_prepare)
|
|
38
|
-
require "hanami/prepare"
|
|
39
|
-
|
|
40
|
-
expect_any_instance_of(Hanami::CLI::Bundler).to receive(:hanami_exec).with("assets compile").and_return(true)
|
|
41
|
-
|
|
42
|
-
Rake::Task["assets:precompile"].invoke
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "doesn't list the task" do
|
|
47
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
48
|
-
write "config/app.rb", <<~'RUBY'
|
|
49
|
-
require "hanami"
|
|
50
|
-
|
|
51
|
-
module TestApp
|
|
52
|
-
class App < Hanami::App
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
RUBY
|
|
56
|
-
|
|
57
|
-
write "Rakefile", <<~RUBY
|
|
58
|
-
# frozen_string_literal: true
|
|
59
|
-
|
|
60
|
-
require "hanami/rake_tasks"
|
|
61
|
-
RUBY
|
|
62
|
-
|
|
63
|
-
before_prepare if respond_to?(:before_prepare)
|
|
64
|
-
require "hanami/prepare"
|
|
65
|
-
|
|
66
|
-
output = `bundle exec rake -T`
|
|
67
|
-
expect(output).to_not include("assets:precompile")
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "when hanami-assets is not bundled" do
|
|
73
|
-
let(:hanami_assets_bundled) { false }
|
|
74
|
-
|
|
75
|
-
it "raises error" do
|
|
76
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
77
|
-
write "config/app.rb", <<~'RUBY'
|
|
78
|
-
require "hanami"
|
|
79
|
-
|
|
80
|
-
module TestApp
|
|
81
|
-
class App < Hanami::App
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
RUBY
|
|
85
|
-
|
|
86
|
-
write "Rakefile", <<~RUBY
|
|
87
|
-
# frozen_string_literal: true
|
|
88
|
-
|
|
89
|
-
require "hanami/rake_tasks"
|
|
90
|
-
RUBY
|
|
91
|
-
|
|
92
|
-
write "app/assets/js/app.js", <<~JS
|
|
93
|
-
console.log("Hello from index.js");
|
|
94
|
-
JS
|
|
95
|
-
|
|
96
|
-
before_prepare if respond_to?(:before_prepare)
|
|
97
|
-
require "hanami/prepare"
|
|
98
|
-
|
|
99
|
-
expect { Rake::Task["assets:precompile"].invoke }.to raise_error do |exception|
|
|
100
|
-
expect(exception).to be_a(RuntimeError)
|
|
101
|
-
expect(exception.message).to match(/Don't know how to build task 'assets:precompile'/)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|