PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/blather/stanza/discos/disco_info_spec.rb

https://github.com/halorgium/blather
Ruby | 207 lines | 172 code | 35 blank | 0 comment | 0 complexity | c24010469698af0cb0db6fd10a7cb573 MD5 | raw file
  1. require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
  2. def disco_info_xml
  3. <<-XML
  4. <iq type='result'
  5. from='romeo@montague.net/orchard'
  6. to='juliet@capulet.com/balcony'
  7. id='info4'>
  8. <query xmlns='http://jabber.org/protocol/disco#info'>
  9. <identity
  10. category='client'
  11. type='pc'
  12. name='Gabber'/>
  13. <feature var='jabber:iq:time'/>
  14. <feature var='jabber:iq:version'/>
  15. </query>
  16. </iq>
  17. XML
  18. end
  19. describe 'Blather::Stanza::Iq::DiscoInfo' do
  20. it 'registers itself' do
  21. XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/disco#info').must_equal Blather::Stanza::Iq::DiscoInfo
  22. end
  23. it 'has a node attribute' do
  24. n = Blather::Stanza::Iq::DiscoInfo.new nil, 'music', [], []
  25. n.node.must_equal 'music'
  26. n.node = :foo
  27. n.node.must_equal 'foo'
  28. end
  29. it 'inherits a list of identities' do
  30. n = XML::Document.string disco_info_xml
  31. r = Stanza::Iq::DiscoInfo.new.inherit n.root
  32. r.identities.size.must_equal 1
  33. r.identities.map { |i| i.class }.uniq.must_equal [Stanza::Iq::DiscoInfo::Identity]
  34. end
  35. it 'inherits a list of features' do
  36. n = XML::Document.string disco_info_xml
  37. r = Stanza::Iq::DiscoInfo.new.inherit n.root
  38. r.features.size.must_equal 2
  39. r.features.map { |i| i.class }.uniq.must_equal [Stanza::Iq::DiscoInfo::Feature]
  40. end
  41. end
  42. describe 'Blather::Stanza::Iq::DiscoInfo identities' do
  43. it 'takes a list of hashes for identities' do
  44. ids = [
  45. {:name => 'name', :type => 'type', :category => 'category'},
  46. {:name => 'name1', :type => 'type1', :category => 'category1'},
  47. ]
  48. control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
  49. Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
  50. di = Stanza::Iq::DiscoInfo.new nil, nil, ids
  51. di.identities.size.must_equal 2
  52. di.identities.each { |i| control.include?(i).must_equal true }
  53. end
  54. it 'takes a list of Identity objects as identities' do
  55. control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
  56. Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
  57. di = Stanza::Iq::DiscoInfo.new nil, nil, control
  58. di.identities.size.must_equal 2
  59. di.identities.each { |i| control.include?(i).must_equal true }
  60. end
  61. it 'takes a single hash as identity' do
  62. control = [Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
  63. di = Stanza::Iq::DiscoInfo.new nil, nil, {:name => 'name', :type => 'type', :category => 'category'}
  64. di.identities.size.must_equal 1
  65. di.identities.each { |i| control.include?(i).must_equal true }
  66. end
  67. it 'takes a single identity object as identity' do
  68. control = [Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
  69. di = Stanza::Iq::DiscoInfo.new nil, nil, control.first
  70. di.identities.size.must_equal 1
  71. di.identities.each { |i| control.include?(i).must_equal true }
  72. end
  73. it 'takes a mix of hashes and identity objects as identities' do
  74. ids = [
  75. {:name => 'name', :type => 'type', :category => 'category'},
  76. Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1]),
  77. ]
  78. control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
  79. Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
  80. di = Stanza::Iq::DiscoInfo.new nil, nil, ids
  81. di.identities.size.must_equal 2
  82. di.identities.each { |i| control.include?(i).must_equal true }
  83. end
  84. end
  85. describe 'Blather::Stanza::Iq::DiscoInfo features' do
  86. it 'takes a list of features as strings' do
  87. features = %w[feature1 feature2 feature3]
  88. control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
  89. di = Stanza::Iq::DiscoInfo.new nil, nil, [], features
  90. di.features.size.must_equal 3
  91. di.features.each { |f| control.include?(f).must_equal true }
  92. end
  93. it 'takes a list of features as Feature objects' do
  94. features = %w[feature1 feature2 feature3]
  95. control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
  96. di = Stanza::Iq::DiscoInfo.new nil, nil, [], control
  97. di.features.size.must_equal 3
  98. di.features.each { |f| control.include?(f).must_equal true }
  99. end
  100. it 'takes a single string' do
  101. control = [Stanza::Iq::DiscoInfo::Feature.new('feature1')]
  102. di = Stanza::Iq::DiscoInfo.new nil, nil, [], 'feature1'
  103. di.features.size.must_equal 1
  104. di.features.each { |f| control.include?(f).must_equal true }
  105. end
  106. it 'takes a single Feature object' do
  107. control = [Stanza::Iq::DiscoInfo::Feature.new('feature1')]
  108. di = Stanza::Iq::DiscoInfo.new nil, nil, [], control.first
  109. di.features.size.must_equal 1
  110. di.features.each { |f| control.include?(f).must_equal true }
  111. end
  112. it 'takes a mixed list of features as Feature objects and strings' do
  113. features = %w[feature1 feature2 feature3]
  114. control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
  115. features[1] = control[1]
  116. di = Stanza::Iq::DiscoInfo.new nil, nil, [], features
  117. di.features.size.must_equal 3
  118. di.features.each { |f| control.include?(f).must_equal true }
  119. end
  120. end
  121. describe 'Blather::Stanza::Iq::DiscoInfo::Identity' do
  122. it 'will auto-inherit nodes' do
  123. n = XML::Document.string "<identity name='Personal Events' type='pep' category='pubsub' node='publish' />"
  124. i = Stanza::Iq::DiscoInfo::Identity.new n.root
  125. i.name.must_equal 'Personal Events'
  126. i.type.must_equal :pep
  127. i.category.must_equal :pubsub
  128. end
  129. it 'has a category attribute' do
  130. n = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
  131. n.category.must_equal :cat
  132. n.category = :foo
  133. n.category.must_equal :foo
  134. end
  135. it 'has a type attribute' do
  136. n = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
  137. n.type.must_equal :type
  138. n.type = :foo
  139. n.type.must_equal :foo
  140. end
  141. it 'has a name attribute' do
  142. n = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
  143. n.name.must_equal 'name'
  144. n.name = :foo
  145. n.name.must_equal 'foo'
  146. end
  147. it 'can determine equality' do
  148. a = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
  149. a.must_respond_to :eql?
  150. a.must_equal Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
  151. a.wont_equal "<identity name='Personal Events' type='pep' category='pubsub' node='publish' />"
  152. end
  153. end
  154. describe 'Blather::Stanza::Iq::DiscoInfo::Feature' do
  155. it 'will auto-inherit nodes' do
  156. n = XML::Document.string "<feature var='ipv6' />"
  157. i = Stanza::Iq::DiscoInfo::Feature.new n.root
  158. i.var.must_equal 'ipv6'
  159. end
  160. it 'has a var attribute' do
  161. n = Blather::Stanza::Iq::DiscoInfo::Feature.new 'var'
  162. n.var.must_equal 'var'
  163. n.var = :foo
  164. n.var.must_equal 'foo'
  165. end
  166. it 'can determine equality' do
  167. a = Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
  168. a.must_respond_to :eql?
  169. a.must_equal Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
  170. a.wont_equal "<feature var='ipv6' />"
  171. end
  172. end