File tree Expand file tree Collapse file tree 5 files changed +39
-4
lines changed
lib/rails_semantic_logger/extensions/action_dispatch Expand file tree Collapse file tree 5 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,17 @@ class DebugExceptions
6
6
private
7
7
8
8
undef_method :log_error
9
- def log_error ( _request , wrapper )
10
- ActiveSupport ::Deprecation . silence do
11
- ActionController ::Base . logger . fatal ( wrapper . exception )
9
+ if ( Rails ::VERSION ::MAJOR == 7 && Rails ::VERSION ::MINOR >= 1 ) || Rails ::VERSION ::MAJOR > 7
10
+ def log_error ( _request , wrapper )
11
+ Rails . application . deprecators . silence do
12
+ ActionController ::Base . logger . fatal ( wrapper . exception )
13
+ end
14
+ end
15
+ else
16
+ def log_error ( _request , wrapper )
17
+ ActiveSupport ::Deprecation . silence do
18
+ ActionController ::Base . logger . fatal ( wrapper . exception )
19
+ end
12
20
end
13
21
end
14
22
end
Original file line number Diff line number Diff line change @@ -84,5 +84,24 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest
84
84
)
85
85
end
86
86
end
87
+
88
+ describe "#show" do
89
+ it "raises and logs exception" do
90
+ # we're testing ActionDispatch::DebugExceptions in fact
91
+ messages = semantic_logger_events do
92
+ old_show = Rails . application . env_config [ "action_dispatch.show_exceptions" ]
93
+ begin
94
+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = :all
95
+ get article_url ( :show )
96
+ rescue ActiveRecord ::RecordNotFound => e
97
+ # expected
98
+ ensure
99
+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = old_show
100
+ end
101
+ end
102
+ assert_equal 4 , messages . count , messages
103
+ assert_kind_of ActiveRecord ::RecordNotFound , messages [ 3 ] . exception
104
+ end
105
+ end
87
106
end
88
107
end
Original file line number Diff line number Diff line change 5
5
def create
6
6
render plain : params [ :article ] . inspect
7
7
end
8
+
9
+ def show
10
+ raise ActiveRecord ::RecordNotFound
11
+ end
8
12
end
Original file line number Diff line number Diff line change 6
6
7
7
module Dummy
8
8
class Application < Rails ::Application
9
+ if config . respond_to? ( :load_defaults )
10
+ config . load_defaults "#{ Rails ::VERSION ::MAJOR } .#{ Rails ::VERSION ::MINOR } "
11
+ end
12
+
9
13
# Configure sensitive parameters which will be filtered from the log file.
10
14
config . filter_parameters += [ :password ]
11
15
config . active_record . sqlite3 . represent_boolean_as_integer = true if config . active_record . sqlite3
Original file line number Diff line number Diff line change 19
19
config . action_controller . perform_caching = false
20
20
21
21
# Raise exceptions instead of rendering exception templates
22
- config . action_dispatch . show_exceptions = false
22
+ config . action_dispatch . show_exceptions = Rails :: VERSION :: MAJOR >= 7 ? :none : false
23
23
24
24
# Disable request forgery protection in test environment
25
25
config . action_controller . allow_forgery_protection = false
You can’t perform that action at this time.
0 commit comments