Sha256: def63508bf90543930e64d71e9c3432fe9279a4e8f895b0685665f25dcfae5ad

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'electric_slide/agent'

describe ElectricSlide::Agent do
  let(:options) { { id: 1, address: '123@foo.com', presence: :available} }

  class MyAgent < ElectricSlide::Agent
    on_connect { foo }
    on_connection_failed { foo }
    on_disconnect { foo }
    on_presence_change { foo }

    def foo
      :bar
    end
  end

  subject {MyAgent.new options}

  after do
    [:connect_callback, :disconnect_callback, :connection_failed_callback, :presence_change_callback].each do |callback|
      ElectricSlide::Agent.instance_variable_set "@#{callback}", nil
    end
  end

  it 'executes a connect callback' do
    expect(subject.callback(:connect)).to eql :bar
  end

  it 'executes a disconnect callback' do
    expect(subject.callback(:disconnect)).to eql :bar
  end

  it 'executes a connection failed callback' do
    expect(subject.callback(:connection_failed)).to eql :bar
  end

  it 'executes a presence change callback' do
    expect(subject.callback(:presence_change, nil, nil, nil, nil)).to eql :bar
  end

  it 'executes the presence change callback on state change' do
    called = false
    ElectricSlide::Agent.on_presence_change { |queue, agent_call, presence| called = true }
    agent = ElectricSlide::Agent.new presence: :unavailable
    agent.presence = :busy
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
electric_slide-0.3.0 spec/electric_slide/agent_spec.rb