# encoding: utf-8 require 'spec_helper' module Punchblock module Command describe Unjoin do it 'registers itself' do expect(RayoNode.class_from_registration(:unjoin, 'urn:xmpp:rayo:1')).to eq(described_class) end describe "when setting options in initializer" do subject { Unjoin.new :call_uri => 'abc123', :mixer_name => 'blah' } describe '#call_uri' do subject { super().call_uri } it { should be == 'abc123' } end describe '#mixer_name' do subject { super().mixer_name } it { should be == 'blah' } end context "with old call_id attribute" do subject { described_class.new call_id: 'abc123' } describe '#call_uri' do subject { super().call_uri } it { should be == 'abc123' } end end describe "exporting to Rayo" do it "should export to XML that can be understood by its parser" do new_instance = RayoNode.from_xml subject.to_rayo expect(new_instance).to be_instance_of described_class expect(new_instance.call_uri).to eq('abc123') expect(new_instance.mixer_name).to eq('blah') end it "should render to a parent node if supplied" do doc = Nokogiri::XML::Document.new parent = Nokogiri::XML::Node.new 'foo', doc doc.root = parent rayo_doc = subject.to_rayo(parent) expect(rayo_doc).to eq(parent) end context "when attributes are not set" do subject { described_class.new call_uri: 'abc123' } it "should not include them in the XML representation" do expect(subject.to_rayo['call-uri']).to eq('abc123') expect(subject.to_rayo['mixer-name']).to be_nil end end end end describe "from a stanza" do let :stanza do <<-MESSAGE MESSAGE end subject { RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' } it { should be_instance_of described_class } describe '#call_uri' do subject { super().call_uri } it { should be == 'abc123' } end describe '#mixer_name' do subject { super().mixer_name } it { should be == 'blah' } end end end end end