<commit_before># This file is part of Mconf-Web, a web application that provides access
# to the Mconf webconferencing system. Copyright (C) 2010-2012 Mconf
#
# This file is licensed under the Affero General Public License version
# 3 or later. See the LICENSE file.

require 'spec_helper'

describe JoinRequestsWorker do
  let(:worker) { JoinRequestsWorker }
  let(:space) { FactoryGirl.create(:space) }

  it "uses the queue :join_requests" do
    worker.instance_variable_get(:@queue).should eql(:join_requests)
  end

  describe "#perform" do

    context "enqueues all unnotified invites" do
      let!(:join_request1) { FactoryGirl.create(:space_join_request_invite, group: space) }
      let!(:join_request2) { FactoryGirl.create(:space_join_request_invite, group: space) }
      let!(:join_request3) { FactoryGirl.create(:space_join_request_invite, group: space) }
      before {
        # clear automatically created activities
        RecentActivity.destroy_all

        @activity = [join_request1, join_request2, join_request3].map(&:new_activity)

        @activity[0].update_attribute(:notified, false)
        @activity[1].update_attribute(:notified, nil)
        @activity[2].update_attribute(:notified, true)
      }

      before(:each) { worker.perform }
      it { expect(JoinRequestInviteSenderWorker).to have_queue_size_of(2) }
      it { expect(JoinRequestInviteSenderWorker).to have_queued(@activity[0].id) }
      it { expect(JoinRequestInviteSenderWorker).to have_queued(@activity[1].id) }
      it { expect(JoinRequestInviteSenderWorker).not_to have_queued(@activity[2].id) }
    end

    context "enqueues all unnotified requests" do
      let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space) }
      let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space) }
      let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space) }
      before {
        # clear automatically created activities
        RecentActivity.destroy_all

        @activity = [join_request1, join_request2, join_request3].map(&:new_activity)

        @activity[0].update_attribute(:notified, false)
        @activity[1].update_attribute(:notified, nil)
        @activity[2].update_attribute(:notified, true)
      }

      before(:each) { worker.perform }
      it { expect(JoinRequestSenderWorker).to have_queue_size_of(2) }
      it { expect(JoinRequestSenderWorker).to have_queued(@activity[0].id) }
      it { expect(JoinRequestSenderWorker).to have_queued(@activity[1].id) }
      it { expect(JoinRequestSenderWorker).not_to have_queued(@activity[2].id) }
    end

    context "for unnotified processed requests" do
      context "enqueues all " do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        before {
          # clear automatically created activities
          RecentActivity.destroy_all

          @activity1 = space.new_activity(:accept, join_request1.candidate, join_request1)
          @activity2 = space.new_activity(:accept, join_request2.candidate, join_request2)
          @activity3 = space.new_activity(:accept, join_request3.candidate, join_request3)
          @activity1.update_attribute(:notified, false)
          @activity2.update_attribute(:notified, nil)
          @activity3.update_attribute(:notified, true)
        }

        before(:each) { worker.perform }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queue_size_of(2) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity1.id) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity2.id) }
        it { expect(ProcessedJoinRequestSenderWorker).not_to have_queued(@activity3.id) }
      end

      context "ignores requests declined by admins" do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space) }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space) }
        before {
          join_request1.update_attributes :accepted => false, :processed => true
          join_request3.update_attributes :accepted => false, :processed => true

          # clear automatically created activities
          RecentActivity.destroy_all

          @activity1 = space.new_activity(:decline, join_request1.candidate, join_request1)
          @activity2 = space.new_activity(:decline, join_request2.candidate, join_request2)
          @activity3 = space.new_activity(:decline, join_request3.candidate, join_request3)
        }

        before(:each) { worker.perform }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queue_size_of(1) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity2.id) }
      end

      context "warns introducer about declined invitations" do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite') }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite', :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite') }
        before {
          join_request1.update_attributes :accepted => false, :processed => true
          join_request3.update_attributes :accepted => false, :processed => true

          # clear automatically created activities
          RecentActivity.destroy_all<commit_msg>tests to ensure that requests with keys "space.accept" and "space.decline" who are not owned by a Join Request are not being sent to be processed.<commit_after># This file is part of Mconf-Web, a web application that provides access
# to the Mconf webconferencing system. Copyright (C) 2010-2012 Mconf
#
# This file is licensed under the Affero General Public License version
# 3 or later. See the LICENSE file.

require 'spec_helper'

describe JoinRequestsWorker do
  let(:worker) { JoinRequestsWorker }
  let(:space) { FactoryGirl.create(:space) }

  it "uses the queue :join_requests" do
    worker.instance_variable_get(:@queue).should eql(:join_requests)
  end

  describe "#perform" do

    context "enqueues all unnotified invites" do
      let!(:join_request1) { FactoryGirl.create(:space_join_request_invite, group: space) }
      let!(:join_request2) { FactoryGirl.create(:space_join_request_invite, group: space) }
      let!(:join_request3) { FactoryGirl.create(:space_join_request_invite, group: space) }
      before {
        # clear automatically created activities
        RecentActivity.destroy_all

        @activity = [join_request1, join_request2, join_request3].map(&:new_activity)

        @activity[0].update_attribute(:notified, false)
        @activity[1].update_attribute(:notified, nil)
        @activity[2].update_attribute(:notified, true)
      }

      before(:each) { worker.perform }
      it { expect(JoinRequestInviteSenderWorker).to have_queue_size_of(2) }
      it { expect(JoinRequestInviteSenderWorker).to have_queued(@activity[0].id) }
      it { expect(JoinRequestInviteSenderWorker).to have_queued(@activity[1].id) }
      it { expect(JoinRequestInviteSenderWorker).not_to have_queued(@activity[2].id) }
    end

    context "enqueues all unnotified requests" do
      let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space) }
      let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space) }
      let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space) }
      before {
        # clear automatically created activities
        RecentActivity.destroy_all

        @activity = [join_request1, join_request2, join_request3].map(&:new_activity)

        @activity[0].update_attribute(:notified, false)
        @activity[1].update_attribute(:notified, nil)
        @activity[2].update_attribute(:notified, true)
      }

      before(:each) { worker.perform }
      it { expect(JoinRequestSenderWorker).to have_queue_size_of(2) }
      it { expect(JoinRequestSenderWorker).to have_queued(@activity[0].id) }
      it { expect(JoinRequestSenderWorker).to have_queued(@activity[1].id) }
      it { expect(JoinRequestSenderWorker).not_to have_queued(@activity[2].id) }
    end

    context "for unnotified processed requests" do
      context "enqueues all " do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        before {
          # clear automatically created activities
          RecentActivity.destroy_all

          @activity1 = space.new_activity(:accept, join_request1.candidate, join_request1)
          @activity2 = space.new_activity(:accept, join_request2.candidate, join_request2)
          @activity3 = space.new_activity(:accept, join_request3.candidate, join_request3)
          @activity1.update_attribute(:notified, false)
          @activity2.update_attribute(:notified, nil)
          @activity3.update_attribute(:notified, true)
        }

        before(:each) { worker.perform }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queue_size_of(2) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity1.id) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity2.id) }
        it { expect(ProcessedJoinRequestSenderWorker).not_to have_queued(@activity3.id) }
      end

      context "ignores requests declined by admins" do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space) }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space) }
        before {
          join_request1.update_attributes :accepted => false, :processed => true
          join_request3.update_attributes :accepted => false, :processed => true

          # clear automatically created activities
          RecentActivity.destroy_all

          @activity1 = space.new_activity(:decline, join_request1.candidate, join_request1)
          @activity2 = space.new_activity(:decline, join_request2.candidate, join_request2)
          @activity3 = space.new_activity(:decline, join_request3.candidate, join_request3)
        }

        before(:each) { worker.perform }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queue_size_of(1) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity2.id) }
      end

      context "ignores requests that is not owned by join requests" do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space, accepted: true) }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, accepted: true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space, accepted: false) }
        before {
          # clear automatically created activities
          RecentActivity.destroy_all

          @activity1 = space.new_activity(:decline, join_request1.candidate, join_request1)
          @activity1.update_attributes owner: space
          @activity2 = space.new_activity(:decline, join_request2.candidate, join_request2)
          @activity3 = space.new_activity(:decline, join_request3.candidate, join_request3)
        }

        before(:each) { worker.perform }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queue_size_of(1) }
        it { expect(ProcessedJoinRequestSenderWorker).to have_queued(@activity2.id) }
      end

      context "warns introducer about declined invitations" do
        let!(:join_request1) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite') }
        let!(:join_request2) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite', :accepted => true) }
        let!(:join_request3) { FactoryGirl.create(:space_join_request, group: space, :request_type => 'invite') }
        before {
          join_request1.update_attributes :accepted => false, :processed => true
          join_request3.update_attributes :accepted => false, :processed => true

          # clear automatically created activities
          RecentActivity.destroy_all
{'fraction_non_alphanumeric': 0.10612468671679198, 'fraction_numerical': 0.012922932330827067, 'mean_word_length': 3.8422449753507775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4880193', 'n_tokens_mistral': 3759, 'n_tokens_neox': 3656, 'n_words': 736}