-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# frozen_string_literal: true | ||
|
||
feature "Streams" do | ||
channel do | ||
def subscribed | ||
transformer = params[:transformer].to_sym | ||
|
||
stream_from "a", coder: ActiveSupport::JSON do |message| | ||
message["text"] = message["text"].send(transformer) | ||
transmit(message) | ||
end | ||
|
||
# No coder | ||
stream_from "b" do |message| | ||
# transmit as is | ||
transmit(message) | ||
end | ||
|
||
# No interceptor | ||
stream_from "c" | ||
end | ||
end | ||
|
||
let(:client2) { build_client(ignore: %w[ping welcome]) } | ||
|
||
before do | ||
@identifier = {channel:, transformer: "reverse"}.to_json | ||
|
||
subscribe_request = {command: "subscribe", identifier: @identifier} | ||
|
||
client.send(subscribe_request) | ||
|
||
ack = { | ||
"identifier" => @identifier, "type" => "confirm_subscription" | ||
} | ||
|
||
assert_message ack, client.receive | ||
|
||
@identifier2 = {channel:, transformer: "upcase"}.to_json | ||
|
||
subscribe_request = {command: "subscribe", identifier: @identifier2} | ||
|
||
client2.send(subscribe_request) | ||
|
||
ack = { | ||
"identifier" => @identifier2, "type" => "confirm_subscription" | ||
} | ||
|
||
assert_message ack, client2.receive | ||
end | ||
|
||
scenario %( | ||
Intercept with coder | ||
) do | ||
ActionCable.server.broadcast("a", {text: "cable"}) | ||
|
||
msg = { | ||
"identifier" => @identifier, | ||
"message" => {"text" => "elbac"} | ||
} | ||
|
||
assert_message msg, client.receive | ||
|
||
msg = { | ||
"identifier" => @identifier2, | ||
"message" => {"text" => "CABLE"} | ||
} | ||
|
||
assert_message msg, client2.receive | ||
end | ||
|
||
scenario %( | ||
Intercept without coder | ||
) do | ||
ActionCable.server.broadcast("b", {text: "cable"}) | ||
|
||
msg = { | ||
"identifier" => @identifier, | ||
"message" => {"text" => "cable"}.to_json | ||
} | ||
|
||
assert_message msg, client.receive | ||
|
||
msg = { | ||
"identifier" => @identifier2, | ||
"message" => {"text" => "cable"}.to_json | ||
} | ||
|
||
assert_message msg, client2.receive | ||
|
||
ActionCable.server.broadcast("c", {text: "cable"}) | ||
|
||
msg = { | ||
"identifier" => @identifier, | ||
"message" => {"text" => "cable"} | ||
} | ||
|
||
assert_message msg, client.receive | ||
|
||
msg = { | ||
"identifier" => @identifier2, | ||
"message" => {"text" => "cable"} | ||
} | ||
|
||
assert_message msg, client2.receive | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
feature "Subscriptions" do | ||
channel do | ||
periodically :transmit_progress, every: 1.second | ||
|
||
state_attr_accessor :progress | ||
|
||
def subscribed | ||
self.progress = 0 | ||
end | ||
|
||
def transmit_progress | ||
self.progress += 1 | ||
|
||
transmit({progress:}) | ||
end | ||
end | ||
|
||
before do | ||
@identifier = {channel:}.to_json | ||
|
||
subscribe_request = {command: "subscribe", identifier: @identifier} | ||
|
||
client.send(subscribe_request) | ||
|
||
ack = { | ||
"identifier" => @identifier, "type" => "confirm_subscription" | ||
} | ||
|
||
assert_message ack, client.receive | ||
end | ||
|
||
scenario %( | ||
Periodic timers | ||
) do | ||
|
||
msg = client.receive | ||
assert_equal 1, msg["message"]["progress"] | ||
|
||
msg = client.receive | ||
assert_equal 2, msg["message"]["progress"] | ||
end | ||
end |