Skip to content

Commit 07d288f

Browse files
Fix notification payload params absence (reidmorrison#127)
* Fix notification payload params absence * Remove byebug dependency * Added missed files
1 parent 47112b2 commit 07d288f

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

lib/rails_semantic_logger/action_controller/log_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def process_action(event)
1818
# According to PR https://github.com/rocketjob/rails_semantic_logger/pull/37/files
1919
# payload[:params] is not always a Hash.
2020
payload[:params] = payload[:params].to_unsafe_h unless payload[:params].is_a?(Hash)
21-
payload[:params].except!(*INTERNAL_PARAMS)
21+
payload[:params] = payload[:params].except(*INTERNAL_PARAMS)
2222
payload.delete(:params) if payload[:params].empty?
2323

2424
format = payload[:format]

test/controllers/dashboard_controller_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
2323
end
2424

2525
test "get show successfully logs message" do
26-
get dashboard_url
26+
PayloadCollector.wrap do
27+
get dashboard_url
28+
end
2729

2830
SemanticLogger.flush
2931
actual = @mock_logger.message
@@ -39,5 +41,8 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
3941
assert_equal "/dashboard", payload[:path], payload
4042
assert_equal 200, payload[:status], payload
4143
assert_equal "OK", payload[:status_message], payload
44+
45+
payload = PayloadCollector.last
46+
assert_equal payload[:params], {"controller"=>"dashboard", "action"=>"show"}
4247
end
4348
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
2+
event = ActiveSupport::Notifications::Event.new(*args)
3+
PayloadCollector.append(event.payload)
4+
end

test/payload_collector.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class PayloadCollector
2+
class << self
3+
def wrap
4+
@store = true
5+
yield
6+
ensure
7+
@store = false
8+
end
9+
10+
def append(payload)
11+
data.append(payload) if @store
12+
end
13+
14+
def last
15+
data.last
16+
end
17+
18+
def flush
19+
@data = []
20+
end
21+
22+
private
23+
24+
def data
25+
@data ||= []
26+
end
27+
end
28+
end

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
require "rails/test_help"
99
require_relative "mock_logger"
10+
require_relative "payload_collector"
1011

1112
# Include the complete backtrace?
1213
Minitest.backtrace_filter = Minitest::BacktraceFilter.new if ENV["BACKTRACE"].present?

0 commit comments

Comments
 (0)