<commit_before># encoding: utf-8

require 'spec_helper'

module Adhearsion
  describe Calls do
    let(:call) { Adhearsion::Call.new new_offer }

    let(:number_of_calls) { 10 }
    let :calls do
      Array.new(number_of_calls) { Adhearsion::Call.new new_offer }
    end

    def new_offer(call_id = nil, headers = {})
      Punchblock::Event::Offer.new :target_call_id => call_id || random_call_id, :headers => headers
    end

    it 'can create a call and add it to the collection' do
      subject.any?.should be == false
      call = subject.from_offer new_offer
      call.should be_a Adhearsion::Call
      subject.size.should be == 1
      subject[call.id].should be call
    end

    it '#size should return the number of calls in the collection' do
      subject.size.should be == 0
      subject << call
      subject.size.should be == 1
    end

    describe "removing a call" do
      let(:deleted_call) { calls[number_of_calls / 2] }

      before { calls.each { |call| subject << call } }

      context "by call object" do
        before { subject.remove_inactive_call deleted_call }

        it "should remove the call from the collection" do
          subject.size.should be == number_of_calls - 1
          subject[deleted_call.id].should be_nil
        end
      end

      context "by dead call object" do
        before do
          @call_id = deleted_call.id
          deleted_call.terminate
          deleted_call.should_not be_alive
          subject.remove_inactive_call deleted_call
        end

        it "should remove the call from the collection" do
          subject.size.should be == number_of_calls - 1
          subject[@call_id].should be_nil<commit_msg>[BUGFIX] Fix spec issue caused by Celluloid update<commit_after># encoding: utf-8

require 'spec_helper'

module Adhearsion
  describe Calls do
    let(:call) { Adhearsion::Call.new new_offer }

    let(:number_of_calls) { 10 }
    let :calls do
      Array.new(number_of_calls) { Adhearsion::Call.new new_offer }
    end

    def new_offer(call_id = nil, headers = {})
      Punchblock::Event::Offer.new :target_call_id => call_id || random_call_id, :headers => headers
    end

    it 'can create a call and add it to the collection' do
      subject.any?.should be == false
      call = subject.from_offer new_offer
      call.should be_a Adhearsion::Call
      subject.size.should be == 1
      subject[call.id].should be call
    end

    it '#size should return the number of calls in the collection' do
      subject.size.should be == 0
      subject << call
      subject.size.should be == 1
    end

    describe "removing a call" do
      let(:deleted_call) { calls[number_of_calls / 2] }

      before { calls.each { |call| subject << call } }

      context "by call object" do
        before { subject.remove_inactive_call deleted_call }

        it "should remove the call from the collection" do
          subject.size.should be == number_of_calls - 1
          subject[deleted_call.id].should be_nil
        end
      end

      context "by dead call object" do
        before do
          @call_id = deleted_call.id
          deleted_call.kill
          deleted_call.should_not be_alive
          subject.remove_inactive_call deleted_call
        end

        it "should remove the call from the collection" do
          subject.size.should be == number_of_calls - 1
          subject[@call_id].should be_nil
{'fraction_non_alphanumeric': 0.08133411351667642, 'fraction_numerical': 0.0052662375658279695, 'mean_word_length': 2.4465725806451615, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '6412506', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1027, 'n_words': 308}