spec/blather/stanza/message_spec.rb in blather-0.4.14 vs spec/blather/stanza/message_spec.rb in blather-0.4.15

- old
+ new

@@ -1,7 +1,42 @@ -require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper]) +require File.expand_path "../../../spec_helper", __FILE__ +def ichat_message_xml + <<-XML + <message from="juliet@example.com/balcony" to="romeo@example.net" type="chat" id="iChat_5FA6C6DC"> + <body>Hello</body> + <html xmlns="http://www.w3.org/1999/xhtml"> + <body style="background-color:#7bb5ee;color:#000000;"> + <span style="font-family: 'Arial';font-size: 12px;color: #262626;">Hello</span> + <img alt="f5ad3a04d218d7160fa02415e02d41b3.jpg" src="message-attachments:1" width="30" height="30"/> + </body> + </html> + + <x xmlns="http://www.apple.com/xmpp/message-attachments"> + <attachment id="1"> + <sipub xmlns="http://jabber.org/protocol/sipub" from="juliet@example.com/balcony" id="sipubid_77933F62" mime-type="binary/octet-stream" profile="http://jabber.org/protocol/si/profile/file-transfer"> + <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" xmlns:ichat="apple:profile:transfer-extensions" name="f5ad3a04d218d7160fa02415e02d41b3.jpg" size="1245" posixflags="000001A4"/> + </sipub> + </attachment> + </x> + + <iq type="set" id="iChat_4CC32F1F" to="romeo@example.net"> + <si xmlns="http://jabber.org/protocol/si" id="sid_60C2D273" mime-type="binary/octet-stream" profile="http://jabber.org/protocol/si/profile/file-transfer"> + <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" xmlns:ichat="apple:profile:transfer-extensions" name="f5ad3a04d218d7160fa02415e02d41b3.jpg" size="1245" posixflags="000001A4"/> + <feature xmlns="http://jabber.org/protocol/feature-neg"> + <x xmlns="jabber:x:data" type="form"> + <field type="list-single" var="stream-method"> + <option><value>http://jabber.org/protocol/bytestreams</value></option> + </field> + </x> + </feature> + </si> + </iq> + </message> + XML +end + def message_xml <<-XML <message to='romeo@example.net' from='juliet@example.com/balcony' @@ -9,10 +44,11 @@ xml:lang='en'> <body>Wherefore art thou, Romeo?</body> <x xmlns='jabber:x:data' type='form'> <field var='field-name' type='text-single' label='description' /> </x> + <paused xmlns="http://jabber.org/protocol/chatstates"/> </message> XML end describe Blather::Stanza::Message do @@ -20,10 +56,11 @@ Blather::XMPPNode.class_from_registration(:message, nil).must_equal Blather::Stanza::Message end it 'must be importable' do Blather::XMPPNode.import(parse_stanza(message_xml).root).must_be_instance_of Blather::Stanza::Message + Blather::XMPPNode.import(parse_stanza(ichat_message_xml).root).must_be_instance_of Blather::Stanza::Message end it 'provides "attr_accessor" for body' do s = Blather::Stanza::Message.new s.body.must_be_nil @@ -142,10 +179,15 @@ xhtml = "<some>xhtml</some>" msg.xhtml = xhtml msg.xhtml.must_equal(xhtml) end + it 'finds xhtml body when html wrapper has wrong namespace' do + msg = Blather::XMPPNode.import(parse_stanza(ichat_message_xml).root) + msg.xhtml.must_equal "<span style=\"font-family: 'Arial';font-size: 12px;color: #262626;\">Hello</span>\n <img alt=\"f5ad3a04d218d7160fa02415e02d41b3.jpg\" src=\"message-attachments:1\" width=\"30\" height=\"30\"></img>" + end + it 'has a chat state setter' do msg = Blather::Stanza::Message.new msg.chat_state = :composing msg.xpath('ns:composing', :ns => Blather::Stanza::Message::CHAT_STATE_NS).wont_be_empty end @@ -155,11 +197,11 @@ msg.chat_state = :composing msg.chat_state = :paused msg.xpath('ns:*', :ns => Blather::Stanza::Message::CHAT_STATE_NS).size.must_equal(1) end - + it 'ensures chat state setter accepts strings' do msg = Blather::Stanza::Message.new msg.chat_state = "gone" msg.xpath('ns:gone', :ns => Blather::Stanza::Message::CHAT_STATE_NS).wont_be_empty end @@ -179,9 +221,13 @@ it 'has a chat state getter' do msg = Blather::Stanza::Message.new msg.chat_state = :paused msg.chat_state.must_equal(:paused) + end + + it 'imports correct chat state' do + Blather::XMPPNode.import(parse_stanza(message_xml).root).chat_state.must_equal :paused end it 'makes a form child available' do n = Blather::XMPPNode.import(parse_stanza(message_xml).root) n.form.fields.size.must_equal 1 \ No newline at end of file