Sha256: 7f64cc49c29a6e05f49ba54b77dd9edce068c42846bb68db792ea5bcce2074c2

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

module Adhearsion
  describe Calls do
    before { Adhearsion.active_calls.clear! }

    let(:call) { Adhearsion::Call.new new_offer }

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

    it 'can create a call and add it to the active calls' do
      Adhearsion.active_calls.any?.should == false
      call = Adhearsion.active_calls.from_offer new_offer
      call.should be_a Adhearsion::Call
      Adhearsion.active_calls.size.should == 1
    end

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

    it '#remove_inactive_call should delete the call in the Hash' do
      number_of_calls = 10
      calls = Array.new(number_of_calls) { Adhearsion::Call.new new_offer }
      calls.each { |call| subject << call }

      deleted_call = calls[number_of_calls / 2]
      subject.remove_inactive_call deleted_call
      subject.size.should == number_of_calls - 1
    end

    it '#find should pull the Call from the Hash using the id' do
      subject << call
      subject.find(call.id).should be call
    end

    it "finding calls by a tag" do
      calls = Array.new(3) { Adhearsion::Call.new new_offer }
      calls.each { |call| subject << call }

      tagged_call = calls.last
      tagged_call.tag :moderator

      subject.with_tag(:moderator).should == [tagged_call]
    end

    describe "#<<" do
      it "should allow chaining" do
        subject << Call.new(new_offer) << Call.new(new_offer)
        subject.size.should == 2
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adhearsion-2.0.0.beta1 spec/adhearsion/calls_spec.rb
adhearsion-2.0.0.alpha3 spec/adhearsion/calls_spec.rb