Skip to content

Commit

Permalink
detect private current_* methods
Browse files Browse the repository at this point in the history
Some services may declare current_user (or current_* really) as private
methods if there is no need to expose that method in the controller.
Previously we would miss out on sending the user_id with the event if
this was the case, this change allows us to detect these as private
methods.

For testing purposes, we've made the current_* methods private since
that ensures we work with both private and public versions of these
methods.
  • Loading branch information
misaka committed Jul 27, 2022
1 parent 4fc956a commit a2b5462
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dfe/analytics/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def trigger_request_event
.with_response_details(response)
.with_request_uuid(RequestLocals.fetch(:dfe_analytics_request_id) { nil })

request_event.with_user(current_user) if respond_to? :current_user
request_event.with_namespace(current_namespace) if respond_to? :current_namespace
request_event.with_user(current_user) if respond_to?(:current_user, true)
request_event.with_namespace(current_namespace) if respond_to?(:current_namespace, true)

DfE::Analytics::SendEvents.do([request_event.as_json])
end
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def index
render plain: ''
end

private

def current_user
Struct.new(:id).new(1)
end
Expand Down

0 comments on commit a2b5462

Please sign in to comment.