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,117 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/port"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Hanami::Port do
|
|
6
|
-
context "Hanami::Port::DEFAULT" do
|
|
7
|
-
it "returns default value" do
|
|
8
|
-
expect(Hanami::Port::DEFAULT).to eq(2300)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "Hanami::Port::ENV_VAR" do
|
|
13
|
-
it "returns default value" do
|
|
14
|
-
expect(Hanami::Port::ENV_VAR).to eq("HANAMI_PORT")
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context ".call" do
|
|
19
|
-
let(:value) { nil }
|
|
20
|
-
let(:env) { nil }
|
|
21
|
-
|
|
22
|
-
it "is aliased as .[]" do
|
|
23
|
-
expect(described_class[value, env]).to be(2300)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when ENV var is nil" do
|
|
27
|
-
context "and value is nil" do
|
|
28
|
-
it "returns default value" do
|
|
29
|
-
expect(described_class.call(value, env)).to be(2300)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "and value is not nil" do
|
|
34
|
-
let(:value) { 18_000 }
|
|
35
|
-
|
|
36
|
-
it "returns given value" do
|
|
37
|
-
expect(described_class.call(value, env)).to be(value)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "and value is default" do
|
|
41
|
-
let(:value) { 2300 }
|
|
42
|
-
|
|
43
|
-
it "returns given value" do
|
|
44
|
-
expect(described_class.call(value, env)).to be(value)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "when ENV var not nil" do
|
|
51
|
-
let(:env) { 9000 }
|
|
52
|
-
|
|
53
|
-
context "and value is nil" do
|
|
54
|
-
it "returns env value" do
|
|
55
|
-
expect(described_class.call(value, env)).to be(env)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "and value is not nil" do
|
|
60
|
-
let(:value) { 18_000 }
|
|
61
|
-
|
|
62
|
-
it "returns given value" do
|
|
63
|
-
expect(described_class.call(value, env)).to be(value)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context "and value is default" do
|
|
67
|
-
let(:value) { 2300 }
|
|
68
|
-
|
|
69
|
-
it "returns env value" do
|
|
70
|
-
expect(described_class.call(value, env)).to be(env)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context ".call!" do
|
|
78
|
-
before { ENV.delete("HANAMI_PORT") }
|
|
79
|
-
let(:value) { 2300 }
|
|
80
|
-
|
|
81
|
-
context "when given value is default" do
|
|
82
|
-
it "doesn't set env var" do
|
|
83
|
-
described_class.call!(value)
|
|
84
|
-
|
|
85
|
-
expect(ENV.key?("HANAMI_PORT")).to be(false)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context "when given value isn't default" do
|
|
90
|
-
let(:value) { 9000 }
|
|
91
|
-
|
|
92
|
-
it "set env var" do
|
|
93
|
-
described_class.call!(value)
|
|
94
|
-
|
|
95
|
-
expect(ENV.fetch("HANAMI_PORT")).to eq(value.to_s)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
context ".default?" do
|
|
101
|
-
context "when given value is default" do
|
|
102
|
-
let(:value) { 2300 }
|
|
103
|
-
|
|
104
|
-
it "returns true" do
|
|
105
|
-
expect(described_class.default?(value)).to be(true)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "when given value isn't default" do
|
|
110
|
-
let(:value) { 9000 }
|
|
111
|
-
|
|
112
|
-
it "returns false" do
|
|
113
|
-
expect(described_class.default?(value)).to be(false)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/system"
|
|
4
|
-
require "hanami/providers/db"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Hanami::Providers::DB / Config / Default config", :app_integration do
|
|
7
|
-
subject(:config) { provider.source.config }
|
|
8
|
-
|
|
9
|
-
let(:provider) {
|
|
10
|
-
Hanami.app.prepare
|
|
11
|
-
Hanami.app.configure_provider(:db)
|
|
12
|
-
Hanami.app.container.providers[:db]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
before do
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
specify %(relations_path = "relations") do
|
|
23
|
-
expect(config)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "sql adapter" do
|
|
27
|
-
before do
|
|
28
|
-
skip_defaults if respond_to?(:skip_defaults)
|
|
29
|
-
config.adapter(:sql).configure_for_database("mysql://localhost/test_app_development")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "plugins" do
|
|
33
|
-
specify do
|
|
34
|
-
expect(config.adapter(:sql).plugins).to match [
|
|
35
|
-
[{relations: :instrumentation}, instance_of(Proc)],
|
|
36
|
-
[{relations: :auto_restrictions}, nil],
|
|
37
|
-
]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe "skipping defaults" do
|
|
41
|
-
def skip_defaults
|
|
42
|
-
config.adapter(:sql).skip_defaults :plugins
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "configures no plugins" do
|
|
46
|
-
expect(config.adapter(:sql).plugins).to eq []
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "extensions" do
|
|
52
|
-
specify do
|
|
53
|
-
expect(config.adapter(:sql).extensions).to eq [
|
|
54
|
-
:caller_logging,
|
|
55
|
-
:error_sql,
|
|
56
|
-
:sql_comments
|
|
57
|
-
]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "skipping defaults" do
|
|
61
|
-
def skip_defaults
|
|
62
|
-
config.adapter(:sql).skip_defaults :extensions
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "configures no extensions" do
|
|
66
|
-
expect(config.adapter(:sql).extensions).to eq []
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "skipping all defaults" do
|
|
72
|
-
def skip_defaults
|
|
73
|
-
config.adapter(:sql).skip_defaults
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "configures no plugins or extensions" do
|
|
77
|
-
expect(config.adapter(:sql).plugins).to eq []
|
|
78
|
-
expect(config.adapter(:sql).extensions).to eq []
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe "sql adapter for postgres" do
|
|
84
|
-
before do
|
|
85
|
-
config.adapter(:sql).configure_for_database("postgresql://localhost/test_app_development")
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
specify "extensions" do
|
|
89
|
-
expect(config.adapters[:sql].extensions).to eq [
|
|
90
|
-
:caller_logging,
|
|
91
|
-
:error_sql,
|
|
92
|
-
:sql_comments,
|
|
93
|
-
:pg_array,
|
|
94
|
-
:pg_enum,
|
|
95
|
-
:pg_json,
|
|
96
|
-
:pg_range
|
|
97
|
-
]
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/system"
|
|
4
|
-
require "hanami/providers/db"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Hanami::Providers::DB / Config / Gateway config", :app_integration do
|
|
7
|
-
subject(:config) { provider.source.config }
|
|
8
|
-
|
|
9
|
-
let(:provider) {
|
|
10
|
-
Hanami.app.prepare
|
|
11
|
-
Hanami.app.configure_provider(:db)
|
|
12
|
-
Hanami.app.container.providers[:db]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
before do
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "sql adapter" do
|
|
23
|
-
before do
|
|
24
|
-
config.adapter(:sql).configure_for_database("sqlite::memory")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe "connection_options" do
|
|
28
|
-
let(:default) { config.gateway(:default) }
|
|
29
|
-
|
|
30
|
-
it "merges kwargs into connection_options configuration" do
|
|
31
|
-
expect { default.connection_options(timeout: 10_000) }
|
|
32
|
-
.to change { default.connection_options }.from({}).to({timeout: 10_000})
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "sets options per-gateway" do
|
|
36
|
-
other = config.gateway(:other)
|
|
37
|
-
expect { default.connection_options(timeout: 10_000) }
|
|
38
|
-
.to_not change { other.connection_options }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "is reflected in Gateway#cache_keys" do
|
|
42
|
-
default.adapter(:sql) {}
|
|
43
|
-
expect { default.connection_options(timeout: 10_000) }
|
|
44
|
-
.to change { default.cache_keys }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "options" do
|
|
49
|
-
it "combines connection_options with adapter.gateway_options" do
|
|
50
|
-
config.gateway :default do |gw|
|
|
51
|
-
gw.connection_options foo: "bar"
|
|
52
|
-
|
|
53
|
-
gw.adapter :sql do |a|
|
|
54
|
-
a.skip_defaults
|
|
55
|
-
a.extension :baz, :quux
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
expect(config.gateway(:default).options)
|
|
60
|
-
.to include(foo: "bar", extensions: [:baz, :quux])
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "ignores conflicting keys from connection_options" do
|
|
64
|
-
config.gateway :default do |gw|
|
|
65
|
-
gw.connection_options extensions: "foo"
|
|
66
|
-
gw.adapter(:sql) { _1.skip_defaults }
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
expect(config.gateway(:default).options).to eq({extensions: []})
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/system"
|
|
4
|
-
require "hanami/providers/db"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "Hanami::Providers::DB.config", :app_integration do
|
|
7
|
-
subject(:config) { provider.source.config }
|
|
8
|
-
|
|
9
|
-
let(:provider) {
|
|
10
|
-
Hanami.app.prepare
|
|
11
|
-
Hanami.app.configure_provider(:db)
|
|
12
|
-
Hanami.app.container.providers[:db]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
before do
|
|
16
|
-
module TestApp
|
|
17
|
-
class App < Hanami::App
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#adapter" do
|
|
23
|
-
it "adds an adapter" do
|
|
24
|
-
expect { config.adapter(:yaml) }
|
|
25
|
-
.to change { config.adapters.to_h }
|
|
26
|
-
.to hash_including(:yaml)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "yields the adapter for configuration" do
|
|
30
|
-
expect { |b| config.adapter(:yaml, &b) }
|
|
31
|
-
.to yield_with_args(an_instance_of(Hanami::Providers::DB::Adapter))
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "adapters" do
|
|
36
|
-
subject(:adapter) { config.adapter(:yaml) }
|
|
37
|
-
|
|
38
|
-
describe "#plugin" do
|
|
39
|
-
it "adds a plugin without a block" do
|
|
40
|
-
expect { adapter.plugin relations: :foo }
|
|
41
|
-
.to change { adapter.plugins }
|
|
42
|
-
.to [[{relations: :foo}, nil]]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "adds a plugin with a block" do
|
|
46
|
-
block = -> plugin_config { }
|
|
47
|
-
|
|
48
|
-
expect {
|
|
49
|
-
adapter.plugin(relations: :foo, &block)
|
|
50
|
-
}
|
|
51
|
-
.to change { adapter.plugins }
|
|
52
|
-
.to [[{relations: :foo}, block]]
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe "#plugins" do
|
|
57
|
-
it "can be cleared" do
|
|
58
|
-
adapter.plugin relations: :foo
|
|
59
|
-
|
|
60
|
-
expect { adapter.plugins.clear }
|
|
61
|
-
.to change { adapter.plugins }
|
|
62
|
-
.to []
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe "#gateway_cache_keys" do
|
|
67
|
-
it "includes the configured extensions" do
|
|
68
|
-
expect(adapter.gateway_cache_keys).to eq({})
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe "#gateway_options" do
|
|
73
|
-
specify do
|
|
74
|
-
expect(adapter.gateway_options).to eq({})
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "#clear" do
|
|
79
|
-
it "clears previously configured plugins" do
|
|
80
|
-
adapter.plugin relations: :foo
|
|
81
|
-
|
|
82
|
-
expect { adapter.clear }.to change { adapter.plugins }.to([])
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe ":sql adapter" do
|
|
87
|
-
subject(:adapter) { config.adapter(:sql) }
|
|
88
|
-
|
|
89
|
-
describe "#extension" do
|
|
90
|
-
it "adds an extension" do
|
|
91
|
-
adapter.clear
|
|
92
|
-
expect { adapter.extension :foo }
|
|
93
|
-
.to change { adapter.extensions }
|
|
94
|
-
.to [:foo]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "adds multiple extensions" do
|
|
98
|
-
adapter.clear
|
|
99
|
-
expect { adapter.extension :foo, :bar }
|
|
100
|
-
.to change { adapter.extensions }
|
|
101
|
-
.to [:foo, :bar]
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
describe "#extensions" do
|
|
106
|
-
it "can be cleareed" do
|
|
107
|
-
adapter.extension :foo
|
|
108
|
-
|
|
109
|
-
expect { adapter.extensions.clear }
|
|
110
|
-
.to change { adapter.extensions }
|
|
111
|
-
.to []
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
describe "#gateway_cache_keys" do
|
|
116
|
-
it "includes the configured extensions" do
|
|
117
|
-
adapter.clear
|
|
118
|
-
adapter.extension :foo, :bar
|
|
119
|
-
expect(adapter.gateway_cache_keys).to eq(extensions: [:foo, :bar])
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "#gateway_options" do
|
|
124
|
-
it "includes the configured extensions" do
|
|
125
|
-
adapter.clear
|
|
126
|
-
adapter.extension :foo, :bar
|
|
127
|
-
expect(adapter.gateway_options).to eq(extensions: [:foo, :bar])
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
describe "#clear" do
|
|
132
|
-
it "clears previously configured plugins and extensions" do
|
|
133
|
-
adapter.plugin relations: :foo
|
|
134
|
-
adapter.extension :foo
|
|
135
|
-
|
|
136
|
-
expect { adapter.clear }
|
|
137
|
-
.to change { adapter.plugins }.to([])
|
|
138
|
-
.and change { adapter.extensions }.to([])
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/router"
|
|
4
|
-
require "hanami/extensions/router/errors"
|
|
5
|
-
|
|
6
|
-
RSpec.describe(Hanami::Router::NotAllowedError) do
|
|
7
|
-
subject(:error) { described_class.new(env, allowed_methods) }
|
|
8
|
-
|
|
9
|
-
let(:env) { Rack::MockRequest.env_for("http://example.com/example", method: "POST") }
|
|
10
|
-
let(:allowed_methods) { ["GET", "HEAD"] }
|
|
11
|
-
|
|
12
|
-
it "is a Hanami::Router::Error" do
|
|
13
|
-
expect(error.class).to be < Hanami::Router::Error
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns a relevant message" do
|
|
17
|
-
expect(error.to_s).to eq "Only GET, HEAD requests are allowed at /example"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "returns the env" do
|
|
21
|
-
expect(error.env).to be env
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "returns the allowed methods" do
|
|
25
|
-
expect(error.allowed_methods).to be allowed_methods
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/router"
|
|
4
|
-
require "hanami/extensions/router/errors"
|
|
5
|
-
|
|
6
|
-
RSpec.describe(Hanami::Router::NotFoundError) do
|
|
7
|
-
subject(:error) { described_class.new(env) }
|
|
8
|
-
|
|
9
|
-
let(:env) { Rack::MockRequest.env_for("http://example.com/example", method: "GET") }
|
|
10
|
-
|
|
11
|
-
it "is a Hanami::Router::Error" do
|
|
12
|
-
expect(error.class).to be < Hanami::Router::Error
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "returns a relevant message" do
|
|
16
|
-
expect(error.to_s).to eq "No route found for GET /example"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "returns the env" do
|
|
20
|
-
expect(error.env).to be env
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/settings/env_store"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Hanami::Settings::EnvStore do
|
|
6
|
-
it "defaults to using ENV as the store" do
|
|
7
|
-
orig_env = ENV.to_h
|
|
8
|
-
|
|
9
|
-
ENV["FOO"] = "bar"
|
|
10
|
-
expect(described_class.new.fetch("FOO")).to eq "bar"
|
|
11
|
-
|
|
12
|
-
ENV.replace(orig_env)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "#fetch" do
|
|
16
|
-
it "fetches from ENV" do
|
|
17
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
18
|
-
|
|
19
|
-
expect(store.fetch("FOO")).to eq("bar")
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "capitalizes name" do
|
|
23
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
24
|
-
|
|
25
|
-
expect(store.fetch("foo")).to eq("bar")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "coerces name to string" do
|
|
29
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
30
|
-
|
|
31
|
-
expect(store.fetch(:foo)).to eq("bar")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "returns default when value is not found" do
|
|
35
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
36
|
-
|
|
37
|
-
expect(store.fetch("BAZ", "qux")).to eq("qux")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "returns the block execution when value is not found" do
|
|
41
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
42
|
-
|
|
43
|
-
expect(store.fetch("BAZ") { "qux" }).to eq("qux") # rubocop:disable Style/RedundantFetchBlock
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "raises KeyError when value is not found and no default is given" do
|
|
47
|
-
store = described_class.new(store: {"FOO" => "bar"})
|
|
48
|
-
|
|
49
|
-
expect { store.fetch("BAZ") }.to raise_error(KeyError)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/settings"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Hanami::Settings do
|
|
6
|
-
describe "#initialize" do
|
|
7
|
-
it "uses values from the store when present" do
|
|
8
|
-
settings_class = Class.new(described_class) do
|
|
9
|
-
setting :database_url, default: "postgres://localhost/test_app_development"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
store = {database_url: "mysql://localhost/test_app_development"}.freeze
|
|
13
|
-
|
|
14
|
-
instance = settings_class.new(store)
|
|
15
|
-
|
|
16
|
-
expect(instance.config.database_url).to eq("mysql://localhost/test_app_development")
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "uses defaults when values are not present in the store" do
|
|
20
|
-
settings_class = Class.new(described_class) do
|
|
21
|
-
setting :database_url, default: "postgres://localhost/test_app_development"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
store = {}.freeze
|
|
25
|
-
|
|
26
|
-
instance = settings_class.new(store)
|
|
27
|
-
|
|
28
|
-
expect(instance.config.database_url).to eq("postgres://localhost/test_app_development")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "collects error for all setting values failing their constructors" do
|
|
32
|
-
settings_class = Class.new(described_class) do
|
|
33
|
-
setting :database_url, constructor: ->(_v) { raise "nope to database" }
|
|
34
|
-
setting :redis_url, constructor: ->(_v) { raise "nope to redis" }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
store = {
|
|
38
|
-
database_url: "postgres://localhost/test_app_development",
|
|
39
|
-
redis_url: "redis://localhost:6379"
|
|
40
|
-
}.freeze
|
|
41
|
-
|
|
42
|
-
expect { settings_class.new(store) }.to raise_error(
|
|
43
|
-
described_class::InvalidSettingsError,
|
|
44
|
-
/(database_url: nope to database).*(redis_url: nope to redis)/m,
|
|
45
|
-
)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "collects errors for missing settings failing their constructors" do
|
|
49
|
-
settings_class = Class.new(described_class) do
|
|
50
|
-
setting :database_url, constructor: ->(_v) { raise "nope to database" }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
store = {}
|
|
54
|
-
|
|
55
|
-
expect { settings_class.new(store) }.to raise_error(
|
|
56
|
-
described_class::InvalidSettingsError,
|
|
57
|
-
/database_url: nope to database/m,
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "finalizes the config" do
|
|
62
|
-
settings_class = Class.new(described_class) do
|
|
63
|
-
setting :database_url
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
store = {database_url: "postgres://localhost/test_app_development"}
|
|
67
|
-
|
|
68
|
-
settings = settings_class.new(store)
|
|
69
|
-
|
|
70
|
-
expect(settings.config).to be_frozen
|
|
71
|
-
expect { settings.database_url = "new" }.to raise_error(Dry::Configurable::FrozenConfigError)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe "#inspect" do
|
|
76
|
-
it "shows keys" do
|
|
77
|
-
settings_class = Class.new(described_class) do
|
|
78
|
-
setting :password, default: "dont_tell_anybody"
|
|
79
|
-
setting :passphrase, default: "shhhh"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
expect(settings_class.new.inspect).to eq(
|
|
83
|
-
"#<#{settings_class.to_s} [password, passphrase]>"
|
|
84
|
-
)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe "#inspect_values" do
|
|
89
|
-
it "shows keys & values" do
|
|
90
|
-
settings_class = Class.new(described_class) do
|
|
91
|
-
setting :password, default: "dont_tell_anybody"
|
|
92
|
-
setting :passphrase, default: "shhh"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
expect(settings_class.new.inspect_values).to eq(
|
|
96
|
-
"#<#{settings_class.to_s} password=\"dont_tell_anybody\" passphrase=\"shhh\">"
|
|
97
|
-
)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "delegates unknown methods to config" do
|
|
102
|
-
settings_class = Class.new(described_class) do
|
|
103
|
-
setting :foo, default: "bar"
|
|
104
|
-
end
|
|
105
|
-
store = {}.freeze
|
|
106
|
-
|
|
107
|
-
instance = settings_class.new(store)
|
|
108
|
-
|
|
109
|
-
expect(instance.foo).to eq("bar")
|
|
110
|
-
end
|
|
111
|
-
end
|