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,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
RSpec.describe "CLI plugins", type: :integration do
|
6
|
-
xit "includes its commands in CLI output" do
|
7
|
-
with_project do
|
8
|
-
bundle_exec "hanami"
|
9
|
-
expect(out).to include("hanami plugin [SUBCOMMAND]")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
xit "executes command from plugin" do
|
14
|
-
with_project do
|
15
|
-
bundle_exec "hanami plugin version"
|
16
|
-
expect(out).to include("v0.1.0")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# See https://github.com/hanami/hanami/issues/838
|
21
|
-
it "guarantees 'hanami new' to generate a project" do
|
22
|
-
project = "bookshelf_without_gemfile"
|
23
|
-
|
24
|
-
with_system_tmp_directory do
|
25
|
-
run_cmd_with_clean_env "hanami new #{project}"
|
26
|
-
destination = Pathname.new(Dir.pwd).join(project)
|
27
|
-
|
28
|
-
expect(destination).to exist
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def with_project
|
35
|
-
super("bookshelf", gems: { "hanami-plugin" => { groups: [:plugins], path: Pathname.new(__dir__).join("..", "..", "..", "spec", "support", "fixtures", "hanami-plugin").realpath.to_s } }) do
|
36
|
-
yield
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "hanami routes", type: :integration do
|
4
|
-
it "prints app routes" do
|
5
|
-
with_project do
|
6
|
-
generate "app admin"
|
7
|
-
|
8
|
-
write "lib/ping.rb", <<~EOF
|
9
|
-
class Ping
|
10
|
-
def call(env)
|
11
|
-
[200, {}, ["PONG"]]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
EOF
|
15
|
-
|
16
|
-
unshift "config/environment.rb", "require_relative '../lib/ping'"
|
17
|
-
replace "config/environment.rb", "Hanami.configure do", "Hanami.configure do\nmount Ping, at: '/ping'"
|
18
|
-
|
19
|
-
generate "action web home#index --url=/"
|
20
|
-
generate "action web books#create --url=/books --method=POST"
|
21
|
-
|
22
|
-
generate "action admin home#index --url=/"
|
23
|
-
|
24
|
-
hanami "routes"
|
25
|
-
|
26
|
-
expect(out).to eq "Name Method Path Action \n\n /ping Ping \n\n Name Method Path Action \n\n GET, HEAD /admin Admin::Controllers::Home::Index\n\n Name Method Path Action \n\n GET, HEAD / Web::Controllers::Home::Index \n POST /books Web::Controllers::Books::Create"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "prints help message" do
|
31
|
-
with_project do
|
32
|
-
output = <<~OUT
|
33
|
-
Command:
|
34
|
-
hanami routes
|
35
|
-
|
36
|
-
Usage:
|
37
|
-
hanami routes
|
38
|
-
|
39
|
-
Description:
|
40
|
-
Prints routes
|
41
|
-
|
42
|
-
Options:
|
43
|
-
--help, -h # Print this help
|
44
|
-
OUT
|
45
|
-
|
46
|
-
run_cmd 'hanami routes --help', output
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,626 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
RSpec.describe "hanami server", type: :integration do
|
6
|
-
context "without routes" do
|
7
|
-
it "shows welcome page" do
|
8
|
-
with_project do
|
9
|
-
server do
|
10
|
-
visit "/"
|
11
|
-
|
12
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
13
|
-
|
14
|
-
expect(page).to have_content("The web, with simplicity.")
|
15
|
-
expect(page).to have_content("Hanami is Open Source Software for MVC web development with Ruby.")
|
16
|
-
expect(page).to have_content("bundle exec hanami generate action web 'home#index' --url=/")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "shows welcome page for generated app" do
|
22
|
-
with_project do
|
23
|
-
generate "app admin"
|
24
|
-
|
25
|
-
server do
|
26
|
-
visit "/admin"
|
27
|
-
|
28
|
-
expect(page).to have_content("bundle exec hanami generate action admin 'home#index' --url=/")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with routes" do
|
35
|
-
it "serves action" do
|
36
|
-
with_project do
|
37
|
-
server do
|
38
|
-
generate "action web home#index --url=/"
|
39
|
-
|
40
|
-
visit "/"
|
41
|
-
expect(page).to have_title("Web")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "serves static asset" do
|
47
|
-
with_project do
|
48
|
-
server do
|
49
|
-
write "apps/web/assets/javascripts/app.js", <<~EOF
|
50
|
-
console.log('test');
|
51
|
-
EOF
|
52
|
-
visit "/assets/app.js"
|
53
|
-
expect(page).to have_content("console.log('test');")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "serves contents from database" do
|
59
|
-
with_project do
|
60
|
-
setup_model
|
61
|
-
console do |input, _, _|
|
62
|
-
input.puts("BookRepository.new.create(title: 'Learn Hanami')")
|
63
|
-
input.puts("exit")
|
64
|
-
end
|
65
|
-
|
66
|
-
generate "action web books#show --url=/books/:id"
|
67
|
-
rewrite "apps/web/controllers/books/show.rb", <<~EOF
|
68
|
-
module Web::Controllers::Books
|
69
|
-
class Show
|
70
|
-
include Web::Action
|
71
|
-
expose :book
|
72
|
-
|
73
|
-
def call(params)
|
74
|
-
@book = BookRepository.new.find(params[:id]) or halt(404)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
EOF
|
79
|
-
rewrite "apps/web/templates/books/show.html.erb", <<~EOF
|
80
|
-
<h1><%= book.title %></h1>
|
81
|
-
EOF
|
82
|
-
|
83
|
-
server do
|
84
|
-
visit "/books/1"
|
85
|
-
expect(page).to have_content("Learn Hanami")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "logging" do
|
92
|
-
let(:log) { "log/development.log" }
|
93
|
-
let(:project) { "bookshelf" }
|
94
|
-
|
95
|
-
context "when enabled" do
|
96
|
-
it "logs GET requests" do
|
97
|
-
with_project(project) do
|
98
|
-
touch log
|
99
|
-
replace "config/environment.rb", "logger level: :debug", %(logger level: :debug, stream: "#{log}")
|
100
|
-
|
101
|
-
server do
|
102
|
-
visit "/"
|
103
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
104
|
-
end
|
105
|
-
|
106
|
-
content = contents(log)
|
107
|
-
expect(content).to include("[#{project}] [INFO]")
|
108
|
-
expect(content).to match(%r{HTTP/1.1 GET 200 (.*) /})
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "logs GET requests with query string" do
|
113
|
-
with_project(project) do
|
114
|
-
touch log
|
115
|
-
replace "config/environment.rb", "logger level: :debug", %(logger level: :debug, stream: "#{log}")
|
116
|
-
|
117
|
-
run_cmd "hanami generate action web home#index --url=/", []
|
118
|
-
|
119
|
-
server do
|
120
|
-
visit "/?ping=pong"
|
121
|
-
expect(page).to have_title("Web")
|
122
|
-
end
|
123
|
-
|
124
|
-
content = contents(log)
|
125
|
-
expect(content).to include("[#{project}] [INFO]")
|
126
|
-
expect(content).to match(%({"ping"=>"pong"}))
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
it "logs non-GET requests with payload" do
|
131
|
-
with_project(project) do
|
132
|
-
touch log
|
133
|
-
replace "config/environment.rb", "logger level: :debug", %(logger level: :debug, stream: "#{log}")
|
134
|
-
|
135
|
-
run_cmd "hanami generate action web books#create --method=POST", []
|
136
|
-
|
137
|
-
server do
|
138
|
-
post "/books", book: { title: "Functions" }
|
139
|
-
end
|
140
|
-
|
141
|
-
content = contents(log)
|
142
|
-
expect(content).to include("[#{project}] [INFO]")
|
143
|
-
expect(content).to match(%({"book"=>{"title"=>"Functions"}}))
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
it "logs non-GET requests from body parsers" do
|
148
|
-
with_project(project) do
|
149
|
-
touch log
|
150
|
-
replace "config/environment.rb", "logger level: :debug", %(logger level: :debug, stream: "#{log}")
|
151
|
-
inject_line_after "config/environment.rb", "Hanami.configure", "require 'hanami/middleware/body_parser'\nmiddleware.use Hanami::Middleware::BodyParser, :json"
|
152
|
-
|
153
|
-
run_cmd "hanami generate action web books#create --method=POST", []
|
154
|
-
inject_line_after "apps/web/controllers/books/create.rb", "call", 'Hanami.logger.debug(request.env["CONTENT_TYPE"]);self.body = %({"status":"OK"})'
|
155
|
-
|
156
|
-
server do
|
157
|
-
post "/books", book: { title: "Why we sleep" }
|
158
|
-
post "/books", JSON.generate(book: { title: "Parsers" }), "CONTENT_TYPE" => "app/json", "HTTP_ACCEPT" => "app/json"
|
159
|
-
post "/books", JSON.generate(%w[this is cool]), "CONTENT_TYPE" => "app/json", "HTTP_ACCEPT" => "app/json"
|
160
|
-
end
|
161
|
-
|
162
|
-
content = contents(log)
|
163
|
-
expect(content).to include("[#{project}] [INFO]")
|
164
|
-
expect(content).to include("POST 200")
|
165
|
-
|
166
|
-
expect(content).to include("app/x-www-form-urlencoded")
|
167
|
-
expect(content).to include(%({"book"=>{"title"=>"Why we sleep"}}))
|
168
|
-
|
169
|
-
expect(content).to include("app/json")
|
170
|
-
expect(content).to include(%({"book"=>{"title"=>"Parsers"}}))
|
171
|
-
expect(content).to include(%({"_"=>["this", "is", "cool"]}))
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when not enabled" do
|
177
|
-
it "does not log request" do
|
178
|
-
with_project(project) do
|
179
|
-
replace "config/environment.rb", "logger level: :debug", ""
|
180
|
-
|
181
|
-
server do
|
182
|
-
visit "/"
|
183
|
-
end
|
184
|
-
|
185
|
-
expect(log).to_not be_an_existing_file
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context "--host" do
|
192
|
-
it "starts on given host" do
|
193
|
-
with_project do
|
194
|
-
server(host: "127.0.0.1") do
|
195
|
-
visit "/"
|
196
|
-
|
197
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
xit "fails when missing" do
|
203
|
-
with_project do
|
204
|
-
server(host: nil)
|
205
|
-
|
206
|
-
expect(exitstatus).to eq(1)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context "--port" do
|
212
|
-
it "starts on given port" do
|
213
|
-
with_project do
|
214
|
-
server(port: 1982) do
|
215
|
-
visit "/"
|
216
|
-
|
217
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
xit "fails when missing" do
|
223
|
-
with_project do
|
224
|
-
server(port: nil)
|
225
|
-
|
226
|
-
expect(exitstatus).to eq(1)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "environment" do
|
232
|
-
it "starts with given environment" do
|
233
|
-
with_project do
|
234
|
-
generate "action web home#index --url=/"
|
235
|
-
|
236
|
-
rewrite "apps/web/controllers/home/index.rb", <<~EOF
|
237
|
-
module Web::Controllers::Home
|
238
|
-
class Index
|
239
|
-
include Web::Action
|
240
|
-
|
241
|
-
def call(params)
|
242
|
-
self.body = Hanami.env
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
EOF
|
247
|
-
|
248
|
-
RSpec::Support::Env["HANAMI_ENV"] = env = "production"
|
249
|
-
RSpec::Support::Env["DATABASE_URL"] = "sqlite://#{Pathname.new('db').join('bookshelf.sqlite')}"
|
250
|
-
RSpec::Support::Env["SMTP_HOST"] = "localhost"
|
251
|
-
RSpec::Support::Env["SMTP_PORT"] = "25"
|
252
|
-
|
253
|
-
server do
|
254
|
-
visit "/"
|
255
|
-
|
256
|
-
expect(page).to have_content(env)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
xit "fails when missing" do
|
262
|
-
with_project do
|
263
|
-
server(environment: nil)
|
264
|
-
|
265
|
-
expect(exitstatus).to eq(1)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context "puma" do
|
271
|
-
it "starts" do
|
272
|
-
with_project("bookshelf_server_puma", server: :puma) do
|
273
|
-
server do
|
274
|
-
visit "/"
|
275
|
-
|
276
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
context "unicorn" do
|
283
|
-
it "starts" do
|
284
|
-
with_project("bookshelf_server_unicorn", server: :unicorn) do
|
285
|
-
server do
|
286
|
-
visit "/"
|
287
|
-
|
288
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
context "code reloading" do
|
295
|
-
it "reloads templates code" do
|
296
|
-
with_project do
|
297
|
-
server do
|
298
|
-
visit "/"
|
299
|
-
|
300
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
301
|
-
generate "action web home#index --url=/"
|
302
|
-
|
303
|
-
rewrite "apps/web/templates/home/index.html.erb", <<~EOF
|
304
|
-
<h1>Hello, World!</h1>
|
305
|
-
EOF
|
306
|
-
|
307
|
-
visit "/"
|
308
|
-
expect(page).to have_title("Web")
|
309
|
-
expect(page).to have_content("Hello, World!")
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
it "reloads view" do
|
315
|
-
with_project do
|
316
|
-
server do
|
317
|
-
visit "/"
|
318
|
-
|
319
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
320
|
-
generate "action web home#index --url=/"
|
321
|
-
|
322
|
-
rewrite "apps/web/views/home/index.rb", <<~EOF
|
323
|
-
module Web::Views::Home
|
324
|
-
class Index
|
325
|
-
include Web::View
|
326
|
-
|
327
|
-
def greeting
|
328
|
-
"Ciao!"
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|
332
|
-
EOF
|
333
|
-
|
334
|
-
rewrite "apps/web/templates/home/index.html.erb", <<~EOF
|
335
|
-
<%= greeting %>
|
336
|
-
EOF
|
337
|
-
|
338
|
-
visit "/"
|
339
|
-
expect(page).to have_title("Web")
|
340
|
-
expect(page).to have_content("Ciao!")
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
it "reloads action" do
|
346
|
-
with_project do
|
347
|
-
server do
|
348
|
-
visit "/"
|
349
|
-
|
350
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
351
|
-
generate "action web home#index --url=/"
|
352
|
-
|
353
|
-
rewrite "apps/web/controllers/home/index.rb", <<~EOF
|
354
|
-
module Web::Controllers::Home
|
355
|
-
class Index
|
356
|
-
include Web::Action
|
357
|
-
|
358
|
-
def call(params)
|
359
|
-
self.body = "Hi!"
|
360
|
-
end
|
361
|
-
end
|
362
|
-
end
|
363
|
-
EOF
|
364
|
-
|
365
|
-
visit "/"
|
366
|
-
expect(page).to have_content("Hi!")
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
it "reloads model" do
|
372
|
-
project_name = "bookshelf"
|
373
|
-
|
374
|
-
with_project(project_name) do
|
375
|
-
# STEP 1: prepare the database and the repository
|
376
|
-
generate_model "user"
|
377
|
-
generate_migration "create_users", <<~EOF
|
378
|
-
Hanami::Model.migration do
|
379
|
-
change do
|
380
|
-
create_table :users do
|
381
|
-
primary_key :id
|
382
|
-
column :name, String
|
383
|
-
end
|
384
|
-
|
385
|
-
execute "INSERT INTO users (name) VALUES('L')"
|
386
|
-
execute "INSERT INTO users (name) VALUES('MG')"
|
387
|
-
end
|
388
|
-
end
|
389
|
-
EOF
|
390
|
-
|
391
|
-
rewrite "lib/#{project_name}/repositories/user_repository.rb", <<~EOF
|
392
|
-
class UserRepository < Hanami::Repository
|
393
|
-
def listing
|
394
|
-
all
|
395
|
-
end
|
396
|
-
end
|
397
|
-
EOF
|
398
|
-
|
399
|
-
hanami "db prepare"
|
400
|
-
|
401
|
-
# STEP 2: generate the action
|
402
|
-
generate "action web users#index --url=/users"
|
403
|
-
|
404
|
-
rewrite "apps/web/controllers/users/index.rb", <<~EOF
|
405
|
-
module Web::Controllers::Users
|
406
|
-
class Index
|
407
|
-
include Web::Action
|
408
|
-
|
409
|
-
def call(params)
|
410
|
-
self.body = UserRepository.new.listing.map(&:name).join(", ")
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
EOF
|
415
|
-
|
416
|
-
server do
|
417
|
-
# STEP 3: visit the page
|
418
|
-
visit "/users"
|
419
|
-
|
420
|
-
expect(page).to have_content("L, MG")
|
421
|
-
|
422
|
-
# STEP 4: change the repository, then visit the page again
|
423
|
-
rewrite "lib/#{project_name}/repositories/user_repository.rb", <<~EOF
|
424
|
-
class UserRepository < Hanami::Repository
|
425
|
-
def listing
|
426
|
-
all.reverse
|
427
|
-
end
|
428
|
-
end
|
429
|
-
EOF
|
430
|
-
visit "/users"
|
431
|
-
|
432
|
-
expect(page).to have_content("MG, L")
|
433
|
-
end
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
xit "reloads asset" do
|
438
|
-
with_project do
|
439
|
-
server do
|
440
|
-
write "apps/web/assets/stylesheets/style.css", <<~EOF
|
441
|
-
body { background-color: #fff; }
|
442
|
-
EOF
|
443
|
-
|
444
|
-
visit "/assets/style.css"
|
445
|
-
expect(page).to have_content("#fff")
|
446
|
-
|
447
|
-
rewrite "apps/web/assets/stylesheets/style.css", <<~EOF
|
448
|
-
body { background-color: #333; }
|
449
|
-
EOF
|
450
|
-
|
451
|
-
visit "/assets/style.css"
|
452
|
-
expect(page).to have_content("#333")
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
context "without code reloading" do
|
459
|
-
it "doesn't reload code" do
|
460
|
-
with_project do
|
461
|
-
server("no-code-reloading" => nil) do
|
462
|
-
visit "/"
|
463
|
-
|
464
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
465
|
-
generate "action web home#index --url=/"
|
466
|
-
|
467
|
-
visit "/"
|
468
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
469
|
-
end
|
470
|
-
end
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
context "without hanami model" do
|
475
|
-
it "uses custom model domain" do
|
476
|
-
project_without_hanami_model("bookshelf", gems: ["dry-struct"]) do
|
477
|
-
write "lib/entities/access_token.rb", <<~EOF
|
478
|
-
require 'dry-struct'
|
479
|
-
require 'securerandom'
|
480
|
-
|
481
|
-
module Types
|
482
|
-
include Dry::Types.module
|
483
|
-
end
|
484
|
-
|
485
|
-
class AccessToken < Dry::Struct
|
486
|
-
attribute :id, Types::String.default { SecureRandom.uuid }
|
487
|
-
attribute :secret, Types::String
|
488
|
-
attribute :digest, Types::String
|
489
|
-
end
|
490
|
-
EOF
|
491
|
-
generate "action web access_tokens#show --url=/access_tokens/:id"
|
492
|
-
rewrite "apps/web/controllers/access_tokens/show.rb", <<~EOF
|
493
|
-
module Web::Controllers::AccessTokens
|
494
|
-
class Show
|
495
|
-
include Web::Action
|
496
|
-
expose :access_token
|
497
|
-
|
498
|
-
def call(params)
|
499
|
-
@access_token = AccessToken.new(id: '1', secret: 'shh', digest: 'abc')
|
500
|
-
end
|
501
|
-
end
|
502
|
-
end
|
503
|
-
EOF
|
504
|
-
rewrite "apps/web/templates/access_tokens/show.html.erb", <<~EOF
|
505
|
-
<h1><%= access_token.secret %></h1>
|
506
|
-
EOF
|
507
|
-
|
508
|
-
server do
|
509
|
-
visit "/access_tokens/1"
|
510
|
-
visit "/access_tokens/1" # forces code reloading
|
511
|
-
expect(page).to have_content("shh")
|
512
|
-
end
|
513
|
-
end
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
context "without mailer" do
|
518
|
-
it "returns page" do
|
519
|
-
with_project do
|
520
|
-
remove_block "config/environment.rb", "mailer do"
|
521
|
-
|
522
|
-
server do
|
523
|
-
visit "/"
|
524
|
-
expect(page).to have_title("Hanami | The web, with simplicity")
|
525
|
-
end
|
526
|
-
end
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
it "prints help message" do
|
531
|
-
with_project do
|
532
|
-
output = <<-OUT
|
533
|
-
Command:
|
534
|
-
hanami server
|
535
|
-
|
536
|
-
Usage:
|
537
|
-
hanami server
|
538
|
-
|
539
|
-
Description:
|
540
|
-
Start Hanami server (only for development)
|
541
|
-
|
542
|
-
Options:
|
543
|
-
--server=VALUE # Force a server engine (eg, webrick, puma, thin, etc..)
|
544
|
-
--host=VALUE # The host address to bind to
|
545
|
-
--port=VALUE, -p VALUE # The port to run the server on
|
546
|
-
--debug=VALUE # Turn on debug output
|
547
|
-
--warn=VALUE # Turn on warnings
|
548
|
-
--daemonize=VALUE # Daemonize the server
|
549
|
-
--pid=VALUE # Path to write a pid file after daemonize
|
550
|
-
--[no-]code-reloading # Code reloading, default: true
|
551
|
-
--help, -h # Print this help
|
552
|
-
|
553
|
-
Examples:
|
554
|
-
hanami server # Basic usage (it uses the bundled server engine)
|
555
|
-
hanami server --server=webrick # Force `webrick` server engine
|
556
|
-
hanami server --host=0.0.0.0 # Bind to a host
|
557
|
-
hanami server --port=2306 # Bind to a port
|
558
|
-
hanami server --no-code-reloading # Disable code reloading
|
559
|
-
OUT
|
560
|
-
|
561
|
-
run_cmd 'hanami server --help', output
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
context "with HANAMI_APPS ENV variable" do
|
566
|
-
it "loads only specific app" do
|
567
|
-
with_project do
|
568
|
-
generate "app admin"
|
569
|
-
|
570
|
-
remove_line "config/environment.rb", "require_relative '../apps/admin/app'"
|
571
|
-
remove_line "config/environment.rb", "mount Admin::App"
|
572
|
-
|
573
|
-
remove_line "config/environment.rb", "require_relative '../apps/web/app'"
|
574
|
-
remove_line "config/environment.rb", "mount Web::App"
|
575
|
-
|
576
|
-
inject_line_after "config/environment.rb", "Hanami.configure", <<-EOL
|
577
|
-
if Hanami.app?(:admin)
|
578
|
-
require_relative '../apps/admin/app'
|
579
|
-
mount Admin::App, at: '/admin'
|
580
|
-
end
|
581
|
-
|
582
|
-
if Hanami.app?(:web)
|
583
|
-
require_relative '../apps/web/app'
|
584
|
-
mount Web::App, at: '/'
|
585
|
-
end
|
586
|
-
EOL
|
587
|
-
generate "action web home#index --url=/"
|
588
|
-
|
589
|
-
rewrite "apps/web/controllers/home/index.rb", <<~EOF
|
590
|
-
module Web::Controllers::Home
|
591
|
-
class Index
|
592
|
-
include Web::Action
|
593
|
-
|
594
|
-
def call(params)
|
595
|
-
self.body = "app: web"
|
596
|
-
end
|
597
|
-
end
|
598
|
-
end
|
599
|
-
EOF
|
600
|
-
generate "action admin home#index --url=/"
|
601
|
-
|
602
|
-
rewrite "apps/admin/controllers/home/index.rb", <<~EOF
|
603
|
-
module Web::Controllers::Home
|
604
|
-
class Index
|
605
|
-
include Admin::Action
|
606
|
-
|
607
|
-
def call(params)
|
608
|
-
self.body = "app: admin"
|
609
|
-
end
|
610
|
-
end
|
611
|
-
end
|
612
|
-
EOF
|
613
|
-
|
614
|
-
RSpec::Support::Env["HANAMI_APPS"] = "web"
|
615
|
-
|
616
|
-
server do
|
617
|
-
visit "/"
|
618
|
-
expect(page).to have_content("app: web")
|
619
|
-
|
620
|
-
visit "/admin"
|
621
|
-
expect(page).to have_content("Not Found")
|
622
|
-
end
|
623
|
-
end
|
624
|
-
end
|
625
|
-
end
|
626
|
-
end
|