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,189 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "hanami generate", type: :integration do
|
4
|
-
describe "mailer" do
|
5
|
-
context "generates a new mailer" do
|
6
|
-
let(:output) do
|
7
|
-
["create lib/bookshelf_generate_mailer/mailers/welcome.rb",
|
8
|
-
"create spec/bookshelf_generate_mailer/mailers/welcome_spec.rb",
|
9
|
-
"create lib/bookshelf_generate_mailer/mailers/templates/welcome.txt.erb",
|
10
|
-
"create lib/bookshelf_generate_mailer/mailers/templates/welcome.html.erb"]
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'generate the mailer files' do
|
14
|
-
with_project('bookshelf_generate_mailer', test: 'rspec') do
|
15
|
-
run_cmd "hanami generate mailer welcome", output
|
16
|
-
#
|
17
|
-
# lib/bookshelf_generate_mailer/mailers/welcome.rb
|
18
|
-
#
|
19
|
-
expect("lib/bookshelf_generate_mailer/mailers/welcome.rb").to have_file_content <<~END
|
20
|
-
module Mailers
|
21
|
-
class Welcome
|
22
|
-
include Hanami::Mailer
|
23
|
-
|
24
|
-
from '<from>'
|
25
|
-
to '<to>'
|
26
|
-
subject 'Hello'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
END
|
30
|
-
|
31
|
-
expect("lib/bookshelf_generate_mailer/mailers/templates/welcome.txt.erb").to have_file_content ""
|
32
|
-
expect("lib/bookshelf_generate_mailer/mailers/templates/welcome.html.erb").to have_file_content ""
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'generates a proper minitest file' do
|
37
|
-
with_project('bookshelf_generate_mailer', test: 'minitest') do
|
38
|
-
run_cmd "hanami generate mailer welcome", output
|
39
|
-
#
|
40
|
-
# spec/bookshelf_generate_mailer/mailers/welcome_spec.rb
|
41
|
-
#
|
42
|
-
expect("spec/bookshelf_generate_mailer/mailers/welcome_spec.rb").to have_file_content <<~END
|
43
|
-
require_relative '../../spec_helper'
|
44
|
-
|
45
|
-
describe Mailers::Welcome do
|
46
|
-
it 'delivers email' do
|
47
|
-
mail = Mailers::Welcome.deliver
|
48
|
-
end
|
49
|
-
end
|
50
|
-
END
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'generates a proper RSpec file' do
|
55
|
-
with_project('bookshelf_generate_mailer', test: 'rspec') do
|
56
|
-
run_cmd "hanami generate mailer welcome", output
|
57
|
-
#
|
58
|
-
# spec/bookshelf_generate_mailer/mailers/welcome_spec.rb
|
59
|
-
#
|
60
|
-
expect("spec/bookshelf_generate_mailer/mailers/welcome_spec.rb").to have_file_content <<~END
|
61
|
-
RSpec.describe Mailers::Welcome, type: :mailer do
|
62
|
-
it 'delivers email' do
|
63
|
-
mail = Mailers::Welcome.deliver
|
64
|
-
end
|
65
|
-
end
|
66
|
-
END
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it "generates mailer with options from, to and subject with single quotes" do
|
72
|
-
with_project("bookshelf_generate_mailer_with_options") do
|
73
|
-
output = [
|
74
|
-
"create spec/bookshelf_generate_mailer_with_options/mailers/welcome_spec.rb",
|
75
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb",
|
76
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.txt.erb",
|
77
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.html.erb"
|
78
|
-
]
|
79
|
-
|
80
|
-
run_cmd "hanami generate mailer welcome --from=\"'mail@example.com'\" --to=\"'user@example.com'\" --subject=\"'Let\'s start'\"", output
|
81
|
-
|
82
|
-
expect("lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb").to have_file_content <<~END
|
83
|
-
module Mailers
|
84
|
-
class Welcome
|
85
|
-
include Hanami::Mailer
|
86
|
-
|
87
|
-
from 'mail@example.com'
|
88
|
-
to 'user@example.com'
|
89
|
-
subject 'Let\'s start'
|
90
|
-
end
|
91
|
-
end
|
92
|
-
END
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "generates mailer with options from, to and subject with double quotes" do
|
97
|
-
with_project("bookshelf_generate_mailer_with_options") do
|
98
|
-
output = [
|
99
|
-
"create spec/bookshelf_generate_mailer_with_options/mailers/welcome_spec.rb",
|
100
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb",
|
101
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.txt.erb",
|
102
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.html.erb"
|
103
|
-
]
|
104
|
-
|
105
|
-
run_cmd "hanami generate mailer welcome --from='\"mail@example.com\"' --to='\"user@example.com\"' --subject='\"Come on \"Folks\"\"'", output
|
106
|
-
|
107
|
-
expect("lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb").to have_file_content <<~END
|
108
|
-
module Mailers
|
109
|
-
class Welcome
|
110
|
-
include Hanami::Mailer
|
111
|
-
|
112
|
-
from 'mail@example.com'
|
113
|
-
to 'user@example.com'
|
114
|
-
subject 'Come on "Folks"'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
END
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
it "generates mailer with options from, to and subject without quotes" do
|
122
|
-
with_project("bookshelf_generate_mailer_with_options") do
|
123
|
-
output = [
|
124
|
-
"create spec/bookshelf_generate_mailer_with_options/mailers/welcome_spec.rb",
|
125
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb",
|
126
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.txt.erb",
|
127
|
-
"create lib/bookshelf_generate_mailer_with_options/mailers/templates/welcome.html.erb"
|
128
|
-
]
|
129
|
-
|
130
|
-
run_cmd "hanami generate mailer welcome --from=mail@example.com --to=user@example.com --subject=Welcome", output
|
131
|
-
|
132
|
-
expect("lib/bookshelf_generate_mailer_with_options/mailers/welcome.rb").to have_file_content <<~END
|
133
|
-
module Mailers
|
134
|
-
class Welcome
|
135
|
-
include Hanami::Mailer
|
136
|
-
|
137
|
-
from 'mail@example.com'
|
138
|
-
to 'user@example.com'
|
139
|
-
subject 'Welcome'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
END
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it "fails with missing arguments" do
|
147
|
-
with_project("bookshelf_generate_mailer_without_args") do
|
148
|
-
output = <<~OUT
|
149
|
-
ERROR: "hanami generate mailer" was called with no arguments
|
150
|
-
Usage: "hanami generate mailer MAILER"
|
151
|
-
OUT
|
152
|
-
|
153
|
-
run_cmd "hanami generate mailer", output, exit_status: 1
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it "prints help message" do
|
158
|
-
with_project do
|
159
|
-
output = <<~OUT
|
160
|
-
Command:
|
161
|
-
hanami generate mailer
|
162
|
-
|
163
|
-
Usage:
|
164
|
-
hanami generate mailer MAILER
|
165
|
-
|
166
|
-
Description:
|
167
|
-
Generate a mailer
|
168
|
-
|
169
|
-
Arguments:
|
170
|
-
MAILER # REQUIRED The mailer name (eg. `welcome`)
|
171
|
-
|
172
|
-
Options:
|
173
|
-
--from=VALUE # The default `from` field of the mail
|
174
|
-
--to=VALUE # The default `to` field of the mail
|
175
|
-
--subject=VALUE # The mail subject
|
176
|
-
--help, -h # Print this help
|
177
|
-
|
178
|
-
Examples:
|
179
|
-
hanami generate mailer welcome # Basic usage
|
180
|
-
hanami generate mailer welcome --from="noreply@example.com" # Generate with default `from` value
|
181
|
-
hanami generate mailer announcement --to="users@example.com" # Generate with default `to` value
|
182
|
-
hanami generate mailer forgot_password --subject="Your password reset" # Generate with default `subject`
|
183
|
-
OUT
|
184
|
-
|
185
|
-
run_cmd 'hanami generate mailer --help', output
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "hanami generate", type: :integration do
|
4
|
-
describe "migration" do
|
5
|
-
context "with migration name" do
|
6
|
-
it_behaves_like "a new migration" do
|
7
|
-
let(:input) { "users" }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context "with underscored name" do
|
12
|
-
it_behaves_like "a new migration" do
|
13
|
-
let(:input) { "create_users" }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with dashed name" do
|
18
|
-
it_behaves_like "a new migration" do
|
19
|
-
let(:input) { "add-verified-at-to-users" }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "with camel case app name" do
|
24
|
-
it_behaves_like "a new migration" do
|
25
|
-
let(:input) { "AddUniqueIndexUsersEmail" }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with missing argument" do
|
30
|
-
it "fails" do
|
31
|
-
with_project('bookshelf_generate_migration_missing_arguments') do
|
32
|
-
output = <<-END
|
33
|
-
ERROR: "hanami generate migration" was called with no arguments
|
34
|
-
Usage: "hanami generate migration MIGRATION"
|
35
|
-
END
|
36
|
-
|
37
|
-
run_cmd "hanami generate migration", output, exit_status: 1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "prints help message" do
|
43
|
-
with_project do
|
44
|
-
banner = <<~OUT
|
45
|
-
Command:
|
46
|
-
hanami generate migration
|
47
|
-
|
48
|
-
Usage:
|
49
|
-
hanami generate migration MIGRATION
|
50
|
-
|
51
|
-
Description:
|
52
|
-
Generate a migration
|
53
|
-
|
54
|
-
Arguments:
|
55
|
-
MIGRATION # REQUIRED The migration name (eg. `create_users`)
|
56
|
-
|
57
|
-
Options:
|
58
|
-
--help, -h # Print this help
|
59
|
-
|
60
|
-
Examples:
|
61
|
-
OUT
|
62
|
-
|
63
|
-
output = [
|
64
|
-
banner,
|
65
|
-
%r{ hanami generate migration create_users # Generate `db/migrations/[\d]{14}_create_users.rb`},
|
66
|
-
]
|
67
|
-
|
68
|
-
run_cmd 'hanami generate migration --help', output
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end # migration
|
72
|
-
end
|
@@ -1,290 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/utils/string"
|
4
|
-
|
5
|
-
RSpec.describe "hanami generate", type: :integration do
|
6
|
-
describe "model" do
|
7
|
-
context "with model name" do
|
8
|
-
it_behaves_like "a new model" do
|
9
|
-
let(:input) { "user" }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with underscored name" do
|
14
|
-
it_behaves_like "a new model" do
|
15
|
-
let(:input) { "discounted_book" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with dashed name" do
|
20
|
-
it_behaves_like "a new model" do
|
21
|
-
let(:input) { "user-event" }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with camel case name" do
|
26
|
-
it_behaves_like "a new model" do
|
27
|
-
let(:input) { "VerifiedUser" }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with missing argument" do
|
32
|
-
it "fails" do
|
33
|
-
with_project('bookshelf_generate_model_missing_arguments') do
|
34
|
-
output = <<-END
|
35
|
-
ERROR: "hanami generate model" was called with no arguments
|
36
|
-
Usage: "hanami generate model MODEL"
|
37
|
-
END
|
38
|
-
|
39
|
-
run_cmd "hanami generate model", output, exit_status: 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "with missing migrations directory" do
|
45
|
-
it "will create directory and migration" do
|
46
|
-
with_project do
|
47
|
-
model_name = "book"
|
48
|
-
directory = Pathname.new("db").join("migrations")
|
49
|
-
FileUtils.rm_rf(directory)
|
50
|
-
|
51
|
-
run_cmd "hanami generate model #{model_name}"
|
52
|
-
expect(directory).to be_directory
|
53
|
-
|
54
|
-
migration = directory.children.find do |m|
|
55
|
-
m.to_s.include?(model_name)
|
56
|
-
end
|
57
|
-
|
58
|
-
expect(migration).to_not be(nil)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "with skip-migration" do
|
64
|
-
it "doesn't create a migration file" do
|
65
|
-
model_name = "user"
|
66
|
-
table_name = "users"
|
67
|
-
project = "bookshelf_generate_model_skip_migration"
|
68
|
-
with_project(project) do
|
69
|
-
run_cmd "hanami generate model #{model_name} --skip-migration"
|
70
|
-
#
|
71
|
-
# db/migrations/<timestamp>_create_<models>.rb
|
72
|
-
#
|
73
|
-
migrations = Pathname.new("db").join("migrations").children
|
74
|
-
file = migrations.find do |child|
|
75
|
-
child.to_s.include?("create_#{table_name}")
|
76
|
-
end
|
77
|
-
|
78
|
-
expect(file).to be_nil, "Expected to not find a migration matching: create_#{table_name}. Found #{file&.to_s}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
it "doesn't create a migration file when --relation is used" do
|
83
|
-
model_name = "user"
|
84
|
-
table_name = "accounts"
|
85
|
-
project = "bookshelf_generate_model_skip_migration"
|
86
|
-
with_project(project) do
|
87
|
-
run_cmd "hanami generate model #{model_name} --skip-migration --relation=#{table_name}"
|
88
|
-
#
|
89
|
-
# db/migrations/<timestamp>_create_<models>.rb
|
90
|
-
#
|
91
|
-
migrations = Pathname.new("db").join("migrations").children
|
92
|
-
file = migrations.find do |child|
|
93
|
-
child.to_s.include?("create_#{table_name}")
|
94
|
-
end
|
95
|
-
|
96
|
-
expect(file).to be_nil, "Expected to not find a migration matching: create_#{table_name}. Found #{file&.to_s}"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "with relation option" do
|
102
|
-
let(:project) { "generate_model_with_relation_name" }
|
103
|
-
let(:model_name) { "stimulus" }
|
104
|
-
let(:class_name) { "Stimulus" }
|
105
|
-
let(:relation_name) { "stimuli" }
|
106
|
-
|
107
|
-
it "creates correct entity, repository, and migration" do
|
108
|
-
with_project(project) do
|
109
|
-
output = [
|
110
|
-
"create lib/#{project}/entities/#{model_name}.rb",
|
111
|
-
"create lib/#{project}/repositories/#{model_name}_repository.rb",
|
112
|
-
/create db\/migrations\/(\d+)_create_#{relation_name}.rb/
|
113
|
-
]
|
114
|
-
|
115
|
-
run_cmd "hanami generate model #{model_name} --relation=#{relation_name}", output
|
116
|
-
|
117
|
-
expect("lib/#{project}/repositories/#{model_name}_repository.rb").to have_file_content <<~END
|
118
|
-
class #{class_name}Repository < Hanami::Repository
|
119
|
-
self.relation = :#{relation_name}
|
120
|
-
end
|
121
|
-
END
|
122
|
-
|
123
|
-
migration = Pathname.new("db").join("migrations").children.find do |child|
|
124
|
-
child.to_s.include?("create_#{relation_name}")
|
125
|
-
end
|
126
|
-
|
127
|
-
expect(migration.to_s).to have_file_content <<~END
|
128
|
-
Hanami::Model.migration do
|
129
|
-
change do
|
130
|
-
create_table :#{relation_name} do
|
131
|
-
primary_key :id
|
132
|
-
|
133
|
-
column :created_at, DateTime, null: false
|
134
|
-
column :updated_at, DateTime, null: false
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
END
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
it "handles CamelCase arguments" do
|
143
|
-
with_project(project) do
|
144
|
-
model = "sheep"
|
145
|
-
relation_name = "black_sheeps"
|
146
|
-
output = [
|
147
|
-
"create lib/#{project}/entities/#{model}.rb",
|
148
|
-
"create lib/#{project}/repositories/#{model}_repository.rb",
|
149
|
-
/create db\/migrations\/(\d+)_create_#{relation_name}.rb/
|
150
|
-
]
|
151
|
-
|
152
|
-
run_cmd "hanami generate model #{model} --relation=BlackSheeps", output
|
153
|
-
|
154
|
-
expect("lib/#{project}/repositories/sheep_repository.rb").to have_file_content <<~END
|
155
|
-
class SheepRepository < Hanami::Repository
|
156
|
-
self.relation = :#{relation_name}
|
157
|
-
end
|
158
|
-
END
|
159
|
-
|
160
|
-
migration = Pathname.new("db").join("migrations").children.find do |child|
|
161
|
-
child.to_s.include?("create_#{relation_name}")
|
162
|
-
end
|
163
|
-
|
164
|
-
expect(migration.to_s).to have_file_content <<~END
|
165
|
-
Hanami::Model.migration do
|
166
|
-
change do
|
167
|
-
create_table :#{relation_name} do
|
168
|
-
primary_key :id
|
169
|
-
|
170
|
-
column :created_at, DateTime, null: false
|
171
|
-
column :updated_at, DateTime, null: false
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
END
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
it "returns error for blank option" do
|
180
|
-
with_project(project) do
|
181
|
-
run_cmd "hanami generate model #{model_name} --relation=", "`' is not a valid relation name", exit_status: 1
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "minitest" do
|
187
|
-
it "generates model" do
|
188
|
-
project = "bookshelf_generate_model_minitest"
|
189
|
-
|
190
|
-
with_project(project, test: :minitest) do
|
191
|
-
model = "book"
|
192
|
-
class_name = Hanami::Utils::String.new(model).classify
|
193
|
-
output = [
|
194
|
-
"create spec/#{project}/entities/#{model}_spec.rb",
|
195
|
-
"create spec/#{project}/repositories/#{model}_repository_spec.rb"
|
196
|
-
]
|
197
|
-
|
198
|
-
run_cmd "hanami generate model #{model}", output
|
199
|
-
|
200
|
-
#
|
201
|
-
# spec/<project>/entities/<model>_spec.rb
|
202
|
-
#
|
203
|
-
expect("spec/#{project}/entities/#{model}_spec.rb").to have_file_content <<~END
|
204
|
-
require_relative '../../spec_helper'
|
205
|
-
|
206
|
-
describe #{class_name} do
|
207
|
-
# place your tests here
|
208
|
-
end
|
209
|
-
END
|
210
|
-
|
211
|
-
#
|
212
|
-
# spec/<project>/repositories/<model>_repository_spec.rb
|
213
|
-
#
|
214
|
-
expect("spec/#{project}/repositories/#{model}_repository_spec.rb").to have_file_content <<~END
|
215
|
-
require_relative '../../spec_helper'
|
216
|
-
|
217
|
-
describe #{class_name}Repository do
|
218
|
-
# place your tests here
|
219
|
-
end
|
220
|
-
END
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end # minitest
|
224
|
-
|
225
|
-
context "rspec" do
|
226
|
-
it "generates model" do
|
227
|
-
project = "bookshelf_generate_model_rspec"
|
228
|
-
|
229
|
-
with_project(project, test: :rspec) do
|
230
|
-
model = "book"
|
231
|
-
class_name = Hanami::Utils::String.new(model).classify
|
232
|
-
output = [
|
233
|
-
"create spec/#{project}/entities/#{model}_spec.rb",
|
234
|
-
"create spec/#{project}/repositories/#{model}_repository_spec.rb"
|
235
|
-
]
|
236
|
-
|
237
|
-
run_cmd "hanami generate model #{model}", output
|
238
|
-
|
239
|
-
#
|
240
|
-
# spec/<project>/entities/<model>_spec.rb
|
241
|
-
#
|
242
|
-
expect("spec/#{project}/entities/#{model}_spec.rb").to have_file_content <<~END
|
243
|
-
RSpec.describe #{class_name}, type: :entity do
|
244
|
-
# place your tests here
|
245
|
-
end
|
246
|
-
END
|
247
|
-
|
248
|
-
#
|
249
|
-
# spec/<project>/repositories/<model>_repository_spec.rb
|
250
|
-
#
|
251
|
-
expect("spec/#{project}/repositories/#{model}_repository_spec.rb").to have_file_content <<~END
|
252
|
-
RSpec.describe BookRepository, type: :repository do
|
253
|
-
# place your tests here
|
254
|
-
end
|
255
|
-
END
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end # rspec
|
259
|
-
|
260
|
-
it "prints help message" do
|
261
|
-
with_project do
|
262
|
-
output = <<~OUT
|
263
|
-
Command:
|
264
|
-
hanami generate model
|
265
|
-
|
266
|
-
Usage:
|
267
|
-
hanami generate model MODEL
|
268
|
-
|
269
|
-
Description:
|
270
|
-
Generate a model
|
271
|
-
|
272
|
-
Arguments:
|
273
|
-
MODEL # REQUIRED Model name (eg. `user`)
|
274
|
-
|
275
|
-
Options:
|
276
|
-
--[no-]skip-migration # Skip migration, default: false
|
277
|
-
--relation=VALUE # Name of the database relation, default: pluralized model name
|
278
|
-
--help, -h # Print this help
|
279
|
-
|
280
|
-
Examples:
|
281
|
-
hanami generate model user # Generate `User` entity, `UserRepository` repository, and the migration
|
282
|
-
hanami generate model user --skip-migration # Generate `User` entity and `UserRepository` repository
|
283
|
-
hanami generate model user --relation=accounts # Generate `User` entity, `UserRepository` and migration to create `accounts` table
|
284
|
-
OUT
|
285
|
-
|
286
|
-
run_cmd 'hanami generate model --help', output
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end # model
|
290
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "hanami generate", type: :integration do
|
4
|
-
describe "secret" do
|
5
|
-
context "without app name" do
|
6
|
-
it "prints secret" do
|
7
|
-
with_project do
|
8
|
-
generate "secret"
|
9
|
-
|
10
|
-
expect(out).to match(/[\w]{64}/)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "with app name" do
|
16
|
-
it "prints secret" do
|
17
|
-
with_project do
|
18
|
-
generate "secret web"
|
19
|
-
|
20
|
-
expect(out).to match(%r{WEB_SESSIONS_SECRET="[\w]{64}"})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'prints help message' do
|
26
|
-
with_project do
|
27
|
-
banner = <<~OUT
|
28
|
-
Command:
|
29
|
-
hanami generate secret
|
30
|
-
|
31
|
-
Usage:
|
32
|
-
hanami generate secret [APP]
|
33
|
-
|
34
|
-
Description:
|
35
|
-
Generate session secret
|
36
|
-
|
37
|
-
Arguments:
|
38
|
-
APP # The app name (eg. `web`)
|
39
|
-
|
40
|
-
Options:
|
41
|
-
--help, -h # Print this help
|
42
|
-
|
43
|
-
Examples:
|
44
|
-
OUT
|
45
|
-
|
46
|
-
output = [
|
47
|
-
banner,
|
48
|
-
# %r{ hanami generate secret # Prints secret (eg. `[\w]{64}`)},
|
49
|
-
# %r{ hanami generate secret web # Prints session secret (eg. `WEB_SESSIONS_SECRET=[\w]{64}`)}
|
50
|
-
]
|
51
|
-
|
52
|
-
run_cmd 'hanami generate secret --help', output
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end # secret
|
56
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe "hanami generate", type: :integration do
|
4
|
-
it "prints subcommands" do
|
5
|
-
with_project do
|
6
|
-
output = <<~OUT
|
7
|
-
Commands:
|
8
|
-
hanami generate action APP ACTION # Generate an action for app
|
9
|
-
hanami generate app APP # Generate an app
|
10
|
-
hanami generate mailer MAILER # Generate a mailer
|
11
|
-
hanami generate migration MIGRATION # Generate a migration
|
12
|
-
hanami generate model MODEL # Generate a model
|
13
|
-
hanami generate secret [APP] # Generate session secret
|
14
|
-
OUT
|
15
|
-
|
16
|
-
run_cmd "hanami generate", output, exit_status: 1
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|