hanami 2.3.2 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -19
- data/LICENSE +20 -0
- data/README.md +18 -35
- data/hanami.gemspec +36 -37
- data/lib/hanami/config/db.rb +2 -0
- data/lib/hanami/config/i18n.rb +138 -0
- data/lib/hanami/config/logger.rb +15 -7
- data/lib/hanami/config/null_config.rb +1 -1
- data/lib/hanami/config/views.rb +17 -0
- data/lib/hanami/config.rb +66 -22
- data/lib/hanami/errors.rb +6 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/extensions/action.rb +2 -2
- data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
- data/lib/hanami/extensions/mailer.rb +28 -0
- data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
- data/lib/hanami/extensions/view/context.rb +26 -4
- data/lib/hanami/extensions/view/part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions.rb +6 -1
- data/lib/hanami/helpers/assets_helper.rb +0 -4
- data/lib/hanami/helpers/form_helper.rb +1 -1
- data/lib/hanami/helpers/i18n_helper.rb +176 -0
- data/lib/hanami/logger/rack_formatter.rb +73 -0
- data/lib/hanami/logger/sql_formatter.rb +80 -0
- data/lib/hanami/logger/sql_logger.rb +48 -0
- data/lib/hanami/middleware/render_errors.rb +2 -2
- data/lib/hanami/providers/db.rb +7 -2
- data/lib/hanami/providers/db_logging.rb +4 -7
- data/lib/hanami/providers/i18n/backend.rb +369 -0
- data/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/lib/hanami/providers/i18n.rb +114 -0
- data/lib/hanami/providers/mailers.rb +101 -0
- data/lib/hanami/routes.rb +1 -0
- data/lib/hanami/settings/composite_store.rb +53 -0
- data/lib/hanami/settings.rb +4 -4
- data/lib/hanami/slice/router.rb +15 -10
- data/lib/hanami/slice.rb +71 -11
- data/lib/hanami/slice_registrar.rb +2 -2
- data/lib/hanami/universal_logger.rb +250 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +2 -80
- data/lib/hanami/web/welcome.html.erb +443 -58
- data/lib/hanami.rb +4 -2
- metadata +28 -276
- data/CODE_OF_CONDUCT.md +0 -74
- data/FEATURES.md +0 -269
- data/LICENSE.md +0 -22
- data/spec/integration/action/cookies_spec.rb +0 -58
- data/spec/integration/action/csrf_protection_spec.rb +0 -54
- data/spec/integration/action/format_config_spec.rb +0 -129
- data/spec/integration/action/routes_spec.rb +0 -71
- data/spec/integration/action/sessions_spec.rb +0 -50
- data/spec/integration/action/slice_configuration_spec.rb +0 -284
- data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
- data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
- data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
- data/spec/integration/action/view_rendering_spec.rb +0 -89
- data/spec/integration/assets/assets_spec.rb +0 -155
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
- data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
- data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
- data/spec/integration/container/application_routes_helper_spec.rb +0 -48
- data/spec/integration/container/auto_injection_spec.rb +0 -53
- data/spec/integration/container/auto_registration_spec.rb +0 -86
- data/spec/integration/container/autoloader_spec.rb +0 -82
- data/spec/integration/container/imports_spec.rb +0 -253
- data/spec/integration/container/prepare_container_spec.rb +0 -125
- data/spec/integration/container/provider_environment_spec.rb +0 -52
- data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
- data/spec/integration/container/shutdown_spec.rb +0 -91
- data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
- data/spec/integration/container/standard_providers_spec.rb +0 -124
- data/spec/integration/db/auto_registration_spec.rb +0 -39
- data/spec/integration/db/commands_spec.rb +0 -80
- data/spec/integration/db/db_inflector_spec.rb +0 -57
- data/spec/integration/db/db_slices_spec.rb +0 -398
- data/spec/integration/db/db_spec.rb +0 -245
- data/spec/integration/db/gateways_spec.rb +0 -361
- data/spec/integration/db/logging_spec.rb +0 -301
- data/spec/integration/db/mappers_spec.rb +0 -84
- data/spec/integration/db/provider_config_spec.rb +0 -88
- data/spec/integration/db/provider_spec.rb +0 -35
- data/spec/integration/db/relations_spec.rb +0 -60
- data/spec/integration/db/repo_spec.rb +0 -300
- data/spec/integration/db/slices_importing_from_parent.rb +0 -130
- data/spec/integration/dotenv_loading_spec.rb +0 -138
- data/spec/integration/logging/exception_logging_spec.rb +0 -120
- data/spec/integration/logging/notifications_spec.rb +0 -68
- data/spec/integration/logging/request_logging_spec.rb +0 -202
- data/spec/integration/operations/extension_spec.rb +0 -122
- data/spec/integration/rack_app/body_parser_spec.rb +0 -108
- data/spec/integration/rack_app/method_override_spec.rb +0 -97
- data/spec/integration/rack_app/middleware_spec.rb +0 -720
- data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
- data/spec/integration/rack_app/rack_app_spec.rb +0 -442
- data/spec/integration/rake_tasks_spec.rb +0 -107
- data/spec/integration/router/resource_routes_spec.rb +0 -281
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
- data/spec/integration/settings/access_to_constants_spec.rb +0 -46
- data/spec/integration/settings/loading_from_env_spec.rb +0 -188
- data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
- data/spec/integration/settings/slice_registration_spec.rb +0 -145
- data/spec/integration/settings/using_types_spec.rb +0 -80
- data/spec/integration/setup_spec.rb +0 -165
- data/spec/integration/slices/external_slice_spec.rb +0 -91
- data/spec/integration/slices/slice_configuration_spec.rb +0 -42
- data/spec/integration/slices/slice_loading_spec.rb +0 -171
- data/spec/integration/slices/slice_registrations_spec.rb +0 -80
- data/spec/integration/slices/slice_routing_spec.rb +0 -219
- data/spec/integration/slices_spec.rb +0 -471
- data/spec/integration/view/config/default_context_spec.rb +0 -149
- data/spec/integration/view/config/inflector_spec.rb +0 -57
- data/spec/integration/view/config/part_class_spec.rb +0 -147
- data/spec/integration/view/config/part_namespace_spec.rb +0 -103
- data/spec/integration/view/config/paths_spec.rb +0 -119
- data/spec/integration/view/config/scope_class_spec.rb +0 -147
- data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
- data/spec/integration/view/config/template_spec.rb +0 -38
- data/spec/integration/view/context/assets_spec.rb +0 -79
- data/spec/integration/view/context/inflector_spec.rb +0 -40
- data/spec/integration/view/context/request_spec.rb +0 -57
- data/spec/integration/view/context/routes_spec.rb +0 -84
- data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
- data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
- data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
- data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
- data/spec/integration/view/slice_configuration_spec.rb +0 -289
- data/spec/integration/view/views_spec.rb +0 -103
- data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
- data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
- data/spec/integration/web/render_errors_spec.rb +0 -242
- data/spec/integration/web/welcome_view_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -28
- data/spec/support/app_integration.rb +0 -157
- data/spec/support/coverage.rb +0 -1
- data/spec/support/matchers.rb +0 -32
- data/spec/support/rspec.rb +0 -27
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
- data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
- data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
- data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
- data/spec/unit/hanami/config/actions_spec.rb +0 -52
- data/spec/unit/hanami/config/base_url_spec.rb +0 -25
- data/spec/unit/hanami/config/console_spec.rb +0 -22
- data/spec/unit/hanami/config/db_spec.rb +0 -38
- data/spec/unit/hanami/config/inflector_spec.rb +0 -35
- data/spec/unit/hanami/config/logger_spec.rb +0 -195
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/router_spec.rb +0 -44
- data/spec/unit/hanami/config/slices_spec.rb +0 -34
- data/spec/unit/hanami/config/views_spec.rb +0 -80
- data/spec/unit/hanami/env_spec.rb +0 -37
- data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
- data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
- data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
- data/spec/unit/hanami/port_spec.rb +0 -117
- data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
- data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
- data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
- data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
- data/spec/unit/hanami/settings_spec.rb +0 -111
- data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
- data/spec/unit/hanami/slice_name_spec.rb +0 -47
- data/spec/unit/hanami/slice_spec.rb +0 -99
- data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Mappers", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "registers custom mappers" do
|
|
14
|
-
with_tmp_directory(@dir = Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
config.logger.stream = File::NULL
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
26
|
-
module TestApp
|
|
27
|
-
module Relations
|
|
28
|
-
class Posts < Hanami::DB::Relation
|
|
29
|
-
schema :posts, infer: true
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
RUBY
|
|
34
|
-
|
|
35
|
-
write "app/db/mappers/nested/default_title_mapper.rb", <<~RUBY
|
|
36
|
-
require "rom/transformer"
|
|
37
|
-
|
|
38
|
-
module TestApp
|
|
39
|
-
module DB
|
|
40
|
-
module Mappers
|
|
41
|
-
module Nested
|
|
42
|
-
class DefaultTitleMapper < ROM::Transformer
|
|
43
|
-
relation :posts
|
|
44
|
-
register_as :default_title_mapper
|
|
45
|
-
|
|
46
|
-
map do
|
|
47
|
-
set_default_title
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def set_default_title(row)
|
|
51
|
-
row[:title] ||= "Default title from mapper"
|
|
52
|
-
row
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
RUBY
|
|
60
|
-
|
|
61
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
62
|
-
|
|
63
|
-
require "hanami/prepare"
|
|
64
|
-
|
|
65
|
-
Hanami.app.prepare :db
|
|
66
|
-
|
|
67
|
-
# Manually run a migration and add a test record
|
|
68
|
-
gateway = TestApp::App["db.gateway"]
|
|
69
|
-
migration = gateway.migration do
|
|
70
|
-
change do
|
|
71
|
-
create_table :posts do
|
|
72
|
-
primary_key :id
|
|
73
|
-
column :title, :text
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
migration.apply(gateway, :up)
|
|
78
|
-
gateway.connection.execute("INSERT INTO posts (title) VALUES (NULL)")
|
|
79
|
-
|
|
80
|
-
post = TestApp::App["relations.posts"].map_with(:default_title_mapper).to_a[0]
|
|
81
|
-
expect(post[:title]).to eq "Default title from mapper"
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Provider / Config", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "default config" do
|
|
14
|
-
it "provides default plugins and extensions" do
|
|
15
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
16
|
-
write "config/app.rb", <<~RUBY
|
|
17
|
-
require "hanami"
|
|
18
|
-
|
|
19
|
-
module TestApp
|
|
20
|
-
class App < Hanami::App
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "config/db/.keep", ""
|
|
26
|
-
|
|
27
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
28
|
-
|
|
29
|
-
require "hanami/prepare"
|
|
30
|
-
|
|
31
|
-
Hanami.app.prepare :db
|
|
32
|
-
|
|
33
|
-
plugins = Hanami.app["db.config"].setup.plugins
|
|
34
|
-
expect(plugins).to match [
|
|
35
|
-
an_object_satisfying {
|
|
36
|
-
_1.name == :instrumentation && _1.type == :relation &&
|
|
37
|
-
_1.config.notifications == Hanami.app["notifications"]
|
|
38
|
-
},
|
|
39
|
-
an_object_satisfying { _1.name == :auto_restrictions && _1.type == :relation }
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
extensions = Hanami.app["db.gateway"].options[:extensions]
|
|
43
|
-
expect(extensions).to eq [:caller_logging, :error_sql, :sql_comments]
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "evaluates plugin config blocks in the context of the provider" do
|
|
49
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
50
|
-
write "config/app.rb", <<~RUBY
|
|
51
|
-
require "hanami"
|
|
52
|
-
|
|
53
|
-
module TestApp
|
|
54
|
-
class App < Hanami::App
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
RUBY
|
|
58
|
-
|
|
59
|
-
write "config/providers/db.rb", <<~RUBY
|
|
60
|
-
Hanami.app.configure_provider :db do
|
|
61
|
-
config.adapter :sql do |a|
|
|
62
|
-
a.skip_defaults :plugins
|
|
63
|
-
|
|
64
|
-
a.plugin relations: :instrumentation do |plugin|
|
|
65
|
-
plugin.notifications = target["custom_notifications"]
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
RUBY
|
|
70
|
-
|
|
71
|
-
write "app/custom_notifications.rb", <<~RUBY
|
|
72
|
-
module TestApp
|
|
73
|
-
class CustomNotifications
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
RUBY
|
|
77
|
-
|
|
78
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
79
|
-
|
|
80
|
-
require "hanami/prepare"
|
|
81
|
-
|
|
82
|
-
Hanami.app.prepare :db
|
|
83
|
-
|
|
84
|
-
plugin = Hanami.app["db.config"].setup.plugins.find { _1.name == :instrumentation }
|
|
85
|
-
expect(plugin.config.notifications).to be_an_instance_of TestApp::CustomNotifications
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Provider", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "is registered when only a config/db/ dir exists" do
|
|
14
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "config/db/.keep", ""
|
|
25
|
-
|
|
26
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
27
|
-
|
|
28
|
-
require "hanami/prepare"
|
|
29
|
-
|
|
30
|
-
Hanami.app.prepare :db
|
|
31
|
-
|
|
32
|
-
expect(Hanami.app["db.gateway"]).to be
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Relations", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "registers nested relations" do
|
|
14
|
-
with_tmp_directory(@dir = Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
config.logger.stream = File::NULL
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/relations/nested/posts.rb", <<~RUBY
|
|
26
|
-
module TestApp
|
|
27
|
-
module Relations
|
|
28
|
-
module Nested
|
|
29
|
-
class Posts < Hanami::DB::Relation
|
|
30
|
-
schema :posts, infer: true
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
RUBY
|
|
36
|
-
|
|
37
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
38
|
-
|
|
39
|
-
require "hanami/prepare"
|
|
40
|
-
|
|
41
|
-
Hanami.app.prepare :db
|
|
42
|
-
|
|
43
|
-
# Manually run a migration and add a test record
|
|
44
|
-
gateway = TestApp::App["db.gateway"]
|
|
45
|
-
migration = gateway.migration do
|
|
46
|
-
change do
|
|
47
|
-
create_table :posts do
|
|
48
|
-
primary_key :id
|
|
49
|
-
column :title, :text
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
migration.apply(gateway, :up)
|
|
54
|
-
gateway.connection.execute("INSERT INTO posts (title) VALUES ('Hi from nested relation')")
|
|
55
|
-
|
|
56
|
-
post = TestApp::App["relations.posts"].to_a[0]
|
|
57
|
-
expect(post[:title]).to eq "Hi from nested relation"
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Repo", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
specify "repos have a root inferred from their name, or can set their own" do
|
|
14
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "app/repo.rb", <<~RUBY
|
|
25
|
-
module TestApp
|
|
26
|
-
class Repo < Hanami::DB::Repo
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
RUBY
|
|
30
|
-
|
|
31
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
32
|
-
module TestApp
|
|
33
|
-
module Relations
|
|
34
|
-
class Posts < Hanami::DB::Relation
|
|
35
|
-
schema :posts, infer: true
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
RUBY
|
|
40
|
-
|
|
41
|
-
write "app/repos/post_repo.rb", <<~RUBY
|
|
42
|
-
module TestApp
|
|
43
|
-
module Repos
|
|
44
|
-
class PostRepo < Repo
|
|
45
|
-
def get(id)
|
|
46
|
-
posts.by_pk(id).one!
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
RUBY
|
|
52
|
-
|
|
53
|
-
write "app/repos/no_implicit_root_relation_repo.rb", <<~RUBY
|
|
54
|
-
module TestApp
|
|
55
|
-
module Repos
|
|
56
|
-
class NoImplicitRootRelationRepo < Repo
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
RUBY
|
|
61
|
-
|
|
62
|
-
write "app/repos/explicit_root_relation_repo.rb", <<~RUBY
|
|
63
|
-
module TestApp
|
|
64
|
-
module Repos
|
|
65
|
-
class ExplicitRootRelationRepo < Repo[:posts]
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
RUBY
|
|
70
|
-
|
|
71
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
72
|
-
|
|
73
|
-
require "hanami/prepare"
|
|
74
|
-
|
|
75
|
-
Hanami.app.prepare :db
|
|
76
|
-
|
|
77
|
-
# Manually run a migration and add a test record
|
|
78
|
-
gateway = Hanami.app["db.gateway"]
|
|
79
|
-
migration = gateway.migration do
|
|
80
|
-
change do
|
|
81
|
-
# drop_table? :posts
|
|
82
|
-
create_table :posts do
|
|
83
|
-
primary_key :id
|
|
84
|
-
column :title, :text, null: false
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
migration.apply(gateway, :up)
|
|
89
|
-
gateway.connection.execute("INSERT INTO posts (title) VALUES ('Together breakfast')")
|
|
90
|
-
|
|
91
|
-
# Repos use a matching root relation automatically
|
|
92
|
-
repo = Hanami.app["repos.post_repo"]
|
|
93
|
-
expect(repo.get(1).title).to eq "Together breakfast"
|
|
94
|
-
expect(repo.root).to eql Hanami.app["relations.posts"]
|
|
95
|
-
|
|
96
|
-
# Non-matching repos still work, just with no root relation
|
|
97
|
-
repo = Hanami.app["repos.no_implicit_root_relation_repo"]
|
|
98
|
-
expect(repo.root).to be nil
|
|
99
|
-
|
|
100
|
-
# Repos can provide an explicit root relation
|
|
101
|
-
repo = Hanami.app["repos.explicit_root_relation_repo"]
|
|
102
|
-
expect(repo.root).to eql Hanami.app["relations.posts"]
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
specify "repos use relations and structs only from their own slice" do
|
|
107
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
108
|
-
write "config/app.rb", <<~RUBY
|
|
109
|
-
require "hanami"
|
|
110
|
-
|
|
111
|
-
module TestApp
|
|
112
|
-
class App < Hanami::App
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
RUBY
|
|
116
|
-
|
|
117
|
-
write "app/repo.rb", <<~RUBY
|
|
118
|
-
module TestApp
|
|
119
|
-
class Repo < Hanami::DB::Repo
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
RUBY
|
|
123
|
-
|
|
124
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
125
|
-
|
|
126
|
-
write "slices/admin/db/struct.rb", <<~RUBY
|
|
127
|
-
module Admin
|
|
128
|
-
module DB
|
|
129
|
-
class Struct < Hanami::DB::Struct
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
RUBY
|
|
134
|
-
|
|
135
|
-
write "slices/admin/relations/posts.rb", <<~RUBY
|
|
136
|
-
module Admin
|
|
137
|
-
module Relations
|
|
138
|
-
class Posts < Hanami::DB::Relation
|
|
139
|
-
schema :posts, infer: true
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
RUBY
|
|
144
|
-
|
|
145
|
-
write "slices/admin/repo.rb", <<~RUBY
|
|
146
|
-
module Admin
|
|
147
|
-
class Repo < TestApp::Repo
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
RUBY
|
|
151
|
-
|
|
152
|
-
write "slices/admin/repos/post_repo.rb", <<~RUBY
|
|
153
|
-
module Admin
|
|
154
|
-
module Repos
|
|
155
|
-
class PostRepo < Repo
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
RUBY
|
|
160
|
-
|
|
161
|
-
write "slices/admin/structs/post.rb", <<~RUBY
|
|
162
|
-
module Admin
|
|
163
|
-
module Structs
|
|
164
|
-
class Post < DB::Struct
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
RUBY
|
|
169
|
-
|
|
170
|
-
write "slices/main/relations/posts.rb", <<~RUBY
|
|
171
|
-
module Main
|
|
172
|
-
module Relations
|
|
173
|
-
class Posts < Hanami::DB::Relation
|
|
174
|
-
schema :posts, infer: true
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
RUBY
|
|
179
|
-
|
|
180
|
-
write "slices/main/repo.rb", <<~RUBY
|
|
181
|
-
module Main
|
|
182
|
-
class Repo < TestApp::Repo
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
RUBY
|
|
186
|
-
|
|
187
|
-
write "slices/main/repos/post_repo.rb", <<~RUBY
|
|
188
|
-
module Main
|
|
189
|
-
module Repos
|
|
190
|
-
class PostRepo < Repo
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
RUBY
|
|
195
|
-
|
|
196
|
-
write "slices/main/repositories/post_repository.rb", <<~RUBY
|
|
197
|
-
module Main
|
|
198
|
-
module Repositories
|
|
199
|
-
class PostRepository < Repo
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
RUBY
|
|
204
|
-
|
|
205
|
-
require "hanami/prepare"
|
|
206
|
-
|
|
207
|
-
Admin::Slice.prepare :db
|
|
208
|
-
|
|
209
|
-
# Manually run a migration
|
|
210
|
-
gateway = Admin::Slice["db.gateway"]
|
|
211
|
-
migration = gateway.migration do
|
|
212
|
-
change do
|
|
213
|
-
# drop_table? :posts
|
|
214
|
-
create_table :posts do
|
|
215
|
-
primary_key :id
|
|
216
|
-
column :title, :text, null: false
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
migration.apply(gateway, :up)
|
|
221
|
-
gateway.connection.execute("INSERT INTO posts (title) VALUES ('Together breakfast')")
|
|
222
|
-
|
|
223
|
-
expect(Admin::Slice["repos.post_repo"].root).to eql Admin::Slice["relations.posts"]
|
|
224
|
-
expect(Admin::Slice["repos.post_repo"].posts).to eql Admin::Slice["relations.posts"]
|
|
225
|
-
expect(Admin::Slice["repos.post_repo"].posts.by_pk(1).one!.class).to be < Admin::Structs::Post
|
|
226
|
-
|
|
227
|
-
expect(Main::Slice["repos.post_repo"].posts).to eql Main::Slice["relations.posts"]
|
|
228
|
-
expect(Main::Slice["repositories.post_repository"].posts).to eql Main::Slice["relations.posts"]
|
|
229
|
-
# Slice struct namespace used even when no concrete struct classes are defined
|
|
230
|
-
expect(Main::Slice["repos.post_repo"].posts.by_pk(1).one!.class).to be < Main::Structs::Post
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
specify "repos resolve registered container dependencies with Deps[]" do
|
|
235
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
236
|
-
write "config/app.rb", <<~RUBY
|
|
237
|
-
require "hanami"
|
|
238
|
-
|
|
239
|
-
module TestApp
|
|
240
|
-
class App < Hanami::App
|
|
241
|
-
Hanami.app.register("dependency") { -> { "Hello dependency!" } }
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
RUBY
|
|
245
|
-
|
|
246
|
-
write "app/repo.rb", <<~RUBY
|
|
247
|
-
module TestApp
|
|
248
|
-
class Repo < Hanami::DB::Repo
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
RUBY
|
|
252
|
-
|
|
253
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
254
|
-
module TestApp
|
|
255
|
-
module Relations
|
|
256
|
-
class Posts < Hanami::DB::Relation
|
|
257
|
-
schema :posts, infer: true
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
RUBY
|
|
262
|
-
|
|
263
|
-
write "app/repos/post_repo.rb", <<~RUBY
|
|
264
|
-
module TestApp
|
|
265
|
-
module Repos
|
|
266
|
-
class PostRepo < Repo
|
|
267
|
-
include Deps["dependency"]
|
|
268
|
-
|
|
269
|
-
def test
|
|
270
|
-
dependency.call
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
end
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
RUBY
|
|
277
|
-
|
|
278
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
279
|
-
|
|
280
|
-
require "hanami/prepare"
|
|
281
|
-
|
|
282
|
-
Hanami.app.prepare :db
|
|
283
|
-
|
|
284
|
-
# Manually run a migration and add a test record
|
|
285
|
-
gateway = Hanami.app["db.gateway"]
|
|
286
|
-
migration = gateway.migration do
|
|
287
|
-
change do
|
|
288
|
-
create_table :posts do
|
|
289
|
-
primary_key :id
|
|
290
|
-
column :title, :text, null: false
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
migration.apply(gateway, :up)
|
|
295
|
-
|
|
296
|
-
repo = Hanami.app["repos.post_repo"]
|
|
297
|
-
expect(repo.test).to eq "Hello dependency!"
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
end
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "DB / Slices / Importing from app", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
@env = ENV.to_h
|
|
6
|
-
allow(Hanami::Env).to receive(:loaded?).and_return(false)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after do
|
|
10
|
-
ENV.replace(@env)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
specify "app DB components do not import into slices by default" do
|
|
14
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
15
|
-
write "config/app.rb", <<~RUBY
|
|
16
|
-
require "hanami"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class App < Hanami::App
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
25
|
-
module TestApp
|
|
26
|
-
module Relations
|
|
27
|
-
class Posts < Hanami::DB::Relation
|
|
28
|
-
schema :posts, infer: true
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
write "slices/admin/.keep", ""
|
|
35
|
-
|
|
36
|
-
require "hanami/prepare"
|
|
37
|
-
|
|
38
|
-
expect { Admin::Slice.start :db }.to raise_error Dry::System::ProviderNotFoundError
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
specify "importing app DB components into slices via config.db.import_from_parent = true" do
|
|
43
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
44
|
-
write "config/app.rb", <<~RUBY
|
|
45
|
-
require "hanami"
|
|
46
|
-
|
|
47
|
-
module TestApp
|
|
48
|
-
class App < Hanami::App
|
|
49
|
-
config.db.import_from_parent = true
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
RUBY
|
|
53
|
-
|
|
54
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
55
|
-
module TestApp
|
|
56
|
-
module Relations
|
|
57
|
-
class Posts < Hanami::DB::Relation
|
|
58
|
-
schema :posts, infer: true
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
RUBY
|
|
63
|
-
|
|
64
|
-
write "slices/admin/.keep", ""
|
|
65
|
-
|
|
66
|
-
ENV["DATABASE_URL"] = "sqlite::memory"
|
|
67
|
-
|
|
68
|
-
require "hanami/prepare"
|
|
69
|
-
|
|
70
|
-
Hanami.app.prepare :db
|
|
71
|
-
|
|
72
|
-
# Manually run a migration and add a test record
|
|
73
|
-
gateway = Hanami.app["db.gateway"]
|
|
74
|
-
migration = gateway.migration do
|
|
75
|
-
change do
|
|
76
|
-
# drop_table? :posts
|
|
77
|
-
create_table :posts do
|
|
78
|
-
primary_key :id
|
|
79
|
-
column :title, :text, null: false
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
migration.apply(gateway, :up)
|
|
84
|
-
gateway.connection.execute("INSERT INTO posts (title) VALUES ('Together breakfast')")
|
|
85
|
-
|
|
86
|
-
Admin::Slice.start :db
|
|
87
|
-
|
|
88
|
-
expect(Admin::Slice["db.rom"]).to be(Hanami.app["db.rom"])
|
|
89
|
-
expect(Admin::Slice["relations.posts"]).to be(Hanami.app["relations.posts"])
|
|
90
|
-
|
|
91
|
-
expect(Admin::Slice["relations.posts"].to_a).to eq [{id: 1, title: "Together breakfast"}]
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
specify "disabling import of the DB components within a specific slice" do
|
|
96
|
-
with_tmp_directory(Dir.mktmpdir) do
|
|
97
|
-
write "config/app.rb", <<~RUBY
|
|
98
|
-
require "hanami"
|
|
99
|
-
|
|
100
|
-
module TestApp
|
|
101
|
-
class App < Hanami::App
|
|
102
|
-
config.db.import_from_parent = true
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
RUBY
|
|
106
|
-
|
|
107
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
108
|
-
module Admin
|
|
109
|
-
class Slice < Hanami::Slice
|
|
110
|
-
config.db.import_from_parent = false
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
RUBY
|
|
114
|
-
|
|
115
|
-
write "app/relations/posts.rb", <<~RUBY
|
|
116
|
-
module TestApp
|
|
117
|
-
module Relations
|
|
118
|
-
class Posts < Hanami::DB::Relation
|
|
119
|
-
schema :posts, infer: true
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
RUBY
|
|
124
|
-
|
|
125
|
-
require "hanami/prepare"
|
|
126
|
-
|
|
127
|
-
expect { Admin::Slice.start :db }.to raise_error Dry::System::ProviderNotFoundError
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|