hanami 2.0.0.alpha7.1 → 2.0.0.beta1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +457 -237
- data/FEATURES.md +30 -9
- data/README.md +1 -3
- data/hanami.gemspec +21 -11
- data/lib/hanami/app.rb +141 -0
- data/lib/hanami/assets/application_configuration.rb +10 -4
- data/lib/hanami/configuration/actions/content_security_policy.rb +118 -0
- data/lib/hanami/configuration/actions/cookies.rb +29 -0
- data/lib/hanami/configuration/actions/sessions.rb +46 -0
- data/lib/hanami/configuration/actions.rb +23 -12
- data/lib/hanami/configuration/logger.rb +13 -10
- data/lib/hanami/configuration/router.rb +2 -6
- data/lib/hanami/configuration/sessions.rb +1 -1
- data/lib/hanami/configuration/views.rb +86 -0
- data/lib/hanami/configuration.rb +139 -82
- data/lib/hanami/constants.rb +30 -2
- data/lib/hanami/errors.rb +4 -1
- data/lib/hanami/extensions/action/slice_configured_action.rb +103 -0
- data/lib/hanami/extensions/action.rb +79 -0
- data/lib/hanami/extensions/view/context.rb +106 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +71 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +107 -0
- data/lib/hanami/extensions/view.rb +33 -0
- data/lib/hanami/extensions.rb +10 -0
- data/lib/hanami/providers/inflector.rb +13 -0
- data/lib/hanami/providers/logger.rb +13 -0
- data/lib/hanami/providers/rack.rb +27 -0
- data/lib/hanami/providers/routes.rb +33 -0
- data/lib/hanami/providers/settings.rb +23 -0
- data/lib/hanami/rake_tasks.rb +61 -0
- data/lib/hanami/routes.rb +51 -0
- data/lib/hanami/server.rb +1 -1
- data/lib/hanami/settings/dotenv_store.rb +58 -0
- data/lib/hanami/settings.rb +90 -0
- data/lib/hanami/setup.rb +4 -2
- data/lib/hanami/{application → slice}/router.rb +18 -13
- data/lib/hanami/slice/routes_helper.rb +37 -0
- data/lib/hanami/{application → slice}/routing/middleware/stack.rb +43 -5
- data/lib/hanami/slice/routing/resolver.rb +97 -0
- data/lib/hanami/slice/view_name_inferrer.rb +63 -0
- data/lib/hanami/slice.rb +252 -82
- data/lib/hanami/slice_configurable.rb +62 -0
- data/lib/hanami/slice_name.rb +111 -0
- data/lib/hanami/slice_registrar.rb +119 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +1 -1
- data/lib/hanami.rb +34 -26
- data/spec/integration/application_middleware_stack_spec.rb +84 -0
- data/spec/integration/assets/cdn_spec.rb +48 -0
- data/spec/integration/assets/fingerprint_spec.rb +42 -0
- data/spec/integration/assets/helpers_spec.rb +50 -0
- data/spec/integration/assets/serve_spec.rb +70 -0
- data/spec/integration/assets/subresource_integrity_spec.rb +54 -0
- data/spec/integration/body_parsers_spec.rb +50 -0
- data/spec/integration/cli/assets/precompile_spec.rb +147 -0
- data/spec/integration/cli/assets_spec.rb +14 -0
- data/spec/integration/cli/console_spec.rb +105 -0
- data/spec/integration/cli/db/apply_spec.rb +74 -0
- data/spec/integration/cli/db/console_spec.rb +40 -0
- data/spec/integration/cli/db/create_spec.rb +50 -0
- data/spec/integration/cli/db/drop_spec.rb +54 -0
- data/spec/integration/cli/db/migrate_spec.rb +108 -0
- data/spec/integration/cli/db/prepare_spec.rb +36 -0
- data/spec/integration/cli/db/rollback_spec.rb +96 -0
- data/spec/integration/cli/db/version_spec.rb +38 -0
- data/spec/integration/cli/db_spec.rb +21 -0
- data/spec/integration/cli/destroy/action_spec.rb +143 -0
- data/spec/integration/cli/destroy/app_spec.rb +118 -0
- data/spec/integration/cli/destroy/mailer_spec.rb +74 -0
- data/spec/integration/cli/destroy/migration_spec.rb +70 -0
- data/spec/integration/cli/destroy/model_spec.rb +113 -0
- data/spec/integration/cli/destroy_spec.rb +18 -0
- data/spec/integration/cli/generate/action_spec.rb +469 -0
- data/spec/integration/cli/generate/app_spec.rb +215 -0
- data/spec/integration/cli/generate/mailer_spec.rb +189 -0
- data/spec/integration/cli/generate/migration_spec.rb +72 -0
- data/spec/integration/cli/generate/model_spec.rb +290 -0
- data/spec/integration/cli/generate/secret_spec.rb +56 -0
- data/spec/integration/cli/generate_spec.rb +19 -0
- data/spec/integration/cli/new/database_spec.rb +235 -0
- data/spec/integration/cli/new/hanami_head_spec.rb +27 -0
- data/spec/integration/cli/new/template_spec.rb +118 -0
- data/spec/integration/cli/new/test_spec.rb +274 -0
- data/spec/integration/cli/new_spec.rb +970 -0
- data/spec/integration/cli/plugins_spec.rb +39 -0
- data/spec/integration/cli/routes_spec.rb +49 -0
- data/spec/integration/cli/server_spec.rb +626 -0
- data/spec/integration/cli/version_spec.rb +85 -0
- data/spec/integration/early_hints_spec.rb +35 -0
- data/spec/integration/handle_exceptions_spec.rb +244 -0
- data/spec/integration/head_spec.rb +89 -0
- data/spec/integration/http_headers_spec.rb +29 -0
- data/spec/integration/mailer_spec.rb +32 -0
- data/spec/integration/middleware_spec.rb +81 -0
- data/spec/integration/mount_applications_spec.rb +88 -0
- data/spec/integration/project_initializers_spec.rb +40 -0
- data/spec/integration/rackup_spec.rb +35 -0
- data/spec/integration/rake/with_minitest_spec.rb +67 -0
- data/spec/integration/rake/with_rspec_spec.rb +69 -0
- data/spec/integration/routing_helpers_spec.rb +61 -0
- data/spec/integration/security/content_security_policy_spec.rb +46 -0
- data/spec/integration/security/csrf_protection_spec.rb +42 -0
- data/spec/integration/security/force_ssl_spec.rb +29 -0
- data/spec/integration/security/x_content_type_options_spec.rb +46 -0
- data/spec/integration/security/x_frame_options_spec.rb +46 -0
- data/spec/integration/security/x_xss_protection_spec.rb +46 -0
- data/spec/integration/send_file_spec.rb +51 -0
- data/spec/integration/sessions_spec.rb +247 -0
- data/spec/integration/static_middleware_spec.rb +21 -0
- data/spec/integration/streaming_spec.rb +41 -0
- data/spec/integration/unsafe_send_file_spec.rb +52 -0
- data/spec/isolation/hanami/application/already_configured_spec.rb +19 -0
- data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +10 -0
- data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +14 -0
- data/spec/isolation/hanami/application/not_configured_spec.rb +9 -0
- data/spec/isolation/hanami/application/routes/configured_spec.rb +44 -0
- data/spec/isolation/hanami/application/routes/not_configured_spec.rb +16 -0
- data/spec/isolation/hanami/boot/success_spec.rb +50 -0
- data/spec/new_integration/action/configuration_spec.rb +26 -0
- data/spec/new_integration/action/cookies_spec.rb +58 -0
- data/spec/new_integration/action/csrf_protection_spec.rb +54 -0
- data/spec/new_integration/action/routes_spec.rb +73 -0
- data/spec/new_integration/action/sessions_spec.rb +50 -0
- data/spec/new_integration/action/view_integration_spec.rb +165 -0
- data/spec/new_integration/action/view_rendering/automatic_rendering_spec.rb +247 -0
- data/spec/new_integration/action/view_rendering/paired_view_inference_spec.rb +115 -0
- data/spec/new_integration/action/view_rendering_spec.rb +107 -0
- data/spec/new_integration/code_loading/loading_from_app_spec.rb +152 -0
- data/spec/new_integration/code_loading/loading_from_slice_spec.rb +165 -0
- data/spec/new_integration/container/application_routes_helper_spec.rb +48 -0
- data/spec/new_integration/container/auto_injection_spec.rb +53 -0
- data/spec/new_integration/container/auto_registration_spec.rb +86 -0
- data/spec/new_integration/container/autoloader_spec.rb +80 -0
- data/spec/new_integration/container/imports_spec.rb +253 -0
- data/spec/new_integration/container/prepare_container_spec.rb +123 -0
- data/spec/new_integration/container/shutdown_spec.rb +91 -0
- data/spec/new_integration/container/standard_bootable_components_spec.rb +124 -0
- data/spec/new_integration/rack_app/middleware_spec.rb +215 -0
- data/spec/new_integration/rack_app/non_booted_rack_app_spec.rb +105 -0
- data/spec/new_integration/rack_app/rack_app_spec.rb +524 -0
- data/spec/new_integration/settings_spec.rb +115 -0
- data/spec/new_integration/slices/external_slice_spec.rb +92 -0
- data/spec/new_integration/slices/slice_configuration_spec.rb +40 -0
- data/spec/new_integration/slices/slice_routing_spec.rb +226 -0
- data/spec/new_integration/slices/slice_settings_spec.rb +141 -0
- data/spec/new_integration/slices_spec.rb +101 -0
- data/spec/new_integration/view/configuration_spec.rb +49 -0
- data/spec/new_integration/view/context/assets_spec.rb +67 -0
- data/spec/new_integration/view/context/inflector_spec.rb +48 -0
- data/spec/new_integration/view/context/request_spec.rb +61 -0
- data/spec/new_integration/view/context/routes_spec.rb +86 -0
- data/spec/new_integration/view/context/settings_spec.rb +50 -0
- data/spec/new_integration/view/inflector_spec.rb +57 -0
- data/spec/new_integration/view/part_namespace_spec.rb +96 -0
- data/spec/new_integration/view/path_spec.rb +56 -0
- data/spec/new_integration/view/template_spec.rb +68 -0
- data/spec/new_integration/view/views_spec.rb +103 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/app_integration.rb +91 -0
- data/spec/support/coverage.rb +1 -0
- data/spec/support/fixtures/hanami-plugin/Gemfile +8 -0
- data/spec/support/fixtures/hanami-plugin/README.md +35 -0
- data/spec/support/fixtures/hanami-plugin/Rakefile +4 -0
- data/spec/support/fixtures/hanami-plugin/bin/console +15 -0
- data/spec/support/fixtures/hanami-plugin/bin/setup +8 -0
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +28 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +19 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +7 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +8 -0
- data/spec/support/rspec.rb +27 -0
- data/spec/support/shared_examples/cli/generate/app.rb +494 -0
- data/spec/support/shared_examples/cli/generate/migration.rb +32 -0
- data/spec/support/shared_examples/cli/generate/model.rb +81 -0
- data/spec/support/shared_examples/cli/new.rb +97 -0
- data/spec/unit/hanami/configuration/actions/content_security_policy_spec.rb +102 -0
- data/spec/unit/hanami/configuration/actions/cookies_spec.rb +46 -0
- data/spec/unit/hanami/configuration/actions/csrf_protection_spec.rb +57 -0
- data/spec/unit/hanami/configuration/actions/default_values_spec.rb +52 -0
- data/spec/unit/hanami/configuration/actions/sessions_spec.rb +50 -0
- data/spec/unit/hanami/configuration/actions_spec.rb +78 -0
- data/spec/unit/hanami/configuration/base_url_spec.rb +25 -0
- data/spec/unit/hanami/configuration/inflector_spec.rb +35 -0
- data/spec/unit/hanami/configuration/logger_spec.rb +203 -0
- data/spec/unit/hanami/configuration/views_spec.rb +120 -0
- data/spec/unit/hanami/configuration_spec.rb +43 -0
- data/spec/unit/hanami/env_spec.rb +54 -0
- data/spec/unit/hanami/routes_spec.rb +25 -0
- data/spec/unit/hanami/settings/dotenv_store_spec.rb +119 -0
- data/spec/unit/hanami/settings_spec.rb +56 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +104 -0
- data/spec/unit/hanami/slice_name_spec.rb +47 -0
- data/spec/unit/hanami/slice_spec.rb +17 -0
- data/spec/unit/hanami/version_spec.rb +7 -0
- data/spec/unit/hanami/web/rack_logger_spec.rb +78 -0
- metadata +363 -55
- data/lib/hanami/application/container/providers/inflector.rb +0 -7
- data/lib/hanami/application/container/providers/logger.rb +0 -7
- data/lib/hanami/application/container/providers/rack_logger.rb +0 -15
- data/lib/hanami/application/container/providers/rack_monitor.rb +0 -12
- data/lib/hanami/application/container/providers/routes_helper.rb +0 -9
- data/lib/hanami/application/container/providers/settings.rb +0 -7
- data/lib/hanami/application/routes.rb +0 -55
- data/lib/hanami/application/routes_helper.rb +0 -34
- data/lib/hanami/application/routing/resolver/node.rb +0 -50
- data/lib/hanami/application/routing/resolver/trie.rb +0 -59
- data/lib/hanami/application/routing/resolver.rb +0 -87
- data/lib/hanami/application/routing/router.rb +0 -36
- data/lib/hanami/application/settings/dotenv_store.rb +0 -60
- data/lib/hanami/application/settings.rb +0 -93
- data/lib/hanami/application/slice_registrar.rb +0 -106
- data/lib/hanami/application.rb +0 -299
- data/lib/hanami/boot/source_dirs.rb +0 -44
- data/lib/hanami/cli/application/cli.rb +0 -40
- data/lib/hanami/cli/application/command.rb +0 -47
- data/lib/hanami/cli/application/commands/console.rb +0 -81
- data/lib/hanami/cli/application/commands.rb +0 -16
- data/lib/hanami/cli/base_command.rb +0 -48
- data/lib/hanami/cli/commands/command.rb +0 -171
- data/lib/hanami/cli/commands/server.rb +0 -88
- data/lib/hanami/cli/commands.rb +0 -65
- data/lib/hanami/configuration/middleware.rb +0 -20
- data/lib/hanami/configuration/source_dirs.rb +0 -42
@@ -0,0 +1,469 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami generate", type: :integration do
|
4
|
+
describe "action" do
|
5
|
+
it "generates action" do
|
6
|
+
with_project("bookshelf_generate_action") do
|
7
|
+
output = [
|
8
|
+
"create spec/web/controllers/authors/index_spec.rb",
|
9
|
+
"create apps/web/controllers/authors/index.rb",
|
10
|
+
"create apps/web/views/authors/index.rb",
|
11
|
+
"create apps/web/templates/authors/index.html.erb",
|
12
|
+
"create spec/web/views/authors/index_spec.rb",
|
13
|
+
"insert apps/web/config/routes.rb"
|
14
|
+
]
|
15
|
+
|
16
|
+
run_cmd "hanami generate action web authors#index", output
|
17
|
+
|
18
|
+
#
|
19
|
+
# apps/web/controllers/authors/index.rb
|
20
|
+
#
|
21
|
+
expect("apps/web/controllers/authors/index.rb").to have_file_content <<~END
|
22
|
+
module Web
|
23
|
+
module Controllers
|
24
|
+
module Authors
|
25
|
+
class Index
|
26
|
+
include Web::Action
|
27
|
+
|
28
|
+
def call(params)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
END
|
35
|
+
|
36
|
+
#
|
37
|
+
# apps/web/views/authors/index.rb
|
38
|
+
#
|
39
|
+
expect("apps/web/views/authors/index.rb").to have_file_content <<~END
|
40
|
+
module Web
|
41
|
+
module Views
|
42
|
+
module Authors
|
43
|
+
class Index
|
44
|
+
include Web::View
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
END
|
50
|
+
|
51
|
+
#
|
52
|
+
# apps/web/config/routes.rb
|
53
|
+
#
|
54
|
+
expect("apps/web/config/routes.rb").to have_file_content(%r{get '/authors', to: 'authors#index'})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "generates namespaced action" do
|
59
|
+
with_project("bookshelf_generate_action") do
|
60
|
+
output = [
|
61
|
+
"create spec/web/controllers/api/authors/index_spec.rb",
|
62
|
+
"create apps/web/controllers/api/authors/index.rb",
|
63
|
+
"create apps/web/views/api/authors/index.rb",
|
64
|
+
"create apps/web/templates/api/authors/index.html.erb",
|
65
|
+
"create spec/web/views/api/authors/index_spec.rb",
|
66
|
+
"insert apps/web/config/routes.rb"
|
67
|
+
]
|
68
|
+
|
69
|
+
run_cmd "hanami generate action web api/authors#index", output
|
70
|
+
|
71
|
+
#
|
72
|
+
# apps/web/controllers/api/authors/index.rb
|
73
|
+
#
|
74
|
+
expect("apps/web/controllers/api/authors/index.rb").to have_file_content <<~END
|
75
|
+
module Web
|
76
|
+
module Controllers
|
77
|
+
module Api
|
78
|
+
module Authors
|
79
|
+
class Index
|
80
|
+
include Web::Action
|
81
|
+
|
82
|
+
def call(params)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
END
|
90
|
+
|
91
|
+
#
|
92
|
+
# apps/web/views/api/authors/index.rb
|
93
|
+
#
|
94
|
+
expect("apps/web/views/api/authors/index.rb").to have_file_content <<~END
|
95
|
+
module Web
|
96
|
+
module Views
|
97
|
+
module Api
|
98
|
+
module Authors
|
99
|
+
class Index
|
100
|
+
include Web::View
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
END
|
107
|
+
|
108
|
+
#
|
109
|
+
# apps/web/config/routes.rb
|
110
|
+
#
|
111
|
+
expect("apps/web/config/routes.rb").to have_file_content(%r{get '/api/authors', to: 'api/authors#index'})
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "generates non-RESTful actions" do
|
116
|
+
with_project do
|
117
|
+
run_cmd "hanami generate action web sessions#sign_out"
|
118
|
+
|
119
|
+
#
|
120
|
+
# apps/web/config/routes.rb
|
121
|
+
#
|
122
|
+
expect("apps/web/config/routes.rb").to have_file_content(%r{get '/sessions/sign_out', to: 'sessions#sign_out'})
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "fails with missing arguments" do
|
127
|
+
with_project("bookshelf_generate_action_without_args") do
|
128
|
+
output = <<~OUT
|
129
|
+
ERROR: "hanami generate action" was called with no arguments
|
130
|
+
Usage: "hanami generate action APP ACTION"
|
131
|
+
OUT
|
132
|
+
run_cmd "hanami generate action", output, exit_status: 1
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "fails with missing app" do
|
137
|
+
with_project("bookshelf_generate_action_without_app") do
|
138
|
+
output = <<~OUT
|
139
|
+
ERROR: "hanami generate action" was called with arguments ["home#index"]
|
140
|
+
Usage: "hanami generate action APP ACTION"
|
141
|
+
OUT
|
142
|
+
|
143
|
+
run_cmd "hanami generate action home#index", output, exit_status: 1
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "fails with unknown app" do
|
148
|
+
with_project("bookshelf_generate_action_with_unknown_app") do
|
149
|
+
output = "`foo' is not a valid APP. Please specify one of: `web'"
|
150
|
+
|
151
|
+
run_cmd "hanami generate action foo home#index", output, exit_status: 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "--url" do
|
156
|
+
it "generates action" do
|
157
|
+
with_project("bookshelf_generate_action_url") do
|
158
|
+
output = [
|
159
|
+
"insert apps/web/config/routes.rb"
|
160
|
+
]
|
161
|
+
|
162
|
+
run_cmd "hanami generate action web home#index --url=/", output
|
163
|
+
|
164
|
+
#
|
165
|
+
# apps/web/config/routes.rb
|
166
|
+
#
|
167
|
+
expect("apps/web/config/routes.rb").to have_file_content(%r{get '/', to: 'home#index'})
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "fails with missing argument" do
|
172
|
+
with_project("bookshelf_generate_action_missing_url") do
|
173
|
+
output = "`' is not a valid URL"
|
174
|
+
run_cmd "hanami generate action web books#create --url=", output, exit_status: 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "--skip-view" do
|
180
|
+
it "generates action" do
|
181
|
+
with_project("bookshelf_generate_action_skip_view") do
|
182
|
+
output = [
|
183
|
+
"create apps/web/controllers/status/check.rb",
|
184
|
+
"create spec/web/controllers/status/check_spec.rb",
|
185
|
+
"insert apps/web/config/routes.rb"
|
186
|
+
]
|
187
|
+
run_cmd "hanami generate action web status#check --skip-view", output
|
188
|
+
|
189
|
+
#
|
190
|
+
# apps/web/controllers/status/check.rb
|
191
|
+
#
|
192
|
+
expect("apps/web/controllers/status/check.rb").to have_file_content <<~END
|
193
|
+
module Web
|
194
|
+
module Controllers
|
195
|
+
module Status
|
196
|
+
class Check
|
197
|
+
include Web::Action
|
198
|
+
|
199
|
+
def call(params)
|
200
|
+
self.body = 'OK'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
END
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
it "generates namespaced action" do
|
211
|
+
with_project("bookshelf_generate_action_skip_view") do
|
212
|
+
output = [
|
213
|
+
"create apps/web/controllers/api/authors/index.rb",
|
214
|
+
"create spec/web/controllers/api/authors/index_spec.rb",
|
215
|
+
"insert apps/web/config/routes.rb"
|
216
|
+
]
|
217
|
+
run_cmd "hanami generate action web api/authors#index --skip-view", output
|
218
|
+
|
219
|
+
#
|
220
|
+
# apps/web/controllers/status/check.rb
|
221
|
+
#
|
222
|
+
expect("apps/web/controllers/api/authors/index.rb").to have_file_content <<~END
|
223
|
+
module Web
|
224
|
+
module Controllers
|
225
|
+
module Api
|
226
|
+
module Authors
|
227
|
+
class Index
|
228
|
+
include Web::Action
|
229
|
+
|
230
|
+
def call(params)
|
231
|
+
self.body = 'OK'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
END
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "--method" do
|
244
|
+
it "generates action" do
|
245
|
+
with_project("bookshelf_generate_action_method") do
|
246
|
+
output = [
|
247
|
+
"insert apps/web/config/routes.rb"
|
248
|
+
]
|
249
|
+
|
250
|
+
run_cmd "hanami generate action web books#create --method=POST", output
|
251
|
+
|
252
|
+
#
|
253
|
+
# apps/web/config/routes.rb
|
254
|
+
#
|
255
|
+
expect("apps/web/config/routes.rb").to have_file_content(%r{post '/books', to: 'books#create'})
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
it "fails with missing argument" do
|
260
|
+
with_project("bookshelf_generate_action_missing_method") do
|
261
|
+
output = "`' is not a valid HTTP method. Please use one of: `GET' `POST' `PUT' `DELETE' `HEAD' `OPTIONS' `TRACE' `PATCH' `OPTIONS' `LINK' `UNLINK'"
|
262
|
+
run_cmd "hanami generate action web books#create --method=", output, exit_status: 1
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it "fails with unknown argument" do
|
267
|
+
with_project('bookshelf_generate_action_unknown_method') do
|
268
|
+
output = "`FOO' is not a valid HTTP method. Please use one of: `GET' `POST' `PUT' `DELETE' `HEAD' `OPTIONS' `TRACE' `PATCH' `OPTIONS' `LINK' `UNLINK'"
|
269
|
+
run_cmd "hanami generate action web books#create --method=FOO", output, exit_status: 1
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "erb" do
|
275
|
+
it "generates action" do
|
276
|
+
with_project("bookshelf_generate_action_erb", template: "erb") do
|
277
|
+
output = [
|
278
|
+
"create apps/web/templates/books/index.html.erb"
|
279
|
+
]
|
280
|
+
|
281
|
+
run_cmd "hanami generate action web books#index", output
|
282
|
+
|
283
|
+
#
|
284
|
+
# apps/web/templates/books/index.html.erb
|
285
|
+
#
|
286
|
+
expect("apps/web/templates/books/index.html.erb").to have_file_content <<~END
|
287
|
+
END
|
288
|
+
|
289
|
+
#
|
290
|
+
# spec/web/views/books/index_spec.rb
|
291
|
+
#
|
292
|
+
expect("spec/web/views/books/index_spec.rb").to have_file_content %r{'apps/web/templates/books/index.html.erb'}
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end # erb
|
296
|
+
|
297
|
+
context "haml" do
|
298
|
+
it "generates action" do
|
299
|
+
with_project("bookshelf_generate_action_haml", template: "haml") do
|
300
|
+
output = [
|
301
|
+
"create apps/web/templates/books/index.html.haml"
|
302
|
+
]
|
303
|
+
|
304
|
+
run_cmd "hanami generate action web books#index", output
|
305
|
+
|
306
|
+
#
|
307
|
+
# apps/web/templates/books/index.html.haml
|
308
|
+
#
|
309
|
+
expect("apps/web/templates/books/index.html.haml").to have_file_content <<~END
|
310
|
+
END
|
311
|
+
|
312
|
+
#
|
313
|
+
# spec/web/views/books/index_spec.rb
|
314
|
+
#
|
315
|
+
expect("spec/web/views/books/index_spec.rb").to have_file_content(%r{'apps/web/templates/books/index.html.haml'})
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end # haml
|
319
|
+
|
320
|
+
context "slim" do
|
321
|
+
it "generates action" do
|
322
|
+
with_project("bookshelf_generate_action_slim", template: "slim") do
|
323
|
+
output = [
|
324
|
+
"create apps/web/templates/books/index.html.slim"
|
325
|
+
]
|
326
|
+
|
327
|
+
run_cmd "hanami generate action web books#index", output
|
328
|
+
|
329
|
+
#
|
330
|
+
# apps/web/templates/books/index.html.slim
|
331
|
+
#
|
332
|
+
expect("apps/web/templates/books/index.html.slim").to have_file_content <<~END
|
333
|
+
END
|
334
|
+
|
335
|
+
#
|
336
|
+
# spec/web/views/books/index_spec.rb
|
337
|
+
#
|
338
|
+
expect("spec/web/views/books/index_spec.rb").to have_file_content %r{'apps/web/templates/books/index.html.slim'}
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end # slim
|
342
|
+
|
343
|
+
context "minitest" do
|
344
|
+
it "generates action" do
|
345
|
+
with_project("bookshelf_generate_action_minitest", test: "minitest") do
|
346
|
+
output = [
|
347
|
+
"create spec/web/controllers/books/index_spec.rb",
|
348
|
+
"create spec/web/views/books/index_spec.rb"
|
349
|
+
]
|
350
|
+
|
351
|
+
run_cmd "hanami generate action web books#index", output
|
352
|
+
|
353
|
+
#
|
354
|
+
# spec/web/controllers/books/index_spec.rb
|
355
|
+
#
|
356
|
+
expect("spec/web/controllers/books/index_spec.rb").to have_file_content <<~END
|
357
|
+
require_relative '../../../spec_helper'
|
358
|
+
|
359
|
+
describe Web::Controllers::Books::Index do
|
360
|
+
let(:action) { Web::Controllers::Books::Index.new }
|
361
|
+
let(:params) { Hash[] }
|
362
|
+
|
363
|
+
it 'is successful' do
|
364
|
+
response = action.call(params)
|
365
|
+
_(response[0]).must_equal 200
|
366
|
+
end
|
367
|
+
end
|
368
|
+
END
|
369
|
+
|
370
|
+
#
|
371
|
+
# spec/web/views/books/index_spec.rb
|
372
|
+
#
|
373
|
+
expect("spec/web/views/books/index_spec.rb").to have_file_content <<~END
|
374
|
+
require_relative '../../../spec_helper'
|
375
|
+
|
376
|
+
describe Web::Views::Books::Index do
|
377
|
+
let(:exposures) { Hash[format: :html] }
|
378
|
+
let(:template) { Hanami::View::Template.new('apps/web/templates/books/index.html.erb') }
|
379
|
+
let(:view) { Web::Views::Books::Index.new(template, exposures) }
|
380
|
+
let(:rendered) { view.render }
|
381
|
+
|
382
|
+
it 'exposes #format' do
|
383
|
+
_(view.format).must_equal exposures.fetch(:format)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
END
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end # minitest
|
390
|
+
|
391
|
+
context "rspec" do
|
392
|
+
it "generates action" do
|
393
|
+
with_project("bookshelf_generate_action_rspec", test: "rspec") do
|
394
|
+
output = [
|
395
|
+
"create spec/web/controllers/books/index_spec.rb",
|
396
|
+
"create spec/web/views/books/index_spec.rb"
|
397
|
+
]
|
398
|
+
|
399
|
+
run_cmd "hanami generate action web books#index", output
|
400
|
+
|
401
|
+
#
|
402
|
+
# spec/web/controllers/books/index_spec.rb
|
403
|
+
#
|
404
|
+
expect("spec/web/controllers/books/index_spec.rb").to have_file_content <<~END
|
405
|
+
RSpec.describe Web::Controllers::Books::Index, type: :action do
|
406
|
+
let(:action) { described_class.new }
|
407
|
+
let(:params) { Hash[] }
|
408
|
+
|
409
|
+
it 'is successful' do
|
410
|
+
response = action.call(params)
|
411
|
+
expect(response[0]).to eq 200
|
412
|
+
end
|
413
|
+
end
|
414
|
+
END
|
415
|
+
|
416
|
+
#
|
417
|
+
# spec/web/views/books/index_spec.rb
|
418
|
+
#
|
419
|
+
expect("spec/web/views/books/index_spec.rb").to have_file_content <<~END
|
420
|
+
RSpec.describe Web::Views::Books::Index, type: :view do
|
421
|
+
let(:exposures) { Hash[format: :html] }
|
422
|
+
let(:template) { Hanami::View::Template.new('apps/web/templates/books/index.html.erb') }
|
423
|
+
let(:view) { described_class.new(template, exposures) }
|
424
|
+
let(:rendered) { view.render }
|
425
|
+
|
426
|
+
it 'exposes #format' do
|
427
|
+
expect(view.format).to eq exposures.fetch(:format)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
END
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end # rspec
|
434
|
+
|
435
|
+
it "prints help message" do
|
436
|
+
with_project do
|
437
|
+
output = <<~OUT
|
438
|
+
Command:
|
439
|
+
hanami generate action
|
440
|
+
|
441
|
+
Usage:
|
442
|
+
hanami generate action APP ACTION
|
443
|
+
|
444
|
+
Description:
|
445
|
+
Generate an action for app
|
446
|
+
|
447
|
+
Arguments:
|
448
|
+
APP # REQUIRED The app name (eg. `web`)
|
449
|
+
ACTION # REQUIRED The action name (eg. `home#index`)
|
450
|
+
|
451
|
+
Options:
|
452
|
+
--url=VALUE # The action URL
|
453
|
+
--method=VALUE # The action HTTP method
|
454
|
+
--[no-]skip-view # Skip view and template, default: false
|
455
|
+
--help, -h # Print this help
|
456
|
+
|
457
|
+
Examples:
|
458
|
+
hanami generate action web home#index # Basic usage
|
459
|
+
hanami generate action admin home#index # Generate for `admin` app
|
460
|
+
hanami generate action web home#index --url=/ # Specify URL
|
461
|
+
hanami generate action web sessions#destroy --method=GET # Specify HTTP method
|
462
|
+
hanami generate action web books#create --skip-view # Skip view and template
|
463
|
+
OUT
|
464
|
+
|
465
|
+
run_cmd 'hanami generate action --help', output
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end # action
|
469
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/utils/string"
|
4
|
+
|
5
|
+
RSpec.describe "hanami generate", type: :integration do
|
6
|
+
describe "app" do
|
7
|
+
context "with app name" do
|
8
|
+
it_behaves_like "a new app" do
|
9
|
+
let(:input) { "admin" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with underscored app name" do
|
14
|
+
it_behaves_like "a new app" do
|
15
|
+
let(:input) { "cool_app" }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with dashed app name" do
|
20
|
+
it_behaves_like "a new app" do
|
21
|
+
let(:input) { "awesome-app" }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with camel case app name" do
|
26
|
+
it_behaves_like "a new app" do
|
27
|
+
let(:input) { "CaMElAPp" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "without require_relative" do
|
32
|
+
it "generates app" do
|
33
|
+
with_project("bookshelf_generate_app_without_require_relative") do
|
34
|
+
app = "no_req_relative"
|
35
|
+
app_name = Hanami::Utils::String.new(app).classify
|
36
|
+
output = [
|
37
|
+
"insert config/environment.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
File.write(
|
41
|
+
"config/environment.rb",
|
42
|
+
File
|
43
|
+
.read("config/environment.rb")
|
44
|
+
.lines
|
45
|
+
.reject { |l| l[/^require_relative '.*'\n$/] }
|
46
|
+
.reject { |l| l[/^ mount Web::App, at: '\/'\n$/] }
|
47
|
+
.join("")
|
48
|
+
)
|
49
|
+
|
50
|
+
run_cmd "hanami generate app #{app}", output
|
51
|
+
|
52
|
+
#
|
53
|
+
# config/environment.rb
|
54
|
+
#
|
55
|
+
expect("config/environment.rb").to have_file_content(%r{require_relative '../apps/#{app}/app'})
|
56
|
+
expect("config/environment.rb").to have_file_content(%r{mount #{app_name}::App, at: '/no_req_relative'})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "--app-base-url" do
|
62
|
+
it "generates app" do
|
63
|
+
with_project("bookshelf_generate_app_app_base_url") do
|
64
|
+
app = "api"
|
65
|
+
app_name = Hanami::Utils::String.new(app).classify
|
66
|
+
output = [
|
67
|
+
"insert config/environment.rb"
|
68
|
+
]
|
69
|
+
|
70
|
+
run_cmd "hanami generate app #{app} --app-base-url=/api/v1", output
|
71
|
+
|
72
|
+
#
|
73
|
+
# config/environment.rb
|
74
|
+
#
|
75
|
+
expect("config/environment.rb").to have_file_content(%r{require_relative '../apps/#{app}/app'})
|
76
|
+
expect("config/environment.rb").to have_file_content(%r{mount #{app_name}::App, at: '/api/v1'})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "fails with missing argument" do
|
81
|
+
with_project("bookshelf_generate_app_missing_app_base_url") do
|
82
|
+
output = "`' is not a valid URL"
|
83
|
+
run_cmd "hanami generate app foo --app-base-url=", output, exit_status: 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "erb" do
|
89
|
+
it "generates app" do
|
90
|
+
with_project("bookshelf_generate_app_erb", template: :erb) do
|
91
|
+
app = "admin"
|
92
|
+
app_name = Hanami::Utils::String.new(app).classify
|
93
|
+
output = [
|
94
|
+
"create apps/#{app}/templates/app.html.erb"
|
95
|
+
]
|
96
|
+
|
97
|
+
run_cmd "hanami generate app #{app}", output
|
98
|
+
|
99
|
+
#
|
100
|
+
# apps/admin/templates/app.html.erb
|
101
|
+
#
|
102
|
+
expect("apps/admin/templates/app.html.erb").to have_file_content <<~END
|
103
|
+
<!DOCTYPE html>
|
104
|
+
<html>
|
105
|
+
<head>
|
106
|
+
<title>#{app_name}</title>
|
107
|
+
<%= favicon %>
|
108
|
+
</head>
|
109
|
+
<body>
|
110
|
+
<%= yield %>
|
111
|
+
</body>
|
112
|
+
</html>
|
113
|
+
END
|
114
|
+
#
|
115
|
+
# spec/admin/views/app_layout_spec.rb
|
116
|
+
#
|
117
|
+
expect("spec/admin/views/app_layout_spec.rb").to have_file_content(%r{Admin::Views::AppLayout})
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end # erb
|
121
|
+
|
122
|
+
context "haml" do
|
123
|
+
it "generates app" do
|
124
|
+
with_project("bookshelf_generate_app_haml", template: :haml) do
|
125
|
+
app = "admin"
|
126
|
+
app_name = Hanami::Utils::String.new(app).classify
|
127
|
+
output = [
|
128
|
+
"create apps/#{app}/templates/app.html.haml"
|
129
|
+
]
|
130
|
+
|
131
|
+
run_cmd "hanami generate app #{app}", output
|
132
|
+
|
133
|
+
#
|
134
|
+
# apps/admin/templates/app.html.haml
|
135
|
+
#
|
136
|
+
expect("apps/admin/templates/app.html.haml").to have_file_content <<~END
|
137
|
+
!!!
|
138
|
+
%html
|
139
|
+
%head
|
140
|
+
%title #{app_name}
|
141
|
+
= favicon
|
142
|
+
%body
|
143
|
+
= yield
|
144
|
+
END
|
145
|
+
|
146
|
+
#
|
147
|
+
# spec/admin/views/app_layout_spec.rb
|
148
|
+
#
|
149
|
+
expect("spec/admin/views/app_layout_spec.rb").to have_file_content(%r{Admin::Views::AppLayout})
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end # haml
|
153
|
+
|
154
|
+
context "slim" do
|
155
|
+
it "generates app" do
|
156
|
+
with_project("bookshelf_generate_app_slim", template: :slim) do
|
157
|
+
app = "admin"
|
158
|
+
app_name = Hanami::Utils::String.new(app).classify
|
159
|
+
output = [
|
160
|
+
"create apps/#{app}/templates/app.html.slim"
|
161
|
+
]
|
162
|
+
|
163
|
+
run_cmd "hanami generate app #{app}", output
|
164
|
+
|
165
|
+
#
|
166
|
+
# apps/admin/templates/app.html.slim
|
167
|
+
#
|
168
|
+
expect("apps/admin/templates/app.html.slim").to have_file_content <<~END
|
169
|
+
doctype html
|
170
|
+
html
|
171
|
+
head
|
172
|
+
title
|
173
|
+
| #{app_name}
|
174
|
+
= favicon
|
175
|
+
body
|
176
|
+
= yield
|
177
|
+
END
|
178
|
+
|
179
|
+
#
|
180
|
+
# spec/admin/views/app_layout_spec.rb
|
181
|
+
#
|
182
|
+
expect("spec/admin/views/app_layout_spec.rb").to have_file_content(%r{Admin::Views::AppLayout})
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end # slim
|
186
|
+
|
187
|
+
it "prints help message" do
|
188
|
+
with_project do
|
189
|
+
output = <<~OUT
|
190
|
+
Command:
|
191
|
+
hanami generate app
|
192
|
+
|
193
|
+
Usage:
|
194
|
+
hanami generate app APP
|
195
|
+
|
196
|
+
Description:
|
197
|
+
Generate an app
|
198
|
+
|
199
|
+
Arguments:
|
200
|
+
APP # REQUIRED The app name (eg. `web`)
|
201
|
+
|
202
|
+
Options:
|
203
|
+
--app-base-url=VALUE # The app base URL (eg. `/api/v1`)
|
204
|
+
--help, -h # Print this help
|
205
|
+
|
206
|
+
Examples:
|
207
|
+
hanami generate app admin # Generate `admin` app
|
208
|
+
hanami generate app api --app-base-url=/api/v1 # Generate `api` app and mount at `/api/v1`
|
209
|
+
OUT
|
210
|
+
|
211
|
+
run_cmd 'hanami generate app --help', output
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end # app
|
215
|
+
end
|