diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 15:40:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 15:40:28 +0000 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/channels | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) | |
download | gitlab-ce-b595cb0c1dec83de5bdee18284abe86614bed33b.tar.gz |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/channels')
-rw-r--r-- | spec/channels/application_cable/connection_spec.rb | 4 | ||||
-rw-r--r-- | spec/channels/awareness_channel_spec.rb | 80 |
2 files changed, 82 insertions, 2 deletions
diff --git a/spec/channels/application_cable/connection_spec.rb b/spec/channels/application_cable/connection_spec.rb index affde0095cf..f5b2cdd2fca 100644 --- a/spec/channels/application_cable/connection_spec.rb +++ b/spec/channels/application_cable/connection_spec.rb @@ -12,7 +12,7 @@ RSpec.describe ApplicationCable::Connection, :clean_gitlab_redis_sessions do context 'when user is logged in' do let(:user) { create(:user) } - let(:session_hash) { { 'warden.user.user.key' => [[user.id], user.encrypted_password[0, 29]] } } + let(:session_hash) { { 'warden.user.user.key' => [[user.id], user.authenticatable_salt] } } it 'sets current_user' do connect @@ -21,7 +21,7 @@ RSpec.describe ApplicationCable::Connection, :clean_gitlab_redis_sessions do end context 'with a stale password' do - let(:partial_password_hash) { build(:user, password: 'some_old_password').encrypted_password[0, 29] } + let(:partial_password_hash) { build(:user, password: 'some_old_password').authenticatable_salt } let(:session_hash) { { 'warden.user.user.key' => [[user.id], partial_password_hash] } } it 'sets current_user to nil' do diff --git a/spec/channels/awareness_channel_spec.rb b/spec/channels/awareness_channel_spec.rb new file mode 100644 index 00000000000..8d6dc36f6bd --- /dev/null +++ b/spec/channels/awareness_channel_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe AwarenessChannel, :clean_gitlab_redis_shared_state, type: :channel do + before do + stub_action_cable_connection(current_user: user) + end + + context "with user" do + let(:user) { create(:user) } + + describe "when no path parameter given" do + it "rejects subscription" do + subscribe path: nil + + expect(subscription).to be_rejected + end + end + + describe "with valid path parameter" do + it "successfully subscribes" do + subscribe path: "/test" + + session = AwarenessSession.for("/test") + + expect(subscription).to be_confirmed + # check if we can use session object instead + expect(subscription).to have_stream_from("awareness:#{session.to_param}") + end + + it "broadcasts set of collaborators when subscribing" do + session = AwarenessSession.for("/test") + + freeze_time do + collaborator = { + id: user.id, + name: user.name, + avatar_url: user.avatar_url(size: 36), + last_activity: Time.zone.now, + last_activity_humanized: ActionController::Base.helpers.distance_of_time_in_words( + Time.zone.now, Time.zone.now + ) + } + + expect do + subscribe path: "/test" + end.to have_broadcasted_to("awareness:#{session.to_param}") + .with(collaborators: [collaborator]) + end + end + + it "transmits payload when user is touched" do + subscribe path: "/test" + + perform :touch + + expect(transmissions.size).to be 1 + end + + it "unsubscribes from channel" do + subscribe path: "/test" + session = AwarenessSession.for("/test") + + expect { subscription.unsubscribe_from_channel } + .to change { session.size}.by(-1) + end + end + end + + context "with guest" do + let(:user) { nil } + + it "rejects subscription" do + subscribe path: "/test" + + expect(subscription).to be_rejected + end + end +end |