hanami 2.3.2 → 3.0.0

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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +103 -19
  3. data/LICENSE +20 -0
  4. data/README.md +18 -35
  5. data/hanami.gemspec +36 -37
  6. data/lib/hanami/app.rb +12 -2
  7. data/lib/hanami/config/db.rb +2 -0
  8. data/lib/hanami/config/i18n.rb +138 -0
  9. data/lib/hanami/config/logger.rb +15 -7
  10. data/lib/hanami/config/null_config.rb +1 -1
  11. data/lib/hanami/config/views.rb +17 -0
  12. data/lib/hanami/config.rb +66 -22
  13. data/lib/hanami/errors.rb +6 -0
  14. data/lib/hanami/extensions/action/i18n_helper.rb +64 -0
  15. data/lib/hanami/extensions/action/name_inferrer.rb +34 -0
  16. data/lib/hanami/extensions/action/slice_configured_action.rb +31 -2
  17. data/lib/hanami/extensions/action.rb +20 -7
  18. data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +134 -0
  19. data/lib/hanami/extensions/mailer.rb +28 -0
  20. data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
  21. data/lib/hanami/extensions/view/context.rb +26 -4
  22. data/lib/hanami/extensions/view/part.rb +2 -0
  23. data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
  24. data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
  25. data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
  26. data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
  27. data/lib/hanami/extensions.rb +6 -1
  28. data/lib/hanami/helpers/assets_helper.rb +0 -4
  29. data/lib/hanami/helpers/form_helper.rb +1 -1
  30. data/lib/hanami/helpers/i18n_helper.rb +241 -0
  31. data/lib/hanami/logger/rack_formatter.rb +73 -0
  32. data/lib/hanami/logger/sql_formatter.rb +80 -0
  33. data/lib/hanami/logger/sql_logger.rb +48 -0
  34. data/lib/hanami/middleware/render_errors.rb +2 -2
  35. data/lib/hanami/providers/db.rb +7 -2
  36. data/lib/hanami/providers/db_logging.rb +4 -7
  37. data/lib/hanami/providers/i18n/backend.rb +373 -0
  38. data/lib/hanami/providers/i18n/locale/en.yml +57 -0
  39. data/lib/hanami/providers/i18n.rb +114 -0
  40. data/lib/hanami/providers/logger.rb +23 -1
  41. data/lib/hanami/providers/mailers.rb +101 -0
  42. data/lib/hanami/routes.rb +1 -0
  43. data/lib/hanami/settings/composite_store.rb +53 -0
  44. data/lib/hanami/settings.rb +4 -4
  45. data/lib/hanami/slice/router.rb +15 -10
  46. data/lib/hanami/slice.rb +102 -11
  47. data/lib/hanami/slice_configurable.rb +1 -3
  48. data/lib/hanami/slice_registrar.rb +2 -2
  49. data/lib/hanami/universal_logger.rb +250 -0
  50. data/lib/hanami/version.rb +1 -1
  51. data/lib/hanami/web/rack_logger.rb +2 -80
  52. data/lib/hanami/web/welcome.html.erb +443 -58
  53. data/lib/hanami.rb +4 -2
  54. metadata +34 -280
  55. data/CODE_OF_CONDUCT.md +0 -74
  56. data/FEATURES.md +0 -269
  57. data/LICENSE.md +0 -22
  58. data/spec/integration/action/cookies_spec.rb +0 -58
  59. data/spec/integration/action/csrf_protection_spec.rb +0 -54
  60. data/spec/integration/action/format_config_spec.rb +0 -129
  61. data/spec/integration/action/routes_spec.rb +0 -71
  62. data/spec/integration/action/sessions_spec.rb +0 -50
  63. data/spec/integration/action/slice_configuration_spec.rb +0 -284
  64. data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
  65. data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
  66. data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
  67. data/spec/integration/action/view_rendering_spec.rb +0 -89
  68. data/spec/integration/assets/assets_spec.rb +0 -155
  69. data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
  70. data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
  71. data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
  72. data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
  73. data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
  74. data/spec/integration/container/application_routes_helper_spec.rb +0 -48
  75. data/spec/integration/container/auto_injection_spec.rb +0 -53
  76. data/spec/integration/container/auto_registration_spec.rb +0 -86
  77. data/spec/integration/container/autoloader_spec.rb +0 -82
  78. data/spec/integration/container/imports_spec.rb +0 -253
  79. data/spec/integration/container/prepare_container_spec.rb +0 -125
  80. data/spec/integration/container/provider_environment_spec.rb +0 -52
  81. data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
  82. data/spec/integration/container/shutdown_spec.rb +0 -91
  83. data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
  84. data/spec/integration/container/standard_providers_spec.rb +0 -124
  85. data/spec/integration/db/auto_registration_spec.rb +0 -39
  86. data/spec/integration/db/commands_spec.rb +0 -80
  87. data/spec/integration/db/db_inflector_spec.rb +0 -57
  88. data/spec/integration/db/db_slices_spec.rb +0 -398
  89. data/spec/integration/db/db_spec.rb +0 -245
  90. data/spec/integration/db/gateways_spec.rb +0 -361
  91. data/spec/integration/db/logging_spec.rb +0 -301
  92. data/spec/integration/db/mappers_spec.rb +0 -84
  93. data/spec/integration/db/provider_config_spec.rb +0 -88
  94. data/spec/integration/db/provider_spec.rb +0 -35
  95. data/spec/integration/db/relations_spec.rb +0 -60
  96. data/spec/integration/db/repo_spec.rb +0 -300
  97. data/spec/integration/db/slices_importing_from_parent.rb +0 -130
  98. data/spec/integration/dotenv_loading_spec.rb +0 -138
  99. data/spec/integration/logging/exception_logging_spec.rb +0 -120
  100. data/spec/integration/logging/notifications_spec.rb +0 -68
  101. data/spec/integration/logging/request_logging_spec.rb +0 -202
  102. data/spec/integration/operations/extension_spec.rb +0 -122
  103. data/spec/integration/rack_app/body_parser_spec.rb +0 -108
  104. data/spec/integration/rack_app/method_override_spec.rb +0 -97
  105. data/spec/integration/rack_app/middleware_spec.rb +0 -720
  106. data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
  107. data/spec/integration/rack_app/rack_app_spec.rb +0 -442
  108. data/spec/integration/rake_tasks_spec.rb +0 -107
  109. data/spec/integration/router/resource_routes_spec.rb +0 -281
  110. data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
  111. data/spec/integration/settings/access_to_constants_spec.rb +0 -46
  112. data/spec/integration/settings/loading_from_env_spec.rb +0 -188
  113. data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
  114. data/spec/integration/settings/slice_registration_spec.rb +0 -145
  115. data/spec/integration/settings/using_types_spec.rb +0 -80
  116. data/spec/integration/setup_spec.rb +0 -165
  117. data/spec/integration/slices/external_slice_spec.rb +0 -91
  118. data/spec/integration/slices/slice_configuration_spec.rb +0 -42
  119. data/spec/integration/slices/slice_loading_spec.rb +0 -171
  120. data/spec/integration/slices/slice_registrations_spec.rb +0 -80
  121. data/spec/integration/slices/slice_routing_spec.rb +0 -219
  122. data/spec/integration/slices_spec.rb +0 -471
  123. data/spec/integration/view/config/default_context_spec.rb +0 -149
  124. data/spec/integration/view/config/inflector_spec.rb +0 -57
  125. data/spec/integration/view/config/part_class_spec.rb +0 -147
  126. data/spec/integration/view/config/part_namespace_spec.rb +0 -103
  127. data/spec/integration/view/config/paths_spec.rb +0 -119
  128. data/spec/integration/view/config/scope_class_spec.rb +0 -147
  129. data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
  130. data/spec/integration/view/config/template_spec.rb +0 -38
  131. data/spec/integration/view/context/assets_spec.rb +0 -79
  132. data/spec/integration/view/context/inflector_spec.rb +0 -40
  133. data/spec/integration/view/context/request_spec.rb +0 -57
  134. data/spec/integration/view/context/routes_spec.rb +0 -84
  135. data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
  136. data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
  137. data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
  138. data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
  139. data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
  140. data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
  141. data/spec/integration/view/slice_configuration_spec.rb +0 -289
  142. data/spec/integration/view/views_spec.rb +0 -103
  143. data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
  144. data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
  145. data/spec/integration/web/render_errors_spec.rb +0 -242
  146. data/spec/integration/web/welcome_view_spec.rb +0 -84
  147. data/spec/spec_helper.rb +0 -28
  148. data/spec/support/app_integration.rb +0 -157
  149. data/spec/support/coverage.rb +0 -1
  150. data/spec/support/matchers.rb +0 -32
  151. data/spec/support/rspec.rb +0 -27
  152. data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
  153. data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
  154. data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
  155. data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
  156. data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
  157. data/spec/unit/hanami/config/actions_spec.rb +0 -52
  158. data/spec/unit/hanami/config/base_url_spec.rb +0 -25
  159. data/spec/unit/hanami/config/console_spec.rb +0 -22
  160. data/spec/unit/hanami/config/db_spec.rb +0 -38
  161. data/spec/unit/hanami/config/inflector_spec.rb +0 -35
  162. data/spec/unit/hanami/config/logger_spec.rb +0 -195
  163. data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
  164. data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
  165. data/spec/unit/hanami/config/router_spec.rb +0 -44
  166. data/spec/unit/hanami/config/slices_spec.rb +0 -34
  167. data/spec/unit/hanami/config/views_spec.rb +0 -80
  168. data/spec/unit/hanami/env_spec.rb +0 -37
  169. data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
  170. data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
  171. data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
  172. data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
  173. data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
  174. data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
  175. data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
  176. data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
  177. data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
  178. data/spec/unit/hanami/port_spec.rb +0 -117
  179. data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
  180. data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
  181. data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
  182. data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
  183. data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
  184. data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
  185. data/spec/unit/hanami/settings_spec.rb +0 -111
  186. data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
  187. data/spec/unit/hanami/slice_name_spec.rb +0 -47
  188. data/spec/unit/hanami/slice_spec.rb +0 -99
  189. data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/app"
