sprsquish-blather 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +41 -12
  3. data/examples/echo.rb +1 -1
  4. data/examples/execute.rb +0 -5
  5. data/examples/pubsub/cli.rb +64 -0
  6. data/examples/pubsub/ping_pong.rb +18 -0
  7. data/examples/rosterprint.rb +14 -0
  8. data/examples/xmpp4r/echo.rb +35 -0
  9. data/lib/blather/client/client.rb +19 -13
  10. data/lib/blather/client/dsl/pubsub.rb +133 -0
  11. data/lib/blather/client/dsl.rb +16 -0
  12. data/lib/blather/client.rb +1 -1
  13. data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
  14. data/lib/blather/core_ext/active_support.rb +1 -117
  15. data/lib/blather/core_ext/nokogiri.rb +35 -0
  16. data/lib/blather/errors/sasl_error.rb +3 -1
  17. data/lib/blather/errors/stanza_error.rb +10 -17
  18. data/lib/blather/errors/stream_error.rb +11 -14
  19. data/lib/blather/errors.rb +3 -20
  20. data/lib/blather/jid.rb +1 -0
  21. data/lib/blather/roster.rb +9 -0
  22. data/lib/blather/roster_item.rb +6 -1
  23. data/lib/blather/stanza/disco/disco_info.rb +45 -33
  24. data/lib/blather/stanza/disco/disco_items.rb +32 -21
  25. data/lib/blather/stanza/disco.rb +7 -1
  26. data/lib/blather/stanza/iq/query.rb +16 -8
  27. data/lib/blather/stanza/iq/roster.rb +33 -22
  28. data/lib/blather/stanza/iq.rb +13 -8
  29. data/lib/blather/stanza/message.rb +20 -31
  30. data/lib/blather/stanza/presence/status.rb +13 -21
  31. data/lib/blather/stanza/presence/subscription.rb +11 -16
  32. data/lib/blather/stanza/presence.rb +3 -5
  33. data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
  34. data/lib/blather/stanza/pubsub/create.rb +43 -0
  35. data/lib/blather/stanza/pubsub/errors.rb +9 -0
  36. data/lib/blather/stanza/pubsub/event.rb +77 -0
  37. data/lib/blather/stanza/pubsub/items.rb +63 -0
  38. data/lib/blather/stanza/pubsub/publish.rb +58 -0
  39. data/lib/blather/stanza/pubsub/retract.rb +53 -0
  40. data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
  41. data/lib/blather/stanza/pubsub/subscription.rb +66 -0
  42. data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
  43. data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
  44. data/lib/blather/stanza/pubsub.rb +63 -0
  45. data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
  46. data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
  47. data/lib/blather/stanza/pubsub_owner.rb +41 -0
  48. data/lib/blather/stanza.rb +35 -18
  49. data/lib/blather/stream/client.rb +1 -2
  50. data/lib/blather/stream/component.rb +9 -5
  51. data/lib/blather/stream/features/resource.rb +63 -0
  52. data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
  53. data/lib/blather/stream/features/session.rb +44 -0
  54. data/lib/blather/stream/features/tls.rb +28 -0
  55. data/lib/blather/stream/features.rb +53 -0
  56. data/lib/blather/stream/parser.rb +70 -46
  57. data/lib/blather/stream.rb +76 -168
  58. data/lib/blather/xmpp_node.rb +113 -52
  59. data/lib/blather.rb +35 -12
  60. data/spec/blather/client/client_spec.rb +44 -58
  61. data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
  62. data/spec/blather/client/dsl_spec.rb +19 -6
  63. data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
  64. data/spec/blather/errors/sasl_error_spec.rb +8 -8
  65. data/spec/blather/errors/stanza_error_spec.rb +25 -33
  66. data/spec/blather/errors/stream_error_spec.rb +21 -16
  67. data/spec/blather/errors_spec.rb +4 -11
  68. data/spec/blather/jid_spec.rb +31 -30
  69. data/spec/blather/roster_item_spec.rb +34 -23
  70. data/spec/blather/roster_spec.rb +27 -12
  71. data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
  72. data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
  73. data/spec/blather/stanza/iq/query_spec.rb +34 -11
  74. data/spec/blather/stanza/iq/roster_spec.rb +47 -30
  75. data/spec/blather/stanza/iq_spec.rb +19 -14
  76. data/spec/blather/stanza/message_spec.rb +30 -17
  77. data/spec/blather/stanza/presence/status_spec.rb +43 -20
  78. data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
  79. data/spec/blather/stanza/presence_spec.rb +34 -21
  80. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  81. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  82. data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
  83. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  84. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  85. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  86. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  87. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  88. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  89. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
  90. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  91. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  92. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  93. data/spec/blather/stanza/pubsub_spec.rb +62 -0
  94. data/spec/blather/stanza_spec.rb +53 -38
  95. data/spec/blather/stream/client_spec.rb +231 -88
  96. data/spec/blather/stream/component_spec.rb +14 -5
  97. data/spec/blather/stream/parser_spec.rb +145 -0
  98. data/spec/blather/xmpp_node_spec.rb +192 -96
  99. data/spec/fixtures/pubsub.rb +311 -0
  100. data/spec/spec_helper.rb +5 -4
  101. metadata +53 -17
  102. data/Rakefile +0 -139
  103. data/ext/extconf.rb +0 -65
  104. data/ext/push_parser.c +0 -209
  105. data/lib/blather/core_ext/libxml.rb +0 -28
  106. data/lib/blather/stream/resource.rb +0 -48
  107. data/lib/blather/stream/session.rb +0 -36
  108. data/lib/blather/stream/stream_handler.rb +0 -39
  109. data/lib/blather/stream/tls.rb +0 -33
  110. data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -0,0 +1,84 @@
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::Event do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:event, 'http://jabber.org/protocol/pubsub#event').must_equal Blather::Stanza::PubSub::Event
7
+ end
8
+
9
+ it 'is importable' do
10
+ Blather::XMPPNode.import(parse_stanza(event_notification_xml).root).must_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).wont_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"]').must_be_empty
22
+
23
+ evt.event_node.wont_be_nil
24
+ evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).wont_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"]').must_be_empty
31
+
32
+ evt.items_node.wont_be_nil
33
+ evt.find('ns:event/ns:items', :ns => Blather::Stanza::PubSub::Event.registered_ns).wont_be_empty
34
+ end
35
+
36
+ it 'knows the associated node name' do
37
+ evt = Blather::XMPPNode.import(parse_stanza(event_with_payload_xml).root)
38
+ evt.node.must_equal 'princely_musings'
39
+ end
40
+
41
+ it 'ensures newly inherited items are PubSubItem objects' do
42
+ evt = Blather::XMPPNode.import(parse_stanza(event_with_payload_xml).root)
43
+ evt.items?.must_equal true
44
+ evt.retractions?.must_equal false
45
+ evt.items.map { |i| i.class }.uniq.must_equal [Blather::Stanza::PubSub::PubSubItem]
46
+ end
47
+
48
+ it 'will iterate over each item' do
49
+ evt = Blather::XMPPNode.import(parse_stanza(event_with_payload_xml).root)
50
+ evt.items.each { |i| i.class.must_equal Blather::Stanza::PubSub::PubSubItem }
51
+ end
52
+
53
+ it 'handles receiving subscription ids' do
54
+ evt = Blather::XMPPNode.import(parse_stanza(event_subids_xml).root)
55
+ evt.subscription_ids.must_equal ['123-abc', '004-yyy']
56
+ end
57
+
58
+ it 'can have a list of retractions' do
59
+ evt = Blather::XMPPNode.import(parse_stanza(<<-NODE).root)
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?.must_equal true
69
+ evt.items?.must_equal false
70
+ evt.retractions.must_equal %w[ae890ac52d0df67ed7cfdf51b644e901]
71
+ end
72
+
73
+ it 'can be a purge' do
74
+ evt = Blather::XMPPNode.import(parse_stanza(<<-NODE).root)
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?.wont_be_nil
82
+ evt.node.must_equal 'princely_musings'
83
+ end
84
+ end
@@ -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