hanami 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/lib/hanami/configuration/null_configuration.rb +2 -2
- data/lib/hanami/configuration.rb +17 -17
- data/lib/hanami/routes.rb +48 -21
- data/lib/hanami/version.rb +1 -1
- data/spec/{new_integration → integration}/action/cookies_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/csrf_protection_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/routes_spec.rb +3 -5
- data/spec/{new_integration → integration}/action/sessions_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_integration_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering/automatic_rendering_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering/paired_view_inference_spec.rb +0 -0
- data/spec/{new_integration → integration}/action/view_rendering_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_app_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_lib_spec.rb +0 -0
- data/spec/{new_integration → integration}/code_loading/loading_from_slice_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/application_routes_helper_spec.rb +1 -3
- data/spec/{new_integration → integration}/container/auto_injection_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/auto_registration_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/autoloader_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/imports_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/prepare_container_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/shutdown_spec.rb +0 -0
- data/spec/{new_integration → integration}/container/standard_bootable_components_spec.rb +0 -0
- data/spec/{new_integration → integration}/dotenv_loading_spec.rb +0 -0
- data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +9 -15
- data/spec/{new_integration → integration}/rack_app/non_booted_rack_app_spec.rb +3 -5
- data/spec/{new_integration → integration}/rack_app/rack_app_spec.rb +28 -48
- data/spec/{new_integration → integration}/settings/access_to_constants_spec.rb +0 -0
- data/spec/{new_integration → integration}/settings/loading_from_env_spec.rb +0 -0
- data/spec/{new_integration → integration}/settings/settings_component_loading_spec.rb +0 -0
- data/spec/{new_integration → integration}/settings/using_types_spec.rb +0 -0
- data/spec/{new_integration → integration}/setup_spec.rb +20 -0
- data/spec/{new_integration → integration}/slices/external_slice_spec.rb +2 -4
- data/spec/{new_integration → integration}/slices/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/slices/slice_loading_spec.rb +0 -0
- data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
- data/spec/{new_integration → integration}/slices/slice_settings_spec.rb +0 -0
- data/spec/{new_integration → integration}/slices_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/assets_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/inflector_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/request_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/context/routes_spec.rb +1 -3
- data/spec/{new_integration → integration}/view/context/settings_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/inflector_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/part_namespace_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/path_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/slice_configuration_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/template_spec.rb +0 -0
- data/spec/{new_integration → integration}/view/views_spec.rb +0 -0
- data/spec/unit/hanami/configuration/actions_spec.rb +4 -15
- data/spec/unit/hanami/configuration/router_spec.rb +45 -0
- data/spec/unit/hanami/configuration/views_spec.rb +4 -15
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +97 -244
- data/lib/hanami/server.rb +0 -29
- data/spec/integration/application_middleware_stack_spec.rb +0 -84
- data/spec/integration/assets/cdn_spec.rb +0 -48
- data/spec/integration/assets/fingerprint_spec.rb +0 -42
- data/spec/integration/assets/helpers_spec.rb +0 -50
- data/spec/integration/assets/serve_spec.rb +0 -70
- data/spec/integration/assets/subresource_integrity_spec.rb +0 -54
- data/spec/integration/body_parsers_spec.rb +0 -50
- data/spec/integration/cli/assets/precompile_spec.rb +0 -147
- data/spec/integration/cli/assets_spec.rb +0 -14
- data/spec/integration/cli/console_spec.rb +0 -105
- data/spec/integration/cli/db/apply_spec.rb +0 -74
- data/spec/integration/cli/db/console_spec.rb +0 -40
- data/spec/integration/cli/db/create_spec.rb +0 -50
- data/spec/integration/cli/db/drop_spec.rb +0 -54
- data/spec/integration/cli/db/migrate_spec.rb +0 -108
- data/spec/integration/cli/db/prepare_spec.rb +0 -36
- data/spec/integration/cli/db/rollback_spec.rb +0 -96
- data/spec/integration/cli/db/version_spec.rb +0 -38
- data/spec/integration/cli/db_spec.rb +0 -21
- data/spec/integration/cli/destroy/action_spec.rb +0 -143
- data/spec/integration/cli/destroy/app_spec.rb +0 -118
- data/spec/integration/cli/destroy/mailer_spec.rb +0 -74
- data/spec/integration/cli/destroy/migration_spec.rb +0 -70
- data/spec/integration/cli/destroy/model_spec.rb +0 -113
- data/spec/integration/cli/destroy_spec.rb +0 -18
- data/spec/integration/cli/generate/action_spec.rb +0 -469
- data/spec/integration/cli/generate/app_spec.rb +0 -215
- data/spec/integration/cli/generate/mailer_spec.rb +0 -189
- data/spec/integration/cli/generate/migration_spec.rb +0 -72
- data/spec/integration/cli/generate/model_spec.rb +0 -290
- data/spec/integration/cli/generate/secret_spec.rb +0 -56
- data/spec/integration/cli/generate_spec.rb +0 -19
- data/spec/integration/cli/new/database_spec.rb +0 -235
- data/spec/integration/cli/new/hanami_head_spec.rb +0 -27
- data/spec/integration/cli/new/template_spec.rb +0 -118
- data/spec/integration/cli/new/test_spec.rb +0 -274
- data/spec/integration/cli/new_spec.rb +0 -970
- data/spec/integration/cli/plugins_spec.rb +0 -39
- data/spec/integration/cli/routes_spec.rb +0 -49
- data/spec/integration/cli/server_spec.rb +0 -626
- data/spec/integration/cli/version_spec.rb +0 -85
- data/spec/integration/early_hints_spec.rb +0 -35
- data/spec/integration/handle_exceptions_spec.rb +0 -244
- data/spec/integration/head_spec.rb +0 -89
- data/spec/integration/http_headers_spec.rb +0 -29
- data/spec/integration/mailer_spec.rb +0 -32
- data/spec/integration/middleware_spec.rb +0 -81
- data/spec/integration/mount_applications_spec.rb +0 -88
- data/spec/integration/project_initializers_spec.rb +0 -40
- data/spec/integration/rackup_spec.rb +0 -35
- data/spec/integration/rake/with_minitest_spec.rb +0 -67
- data/spec/integration/rake/with_rspec_spec.rb +0 -69
- data/spec/integration/routing_helpers_spec.rb +0 -61
- data/spec/integration/security/content_security_policy_spec.rb +0 -46
- data/spec/integration/security/csrf_protection_spec.rb +0 -42
- data/spec/integration/security/force_ssl_spec.rb +0 -29
- data/spec/integration/security/x_content_type_options_spec.rb +0 -46
- data/spec/integration/security/x_frame_options_spec.rb +0 -46
- data/spec/integration/security/x_xss_protection_spec.rb +0 -46
- data/spec/integration/send_file_spec.rb +0 -51
- data/spec/integration/sessions_spec.rb +0 -247
- data/spec/integration/static_middleware_spec.rb +0 -21
- data/spec/integration/streaming_spec.rb +0 -41
- data/spec/integration/unsafe_send_file_spec.rb +0 -52
- data/spec/support/fixtures/hanami-plugin/Gemfile +0 -8
- data/spec/support/fixtures/hanami-plugin/README.md +0 -35
- data/spec/support/fixtures/hanami-plugin/Rakefile +0 -4
- data/spec/support/fixtures/hanami-plugin/bin/console +0 -15
- data/spec/support/fixtures/hanami-plugin/bin/setup +0 -8
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +0 -28
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +0 -19
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +0 -7
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +0 -8
- data/spec/unit/hanami/routes_spec.rb +0 -25
@@ -1,469 +0,0 @@
|
|
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
|
@@ -1,215 +0,0 @@
|
|
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
|