shingara-blather 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +162 -0
  3. data/examples/echo.rb +18 -0
  4. data/examples/execute.rb +16 -0
  5. data/examples/ping_pong.rb +37 -0
  6. data/examples/print_hierarchy.rb +76 -0
  7. data/examples/rosterprint.rb +14 -0
  8. data/examples/stream_only.rb +27 -0
  9. data/examples/xmpp4r/echo.rb +35 -0
  10. data/lib/blather/client/client.rb +310 -0
  11. data/lib/blather/client/dsl/pubsub.rb +170 -0
  12. data/lib/blather/client/dsl.rb +264 -0
  13. data/lib/blather/client.rb +87 -0
  14. data/lib/blather/core_ext/nokogiri.rb +40 -0
  15. data/lib/blather/errors/sasl_error.rb +43 -0
  16. data/lib/blather/errors/stanza_error.rb +107 -0
  17. data/lib/blather/errors/stream_error.rb +82 -0
  18. data/lib/blather/errors.rb +69 -0
  19. data/lib/blather/jid.rb +142 -0
  20. data/lib/blather/roster.rb +111 -0
  21. data/lib/blather/roster_item.rb +122 -0
  22. data/lib/blather/stanza/disco/disco_info.rb +176 -0
  23. data/lib/blather/stanza/disco/disco_items.rb +132 -0
  24. data/lib/blather/stanza/disco.rb +25 -0
  25. data/lib/blather/stanza/iq/query.rb +53 -0
  26. data/lib/blather/stanza/iq/roster.rb +179 -0
  27. data/lib/blather/stanza/iq.rb +138 -0
  28. data/lib/blather/stanza/message.rb +332 -0
  29. data/lib/blather/stanza/presence/status.rb +212 -0
  30. data/lib/blather/stanza/presence/subscription.rb +101 -0
  31. data/lib/blather/stanza/presence.rb +163 -0
  32. data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
  33. data/lib/blather/stanza/pubsub/create.rb +65 -0
  34. data/lib/blather/stanza/pubsub/errors.rb +18 -0
  35. data/lib/blather/stanza/pubsub/event.rb +123 -0
  36. data/lib/blather/stanza/pubsub/items.rb +103 -0
  37. data/lib/blather/stanza/pubsub/publish.rb +103 -0
  38. data/lib/blather/stanza/pubsub/retract.rb +92 -0
  39. data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
  40. data/lib/blather/stanza/pubsub/subscription.rb +134 -0
  41. data/lib/blather/stanza/pubsub/subscriptions.rb +81 -0
  42. data/lib/blather/stanza/pubsub/unsubscribe.rb +68 -0
  43. data/lib/blather/stanza/pubsub.rb +129 -0
  44. data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
  45. data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
  46. data/lib/blather/stanza/pubsub_owner.rb +51 -0
  47. data/lib/blather/stanza.rb +149 -0
  48. data/lib/blather/stream/client.rb +31 -0
  49. data/lib/blather/stream/component.rb +38 -0
  50. data/lib/blather/stream/features/resource.rb +63 -0
  51. data/lib/blather/stream/features/sasl.rb +187 -0
  52. data/lib/blather/stream/features/session.rb +44 -0
  53. data/lib/blather/stream/features/tls.rb +28 -0
  54. data/lib/blather/stream/features.rb +53 -0
  55. data/lib/blather/stream/parser.rb +102 -0
  56. data/lib/blather/stream.rb +231 -0
  57. data/lib/blather/xmpp_node.rb +218 -0
  58. data/lib/blather.rb +78 -0
  59. data/spec/blather/client/client_spec.rb +559 -0
  60. data/spec/blather/client/dsl/pubsub_spec.rb +462 -0
  61. data/spec/blather/client/dsl_spec.rb +143 -0
  62. data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
  63. data/spec/blather/errors/sasl_error_spec.rb +33 -0
  64. data/spec/blather/errors/stanza_error_spec.rb +129 -0
  65. data/spec/blather/errors/stream_error_spec.rb +108 -0
  66. data/spec/blather/errors_spec.rb +33 -0
  67. data/spec/blather/jid_spec.rb +87 -0
  68. data/spec/blather/roster_item_spec.rb +96 -0
  69. data/spec/blather/roster_spec.rb +103 -0
  70. data/spec/blather/stanza/discos/disco_info_spec.rb +226 -0
  71. data/spec/blather/stanza/discos/disco_items_spec.rb +148 -0
  72. data/spec/blather/stanza/iq/query_spec.rb +64 -0
  73. data/spec/blather/stanza/iq/roster_spec.rb +140 -0
  74. data/spec/blather/stanza/iq_spec.rb +45 -0
  75. data/spec/blather/stanza/message_spec.rb +132 -0
  76. data/spec/blather/stanza/presence/status_spec.rb +132 -0
  77. data/spec/blather/stanza/presence/subscription_spec.rb +105 -0
  78. data/spec/blather/stanza/presence_spec.rb +66 -0
  79. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  80. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  81. data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
  82. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  83. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  84. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  85. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  86. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  87. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  88. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
  89. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  90. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  91. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  92. data/spec/blather/stanza/pubsub_spec.rb +67 -0
  93. data/spec/blather/stanza_spec.rb +116 -0
  94. data/spec/blather/stream/client_spec.rb +1011 -0
  95. data/spec/blather/stream/component_spec.rb +95 -0
  96. data/spec/blather/stream/parser_spec.rb +145 -0
  97. data/spec/blather/xmpp_node_spec.rb +231 -0
  98. data/spec/fixtures/pubsub.rb +311 -0
  99. data/spec/spec_helper.rb +43 -0
  100. metadata +249 -0
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. 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').must_equal Blather::Stanza::PubSub::Items
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(items_all_nodes_xml).root).must_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).wont_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).must_be_empty
22
+
23
+ items.items.wont_be_nil
24
+ items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a get node' do
28
+ aff = Blather::Stanza::PubSub::Items.new
29
+ aff.type.must_equal :get
30
+ end
31
+
32
+ it 'ensures newly inherited items are PubSubItem objects' do
33
+ items = Blather::XMPPNode.import(parse_stanza(items_all_nodes_xml).root)
34
+ items.map { |i| i.class }.uniq.must_equal [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.must_be_instance_of Blather::Stanza::PubSub::PubSubItem; count += 1 }
42
+ count.must_equal 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.must_equal 1
51
+ items.to.must_equal Blather::JID.new(host)
52
+ items.node.must_equal 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.must_equal 2
64
+ items.to.must_equal Blather::JID.new(host)
65
+ items.node.must_equal 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.must_equal 1
75
+ items.to.must_equal Blather::JID.new(host)
76
+ items.node.must_equal node
77
+ items.max_items.must_equal max
78
+ end
79
+ end
@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. 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').must_equal Blather::Stanza::PubSub::Publish
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(publish_xml).root).must_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).wont_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).must_be_empty
22
+
23
+ publish.publish.wont_be_nil
24
+ publish.find('//ns:pubsub/ns:publish', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ publish = Blather::Stanza::PubSub::Publish.new
29
+ publish.type.must_equal :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.must_equal 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.must_equal '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.must_be_instance_of Blather::Stanza::PubSub::PubSubItem
47
+ count += 1
48
+ end
49
+ count.must_equal 1
50
+ end
51
+
52
+ it 'has a node attribute' do
53
+ publish = Blather::Stanza::PubSub::Publish.new
54
+ publish.must_respond_to :node
55
+ publish.node.must_be_nil
56
+ publish.node = 'node-name'
57
+ publish.node.must_equal 'node-name'
58
+ publish.xpath('//ns:publish[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_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.must_equal 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).wont_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.must_equal 2
74
+ publish.xpath('/iq/ns:pubsub/ns:publish[ns:item[.="payload1"] and ns:item[.="payload2"]]', :ns => Blather::Stanza::PubSub.registered_ns).wont_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.must_equal 1
81
+ publish.xpath('/iq/ns:pubsub/ns:publish[ns:item[.="payload"]]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
82
+ end
83
+ end
@@ -0,0 +1,75 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. 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').must_equal Blather::Stanza::PubSub::Retract
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(retract_xml).root).must_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).wont_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).must_be_empty
22
+
23
+ retract.retract.wont_be_nil
24
+ retract.find('//ns:pubsub/ns:retract', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ retract = Blather::Stanza::PubSub::Retract.new
29
+ retract.type.must_equal :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.must_equal 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.must_equal '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).wont_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).wont_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.must_equal 1
57
+ retract.size.must_equal retract.retractions.size
58
+ retract.retractions.must_equal %w[ae890ac52d0df67ed7cfdf51b644e901]
59
+ end
60
+
61
+ it 'has a node attribute' do
62
+ retract = Blather::Stanza::PubSub::Retract.new
63
+ retract.must_respond_to :node
64
+ retract.node.must_be_nil
65
+ retract.node = 'node-name'
66
+ retract.node.must_equal 'node-name'
67
+ retract.xpath('//ns:retract[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
68
+ end
69
+
70
+ it 'will iterate over each retraction' do
71
+ Blather::XMPPNode.import(parse_stanza(retract_xml).root).each do |i|
72
+ i.must_include %w[ae890ac52d0df67ed7cfdf51b644e901]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSub::Subscribe do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:subscribe, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub::Subscribe
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(subscribe_xml).root).must_be_instance_of Blather::Stanza::PubSub::Subscribe
11
+ end
12
+
13
+ it 'ensures an subscribe node is present on create' do
14
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node', 'jid'
15
+ subscribe.find('//ns:pubsub/ns:subscribe', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
16
+ end
17
+
18
+ it 'ensures an subscribe node exists when calling #subscribe' do
19
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node', 'jid'
20
+ subscribe.pubsub.remove_children :subscribe
21
+ subscribe.find('//ns:pubsub/ns:subscribe', :ns => Blather::Stanza::PubSub.registered_ns).must_be_empty
22
+
23
+ subscribe.subscribe.wont_be_nil
24
+ subscribe.find('//ns:pubsub/ns:subscribe', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node', 'jid'
29
+ subscribe.type.must_equal :set
30
+ end
31
+
32
+ it 'sets the host if requested' do
33
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'pubsub.jabber.local', 'node', 'jid'
34
+ subscribe.to.must_equal Blather::JID.new('pubsub.jabber.local')
35
+ end
36
+
37
+ it 'sets the node' do
38
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node-name', 'jid'
39
+ subscribe.node.must_equal 'node-name'
40
+ end
41
+
42
+ it 'has a node attribute' do
43
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node-name', 'jid'
44
+ subscribe.find('//ns:pubsub/ns:subscribe[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
45
+ subscribe.node.must_equal 'node-name'
46
+
47
+ subscribe.node = 'new-node'
48
+ subscribe.find('//ns:pubsub/ns:subscribe[@node="new-node"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
49
+ subscribe.node.must_equal 'new-node'
50
+ end
51
+
52
+ it 'has a jid attribute' do
53
+ subscribe = Blather::Stanza::PubSub::Subscribe.new :set, 'host', 'node-name', 'jid'
54
+ subscribe.find('//ns:pubsub/ns:subscribe[@jid="jid"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
55
+ subscribe.jid.must_equal Blather::JID.new('jid')
56
+
57
+ subscribe.jid = Blather::JID.new('n@d/r')
58
+ subscribe.find('//ns:pubsub/ns:subscribe[@jid="n@d/r"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
59
+ subscribe.jid.must_equal Blather::JID.new('n@d/r')
60
+ end
61
+ end
@@ -0,0 +1,97 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSub::Subscription do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:subscription, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub::Subscription
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(subscription_xml).root).must_be_instance_of Blather::Stanza::PubSub::Subscription
11
+ end
12
+
13
+ it 'ensures an subscription node is present on create' do
14
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node', 'jid', 'subid', :none
15
+ subscription.find('//ns:pubsub/ns:subscription', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
16
+ end
17
+
18
+ it 'ensures an subscription node exists when calling #subscription_node' do
19
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node', 'jid', 'subid', :none
20
+ subscription.pubsub.remove_children :subscription
21
+ subscription.find('//ns:pubsub/ns:subscription', :ns => Blather::Stanza::PubSub.registered_ns).must_be_empty
22
+
23
+ subscription.subscription_node.wont_be_nil
24
+ subscription.find('//ns:pubsub/ns:subscription', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node', 'jid', 'subid', :none
29
+ subscription.type.must_equal :set
30
+ end
31
+
32
+ it 'sets the host if requested' do
33
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'pubsub.jabber.local', 'node', 'jid', 'subid', :none
34
+ subscription.to.must_equal Blather::JID.new('pubsub.jabber.local')
35
+ end
36
+
37
+ it 'sets the node' do
38
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :none
39
+ subscription.node.must_equal 'node-name'
40
+ end
41
+
42
+ it 'has a node attribute' do
43
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :none
44
+ subscription.find('//ns:pubsub/ns:subscription[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
45
+ subscription.node.must_equal 'node-name'
46
+
47
+ subscription.node = 'new-node'
48
+ subscription.find('//ns:pubsub/ns:subscription[@node="new-node"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
49
+ subscription.node.must_equal 'new-node'
50
+ end
51
+
52
+ it 'has a jid attribute' do
53
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :none
54
+ subscription.find('//ns:pubsub/ns:subscription[@jid="jid"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
55
+ subscription.jid.must_equal Blather::JID.new('jid')
56
+
57
+ subscription.jid = Blather::JID.new('n@d/r')
58
+ subscription.find('//ns:pubsub/ns:subscription[@jid="n@d/r"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
59
+ subscription.jid.must_equal Blather::JID.new('n@d/r')
60
+ end
61
+
62
+ it 'has a subid attribute' do
63
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :none
64
+ subscription.find('//ns:pubsub/ns:subscription[@subid="subid"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
65
+ subscription.subid.must_equal 'subid'
66
+
67
+ subscription.subid = 'new-subid'
68
+ subscription.find('//ns:pubsub/ns:subscription[@subid="new-subid"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
69
+ subscription.subid.must_equal 'new-subid'
70
+ end
71
+
72
+ it 'has a subscription attribute' do
73
+ subscription = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :none
74
+ subscription.find('//ns:pubsub/ns:subscription[@subscription="none"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
75
+ subscription.subscription.must_equal :none
76
+
77
+ subscription.subscription = :pending
78
+ subscription.find('//ns:pubsub/ns:subscription[@subscription="pending"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
79
+ subscription.subscription.must_equal :pending
80
+ end
81
+
82
+ it 'ensures subscription is one of Stanza::PubSub::Subscription::VALID_TYPES' do
83
+ lambda { Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', :invalid_type_name }.must_raise(Blather::ArgumentError)
84
+
85
+ Blather::Stanza::PubSub::Subscription::VALID_TYPES.each do |valid_type|
86
+ n = Blather::Stanza::PubSub::Subscription.new :set, 'host', 'node-name', 'jid', 'subid', valid_type
87
+ n.subscription.must_equal valid_type
88
+ end
89
+ end
90
+
91
+ Blather::Stanza::PubSub::Subscription::VALID_TYPES.each do |valid_type|
92
+ it "provides a helper (#{valid_type}?) for type #{valid_type}" do
93
+ Blather::Stanza::PubSub::Subscription.new.must_respond_to :"#{valid_type}?"
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ def control_subscriptions
5
+ { :subscribed => [{:node => 'node1', :jid => 'francisco@denmark.lit'}, {:node => 'node2', :jid => 'francisco@denmark.lit'}],
6
+ :unconfigured => [{:node => 'node3', :jid => 'francisco@denmark.lit'}],
7
+ :pending => [{:node => 'node4', :jid => 'francisco@denmark.lit'}],
8
+ :none => [{:node => 'node5', :jid => 'francisco@denmark.lit'}] }
9
+ end
10
+
11
+ describe Blather::Stanza::PubSub::Subscriptions do
12
+ it 'registers itself' do
13
+ Blather::XMPPNode.class_from_registration(:subscriptions, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub::Subscriptions
14
+ end
15
+
16
+ it 'can be imported' do
17
+ Blather::XMPPNode.import(parse_stanza(subscriptions_xml).root).must_be_instance_of Blather::Stanza::PubSub::Subscriptions
18
+ end
19
+
20
+ it 'ensures an subscriptions node is present on create' do
21
+ subscriptions = Blather::Stanza::PubSub::Subscriptions.new
22
+ subscriptions.find('//ns:pubsub/ns:subscriptions', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
23
+ end
24
+
25
+ it 'ensures an subscriptions node exists when calling #subscriptions' do
26
+ subscriptions = Blather::Stanza::PubSub::Subscriptions.new
27
+ subscriptions.pubsub.remove_children :subscriptions
28
+ subscriptions.find('//ns:pubsub/ns:subscriptions', :ns => Blather::Stanza::PubSub.registered_ns).must_be_empty
29
+
30
+ subscriptions.subscriptions.wont_be_nil
31
+ subscriptions.find('//ns:pubsub/ns:subscriptions', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
32
+ end
33
+
34
+ it 'defaults to a get node' do
35
+ aff = Blather::Stanza::PubSub::Subscriptions.new
36
+ aff.type.must_equal :get
37
+ end
38
+
39
+ it 'sets the host if requested' do
40
+ aff = Blather::Stanza::PubSub::Subscriptions.new :get, 'pubsub.jabber.local'
41
+ aff.to.must_equal Blather::JID.new('pubsub.jabber.local')
42
+ end
43
+
44
+ it 'can import a subscriptions result node' do
45
+ node = parse_stanza(subscriptions_xml).root
46
+
47
+ subscriptions = Blather::Stanza::PubSub::Subscriptions.new.inherit node
48
+ subscriptions.size.must_equal 4
49
+ subscriptions.list.must_equal control_subscriptions
50
+ end
51
+
52
+ it 'will iterate over each subscription' do
53
+ node = parse_stanza(subscriptions_xml).root
54
+ subscriptions = Blather::Stanza::PubSub::Subscriptions.new.inherit node
55
+ subscriptions.each do |type, nodes|
56
+ nodes.must_equal control_subscriptions[type]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSub::Unsubscribe do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:unsubscribe, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub::Unsubscribe
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(unsubscribe_xml).root).must_be_instance_of Blather::Stanza::PubSub::Unsubscribe
11
+ end
12
+
13
+ it 'ensures an unsubscribe node is present on create' do
14
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node', 'jid'
15
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
16
+ end
17
+
18
+ it 'ensures an unsubscribe node exists when calling #unsubscribe' do
19
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node', 'jid'
20
+ unsubscribe.pubsub.remove_children :unsubscribe
21
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe', :ns => Blather::Stanza::PubSub.registered_ns).must_be_empty
22
+
23
+ unsubscribe.unsubscribe.wont_be_nil
24
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'defaults to a set node' do
28
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node', 'jid'
29
+ unsubscribe.type.must_equal :set
30
+ end
31
+
32
+ it 'sets the host if requested' do
33
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'pubsub.jabber.local', 'node', 'jid'
34
+ unsubscribe.to.must_equal Blather::JID.new('pubsub.jabber.local')
35
+ end
36
+
37
+ it 'sets the node' do
38
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node-name', 'jid'
39
+ unsubscribe.node.must_equal 'node-name'
40
+ end
41
+
42
+ it 'has a node attribute' do
43
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node-name', 'jid'
44
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe[@node="node-name"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
45
+ unsubscribe.node.must_equal 'node-name'
46
+
47
+ unsubscribe.node = 'new-node'
48
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe[@node="new-node"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
49
+ unsubscribe.node.must_equal 'new-node'
50
+ end
51
+
52
+ it 'has a jid attribute' do
53
+ unsubscribe = Blather::Stanza::PubSub::Unsubscribe.new :set, 'host', 'node-name', 'jid'
54
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe[@jid="jid"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
55
+ unsubscribe.jid.must_equal Blather::JID.new('jid')
56
+
57
+ unsubscribe.jid = Blather::JID.new('n@d/r')
58
+ unsubscribe.find('//ns:pubsub/ns:unsubscribe[@jid="n@d/r"]', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
59
+ unsubscribe.jid.must_equal Blather::JID.new('n@d/r')
60
+ end
61
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSubOwner::Delete do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:delete, 'http://jabber.org/protocol/pubsub#owner').must_equal Blather::Stanza::PubSubOwner::Delete
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(<<-NODE).root).must_be_instance_of Blather::Stanza::PubSubOwner::Delete
11
+ <iq type='set'
12
+ from='hamlet@denmark.lit/elsinore'
13
+ to='pubsub.shakespeare.lit'
14
+ id='delete1'>
15
+ <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
16
+ <delete node='princely_musings'/>
17
+ </pubsub>
18
+ </iq>
19
+ NODE
20
+ end
21
+
22
+ it 'ensures an delete node is present on delete' do
23
+ delete = Blather::Stanza::PubSubOwner::Delete.new
24
+ delete.find('//ns:pubsub/ns:delete', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'ensures an delete node exists when calling #delete_node' do
28
+ delete = Blather::Stanza::PubSubOwner::Delete.new
29
+ delete.pubsub.remove_children :delete
30
+ delete.find('//ns:pubsub/ns:delete', :ns => Blather::Stanza::PubSubOwner.registered_ns).must_be_empty
31
+
32
+ delete.delete_node.wont_be_nil
33
+ delete.find('//ns:pubsub/ns:delete', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
34
+ end
35
+
36
+ it 'defaults to a set node' do
37
+ delete = Blather::Stanza::PubSubOwner::Delete.new
38
+ delete.type.must_equal :set
39
+ end
40
+
41
+ it 'sets the host if requested' do
42
+ delete = Blather::Stanza::PubSubOwner::Delete.new :set, 'pubsub.jabber.local'
43
+ delete.to.must_equal Blather::JID.new('pubsub.jabber.local')
44
+ end
45
+
46
+ it 'sets the node' do
47
+ delete = Blather::Stanza::PubSubOwner::Delete.new :set, 'host', 'node-name'
48
+ delete.node.must_equal 'node-name'
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSubOwner::Purge do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:purge, 'http://jabber.org/protocol/pubsub#owner').must_equal Blather::Stanza::PubSubOwner::Purge
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(<<-NODE).root).must_be_instance_of Blather::Stanza::PubSubOwner::Purge
11
+ <iq type='set'
12
+ from='hamlet@denmark.lit/elsinore'
13
+ to='pubsub.shakespeare.lit'
14
+ id='purge1'>
15
+ <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
16
+ <purge node='princely_musings'/>
17
+ </pubsub>
18
+ </iq>
19
+ NODE
20
+ end
21
+
22
+ it 'ensures an purge node is present on create' do
23
+ purge = Blather::Stanza::PubSubOwner::Purge.new
24
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'ensures an purge node exists when calling #purge_node' do
28
+ purge = Blather::Stanza::PubSubOwner::Purge.new
29
+ purge.pubsub.remove_children :purge
30
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).must_be_empty
31
+
32
+ purge.purge_node.wont_be_nil
33
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
34
+ end
35
+
36
+ it 'defaults to a set node' do
37
+ purge = Blather::Stanza::PubSubOwner::Purge.new
38
+ purge.type.must_equal :set
39
+ end
40
+
41
+ it 'sets the host if requested' do
42
+ purge = Blather::Stanza::PubSubOwner::Purge.new :set, 'pubsub.jabber.local'
43
+ purge.to.must_equal Blather::JID.new('pubsub.jabber.local')
44
+ end
45
+
46
+ it 'sets the node' do
47
+ purge = Blather::Stanza::PubSubOwner::Purge.new :set, 'host', 'node-name'
48
+ purge.node.must_equal 'node-name'
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. fixtures pubsub])
3
+
4
+ describe Blather::Stanza::PubSubOwner do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:pubsub, 'http://jabber.org/protocol/pubsub#owner').must_equal Blather::Stanza::PubSubOwner
7
+ end
8
+
9
+ it 'ensures a pubusb node is present on create' do
10
+ pubsub = Blather::Stanza::PubSubOwner.new
11
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_nil
12
+ end
13
+
14
+ it 'ensures a pubsub node exists when calling #pubsub' do
15
+ pubsub = Blather::Stanza::PubSubOwner.new
16
+ pubsub.remove_children :pubsub
17
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).must_be_nil
18
+
19
+ pubsub.pubsub.wont_be_nil
20
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_nil
21
+ end
22
+
23
+ it 'sets the host if requested' do
24
+ aff = Blather::Stanza::PubSubOwner.new :get, 'pubsub.jabber.local'
25
+ aff.to.must_equal Blather::JID.new('pubsub.jabber.local')
26
+ end
27
+ end