-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a new DevBackend for testing. (#63)
* Adding a new DevBackend for testing. Renamed the current Backend classes to avoid name collisions. Fixes #61 * This is not needed for the spec
- Loading branch information
Showing
10 changed files
with
113 additions
and
40 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
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,14 @@ | ||
require "../spec_helper" | ||
|
||
describe Cable::DevBackend do | ||
it "stores the broadcast" do | ||
# This is required because the RedisBackend is | ||
# configured by default and memoized | ||
Cable.reset_server | ||
Cable.temp_config(backend_class: Cable::DevBackend) do | ||
ChatChannel.broadcast_to("chat_party", "Yo yo!") | ||
|
||
Cable::DevBackend.published_messages.should contain({"chat_party", "Yo yo!"}) | ||
end | ||
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
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,8 @@ | ||
class DummySocket < HTTP::WebSocket | ||
getter messages : Array(String) = Array(String).new | ||
|
||
def send(message) | ||
return if closed? | ||
@messages << message | ||
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,23 @@ | ||
module RequestHelpers | ||
def builds_request(token : String) : HTTP::Request | ||
headers = HTTP::Headers{ | ||
"Upgrade" => "websocket", | ||
"Connection" => "Upgrade", | ||
"Sec-WebSocket-Key" => "OqColdEJm3i9e/EqMxnxZw==", | ||
"Sec-WebSocket-Protocol" => "actioncable-v1-json, actioncable-unsupported", | ||
"Sec-WebSocket-Version" => "13", | ||
} | ||
HTTP::Request.new("GET", "#{Cable.settings.route}?test_token=#{token}", headers) | ||
end | ||
|
||
def builds_request(token : Nil) : HTTP::Request | ||
headers = HTTP::Headers{ | ||
"Upgrade" => "websocket", | ||
"Connection" => "Upgrade", | ||
"Sec-WebSocket-Key" => "OqColdEJm3i9e/EqMxnxZw==", | ||
"Sec-WebSocket-Protocol" => "actioncable-v1-json, actioncable-unsupported", | ||
"Sec-WebSocket-Version" => "13", | ||
} | ||
HTTP::Request.new("GET", Cable.settings.route, headers) | ||
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,47 @@ | ||
module Cable | ||
class DevBackend < Cable::BackendCore | ||
# Store the published `stream_identifier` and `message` | ||
class_getter published_messages = [] of Tuple(String, String) | ||
|
||
# Store the `stream_identifier` on `subscribe` | ||
class_getter subscriptions = [] of String | ||
|
||
def self.reset | ||
@@published_messages.clear | ||
@@subscriptions.clear | ||
end | ||
|
||
def publish_message(stream_identifier : String, message : String) | ||
@@published_messages << {stream_identifier, message} | ||
end | ||
|
||
def subscribe_connection | ||
end | ||
|
||
def publish_connection | ||
end | ||
|
||
def close_subscribe_connection | ||
end | ||
|
||
def close_publish_connection | ||
end | ||
|
||
def open_subscribe_connection(channel) | ||
end | ||
|
||
def subscribe(stream_identifier : String) | ||
@@subscriptions << stream_identifier | ||
end | ||
|
||
def unsubscribe(stream_identifier : String) | ||
@@subscriptions.delete(stream_identifier) | ||
end | ||
|
||
def ping_redis_subscribe | ||
end | ||
|
||
def ping_redis_publish | ||
end | ||
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
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
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
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