tp-blather 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/.autotest +13 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +19 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +8 -0
  6. data/CHANGELOG.md +249 -0
  7. data/Gemfile +4 -0
  8. data/Guardfile +5 -0
  9. data/LICENSE +22 -0
  10. data/README.md +413 -0
  11. data/Rakefile +20 -0
  12. data/TODO.md +2 -0
  13. data/blather.gemspec +51 -0
  14. data/examples/certs/README +20 -0
  15. data/examples/certs/ca-bundle.crt +3987 -0
  16. data/examples/echo.rb +19 -0
  17. data/examples/execute.rb +17 -0
  18. data/examples/ping_pong.rb +38 -0
  19. data/examples/print_hierarchy.rb +77 -0
  20. data/examples/rosterprint.rb +15 -0
  21. data/examples/stream_only.rb +28 -0
  22. data/examples/trusted_echo.rb +21 -0
  23. data/examples/xmpp4r/echo.rb +36 -0
  24. data/lib/blather.rb +112 -0
  25. data/lib/blather/cert_store.rb +53 -0
  26. data/lib/blather/client.rb +95 -0
  27. data/lib/blather/client/client.rb +345 -0
  28. data/lib/blather/client/dsl.rb +320 -0
  29. data/lib/blather/client/dsl/pubsub.rb +174 -0
  30. data/lib/blather/core_ext/eventmachine.rb +125 -0
  31. data/lib/blather/core_ext/ipaddr.rb +20 -0
  32. data/lib/blather/errors.rb +69 -0
  33. data/lib/blather/errors/sasl_error.rb +44 -0
  34. data/lib/blather/errors/stanza_error.rb +110 -0
  35. data/lib/blather/errors/stream_error.rb +84 -0
  36. data/lib/blather/file_transfer.rb +107 -0
  37. data/lib/blather/file_transfer/ibb.rb +68 -0
  38. data/lib/blather/file_transfer/s5b.rb +114 -0
  39. data/lib/blather/jid.rb +141 -0
  40. data/lib/blather/roster.rb +118 -0
  41. data/lib/blather/roster_item.rb +146 -0
  42. data/lib/blather/stanza.rb +167 -0
  43. data/lib/blather/stanza/disco.rb +32 -0
  44. data/lib/blather/stanza/disco/capabilities.rb +161 -0
  45. data/lib/blather/stanza/disco/disco_info.rb +205 -0
  46. data/lib/blather/stanza/disco/disco_items.rb +134 -0
  47. data/lib/blather/stanza/iq.rb +144 -0
  48. data/lib/blather/stanza/iq/command.rb +339 -0
  49. data/lib/blather/stanza/iq/ibb.rb +86 -0
  50. data/lib/blather/stanza/iq/ping.rb +50 -0
  51. data/lib/blather/stanza/iq/query.rb +53 -0
  52. data/lib/blather/stanza/iq/roster.rb +185 -0
  53. data/lib/blather/stanza/iq/s5b.rb +208 -0
  54. data/lib/blather/stanza/iq/si.rb +415 -0
  55. data/lib/blather/stanza/iq/vcard.rb +149 -0
  56. data/lib/blather/stanza/message.rb +428 -0
  57. data/lib/blather/stanza/message/muc_user.rb +119 -0
  58. data/lib/blather/stanza/muc/muc_user_base.rb +54 -0
  59. data/lib/blather/stanza/presence.rb +172 -0
  60. data/lib/blather/stanza/presence/c.rb +100 -0
  61. data/lib/blather/stanza/presence/muc.rb +35 -0
  62. data/lib/blather/stanza/presence/muc_user.rb +147 -0
  63. data/lib/blather/stanza/presence/status.rb +218 -0
  64. data/lib/blather/stanza/presence/subscription.rb +100 -0
  65. data/lib/blather/stanza/pubsub.rb +119 -0
  66. data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
  67. data/lib/blather/stanza/pubsub/create.rb +65 -0
  68. data/lib/blather/stanza/pubsub/errors.rb +18 -0
  69. data/lib/blather/stanza/pubsub/event.rb +139 -0
  70. data/lib/blather/stanza/pubsub/items.rb +103 -0
  71. data/lib/blather/stanza/pubsub/publish.rb +103 -0
  72. data/lib/blather/stanza/pubsub/retract.rb +92 -0
  73. data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
  74. data/lib/blather/stanza/pubsub/subscription.rb +135 -0
  75. data/lib/blather/stanza/pubsub/subscriptions.rb +83 -0
  76. data/lib/blather/stanza/pubsub/unsubscribe.rb +84 -0
  77. data/lib/blather/stanza/pubsub_owner.rb +51 -0
  78. data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
  79. data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
  80. data/lib/blather/stanza/x.rb +416 -0
  81. data/lib/blather/stream.rb +266 -0
  82. data/lib/blather/stream/client.rb +32 -0
  83. data/lib/blather/stream/component.rb +39 -0
  84. data/lib/blather/stream/features.rb +70 -0
  85. data/lib/blather/stream/features/register.rb +38 -0
  86. data/lib/blather/stream/features/resource.rb +63 -0
  87. data/lib/blather/stream/features/sasl.rb +190 -0
  88. data/lib/blather/stream/features/session.rb +45 -0
  89. data/lib/blather/stream/features/tls.rb +29 -0
  90. data/lib/blather/stream/parser.rb +102 -0
  91. data/lib/blather/version.rb +3 -0
  92. data/lib/blather/xmpp_node.rb +94 -0
  93. data/spec/blather/client/client_spec.rb +687 -0
  94. data/spec/blather/client/dsl/pubsub_spec.rb +492 -0
  95. data/spec/blather/client/dsl_spec.rb +266 -0
  96. data/spec/blather/errors/sasl_error_spec.rb +33 -0
  97. data/spec/blather/errors/stanza_error_spec.rb +129 -0
  98. data/spec/blather/errors/stream_error_spec.rb +108 -0
  99. data/spec/blather/errors_spec.rb +33 -0
  100. data/spec/blather/file_transfer_spec.rb +135 -0
  101. data/spec/blather/jid_spec.rb +87 -0
  102. data/spec/blather/roster_item_spec.rb +134 -0
  103. data/spec/blather/roster_spec.rb +107 -0
  104. data/spec/blather/stanza/discos/disco_info_spec.rb +247 -0
  105. data/spec/blather/stanza/discos/disco_items_spec.rb +154 -0
  106. data/spec/blather/stanza/iq/command_spec.rb +206 -0
  107. data/spec/blather/stanza/iq/ibb_spec.rb +124 -0
  108. data/spec/blather/stanza/iq/ping_spec.rb +45 -0
  109. data/spec/blather/stanza/iq/query_spec.rb +64 -0
  110. data/spec/blather/stanza/iq/roster_spec.rb +139 -0
  111. data/spec/blather/stanza/iq/s5b_spec.rb +57 -0
  112. data/spec/blather/stanza/iq/si_spec.rb +98 -0
  113. data/spec/blather/stanza/iq/vcard_spec.rb +93 -0
  114. data/spec/blather/stanza/iq_spec.rb +61 -0
  115. data/spec/blather/stanza/message/muc_user_spec.rb +152 -0
  116. data/spec/blather/stanza/message_spec.rb +282 -0
  117. data/spec/blather/stanza/presence/c_spec.rb +56 -0
  118. data/spec/blather/stanza/presence/muc_spec.rb +37 -0
  119. data/spec/blather/stanza/presence/muc_user_spec.rb +83 -0
  120. data/spec/blather/stanza/presence/status_spec.rb +144 -0
  121. data/spec/blather/stanza/presence/subscription_spec.rb +102 -0
  122. data/spec/blather/stanza/presence_spec.rb +125 -0
  123. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  124. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  125. data/spec/blather/stanza/pubsub/event_spec.rb +98 -0
  126. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  127. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  128. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  129. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  130. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  131. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  132. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +74 -0
  133. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  134. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  135. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  136. data/spec/blather/stanza/pubsub_spec.rb +68 -0
  137. data/spec/blather/stanza/x_spec.rb +231 -0
  138. data/spec/blather/stanza_spec.rb +134 -0
  139. data/spec/blather/stream/client_spec.rb +1090 -0
  140. data/spec/blather/stream/component_spec.rb +108 -0
  141. data/spec/blather/stream/parser_spec.rb +152 -0
  142. data/spec/blather/stream/ssl_spec.rb +32 -0
  143. data/spec/blather/xmpp_node_spec.rb +47 -0
  144. data/spec/blather_spec.rb +34 -0
  145. data/spec/fixtures/pubsub.rb +311 -0
  146. data/spec/spec_helper.rb +17 -0
  147. data/yard/templates/default/class/html/handlers.erb +18 -0
  148. data/yard/templates/default/class/setup.rb +10 -0
  149. data/yard/templates/default/class/text/handlers.erb +1 -0
  150. metadata +459 -0
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ def control_affiliations
5
+ { :owner => ['node1', 'node2'],
6
+ :publisher => ['node3'],
7
+ :outcast => ['node4'],
8
+ :member => ['node5'],
9
+ :none => ['node6'] }
10
+ end
11
+
12
+ describe Blather::Stanza::PubSub::Affiliations do
13
+ it 'registers itself' do
14
+ Blather::XMPPNode.class_from_registration(:affiliations, Blather::Stanza::PubSub.registered_ns).should == Blather::Stanza::PubSub::Affiliations
15
+ end
16
+
17
+ it 'can be imported' do
18
+ Blather::XMPPNode.parse(affiliations_xml).should be_instance_of Blather::Stanza::PubSub::Affiliations
19
+ end
20
+
21
+ it 'ensures an affiliations node is present on create' do
22
+ affiliations = Blather::Stanza::PubSub::Affiliations.new
23
+ affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_nil
24
+ end
25
+
26
+ it 'ensures an affiliations node exists when calling #affiliations' do
27
+ affiliations = Blather::Stanza::PubSub::Affiliations.new
28
+ affiliations.pubsub.remove_children :affiliations
29
+ affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should be_nil
30
+
31
+ affiliations.affiliations.should_not be_nil
32
+ affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_nil
33
+ end
34
+
35
+ it 'defaults to a get node' do
36
+ Blather::Stanza::PubSub::Affiliations.new.type.should == :get
37
+ end
38
+
39
+ it 'sets the host if requested' do
40
+ aff = Blather::Stanza::PubSub::Affiliations.new :get, 'pubsub.jabber.local'
41
+ aff.to.should == Blather::JID.new('pubsub.jabber.local')
42
+ end
43
+
44
+ it 'can import an affiliates result node' do
45
+ node = parse_stanza(affiliations_xml).root
46
+
47
+ affiliations = Blather::Stanza::PubSub::Affiliations.new.inherit node
48
+ affiliations.size.should == 5
49
+ affiliations.list.should == control_affiliations
50
+ end
51
+
52
+ it 'will iterate over each affiliation' do
53
+ Blather::XMPPNode.parse(affiliations_xml).each do |type, nodes|
54
+ nodes.should == control_affiliations[type]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ describe Blather::Stanza::PubSub::Create do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:create, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Create
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.parse(<<-NODE).should be_instance_of Blather::Stanza::PubSub::Create
11
+ <iq type='set'
12
+ from='hamlet@denmark.lit/elsinore'
13
+ to='pubsub.shakespeare.lit'
14
+ id='create1'>
15
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
16
+ <create node='princely_musings'/>
17
+ <configure/>
18
+ </pubsub>
19
+ </iq>
20
+ NODE
21
+ end
22
+
23
+ it 'ensures a create node is present on create' do
24
+ create = Blather::Stanza::PubSub::Create.new
25
+ create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
26
+ end
27
+
28
+ it 'ensures a configure node is present on create' do
29
+ create = Blather::Stanza::PubSub::Create.new
30
+ create.find('//ns:pubsub/ns:configure', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
31
+ end
32
+
33
+ it 'ensures a create node exists when calling #create_node' do
34
+ create = Blather::Stanza::PubSub::Create.new
35
+ create.pubsub.remove_children :create
36
+ create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
37
+
38
+ create.create_node.should_not be_nil
39
+ create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
40
+ end
41
+
42
+ it 'defaults to a set node' do
43
+ create = Blather::Stanza::PubSub::Create.new
44
+ create.type.should == :set
45
+ end
46
+
47
+ it 'sets the host if requested' do
48
+ create = Blather::Stanza::PubSub::Create.new :set, 'pubsub.jabber.local'
49
+ create.to.should == Blather::JID.new('pubsub.jabber.local')
50
+ end
51
+
52
+ it 'sets the node' do
53
+ create = Blather::Stanza::PubSub::Create.new :set, 'host', 'node-name'
54
+ create.node.should == 'node-name'
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ describe Blather::Stanza::PubSub::Event do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:event, 'http://jabber.org/protocol/pubsub#event').should == Blather::Stanza::PubSub::Event
7
+ end
8
+
9
+ it 'is importable' do
10
+ Blather::XMPPNode.parse(event_notification_xml).should be_instance_of Blather::Stanza::PubSub::Event
11
+ end
12
+
13
+ it 'ensures a query node is present on create' do
14
+ evt = Blather::Stanza::PubSub::Event.new
15
+ evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
16
+ end
17
+
18
+ it 'ensures an event node exists when calling #event_node' do
19
+ evt = Blather::Stanza::PubSub::Event.new
20
+ evt.remove_children :event
21
+ evt.find('*[local-name()="event"]').should be_empty
22
+
23
+ evt.event_node.should_not be_nil
24
+ evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
25
+ end
26
+
27
+ it 'ensures an items node exists when calling #items_node' do
28
+ evt = Blather::Stanza::PubSub::Event.new
29
+ evt.remove_children :items
30
+ evt.find('*[local-name()="items"]').should be_empty
31
+
32
+ evt.items_node.should_not be_nil
33
+ evt.find('ns:event/ns:items', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
34
+ end
35
+
36
+ it 'knows the associated node name' do
37
+ evt = Blather::XMPPNode.parse(event_with_payload_xml)
38
+ evt.node.should == 'princely_musings'
39
+ end
40
+
41
+ it 'ensures newly inherited items are PubSubItem objects' do
42
+ evt = Blather::XMPPNode.parse(event_with_payload_xml)
43
+ evt.items?.should == true
44
+ evt.retractions?.should == false
45
+ evt.items.map { |i| i.class }.uniq.should == [Blather::Stanza::PubSub::PubSubItem]
46
+ end
47
+
48
+ it 'will iterate over each item' do
49
+ evt = Blather::XMPPNode.parse(event_with_payload_xml)
50
+ evt.items.each { |i| i.class.should == Blather::Stanza::PubSub::PubSubItem }
51
+ end
52
+
53
+ it 'handles receiving subscription ids' do
54
+ evt = Blather::XMPPNode.parse(event_subids_xml)
55
+ evt.subscription_ids.should == ['123-abc', '004-yyy']
56
+ end
57
+
58
+ it 'can have a list of retractions' do
59
+ evt = Blather::XMPPNode.parse(<<-NODE)
60
+ <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
61
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
62
+ <items node='princely_musings'>
63
+ <retract id='ae890ac52d0df67ed7cfdf51b644e901'/>
64
+ </items>
65
+ </event>
66
+ </message>
67
+ NODE
68
+ evt.retractions?.should == true
69
+ evt.items?.should == false
70
+ evt.retractions.should == %w[ae890ac52d0df67ed7cfdf51b644e901]
71
+ end
72
+
73
+ it 'can be a purge' do
74
+ evt = Blather::XMPPNode.parse(<<-NODE)
75
+ <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
76
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
77
+ <purge node='princely_musings'/>
78
+ </event>
79
+ </message>
80
+ NODE
81
+ evt.purge?.should_not be_nil
82
+ evt.node.should == 'princely_musings'
83
+ end
84
+
85
+ it 'can be a subscription notification' do
86
+ evt = Blather::XMPPNode.parse(<<-NODE)
87
+ <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
88
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
89
+ <subscription jid='francisco@denmark.lit' subscription='subscribed' node='/example.com/test'/>
90
+ </event>
91
+ </message>
92
+ NODE
93
+ evt.subscription?.should_not be_nil
94
+ evt.subscription[:jid].should == 'francisco@denmark.lit'
95
+ evt.subscription[:subscription].should == 'subscribed'
96
+ evt.subscription[:node].should == '/example.com/test'
97
+ end
98
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ describe Blather::Stanza::PubSub::Items do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:items, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Items
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.parse(items_all_nodes_xml).should be_instance_of Blather::Stanza::PubSub::Items
11
+ end
12
+
13
+ it 'ensures an items node is present on create' do
14
+ items = Blather::Stanza::PubSub::Items.new
15
+ items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
16
+ end
17
+
18
+ it 'ensures an items node exists when calling #items' do
19
+ items = Blather::Stanza::PubSub::Items.new
20
+ items.pubsub.remove_children :items
21
+ items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
22
+
23
+ items.items.should_not be_nil
24
+ items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
25
+ end
26
+
27
+ it 'defaults to a get node' do
28
+ aff = Blather::Stanza::PubSub::Items.new
29
+ aff.type.should == :get
30
+ end
31
+
32
+ it 'ensures newly inherited items are PubSubItem objects' do
33
+ items = Blather::XMPPNode.parse(items_all_nodes_xml)
34
+ items.map { |i| i.class }.uniq.should == [Blather::Stanza::PubSub::PubSubItem]
35
+ end
36
+
37
+ it 'will iterate over each item' do
38
+ n = parse_stanza items_all_nodes_xml
39
+ items = Blather::Stanza::PubSub::Items.new.inherit n.root
40
+ count = 0
41
+ items.each { |i| i.should be_instance_of Blather::Stanza::PubSub::PubSubItem; count += 1 }
42
+ count.should == 4
43
+ end
44
+
45
+ it 'can create an items request node to request all items' do
46
+ host = 'pubsub.jabber.local'
47
+ node = 'princely_musings'
48
+
49
+ items = Blather::Stanza::PubSub::Items.request host, node
50
+ items.find("//ns:items[@node=\"#{node}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 1
51
+ items.to.should == Blather::JID.new(host)
52
+ items.node.should == node
53
+ end
54
+
55
+ it 'can create an items request node to request some items' do
56
+ host = 'pubsub.jabber.local'
57
+ node = 'princely_musings'
58
+ items = %w[item1 item2]
59
+
60
+ items_xpath = items.map { |i| "@id=\"#{i}\"" } * ' or '
61
+
62
+ items = Blather::Stanza::PubSub::Items.request host, node, items
63
+ items.find("//ns:items[@node=\"#{node}\"]/ns:item[#{items_xpath}]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 2
64
+ items.to.should == Blather::JID.new(host)
65
+ items.node.should == node
66
+ end
67
+
68
+ it 'can create an items request node to request "max_number" of items' do
69
+ host = 'pubsub.jabber.local'
70
+ node = 'princely_musings'
71
+ max = 3
72
+
73
+ items = Blather::Stanza::PubSub::Items.request host, node, nil, max
74
+ items.find("//ns:pubsub/ns:items[@node=\"#{node}\" and @max_items=\"#{max}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 1
75
+ items.to.should == Blather::JID.new(host)
76
+ items.node.should == node
77
+ items.max_items.should == max
78
+ end
79
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ describe Blather::Stanza::PubSub::Publish do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:publish, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Publish
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.parse(publish_xml).should be_instance_of Blather::Stanza::PubSub::Publish
11
+ end
12
+
13
+ it 'ensures an publish node is present on create' do
14
+ publish = Blather::Stanza::PubSub::Publish.new
15
+ publish.find('//ns:pubsub/ns:publish', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
16
+ end
17
+
18
+ it 'ensures an publish node exists when calling #publish' do
19
+ publish = Blather::Stanza::PubSub::Publish.new
20
+ publish.pubsub.remove_children :publish
21
+ publish.find('//ns:pubsub/ns:publish', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
22
+
23
+ publish.publish.should_not be_nil
24
+ publish.find('//ns:pubsub/ns:publish', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ publish = Blather::Stanza::PubSub::Publish.new
29
+ publish.type.should == :set
30
+ end
31
+
32
+ it 'sets the host if requested' do
33
+ publish = Blather::Stanza::PubSub::Publish.new 'pubsub.jabber.local'
34
+ publish.to.should == Blather::JID.new('pubsub.jabber.local')
35
+ end
36
+
37
+ it 'sets the node' do
38
+ publish = Blather::Stanza::PubSub::Publish.new 'host', 'node-name'
39
+ publish.node.should == 'node-name'
40
+ end
41
+
42
+ it 'will iterate over each item' do
43
+ publish = Blather::Stanza::PubSub::Publish.new.inherit parse_stanza(publish_xml).root
44
+ count = 0
45
+ publish.each do |i|
46
+ i.should be_instance_of Blather::Stanza::PubSub::PubSubItem
47
+ count += 1
48
+ end
49
+ count.should == 1
50
+ end
51
+
52
+ it 'has a node attribute' do
53
+ publish = Blather::Stanza::PubSub::Publish.new
54
+ publish.should respond_to :node
55
+ publish.node.should be_nil
56
+ publish.node = 'node-name'
57
+ publish.node.should == 'node-name'
58
+ publish.xpath('//ns:publish[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
59
+ end
60
+
61
+ it 'can set the payload with a hash' do
62
+ payload = {'id1' => 'payload1', 'id2' => 'payload2'}
63
+ publish = Blather::Stanza::PubSub::Publish.new
64
+ publish.payload = payload
65
+ publish.size.should == 2
66
+ publish.xpath('/iq/ns:pubsub/ns:publish[ns:item[@id="id1" and .="payload1"] and ns:item[@id="id2" and .="payload2"]]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
67
+ end
68
+
69
+ it 'can set the payload with an array' do
70
+ payload = %w[payload1 payload2]
71
+ publish = Blather::Stanza::PubSub::Publish.new
72
+ publish.payload = payload
73
+ publish.size.should == 2
74
+ publish.xpath('/iq/ns:pubsub/ns:publish[ns:item[.="payload1"] and ns:item[.="payload2"]]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
75
+ end
76
+
77
+ it 'can set the payload with a string' do
78
+ publish = Blather::Stanza::PubSub::Publish.new
79
+ publish.payload = 'payload'
80
+ publish.size.should == 1
81
+ publish.xpath('/iq/ns:pubsub/ns:publish[ns:item[.="payload"]]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
82
+ end
83
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/pubsub'
3
+
4
+ describe Blather::Stanza::PubSub::Retract do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:retract, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Retract
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.parse(retract_xml).should be_instance_of Blather::Stanza::PubSub::Retract
11
+ end
12
+
13
+ it 'ensures an retract node is present on create' do
14
+ retract = Blather::Stanza::PubSub::Retract.new
15
+ retract.find('//ns:pubsub/ns:retract', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
16
+ end
17
+
18
+ it 'ensures an retract node exists when calling #retract' do
19
+ retract = Blather::Stanza::PubSub::Retract.new
20
+ retract.pubsub.remove_children :retract
21
+ retract.find('//ns:pubsub/ns:retract', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
22
+
23
+ retract.retract.should_not be_nil
24
+ retract.find('//ns:pubsub/ns:retract', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ retract = Blather::Stanza::PubSub::Retract.new
29
+ retract.type.should == :set
30
+ end
31
+
32
+ it 'sets the host if requested' do
33
+ retract = Blather::Stanza::PubSub::Retract.new 'pubsub.jabber.local'
34
+ retract.to.should == Blather::JID.new('pubsub.jabber.local')
35
+ end
36
+
37
+ it 'sets the node' do
38
+ retract = Blather::Stanza::PubSub::Retract.new 'host', 'node-name'
39
+ retract.node.should == 'node-name'
40
+ end
41
+
42
+ it 'can set the retractions as a string' do
43
+ retract = Blather::Stanza::PubSub::Retract.new 'host', 'node'
44
+ retract.retractions = 'id1'
45
+ retract.xpath('//ns:retract[ns:item[@id="id1"]]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
46
+ end
47
+
48
+ it 'can set the retractions as an array' do
49
+ retract = Blather::Stanza::PubSub::Retract.new 'host', 'node'
50
+ retract.retractions = %w[id1 id2]
51
+ retract.xpath('//ns:retract[ns:item[@id="id1"] and ns:item[@id="id2"]]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
52
+ end
53
+
54
+ it 'will iterate over each item' do
55
+ retract = Blather::Stanza::PubSub::Retract.new.inherit parse_stanza(retract_xml).root
56
+ retract.retractions.size.should == 1
57
+ retract.size.should == retract.retractions.size
58
+ retract.retractions.should == %w[ae890ac52d0df67ed7cfdf51b644e901]
59
+ end
60
+
61
+ it 'has a node attribute' do
62
+ retract = Blather::Stanza::PubSub::Retract.new
63
+ retract.should respond_to :node
64
+ retract.node.should be_nil
65
+ retract.node = 'node-name'
66
+ retract.node.should == 'node-name'
67
+ retract.xpath('//ns:retract[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
68
+ end
69
+
70
+ it 'will iterate over each retraction' do
71
+ Blather::XMPPNode.parse(retract_xml).each do |i|
72
+ i.should include "ae890ac52d0df67ed7cfdf51b644e901"
73
+ end
74
+ end
75
+ end