Skip to content

Commit ddaf3b2

Browse files
authored
Merge pull request rails#42574 from leastbad/connection_identifier
add connection_identifier to ConnectionStub
2 parents 78e7a7f + b18e6ba commit ddaf3b2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

actioncable/lib/action_cable/channel/test_case.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ def initialize(identifiers = {})
6262
def transmit(cable_message)
6363
transmissions << cable_message.with_indifferent_access
6464
end
65+
66+
def connection_identifier
67+
unless defined? @connection_identifier
68+
@connection_identifier = connection_gid identifiers.filter_map { |id| send(id.to_sym) if id }
69+
end
70+
71+
@connection_identifier
72+
end
73+
74+
private
75+
def connection_gid(ids)
76+
ids.map do |o|
77+
if o.respond_to? :to_gid_param
78+
o.to_gid_param
79+
else
80+
o.to_s
81+
end
82+
end.sort.join(":")
83+
end
6584
end
6685

6786
# Superclass for Action Cable channel functional tests.

actioncable/test/channel/test_case_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_connection_identifiers
6262

6363
assert_equal "John", subscription.username
6464
assert subscription.admin
65+
assert_equal "John:true", connection.connection_identifier
6566
end
6667
end
6768

0 commit comments

Comments
 (0)