4
- require "hanami/slice_configurable"
5
-
6
- RSpec.describe Hanami::SliceConfigurable, :app_integration do
7
- before do
8
- module TestApp
9
- class App < Hanami::App
10
- register_slice :main
11
- register_slice :admin
12
- end
13
-
14
- class BaseClass
15
- extend Hanami::SliceConfigurable
16
-
17
- def self.configure_for_slice(slice)
18
- traces << slice
19
- end
20
-
21
- def self.traces
22
- @traces ||= []
23
- end
24
-
25
- def self.inherited(subclass)
26
- subclass.instance_variable_set(:@traces, traces.dup)
27
- super
28
- end
29
- end
30
- end
31
- end
32
-
33
- context "subclass inside slice namespace" do
34
- before do
35
- module Main
36
- class MySubclass < TestApp::BaseClass; end
37
- end
38
- end
39
-
40
- subject(:subclass) { Main::MySubclass }
41
-
42
- it "calls `configure_for_slice` with the slice" do
43
- expect(subclass.traces).to eq [Main::Slice]
44
- end
45
-
46
- context "further subclass, within same slice" do
47
- before do
48
- module Main
49
- class MySubSubclass < Main::MySubclass; end
50
- end
51
- end
52
-
53
- subject(:subclass) { Main::MySubSubclass }
54
-
55
- it "does not call `configure_for_slice` again" do
56
- expect(subclass.traces).to eq [Main::Slice]
57
- end
58
- end
59
-
60
- context "further subclass, within another slice namespace" do
61
- before do
62
- module Admin
63
- class MySubSubclass < Main::MySubclass; end
64
- end
65
- end
66
-
67
- subject(:subclass) { Admin::MySubSubclass }
68
-
69
- it "calls `configure_for_slice` with the other slice" do
70
- expect(subclass.traces).to eq [Main::Slice, Admin::Slice]
71
- end
72
- end
73
- end
74
-
75
- context "subclass inside slice with name overlapping another slice" do
76
- let(:app_modules) { super() << :ExternalAdmin }
77
-
78
- before do
79
- TestApp::App.register_slice :external_admin
80
-
81
- module ExternalAdmin
82
- class MySubclass < TestApp::BaseClass; end
83
- end
84
- end
85
-
86
- subject(:subclass) { ExternalAdmin::MySubclass }
87
-
88
- it "calls `configure_for_slice` with the correct matching slice" do
89
- expect(subclass.traces).to eq [ExternalAdmin::Slice]
90
- end
91
- end
92
-
93
- context "class inside app" do
94
- before do
95
- module TestApp
96
- class MySubclass < TestApp::BaseClass; end
97
- end
98
- end
99
-
100
- subject(:subclass) { TestApp::MySubclass }
101
-
102
- it "calls `configure_for_slice` with the app instance" do
103
- expect(subclass.traces).to eq [TestApp::App]
104
- end
105
-
106
- context "further subclass, within another slice namespace" do
107
- before do
108
- module Main
109
- class MySubSubclass < TestApp::MySubclass; end
110
- end
111
- end
112
-
113
- subject(:subclass) { Main::MySubSubclass }
114
-
115
- it "calls `configure_for_slice` with the other slice" do
116
- expect(subclass.traces).to eq [TestApp::App, Main::Slice]
117
- end
118
- end
119
- end
120
-
121
- context "subclass inside nested slice namespace" do
122
- before do
123
- module Main
124
- class Slice
125
- register_slice :nested
126
- end
127
-
128
- module Nested
129
- class MySubclass < TestApp::BaseClass
130
- end
131
- end
132
- end
133
- end
134
-
135
- subject(:subclass) { Main::Nested::MySubclass }
136
-
137
- it "calls `configure_for_slice` with the nested slice" do
138
- expect(subclass.traces).to eq [Main::Nested::Slice]
139
- end
140
- end
141
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/slice_name"
4
-
5
- require "dry/inflector"
6
-
7
- RSpec.describe Hanami::SliceName do
8
- subject(:slice_name) { described_class.new(slice, inflector: -> { inflector }) }
9
- let(:slice) { double(name: "Main::Slice") }
10
- let(:inflector) { Dry::Inflector.new }
11
-
12
- let(:slice_module) { Module.new }
13
-
14
- before do
15
- stub_const "Main", slice_module
16
- end
17
-
18
- describe "#name" do
19
- it "returns the downcased, underscored string name of the module containing the slice" do
20
- expect(slice_name.name).to eq "main"
21
- end
22
- end
23
-
24
- describe "#to_s" do
25
- it "returns the downcased, underscored string name of the module containing the slice" do
26
- expect(slice_name.to_s).to eq "main"
27
- end
28
- end
29
-
30
- describe "#to_sym" do
31
- it "returns the downcased, underscored, symbolized name of the module containing the slice" do
32
- expect(slice_name.to_sym).to eq :main
33
- end
34
- end
35
-
36
- describe "#namespace_name" do
37
- it "returns the string name of the module containing the slice" do
38
- expect(slice_name.namespace_name).to eq "Main"
39
- end
40
- end
41
-
42
- describe "#namespace_const" do
43
- it "returns the module containing the slice" do
44
- expect(slice_name.namespace).to be slice_module
45
- end
46
- end
47
- end
@@ -1,99 +0,0 @@
1
- require "hanami/slice"
2
-
3
- RSpec.describe Hanami::Slice, :app_integration do
4
- before do
5
- module TestApp
6
- class App < Hanami::App
7
- end
8
- end
9
- end
10
-
11
- describe ".app" do
12
- subject(:slice) { Hanami.app.register_slice(:main) }
13
-
14
- it "returns the top-level Hanami App slice" do
15
- expect(slice.app).to eq Hanami.app
16
- end
17
- end
18
-
19
- describe ".app?" do
20
- it "returns true if the slice is Hanami.app" do
21
- subject = Hanami.app
22
- expect(subject.app?).to eq true
23
- end
24
-
25
- it "returns false if the slice is not Hanami.app" do
26
- subject = Hanami.app.register_slice(:main)
27
- expect(subject.app?).to eq false
28
- end
29
- end
30
-
31
- describe ".environment" do
32
- subject(:slice) { Hanami.app.register_slice(:main) }
33
-
34
- before do
35
- allow(slice.config).to receive(:env) { :development }
36
- end
37
-
38
- it "evaluates the block with the env matches the Hanami.env" do
39
- expect {
40
- slice.environment(:development) do
41
- config.logger.level = :info
42
- end
43
- }
44
- .to change { slice.config.logger.level }
45
- .to :info
46
- end
47
-
48
- it "yields the slice to the block" do
49
- captured_slice = nil
50
- slice.environment(:development) { |slice| captured_slice = slice }
51
- expect(captured_slice).to be slice
52
- end
53
-
54
- it "does not evaluate the block with the env does not match the Hanami.env" do
55
- expect {
56
- slice.environment(:test) do
57
- config.logger.level = :info
58
- end
59
- }.not_to(change { slice.config.logger.level })
60
- end
61
- end
62
-
63
- describe ".prepare" do
64
- it "raises an error if the slice class is anonymous" do
65
- expect { Class.new(described_class).prepare }
66
- .to raise_error Hanami::SliceLoadError, /Slice must have a class name/
67
- end
68
-
69
- it "does not allow special characters in slice names" do
70
- expect { Hanami.app.register_slice(:'test_$lice') }
71
- .to raise_error(ArgumentError, /must be lowercase alphanumeric text and underscores only/)
72
- end
73
-
74
- it "does not allow uppercase characters in slice names" do
75
- expect { Hanami.app.register_slice(:TEST_slice) }
76
- .to raise_error(ArgumentError, /must be lowercase alphanumeric text and underscores only/)
77
- end
78
-
79
- it "allows lowercase alphanumeric text and underscores only" do
80
- expect { Hanami.app.register_slice(:test_slice) }.not_to raise_error
81
- end
82
-
83
- it "allows single character slice names" do
84
- expect { Hanami.app.register_slice(:t) }.not_to raise_error
85
- end
86
- end
87
-
88
- describe ".source_path" do
89
- it "provides a path to the app directory for Hanami.app" do
90
- subject = Hanami.app
91
- expect(subject.source_path).to eq Hanami.app.root.join("app")
92
- end
93
-
94
- it "provides a path to the slice root for a Slice" do
95
- subject = Hanami.app.register_slice(:main)
96
- expect(subject.source_path).to eq subject.root
97
- end
98
- end
99
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/web/rack_logger"
4
- require "dry/logger"
5
- require "stringio"
6
- require "rack/mock"
7
-
8
- RSpec.describe Hanami::Web::RackLogger do
9
- subject { described_class.new(logger) }
10
-
11
- let(:logger) do
12
- Dry.Logger(
13
- app_name,
14
- stream: stream,
15
- level: :debug,
16
- filters: filters,
17
- formatter: :rack,
18
- template: "[%<progname>s] [%<severity>s] [%<time>s] %<message>s"
19
- )
20
- end
21
-
22
- let(:stream) { StringIO.new }
23
- let(:filters) { ["user.password"] }
24
- let(:app_name) { "my_app" }
25
-
26
- describe "#initialize" do
27
- it "returns an instance of #{described_class}" do
28
- expect(subject).to be_kind_of(described_class)
29
- end
30
- end
31
-
32
- describe "#log_request" do
33
- it "logs current request" do
34
- time = Time.parse("2022-02-04 11:38:25.218816 +0100")
35
- expect(Time).to receive(:now).at_least(:once).and_return(time)
36
-
37
- path = "/users"
38
- ip = "127.0.0.1"
39
- status = 200
40
- elapsed = 0.0001
41
- content_length = 23
42
- verb = "POST"
43
-
44
- env = Rack::MockRequest.env_for(path, method: verb)
45
- env["CONTENT_LENGTH"] = content_length
46
- env["REMOTE_ADDR"] = ip
47
-
48
- params = {"user" => {"password" => "secret"}}
49
- env["router.params"] = params
50
-
51
- subject.log_request(env, status, elapsed)
52
-
53
- stream.rewind
54
- actual = stream.read
55
-
56
- if RUBY_VERSION < "3.4"
57
- expect(actual).to eql(<<~LOG)
58
- [#{app_name}] [INFO] [#{time}] #{verb} #{status} #{elapsed}µs #{ip} #{path} #{content_length}
59
- {"user"=>{"password"=>"[FILTERED]"}}
60
- LOG
61
- else
62
- expect(actual).to eql(<<~LOG)
63
- [#{app_name}] [INFO] [#{time}] #{verb} #{status} #{elapsed}µs #{ip} #{path} #{content_length}
64
- {"user" => {"password" => "[FILTERED]"}}
65
- LOG
66
- end
67
- end
68
-
69
- context "ip" do
70
- it "takes into account HTTP proxy forwarding" do
71
- env = Rack::MockRequest.env_for("/")
72
- env["REMOTE_ADDR"] = remote = "127.0.0.1"
73
- env["HTTP_X_FORWARDED_FOR"] = forwarded = "::1"
74
-
75
- subject.log_request(env, 200, 0.1)
76
-
77
- stream.rewind
78
- actual = stream.read
79
-
80
- expect(actual).to include(forwarded)
81
- expect(actual).to_not include(remote)
82
- end
83
- end
84
-
85
- context "path prefix" do
86
- it "logs full referenced relative path" do
87
- env = Rack::MockRequest.env_for(path = "/users")
88
- env["SCRIPT_NAME"] = script_name = "/v1"
89
-
90
- subject.log_request(env, 200, 0.1)
91
-
92
- stream.rewind
93
- actual = stream.read
94
-
95
- expect(actual).to include(script_name + path)
96
- end
97
- end
98
- end
99
- end