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,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami db", type: :integration do
|
4
|
+
describe "rollback" do
|
5
|
+
it "rollbacks database" do
|
6
|
+
project = "bookshelf_db_rollback"
|
7
|
+
|
8
|
+
with_project(project) do
|
9
|
+
generate_migrations
|
10
|
+
|
11
|
+
hanami "db create"
|
12
|
+
hanami "db migrate"
|
13
|
+
hanami "db rollback"
|
14
|
+
|
15
|
+
db = Pathname.new("db").join("#{project}_development.sqlite")
|
16
|
+
|
17
|
+
users = `sqlite3 #{db} ".schema users"`
|
18
|
+
expect(users).to include("CREATE TABLE `users`(`id` integer DEFAULT (NULL) NOT NULL PRIMARY KEY AUTOINCREMENT, `name` varchar(255) DEFAULT (NULL) NULL);")
|
19
|
+
|
20
|
+
version = `sqlite3 #{db} "SELECT filename FROM schema_migrations ORDER BY filename DESC LIMIT 1"`
|
21
|
+
expect(version).to_not include("add_age_to_users")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "rollbacks database using custom steps" do
|
26
|
+
project = "bookshelf_db_migrate_custom_steps"
|
27
|
+
|
28
|
+
with_project(project) do
|
29
|
+
generate_migrations
|
30
|
+
|
31
|
+
hanami "db create"
|
32
|
+
hanami "db migrate"
|
33
|
+
hanami "db rollback 2"
|
34
|
+
|
35
|
+
db = Pathname.new("db").join("#{project}_development.sqlite")
|
36
|
+
|
37
|
+
users = `sqlite3 #{db} ".schema users"`
|
38
|
+
expect(users).to_not include("CREATE TABLE `users`(`id` integer DEFAULT (NULL) NOT NULL PRIMARY KEY AUTOINCREMENT, `name` varchar(255) DEFAULT (NULL) NULL);")
|
39
|
+
|
40
|
+
version = `sqlite3 #{db} "SELECT filename FROM schema_migrations ORDER BY filename DESC LIMIT 1"`
|
41
|
+
expect(version).to_not include("create_users")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns an error when steps isn't an integer" do
|
46
|
+
with_project do
|
47
|
+
generate_migrations
|
48
|
+
|
49
|
+
hanami "db create"
|
50
|
+
hanami "db migrate"
|
51
|
+
|
52
|
+
output = "the number of steps must be a positive integer (you entered `quindici')."
|
53
|
+
run_cmd "hanami db rollback quindici", output, exit_status: 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns an error when steps is 0" do
|
58
|
+
with_project do
|
59
|
+
generate_migrations
|
60
|
+
|
61
|
+
hanami "db create"
|
62
|
+
hanami "db migrate"
|
63
|
+
|
64
|
+
output = "the number of steps must be a positive integer (you entered `0')."
|
65
|
+
run_cmd "hanami db rollback 0", output, exit_status: 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "prints help message" do
|
70
|
+
with_project do
|
71
|
+
output = <<~OUT
|
72
|
+
Command:
|
73
|
+
hanami db rollback
|
74
|
+
|
75
|
+
Usage:
|
76
|
+
hanami db rollback [STEPS]
|
77
|
+
|
78
|
+
Description:
|
79
|
+
Rollback migrations
|
80
|
+
|
81
|
+
Arguments:
|
82
|
+
STEPS # Number of steps to rollback the database
|
83
|
+
|
84
|
+
Options:
|
85
|
+
--help, -h # Print this help
|
86
|
+
|
87
|
+
Examples:
|
88
|
+
hanami db rollback # Rollbacks latest migration
|
89
|
+
hanami db rollback 2 # Rollbacks last two migration
|
90
|
+
OUT
|
91
|
+
|
92
|
+
run_cmd 'hanami db rollback --help', output
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami db", type: :integration do
|
4
|
+
describe "version" do
|
5
|
+
it "prints database version" do
|
6
|
+
with_project do
|
7
|
+
versions = generate_migrations
|
8
|
+
|
9
|
+
hanami "db create"
|
10
|
+
hanami "db migrate"
|
11
|
+
hanami "db version"
|
12
|
+
|
13
|
+
expect(out).to include(versions.last.to_s)
|
14
|
+
expect(out).to_not include("SELECT * FROM")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "prints help message" do
|
19
|
+
with_project do
|
20
|
+
output = <<~OUT
|
21
|
+
Command:
|
22
|
+
hanami db version
|
23
|
+
|
24
|
+
Usage:
|
25
|
+
hanami db version
|
26
|
+
|
27
|
+
Description:
|
28
|
+
Print the current migrated version
|
29
|
+
|
30
|
+
Options:
|
31
|
+
--help, -h # Print this help
|
32
|
+
OUT
|
33
|
+
|
34
|
+
run_cmd 'hanami db version --help', output
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami db", type: :integration do
|
4
|
+
it "prints subcommands" do
|
5
|
+
with_project do
|
6
|
+
output = <<~OUT
|
7
|
+
Commands:
|
8
|
+
hanami db apply # Migrate, dump the SQL schema, and delete the migrations (experimental)
|
9
|
+
hanami db console # Starts a database console
|
10
|
+
hanami db create # Create the database (only for development/test)
|
11
|
+
hanami db drop # Drop the database (only for development/test)
|
12
|
+
hanami db migrate [VERSION] # Migrate the database
|
13
|
+
hanami db prepare # Drop, create, and migrate the database (only for development/test)
|
14
|
+
hanami db rollback [STEPS] # Rollback migrations
|
15
|
+
hanami db version # Print the current migrated version
|
16
|
+
OUT
|
17
|
+
|
18
|
+
run_cmd "hanami db", output, exit_status: 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami destroy", type: :integration do
|
4
|
+
describe "action" do
|
5
|
+
it "destroys action" do
|
6
|
+
with_project do
|
7
|
+
generate "action web books#index"
|
8
|
+
output = [
|
9
|
+
"subtract apps/web/config/routes.rb",
|
10
|
+
"remove spec/web/views/books/index_spec.rb",
|
11
|
+
"remove apps/web/templates/books/index.html.erb",
|
12
|
+
"remove apps/web/views/books/index.rb",
|
13
|
+
"remove apps/web/controllers/books/index.rb",
|
14
|
+
"remove spec/web/controllers/books/index_spec.rb"
|
15
|
+
]
|
16
|
+
|
17
|
+
run_cmd "hanami destroy action web books#index", output
|
18
|
+
|
19
|
+
expect("spec/web/controllers/books/index_spec.rb").to_not be_an_existing_file
|
20
|
+
expect("apps/web/controllers/books/index.rb").to_not be_an_existing_file
|
21
|
+
expect("apps/web/views/books/index.rb").to_not be_an_existing_file
|
22
|
+
expect("apps/web/templates/books/index.html.erb").to_not be_an_existing_file
|
23
|
+
expect("spec/web/views/books/index_spec.rb").to_not be_an_existing_file
|
24
|
+
|
25
|
+
expect("apps/web/config/routes.rb").to_not have_file_content(%r{get '/books', to: 'books#index'})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "destroys namespaced action" do
|
30
|
+
with_project do
|
31
|
+
generate "action web api/books#index"
|
32
|
+
output = [
|
33
|
+
"subtract apps/web/config/routes.rb",
|
34
|
+
"remove spec/web/views/api/books/index_spec.rb",
|
35
|
+
"remove apps/web/templates/api/books/index.html.erb",
|
36
|
+
"remove apps/web/views/api/books/index.rb",
|
37
|
+
"remove apps/web/controllers/api/books/index.rb",
|
38
|
+
"remove spec/web/controllers/api/books/index_spec.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
run_cmd "hanami destroy action web api/books#index", output
|
42
|
+
|
43
|
+
expect("spec/web/controllers/api/books/index_spec.rb").to_not be_an_existing_file
|
44
|
+
expect("apps/web/controllers/api/books/index.rb").to_not be_an_existing_file
|
45
|
+
expect("apps/web/views/api/books/index.rb").to_not be_an_existing_file
|
46
|
+
expect("apps/web/templates/api/books/index.html.erb").to_not be_an_existing_file
|
47
|
+
expect("spec/web/views/api/books/index_spec.rb").to_not be_an_existing_file
|
48
|
+
|
49
|
+
expect("apps/web/config/routes.rb").to_not have_file_content(%r{get '/api/books', to: 'api/books#index'})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "destroys action without view" do
|
54
|
+
with_project do
|
55
|
+
generate "action web home#ping --skip-view --url=/ping"
|
56
|
+
output = [
|
57
|
+
"subtract apps/web/config/routes.rb",
|
58
|
+
"remove apps/web/controllers/home/ping.rb",
|
59
|
+
"remove spec/web/controllers/home/ping_spec.rb"
|
60
|
+
]
|
61
|
+
|
62
|
+
run_cmd "hanami destroy action web home#ping", output
|
63
|
+
|
64
|
+
expect("spec/web/controllers/home/ping_spec.rb").to_not be_an_existing_file
|
65
|
+
expect("apps/web/controllers/home/ping.rb").to_not be_an_existing_file
|
66
|
+
expect("apps/web/views/home/ping.rb").to_not be_an_existing_file
|
67
|
+
expect("apps/web/templates/home/ping.html.erb").to_not be_an_existing_file
|
68
|
+
expect("spec/web/views/home/ping_spec.rb").to_not be_an_existing_file
|
69
|
+
|
70
|
+
expect("apps/web/config/routes.rb").to_not have_file_content(%r{get '/ping', to: 'home#ping'})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "fails with missing arguments" do
|
75
|
+
with_project do
|
76
|
+
output = <<~OUT
|
77
|
+
ERROR: "hanami destroy action" was called with no arguments
|
78
|
+
Usage: "hanami destroy action APP ACTION"
|
79
|
+
OUT
|
80
|
+
|
81
|
+
run_cmd "hanami destroy action", output, exit_status: 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "fails with missing app" do
|
86
|
+
with_project("bookshelf_generate_action_without_app") do
|
87
|
+
output = <<~OUT
|
88
|
+
ERROR: "hanami destroy action" was called with arguments ["home#index"]
|
89
|
+
Usage: "hanami destroy action APP ACTION"
|
90
|
+
OUT
|
91
|
+
|
92
|
+
run_cmd "hanami destroy action home#index", output, exit_status: 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "fails with unknown app" do
|
97
|
+
with_project("bookshelf_generate_action_with_unknown_app") do
|
98
|
+
output = "`foo' is not a valid APP. Please specify one of: `web'"
|
99
|
+
|
100
|
+
run_cmd "hanami destroy action foo home#index", output, exit_status: 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "fails with unknown action" do
|
105
|
+
with_project("bookshelf_generate_action_with_unknown_action") do
|
106
|
+
output = <<~OUT
|
107
|
+
cannot find `home#index' in `web' app.
|
108
|
+
please run `hanami routes' to know the existing actions.
|
109
|
+
OUT
|
110
|
+
|
111
|
+
run_cmd "hanami destroy action web home#index", output, exit_status: 1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "prints help message" do
|
116
|
+
with_project do
|
117
|
+
output = <<~OUT
|
118
|
+
Command:
|
119
|
+
hanami destroy action
|
120
|
+
|
121
|
+
Usage:
|
122
|
+
hanami destroy action APP ACTION
|
123
|
+
|
124
|
+
Description:
|
125
|
+
Destroy an action from app
|
126
|
+
|
127
|
+
Arguments:
|
128
|
+
APP # REQUIRED The app name (eg. `web`)
|
129
|
+
ACTION # REQUIRED The action name (eg. `home#index`)
|
130
|
+
|
131
|
+
Options:
|
132
|
+
--help, -h # Print this help
|
133
|
+
|
134
|
+
Examples:
|
135
|
+
hanami destroy action web home#index # Basic usage
|
136
|
+
hanami destroy action admin users#index # Destroy from `admin` app
|
137
|
+
OUT
|
138
|
+
|
139
|
+
run_cmd 'hanami destroy action --help', output
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end # action
|
143
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami destroy", type: :integration do
|
4
|
+
describe "app" do
|
5
|
+
it "destroys app" do
|
6
|
+
with_project do
|
7
|
+
generate "app admin"
|
8
|
+
|
9
|
+
output = [
|
10
|
+
"subtract .env.test",
|
11
|
+
"subtract .env.development",
|
12
|
+
"subtract config/environment.rb",
|
13
|
+
"subtract config/environment.rb",
|
14
|
+
"remove spec/admin",
|
15
|
+
"remove apps/admin"
|
16
|
+
]
|
17
|
+
|
18
|
+
run_cmd "hanami destroy app admin", output
|
19
|
+
|
20
|
+
expect(".env.test").to_not have_file_content(%r{ADMIN_SESSIONS_SECRET})
|
21
|
+
expect(".env.development").to_not have_file_content(%r{ADMIN_SESSIONS_SECRET})
|
22
|
+
|
23
|
+
expect("config/environment.rb").to_not have_file_content(%r{mount Admin::App})
|
24
|
+
expect("config/environment.rb").to_not have_file_content("require_relative '../apps/admin/app'")
|
25
|
+
|
26
|
+
expect("public/assets/admin").to_not be_an_existing_path
|
27
|
+
expect("public/assets.json").to_not be_an_existing_path
|
28
|
+
|
29
|
+
expect("spec/admin").to_not be_an_existing_path
|
30
|
+
expect("apps/admin").to_not be_an_existing_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "destroys app with actions and assets" do
|
35
|
+
with_project do
|
36
|
+
generate "app api --app-base-url=/api/v1"
|
37
|
+
generate "action api home#index"
|
38
|
+
|
39
|
+
asset = File.join("apps", "api", "assets", "javascripts", "app.js")
|
40
|
+
touch asset
|
41
|
+
|
42
|
+
hanami "assets precompile"
|
43
|
+
|
44
|
+
output = [
|
45
|
+
"subtract .env.test",
|
46
|
+
"subtract .env.development",
|
47
|
+
"subtract config/environment.rb",
|
48
|
+
"subtract config/environment.rb",
|
49
|
+
"remove public/assets/api/v1",
|
50
|
+
"remove public/assets.json",
|
51
|
+
"remove spec/api",
|
52
|
+
"remove apps/api"
|
53
|
+
]
|
54
|
+
|
55
|
+
run_cmd "hanami destroy app api", output
|
56
|
+
|
57
|
+
expect(".env.test").to_not have_file_content(%r{API_SESSIONS_SECRET})
|
58
|
+
expect(".env.development").to_not have_file_content(%r{API_SESSIONS_SECRET})
|
59
|
+
|
60
|
+
expect("config/environment.rb").to_not have_file_content(%r{mount Api::App})
|
61
|
+
expect("config/environment.rb").to_not have_file_content("require_relative '../apps/api/app'")
|
62
|
+
|
63
|
+
expect("public/assets/api/v1").to_not be_an_existing_path
|
64
|
+
expect("public/assets.json").to_not be_an_existing_path
|
65
|
+
|
66
|
+
expect("spec/api").to_not be_an_existing_path
|
67
|
+
expect("apps/api").to_not be_an_existing_path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "fails with missing argument" do
|
72
|
+
with_project do
|
73
|
+
output = <<-OUT
|
74
|
+
ERROR: "hanami destroy app" was called with no arguments
|
75
|
+
Usage: "hanami destroy app APP"
|
76
|
+
OUT
|
77
|
+
|
78
|
+
run_cmd "hanami destroy app", output, exit_status: 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "fails with unknown app" do
|
83
|
+
with_project do
|
84
|
+
output = <<-OUT
|
85
|
+
`unknown' is not a valid APP. Please specify one of: `web'
|
86
|
+
OUT
|
87
|
+
|
88
|
+
run_cmd "hanami destroy app unknown", output, exit_status: 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "prints help message" do
|
93
|
+
with_project do
|
94
|
+
output = <<~OUT
|
95
|
+
Command:
|
96
|
+
hanami destroy app
|
97
|
+
|
98
|
+
Usage:
|
99
|
+
hanami destroy app APP
|
100
|
+
|
101
|
+
Description:
|
102
|
+
Destroy an app
|
103
|
+
|
104
|
+
Arguments:
|
105
|
+
APP # REQUIRED The app name (eg. `web`)
|
106
|
+
|
107
|
+
Options:
|
108
|
+
--help, -h # Print this help
|
109
|
+
|
110
|
+
Examples:
|
111
|
+
hanami destroy app admin # Destroy `admin` app
|
112
|
+
OUT
|
113
|
+
|
114
|
+
run_cmd 'hanami destroy app --help', output
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end # app
|
118
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami destroy", type: :integration do
|
4
|
+
describe "mailer" do
|
5
|
+
context "destroy a mailer" do
|
6
|
+
let(:output) do
|
7
|
+
["remove spec/bookshelf_generate_mailer/mailers/welcome_spec.rb",
|
8
|
+
"remove lib/bookshelf_generate_mailer/mailers/templates/welcome.html.erb",
|
9
|
+
"remove lib/bookshelf_generate_mailer/mailers/templates/welcome.txt.erb",
|
10
|
+
"remove lib/bookshelf_generate_mailer/mailers/welcome.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "generate the mailer files" do
|
14
|
+
with_project("bookshelf_generate_mailer", test: "rspec") do
|
15
|
+
generate "mailer welcome"
|
16
|
+
|
17
|
+
run_cmd "hanami destroy mailer welcome", output
|
18
|
+
|
19
|
+
expect("spec/bookshelf_generate_mailer/mailers/welcome_spec.rb").to_not be_an_existing_file
|
20
|
+
expect("lib/bookshelf_generate_mailer/mailers/templates/welcome.html.erb").to_not be_an_existing_file
|
21
|
+
expect("lib/bookshelf_generate_mailer/mailers/templates/welcome.txt.erb").to_not be_an_existing_file
|
22
|
+
expect("lib/bookshelf_generate_mailer/mailers/welcome.rb").to_not be_an_existing_file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "fails with missing arguments" do
|
28
|
+
with_project("bookshelf_generate_mailer_without_args") do
|
29
|
+
output = <<~OUT
|
30
|
+
ERROR: "hanami generate mailer" was called with no arguments
|
31
|
+
Usage: "hanami generate mailer MAILER"
|
32
|
+
OUT
|
33
|
+
|
34
|
+
run_cmd "hanami generate mailer", output, exit_status: 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "fails with unknown mailer" do
|
39
|
+
with_project do
|
40
|
+
output = <<~OUT
|
41
|
+
cannot find `unknown' mailer. Please have a look at `lib/bookshelf/mailers' directory to find an existing mailer.
|
42
|
+
OUT
|
43
|
+
|
44
|
+
run_cmd "hanami destroy mailer unknown", output, exit_status: 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "prints help message" do
|
49
|
+
with_project do
|
50
|
+
output = <<~OUT
|
51
|
+
Command:
|
52
|
+
hanami destroy mailer
|
53
|
+
|
54
|
+
Usage:
|
55
|
+
hanami destroy mailer MAILER
|
56
|
+
|
57
|
+
Description:
|
58
|
+
Destroy a mailer
|
59
|
+
|
60
|
+
Arguments:
|
61
|
+
MAILER # REQUIRED The mailer name (eg. `welcome`)
|
62
|
+
|
63
|
+
Options:
|
64
|
+
--help, -h # Print this help
|
65
|
+
|
66
|
+
Examples:
|
67
|
+
hanami destroy mailer welcome # Destroy `WelcomeMailer` mailer
|
68
|
+
OUT
|
69
|
+
|
70
|
+
run_cmd 'hanami destroy mailer --help', output
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
RSpec.describe "hanami destroy", type: :integration do
|
6
|
+
describe "migration" do
|
7
|
+
it "destroys migration" do
|
8
|
+
with_project do
|
9
|
+
migration = Pathname.new("db").join("migrations", "20170127165331_create_users.rb").to_s
|
10
|
+
File.open(migration, "wb+") { |f| f.write("migration") }
|
11
|
+
|
12
|
+
output = [
|
13
|
+
"remove #{migration}"
|
14
|
+
]
|
15
|
+
|
16
|
+
run_cmd "hanami destroy migration create_users", output
|
17
|
+
|
18
|
+
expect(migration).to_not be_an_existing_file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails with missing argument" do
|
23
|
+
with_project do
|
24
|
+
output = <<~OUT
|
25
|
+
ERROR: "hanami destroy migration" was called with no arguments
|
26
|
+
Usage: "hanami destroy migration MIGRATION"
|
27
|
+
OUT
|
28
|
+
run_command "hanami destroy migration", output, exit_status: 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "fails with unknown migration" do
|
33
|
+
with_project do
|
34
|
+
output = <<~OUT
|
35
|
+
cannot find `create_unknowns'. Please have a look at `db/migrations' directory to find an existing migration
|
36
|
+
OUT
|
37
|
+
run_command "hanami destroy migration create_unknowns", output, exit_status: 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "prints help message" do
|
42
|
+
with_project do
|
43
|
+
banner = <<~OUT
|
44
|
+
Command:
|
45
|
+
hanami destroy migration
|
46
|
+
|
47
|
+
Usage:
|
48
|
+
hanami destroy migration MIGRATION
|
49
|
+
|
50
|
+
Description:
|
51
|
+
Destroy a migration
|
52
|
+
|
53
|
+
Arguments:
|
54
|
+
MIGRATION # REQUIRED The migration name (eg. `create_users`)
|
55
|
+
|
56
|
+
Options:
|
57
|
+
--help, -h # Print this help
|
58
|
+
|
59
|
+
Examples:
|
60
|
+
OUT
|
61
|
+
output = [
|
62
|
+
banner,
|
63
|
+
%r{ hanami destroy migration create_users # Destroy `db/migrations/[\d]{14}_create_users.rb`}
|
64
|
+
]
|
65
|
+
|
66
|
+
run_command "hanami destroy migration --help", output
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end # migration
|
70
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
RSpec.describe "hanami destroy", type: :integration do
|
6
|
+
describe "model" do
|
7
|
+
it "destroys model" do
|
8
|
+
with_project do
|
9
|
+
generate "model user"
|
10
|
+
migration = Dir.glob(Pathname.new("db").join("migrations", "*_create_users.rb")).first.to_s
|
11
|
+
|
12
|
+
output = [
|
13
|
+
"remove spec/bookshelf/repositories/user_repository_spec.rb",
|
14
|
+
"remove spec/bookshelf/entities/user_spec.rb",
|
15
|
+
"remove lib/bookshelf/repositories/user_repository.rb",
|
16
|
+
"remove lib/bookshelf/entities/user.rb"
|
17
|
+
]
|
18
|
+
|
19
|
+
run_cmd "hanami destroy model user", output
|
20
|
+
|
21
|
+
expect(migration).to be_an_existing_file
|
22
|
+
|
23
|
+
expect("lib/bookshelf/entities/user.rb").to_not be_an_existing_file
|
24
|
+
expect("lib/bookshelf/repositories/user_repository.rb").to_not be_an_existing_file
|
25
|
+
expect("spec/bookshelf/entities/user_spec.rb").to_not be_an_existing_file
|
26
|
+
expect("spec/bookshelf/repositories/user_repository_spec.rb").to_not be_an_existing_file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "destroys model even if migration was deleted manually" do
|
31
|
+
with_project do
|
32
|
+
generate "model user"
|
33
|
+
migration = Dir.glob(Pathname.new("db").join("migrations", "*_create_users.rb")).first.to_s
|
34
|
+
|
35
|
+
run_simple "rm #{migration}"
|
36
|
+
|
37
|
+
expect(migration).to_not be_an_existing_file
|
38
|
+
|
39
|
+
output = [
|
40
|
+
"remove spec/bookshelf/repositories/user_repository_spec.rb",
|
41
|
+
"remove spec/bookshelf/entities/user_spec.rb",
|
42
|
+
"remove lib/bookshelf/repositories/user_repository.rb",
|
43
|
+
"remove lib/bookshelf/entities/user.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
run_cmd "hanami destroy model user", output
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "fails with missing argument" do
|
51
|
+
with_project do
|
52
|
+
output = <<~OUT
|
53
|
+
ERROR: "hanami destroy model" was called with no arguments
|
54
|
+
Usage: "hanami destroy model MODEL"
|
55
|
+
OUT
|
56
|
+
|
57
|
+
run_cmd "hanami destroy model", output, exit_status: 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
xit "prints help message" do
|
62
|
+
with_project do
|
63
|
+
output = <<~OUT
|
64
|
+
Usage:
|
65
|
+
hanami destroy model NAME
|
66
|
+
|
67
|
+
Description:
|
68
|
+
`hanami destroy model` will destroy an entity along with repository and \n corresponding tests
|
69
|
+
|
70
|
+
> $ hanami destroy model car
|
71
|
+
OUT
|
72
|
+
|
73
|
+
run_cmd 'hanami destroy model --help', output
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "fails with unknown model" do
|
78
|
+
with_project do
|
79
|
+
output = <<~OUT
|
80
|
+
cannot find `unknown' model. Please have a look at `lib/bookshelf/entities' directory to find an existing model.
|
81
|
+
OUT
|
82
|
+
|
83
|
+
run_cmd "hanami destroy model unknown", output, exit_status: 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "prints help message" do
|
88
|
+
with_project do
|
89
|
+
output = <<~OUT
|
90
|
+
Command:
|
91
|
+
hanami destroy model
|
92
|
+
|
93
|
+
Usage:
|
94
|
+
hanami destroy model MODEL
|
95
|
+
|
96
|
+
Description:
|
97
|
+
Destroy a model
|
98
|
+
|
99
|
+
Arguments:
|
100
|
+
MODEL # REQUIRED The model name (eg. `user`)
|
101
|
+
|
102
|
+
Options:
|
103
|
+
--help, -h # Print this help
|
104
|
+
|
105
|
+
Examples:
|
106
|
+
hanami destroy model user # Destroy `User` entity and `UserRepository` repository
|
107
|
+
OUT
|
108
|
+
|
109
|
+
run_cmd 'hanami destroy model --help', output
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end # model
|
113
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "hanami destroy", type: :integration do
|
4
|
+
it "prints subcommands" do
|
5
|
+
with_project do
|
6
|
+
output = <<~OUT
|
7
|
+
Commands:
|
8
|
+
hanami destroy action APP ACTION # Destroy an action from app
|
9
|
+
hanami destroy app APP # Destroy an app
|
10
|
+
hanami destroy mailer MAILER # Destroy a mailer
|
11
|
+
hanami destroy migration MIGRATION # Destroy a migration
|
12
|
+
hanami destroy model MODEL # Destroy a model
|
13
|
+
OUT
|
14
|
+
|
15
|
+
run_cmd "hanami destroy", output, exit_status: 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|