Close live connections from the model on any password change

The sessions end wherever the password changes, but only the profile
page closed the live connections, so a change from a console left a
signed-out device receiving messages until it dropped. Close them after
commit from User, logging rather than failing if the realtime service
can't be reached, since the password is saved by then.

From #371.

(cherry picked from commit c6e0105491)
This commit is contained in:
Jeremy Daer committed 2026-10-19 10:33:48 -07:00
1 parent c78f03fda7
commit 2fb599e21c
3 files changed
+19 -2

No files matched your search

+10
View File
@@ -50,6 +50,14 @@ class UserTest < ActiveSupport::TestCase
end
end
test "changing the password outside a request closes the account's live connections" do
remote_connections = mock
remote_connections.expects(:disconnect).with(reconnect: true)
ActionCable.server.stubs(:remote_connections).returns(mock.tap { |m| m.expects(:where).with(current_user: users(:david)).returns(remote_connections) })
users(:david).update!(password: "a new secret123456")
end
test "changing the password keeps the session it was changed from" do
Current.session = users(:david).sessions.start!(user_agent: "This device", ip_address: "127.0.0.1")
@@ -59,6 +67,8 @@ class UserTest < ActiveSupport::TestCase
end
test "changing other details keeps every session" do
ActionCable.server.expects(:remote_connections).never
assert_no_changes -> { users(:david).sessions.count } do
users(:david).update!(name: "Dave", email_address: "dave@37signals.com")
end