require 'spec_helper' module Punchblock module Component module Asterisk module AMI describe Action do it 'registers itself' do RayoNode.class_from_registration(:action, 'urn:xmpp:rayo:asterisk:ami:1').should == Action end describe "from a stanza" do let :stanza do <<-MESSAGE MESSAGE end subject { RayoNode.import parse_stanza(stanza).root, '9f00061', '1' } it { should be_instance_of Action } it_should_behave_like 'event' its(:name) { should == 'Originate' } its(:params) { should == [Action::Param.new(:channel, 'SIP/101test'), Action::Param.new(:context, 'default'), Action::Param.new(:exten, '8135551212'), Action::Param.new(:priority, '1'), Action::Param.new(:callerid, '3125551212'), Action::Param.new(:timeout, '30000'), Action::Param.new(:variable, 'var1=23|var2=24|var3=25'), Action::Param.new(:async, '1') ]} its(:params_hash) { should == {:channel => 'SIP/101test', :context => 'default', :exten => '8135551212', :priority => '1', :callerid => '3125551212', :timeout => '30000', :variable => 'var1=23|var2=24|var3=25', :async => '1'} } end describe "testing equality" do context "with the same name and params" do it "should be equal" do Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }).should == Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }) end end context "with the same name and different params" do it "should be equal" do Action.new(:name => 'Originate', :params => { :channel => 'SIP/101' }).should_not == Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }) end end context "with a different name and the same params" do it "should be equal" do Action.new(:name => 'Hangup', :params => { :channel => 'SIP/101test' }).should_not == Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }) end end end describe "when setting options in initializer" do subject do Action.new :name => 'Originate', :params => { :channel => 'SIP/101test' } end its(:name) { should == 'Originate' } its(:params) { should == [Action::Param.new(:channel, 'SIP/101test')]} its(:params_hash) { should == { :channel => 'SIP/101test' } } end class Action describe Param do let(:class_name) { Param } let(:element_name) { 'param' } it_should_behave_like 'key_value_pairs' end class Complete describe Success do let :stanza do <<-MESSAGE Originate successfully queued MESSAGE end subject { RayoNode.import(parse_stanza(stanza).root).reason } it { should be_instance_of Success } its(:name) { should == :success } its(:message) { should == "Originate successfully queued" } its(:attributes) { should == [Attribute.new(:channel, 'SIP/101-3f3f'), Attribute.new(:state, 'Ring')]} its(:attributes_hash) { should == {:channel => 'SIP/101-3f3f', :state => 'Ring'} } describe "when setting options in initializer" do subject do Success.new :message => 'Originate successfully queued', :attributes => {:channel => 'SIP/101-3f3f', :state => 'Ring'} end its(:message) { should == 'Originate successfully queued' } its(:attributes) { should == [Attribute.new(:channel, 'SIP/101-3f3f'), Attribute.new(:state, 'Ring')]} its(:attributes_hash) { should == {:channel => 'SIP/101-3f3f', :state => 'Ring'} } end end describe Attribute do let(:class_name) { Attribute } let(:element_name) { 'attribute' } it_should_behave_like 'key_value_pairs' end end end end # Action end # AMI end # Asterisk end # Component end # Punchblock