require 'spec_helper'
describe Blather::Stanza::Presence do
it 'registers itself' do
Blather::XMPPNode.class_from_registration(:presence, nil).should == Blather::Stanza::Presence
end
it 'must be importable' do
Blather::XMPPNode.parse('').should be_instance_of Blather::Stanza::Presence
end
it 'ensures type is one of Blather::Stanza::Presence::VALID_TYPES' do
presence = Blather::Stanza::Presence.new
lambda { presence.type = :invalid_type_name }.should raise_error(Blather::ArgumentError)
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
presence.type = valid_type
presence.type.should == valid_type
end
end
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
it "provides a helper (#{valid_type}?) for type #{valid_type}" do
Blather::Stanza::Presence.new.should respond_to :"#{valid_type}?"
end
it "returns true on call to (#{valid_type}?) if type == #{valid_type}" do
method = "#{valid_type}?".to_sym
pres = Blather::Stanza::Presence.new
pres.type = valid_type
pres.should respond_to method
pres.__send__(method).should == true
end
end
it 'creates a C object when importing a node with a c child' do
string = <<-XML
XML
s = Blather::Stanza::Presence.parse string
s.should be_kind_of Blather::Stanza::Presence::C::InstanceMethods
s.node.should == 'http://www.chatopus.com'
end
it 'creates a Status object when importing a node with type == nil' do
s = Blather::Stanza::Presence.parse('')
s.should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
s.state.should == :available
end
it 'creates a Status object when importing a node with type == "unavailable"' do
s = Blather::Stanza::Presence.parse('')
s.should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
s.state.should == :unavailable
end
it 'creates a Subscription object when importing a node with type == "subscribe"' do
s = Blather::Stanza::Presence.parse('')
s.should be_kind_of Blather::Stanza::Presence::Subscription::InstanceMethods
s.type.should == :subscribe
end
it 'creates a MUC object when importing a node with a form in the MUC namespace' do
string = <<-XML
XML
s = Blather::Stanza::Presence.parse string
s.should be_kind_of Blather::Stanza::Presence::MUC::InstanceMethods
end
it 'creates a MUCUser object when importing a node with a form in the MUC#user namespace' do
string = <<-XML
XML
s = Blather::Stanza::Presence.parse string
s.should be_kind_of Blather::Stanza::Presence::MUCUser::InstanceMethods
end
it 'creates a Presence object when importing a node with type equal to something unknown' do
string = ""
s = Blather::Stanza::Presence.parse string
s.should be_kind_of Blather::Stanza::Presence
s.type.should == :foo
end
it 'behaves like a C, a Status, and a MUCUser when all types of children are present' do
string = <<-XML
chat
foobar
XML
s = Blather::Stanza::Presence.parse string
s.state.should == :chat
s.node.should == 'http://www.chatopus.com'
s.role.should == :participant
end
end