-
Notifications
You must be signed in to change notification settings - Fork 5
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
7 changed files
with
90 additions
and
1 deletion.
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
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,24 @@ | ||
require 'test_helper' | ||
|
||
module ApplicationCable | ||
class ChannelTest < ActiveSupport::TestCase | ||
test "should be a subclass of ActionCable::Channel::Base" do | ||
assert Channel < ActionCable::Channel::Base | ||
end | ||
|
||
test "should be defined within ApplicationCable module" do | ||
assert_equal ApplicationCable::Channel, Channel | ||
end | ||
|
||
test "can be instantiated with connection and identifier" do | ||
connection = Object.new | ||
def connection.identifiers | ||
[:test_identifier] | ||
end | ||
identifier = "test_channel" | ||
assert_nothing_raised do | ||
Channel.new(connection, identifier) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'test_helper' | ||
|
||
module ApplicationCable | ||
class ConnectionTest < ActionCable::Connection::TestCase | ||
def setup | ||
@user = User.create(email: '[email protected]', password: 'password') | ||
end | ||
|
||
test "connects with authenticated user" do | ||
# Simulate Devise authentication | ||
warden = Minitest::Mock.new | ||
warden.expect :user, @user | ||
|
||
connect env: { 'warden' => warden } | ||
|
||
assert_equal @user, connection.current_user | ||
end | ||
|
||
test "rejects connection without authenticated user" do | ||
# Simulate no authenticated user | ||
warden = Minitest::Mock.new | ||
warden.expect :user, nil | ||
|
||
assert_reject_connection { connect env: { 'warden' => warden } } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'test_helper' | ||
|
||
class ExportChannelTest < ActionCable::Channel::TestCase | ||
test "subscribes to export_channel" do | ||
subscribe | ||
assert subscription.confirmed? | ||
assert_has_stream 'export_channel' | ||
end | ||
|
||
test "unsubscribes from export_channel" do | ||
subscribe | ||
assert subscription.confirmed? | ||
|
||
unsubscribe | ||
assert_no_streams | ||
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