spec/blather/stanza/message_spec.rb in blather-0.4.13 vs spec/blather/stanza/message_spec.rb in blather-0.4.14
- old
+ new
@@ -107,34 +107,81 @@
it 'returns an existing node when asked for xhtml_node' do
msg = Blather::Stanza::Message.new
msg << (h = Blather::XMPPNode.new('html', msg.document))
h.namespace = Blather::Stanza::Message::HTML_NS
- h << (b = Blather::XMPPNode.new('body', msg.document))
+ b = Blather::XMPPNode.new('body', msg.document)
b.namespace = Blather::Stanza::Message::HTML_BODY_NS
+ h << b
msg.xhtml_node.must_equal(b)
end
it 'has an xhtml setter' do
msg = Blather::Stanza::Message.new
xhtml = "<some>xhtml</some>"
msg.xhtml = xhtml
- msg.xhtml_node.content.strip.must_equal(xhtml)
+ msg.xhtml_node.inner_html.strip.must_equal(xhtml)
end
it 'sets valid xhtml even if the input is not valid' do
msg = Blather::Stanza::Message.new
xhtml = "<some>xhtml"
msg.xhtml = xhtml
- msg.xhtml_node.content.strip.must_equal("<some>xhtml</some>")
+ msg.xhtml_node.inner_html.strip.must_equal("<some>xhtml</some>")
end
+ it 'sets xhtml with more than one root node' do
+ msg = Blather::Stanza::Message.new
+ xhtml = "<i>xhtml</i> more xhtml"
+ msg.xhtml = xhtml
+ msg.xhtml_node.inner_html.strip.must_equal("<i>xhtml</i> more xhtml")
+ end
+
it 'has an xhtml getter' do
msg = Blather::Stanza::Message.new
xhtml = "<some>xhtml</some>"
msg.xhtml = xhtml
msg.xhtml.must_equal(xhtml)
+ 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
+
+ it 'will only add one chat state at a time' do
+ msg = Blather::Stanza::Message.new
+ 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
+
+ it 'ensures chat state is one of Blather::Stanza::Message::VALID_CHAT_STATES' do
+ lambda do
+ msg = Blather::Stanza::Message.new
+ msg.chat_state = :invalid_chat_state
+ end.must_raise(Blather::ArgumentError)
+
+ Blather::Stanza::Message::VALID_CHAT_STATES.each do |valid_chat_state|
+ msg = Blather::Stanza::Message.new
+ msg.chat_state = valid_chat_state
+ msg.chat_state.must_equal valid_chat_state
+ end
+ end
+
+ it 'has a chat state getter' do
+ msg = Blather::Stanza::Message.new
+ msg.chat_state = :paused
+ msg.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