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
@@ -18,9 +18,14 @@ def disco_info_xml
18
18
  XML
19
19
  end
20
20
 
21
- describe 'Blather::Stanza::Iq::DiscoInfo' do
21
+ describe Blather::Stanza::Iq::DiscoInfo do
22
22
  it 'registers itself' do
23
- XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/disco#info').must_equal Blather::Stanza::Iq::DiscoInfo
23
+ Blather::XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/disco#info').must_equal Blather::Stanza::Iq::DiscoInfo
24
+ end
25
+
26
+ it 'must be importable' do
27
+ doc = parse_stanza disco_info_xml
28
+ Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Iq::DiscoInfo
24
29
  end
25
30
 
26
31
  it 'has a node attribute' do
@@ -31,17 +36,23 @@ describe 'Blather::Stanza::Iq::DiscoInfo' do
31
36
  end
32
37
 
33
38
  it 'inherits a list of identities' do
34
- n = XML::Document.string disco_info_xml
35
- r = Stanza::Iq::DiscoInfo.new.inherit n.root
39
+ n = parse_stanza disco_info_xml
40
+ r = Blather::Stanza::Iq::DiscoInfo.new.inherit n.root
36
41
  r.identities.size.must_equal 1
37
- r.identities.map { |i| i.class }.uniq.must_equal [Stanza::Iq::DiscoInfo::Identity]
42
+ r.identities.map { |i| i.class }.uniq.must_equal [Blather::Stanza::Iq::DiscoInfo::Identity]
38
43
  end
39
44
 
40
45
  it 'inherits a list of features' do
41
- n = XML::Document.string disco_info_xml
42
- r = Stanza::Iq::DiscoInfo.new.inherit n.root
46
+ n = parse_stanza disco_info_xml
47
+ r = Blather::Stanza::Iq::DiscoInfo.new.inherit n.root
43
48
  r.features.size.must_equal 2
44
- r.features.map { |i| i.class }.uniq.must_equal [Stanza::Iq::DiscoInfo::Feature]
49
+ r.features.map { |i| i.class }.uniq.must_equal [Blather::Stanza::Iq::DiscoInfo::Feature]
50
+ end
51
+
52
+ it 'is constructed properly' do
53
+ n = Blather::Stanza::Iq::DiscoInfo.new :get, '/path/to/node'
54
+ n.to = 'to@jid.com'
55
+ n.find("/iq[@to='to@jid.com' and @type='get' and @id='#{n.id}']/ns:query[@node='/path/to/node']", :ns => Blather::Stanza::Iq::DiscoInfo.registered_ns).wont_be_empty
45
56
  end
46
57
  end
47
58
 
@@ -52,35 +63,35 @@ describe 'Blather::Stanza::Iq::DiscoInfo identities' do
52
63
  {:name => 'name1', :type => 'type1', :category => 'category1'},
53
64
  ]
54
65
 
55
- control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
56
- Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
66
+ control = [ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
67
+ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
57
68
 
58
- di = Stanza::Iq::DiscoInfo.new nil, nil, ids
69
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, ids
59
70
  di.identities.size.must_equal 2
60
71
  di.identities.each { |i| control.include?(i).must_equal true }
61
72
  end
62
73
 
63
74
  it 'takes a list of Identity objects as identities' do
64
- control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
65
- Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
75
+ control = [ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
76
+ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
66
77
 
67
- di = Stanza::Iq::DiscoInfo.new nil, nil, control
78
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, control
68
79
  di.identities.size.must_equal 2
69
80
  di.identities.each { |i| control.include?(i).must_equal true }
70
81
  end
71
82
 
72
83
  it 'takes a single hash as identity' do
73
- control = [Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
84
+ control = [Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
74
85
 
75
- di = Stanza::Iq::DiscoInfo.new nil, nil, {:name => 'name', :type => 'type', :category => 'category'}
86
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, {:name => 'name', :type => 'type', :category => 'category'}
76
87
  di.identities.size.must_equal 1
77
88
  di.identities.each { |i| control.include?(i).must_equal true }
78
89
  end
79
90
 
80
91
  it 'takes a single identity object as identity' do
81
- control = [Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
92
+ control = [Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category])]
82
93
 
83
- di = Stanza::Iq::DiscoInfo.new nil, nil, control.first
94
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, control.first
84
95
  di.identities.size.must_equal 1
85
96
  di.identities.each { |i| control.include?(i).must_equal true }
86
97
  end
@@ -88,13 +99,13 @@ describe 'Blather::Stanza::Iq::DiscoInfo identities' do
88
99
  it 'takes a mix of hashes and identity objects as identities' do
89
100
  ids = [
90
101
  {:name => 'name', :type => 'type', :category => 'category'},
91
- Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1]),
102
+ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1]),
92
103
  ]
93
104
 
94
- control = [ Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
95
- Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
105
+ control = [ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type category]),
106
+ Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name1 type1 category1])]
96
107
 
97
- di = Stanza::Iq::DiscoInfo.new nil, nil, ids
108
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, ids
98
109
  di.identities.size.must_equal 2
99
110
  di.identities.each { |i| control.include?(i).must_equal true }
100
111
  end
@@ -103,53 +114,53 @@ end
103
114
  describe 'Blather::Stanza::Iq::DiscoInfo features' do
104
115
  it 'takes a list of features as strings' do
105
116
  features = %w[feature1 feature2 feature3]
106
- control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
117
+ control = features.map { |f| Blather::Stanza::Iq::DiscoInfo::Feature.new f }
107
118
 
108
- di = Stanza::Iq::DiscoInfo.new nil, nil, [], features
119
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, [], features
109
120
  di.features.size.must_equal 3
110
121
  di.features.each { |f| control.include?(f).must_equal true }
111
122
  end
112
123
 
113
124
  it 'takes a list of features as Feature objects' do
114
125
  features = %w[feature1 feature2 feature3]
115
- control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
126
+ control = features.map { |f| Blather::Stanza::Iq::DiscoInfo::Feature.new f }
116
127
 
117
- di = Stanza::Iq::DiscoInfo.new nil, nil, [], control
128
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, [], control
118
129
  di.features.size.must_equal 3
119
130
  di.features.each { |f| control.include?(f).must_equal true }
120
131
  end
121
132
 
122
133
  it 'takes a single string' do
123
- control = [Stanza::Iq::DiscoInfo::Feature.new('feature1')]
134
+ control = [Blather::Stanza::Iq::DiscoInfo::Feature.new('feature1')]
124
135
 
125
- di = Stanza::Iq::DiscoInfo.new nil, nil, [], 'feature1'
136
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, [], 'feature1'
126
137
  di.features.size.must_equal 1
127
138
  di.features.each { |f| control.include?(f).must_equal true }
128
139
  end
129
140
 
130
141
  it 'takes a single Feature object' do
131
- control = [Stanza::Iq::DiscoInfo::Feature.new('feature1')]
142
+ control = [Blather::Stanza::Iq::DiscoInfo::Feature.new('feature1')]
132
143
 
133
- di = Stanza::Iq::DiscoInfo.new nil, nil, [], control.first
144
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, [], control.first
134
145
  di.features.size.must_equal 1
135
146
  di.features.each { |f| control.include?(f).must_equal true }
136
147
  end
137
148
 
138
149
  it 'takes a mixed list of features as Feature objects and strings' do
139
150
  features = %w[feature1 feature2 feature3]
140
- control = features.map { |f| Stanza::Iq::DiscoInfo::Feature.new f }
151
+ control = features.map { |f| Blather::Stanza::Iq::DiscoInfo::Feature.new f }
141
152
  features[1] = control[1]
142
153
 
143
- di = Stanza::Iq::DiscoInfo.new nil, nil, [], features
154
+ di = Blather::Stanza::Iq::DiscoInfo.new nil, nil, [], features
144
155
  di.features.size.must_equal 3
145
156
  di.features.each { |f| control.include?(f).must_equal true }
146
157
  end
147
158
  end
148
159
 
149
- describe 'Blather::Stanza::Iq::DiscoInfo::Identity' do
160
+ describe Blather::Stanza::Iq::DiscoInfo::Identity do
150
161
  it 'will auto-inherit nodes' do
151
- n = XML::Document.string "<identity name='Personal Events' type='pep' category='pubsub' node='publish' />"
152
- i = Stanza::Iq::DiscoInfo::Identity.new n.root
162
+ n = parse_stanza "<identity name='Personal Events' type='pep' category='pubsub' node='publish' />"
163
+ i = Blather::Stanza::Iq::DiscoInfo::Identity.new n.root
153
164
  i.name.must_equal 'Personal Events'
154
165
  i.type.must_equal :pep
155
166
  i.category.must_equal :pubsub
@@ -176,18 +187,22 @@ describe 'Blather::Stanza::Iq::DiscoInfo::Identity' do
176
187
  n.name.must_equal 'foo'
177
188
  end
178
189
 
190
+ it 'raises an error if equality is sent a non DiscoInfo::Identity object' do
191
+ a = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
192
+ lambda { a == 'foo' }.must_raise RuntimeError
193
+ end
194
+
179
195
  it 'can determine equality' do
180
196
  a = Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
181
- a.must_respond_to :eql?
182
197
  a.must_equal Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[name type cat])
183
- a.wont_equal "<identity name='Personal Events' type='pep' category='pubsub' node='publish' />"
198
+ a.wont_equal Blather::Stanza::Iq::DiscoInfo::Identity.new(*%w[not-name not-type not-cat])
184
199
  end
185
200
  end
186
201
 
187
- describe 'Blather::Stanza::Iq::DiscoInfo::Feature' do
202
+ describe Blather::Stanza::Iq::DiscoInfo::Feature do
188
203
  it 'will auto-inherit nodes' do
189
- n = XML::Document.string "<feature var='ipv6' />"
190
- i = Stanza::Iq::DiscoInfo::Feature.new n.root
204
+ n = parse_stanza "<feature var='ipv6' />"
205
+ i = Blather::Stanza::Iq::DiscoInfo::Feature.new n.root
191
206
  i.var.must_equal 'ipv6'
192
207
  end
193
208
 
@@ -198,10 +213,14 @@ describe 'Blather::Stanza::Iq::DiscoInfo::Feature' do
198
213
  n.var.must_equal 'foo'
199
214
  end
200
215
 
216
+ it 'raises an error if equality is sent a non DiscoInfo::Feature object' do
217
+ a = Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
218
+ lambda { a == 'foo' }.must_raise RuntimeError
219
+ end
220
+
201
221
  it 'can determine equality' do
202
222
  a = Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
203
- a.must_respond_to :eql?
204
223
  a.must_equal Blather::Stanza::Iq::DiscoInfo::Feature.new('var')
205
- a.wont_equal "<feature var='ipv6' />"
224
+ a.wont_equal Blather::Stanza::Iq::DiscoInfo::Feature.new('not-var')
206
225
  end
207
226
  end
@@ -21,9 +21,19 @@ def disco_items_xml
21
21
  XML
22
22
  end
23
23
 
24
- describe 'Blather::Stanza::Iq::DiscoItems' do
24
+ describe Blather::Stanza::Iq::DiscoItems do
25
25
  it 'registers itself' do
26
- XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/disco#items').must_equal Blather::Stanza::Iq::DiscoItems
26
+ Blather::XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/disco#items').must_equal Blather::Stanza::Iq::DiscoItems
27
+ end
28
+
29
+ it 'must be importable' do
30
+ Blather::XMPPNode.import(parse_stanza(disco_items_xml).root).must_be_instance_of Blather::Stanza::Iq::DiscoItems
31
+ end
32
+
33
+ it 'is constructed properly' do
34
+ n = Blather::Stanza::Iq::DiscoItems.new :get, '/path/to/node'
35
+ n.to = 'to@jid.com'
36
+ n.find("/iq[@to='to@jid.com' and @type='get' and @id='#{n.id}']/ns:query[@node='/path/to/node']", :ns => Blather::Stanza::Iq::DiscoItems.registered_ns).wont_be_empty
27
37
  end
28
38
 
29
39
  it 'has a node attribute' do
@@ -34,49 +44,47 @@ describe 'Blather::Stanza::Iq::DiscoItems' do
34
44
  end
35
45
 
36
46
  it 'inherits a list of identities' do
37
- n = XML::Document.string disco_items_xml
38
- r = Stanza::Iq::DiscoItems.new.inherit n.root
47
+ n = parse_stanza disco_items_xml
48
+ r = Blather::Stanza::Iq::DiscoItems.new.inherit n.root
39
49
  r.items.size.must_equal 3
40
- r.items.map { |i| i.class }.uniq.must_equal [Stanza::Iq::DiscoItems::Item]
50
+ r.items.map { |i| i.class }.uniq.must_equal [Blather::Stanza::Iq::DiscoItems::Item]
41
51
  end
42
- end
43
52
 
44
- describe 'Blather::Stanza::Iq::DiscoItems items' do
45
53
  it 'takes a list of hashes for items' do
46
54
  items = [
47
55
  {:jid => 'foo@bar/baz', :node => 'node', :name => 'name'},
48
56
  {:jid => 'baz@foo/bar', :node => 'node1', :name => 'name1'},
49
57
  ]
50
58
 
51
- control = [ Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
52
- Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
59
+ control = [ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
60
+ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
53
61
 
54
- di = Stanza::Iq::DiscoItems.new nil, nil, items
62
+ di = Blather::Stanza::Iq::DiscoItems.new nil, nil, items
55
63
  di.items.size.must_equal 2
56
64
  di.items.each { |i| control.include?(i).must_equal true }
57
65
  end
58
66
 
59
67
  it 'takes a list of Item objects as items' do
60
- control = [ Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
61
- Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
68
+ control = [ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
69
+ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
62
70
 
63
- di = Stanza::Iq::DiscoItems.new nil, nil, control
71
+ di = Blather::Stanza::Iq::DiscoItems.new nil, nil, control
64
72
  di.items.size.must_equal 2
65
73
  di.items.each { |i| control.include?(i).must_equal true }
66
74
  end
67
75
 
68
76
  it 'takes a single hash as identity' do
69
- control = [Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name])]
77
+ control = [Blather::Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name])]
70
78
 
71
- di = Stanza::Iq::DiscoItems.new nil, nil, {:jid => 'foo@bar/baz', :node => 'node', :name => 'name'}
79
+ di = Blather::Stanza::Iq::DiscoItems.new nil, nil, {:jid => 'foo@bar/baz', :node => 'node', :name => 'name'}
72
80
  di.items.size.must_equal 1
73
81
  di.items.each { |i| control.include?(i).must_equal true }
74
82
  end
75
83
 
76
84
  it 'takes a single identity object as identity' do
77
- control = [Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name])]
85
+ control = [Blather::Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name])]
78
86
 
79
- di = Stanza::Iq::DiscoItems.new nil, nil, control.first
87
+ di = Blather::Stanza::Iq::DiscoItems.new nil, nil, control.first
80
88
  di.items.size.must_equal 1
81
89
  di.items.each { |i| control.include?(i).must_equal true }
82
90
  end
@@ -84,53 +92,57 @@ describe 'Blather::Stanza::Iq::DiscoItems items' do
84
92
  it 'takes a mix of hashes and identity objects as items' do
85
93
  items = [
86
94
  {:jid => 'foo@bar/baz', :node => 'node', :name => 'name'},
87
- Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1]),
95
+ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1]),
88
96
  ]
89
97
 
90
- control = [ Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
91
- Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
98
+ control = [ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[foo@bar/baz node name]),
99
+ Blather::Stanza::Iq::DiscoItems::Item.new(*%w[baz@foo/bar node1 name1])]
92
100
 
93
- di = Stanza::Iq::DiscoItems.new nil, nil, items
101
+ di = Blather::Stanza::Iq::DiscoItems.new nil, nil, items
94
102
  di.items.size.must_equal 2
95
103
  di.items.each { |i| control.include?(i).must_equal true }
96
104
  end
97
105
  end
98
106
 
99
- describe 'Blather::Stanza::Iq::DiscoItems::Item' do
107
+ describe Blather::Stanza::Iq::DiscoItems::Item do
100
108
  it 'will auto-inherit nodes' do
101
- n = XML::Document.string "<item jid='foo@bar/baz' node='music' name='Music from the time of Shakespeare' />"
102
- i = Stanza::Iq::DiscoItems::Item.new n.root
103
- i.jid.must_equal JID.new('foo@bar/baz')
109
+ n = parse_stanza "<item jid='foo@bar/baz' node='music' name='Music from the time of Shakespeare' />"
110
+ i = Blather::Stanza::Iq::DiscoItems::Item.new n.root
111
+ i.jid.must_equal Blather::JID.new('foo@bar/baz')
104
112
  i.node.must_equal 'music'
105
113
  i.name.must_equal 'Music from the time of Shakespeare'
106
114
  end
107
115
 
108
116
  it 'has a jid attribute' do
109
- n = Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz'
110
- n.jid.must_be_kind_of JID
111
- n.jid.must_equal JID.new('foo@bar/baz')
117
+ n = Blather::Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz'
118
+ n.jid.must_be_kind_of Blather::JID
119
+ n.jid.must_equal Blather::JID.new('foo@bar/baz')
112
120
  n.jid = 'baz@foo/bar'
113
- n.jid.must_equal JID.new('baz@foo/bar')
121
+ n.jid.must_equal Blather::JID.new('baz@foo/bar')
114
122
  end
115
123
 
116
124
  it 'has a node attribute' do
117
- n = Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz', 'music'
125
+ n = Blather::Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz', 'music'
118
126
  n.node.must_equal 'music'
119
127
  n.node = 'book'
120
128
  n.node.must_equal 'book'
121
129
  end
122
130
 
123
131
  it 'has a name attribute' do
124
- n = Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz', nil, 'Music from the time of Shakespeare'
132
+ n = Blather::Stanza::Iq::DiscoItems::Item.new 'foo@bar/baz', nil, 'Music from the time of Shakespeare'
125
133
  n.name.must_equal 'Music from the time of Shakespeare'
126
134
  n.name = 'Books by and about Shakespeare'
127
135
  n.name.must_equal 'Books by and about Shakespeare'
128
136
  end
129
137
 
138
+ it 'raises an error when compared against a non DiscoItems::Item' do
139
+ a = Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
140
+ lambda { a == 'test' }.must_raise RuntimeError
141
+ end
142
+
130
143
  it 'can determine equality' do
131
- a = Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
132
- a.must_respond_to :eql?
133
- a.must_equal Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
134
- a.wont_equal "<item jid='foo@bar/baz' node='music' name='Music from the time of Shakespeare' />"
144
+ a = Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
145
+ a.must_equal Blather::Stanza::Iq::DiscoItems::Item.new('foo@bar/baz')
146
+ a.wont_equal Blather::Stanza::Iq::DiscoItems::Item.new('not-foo@bar/baz')
135
147
  end
136
148
  end
@@ -1,41 +1,64 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
2
2
 
3
- describe 'Blather::Stanza::Iq::Query' do
3
+ describe Blather::Stanza::Iq::Query do
4
4
  it 'registers itself' do
5
- XMPPNode.class_from_registration(:query, nil).must_equal Stanza::Iq::Query
5
+ Blather::XMPPNode.class_from_registration(:query, nil).must_equal Blather::Stanza::Iq::Query
6
+ end
7
+
8
+ it 'can be imported' do
9
+ doc = parse_stanza <<-XML
10
+ <iq from='juliet@example.com/balcony' type='set' id='roster_4'>
11
+ <query>
12
+ <item jid='nurse@example.com' subscription='remove'/>
13
+ </query>
14
+ </iq>
15
+ XML
16
+ Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Iq::Query
6
17
  end
7
18
 
8
19
  it 'ensures a query node is present on create' do
9
- query = Stanza::Iq::Query.new
10
- query.children.detect { |n| n.element_name == 'query' }.wont_be_nil
20
+ query = Blather::Stanza::Iq::Query.new
21
+ query.xpath('query').wont_be_empty
11
22
  end
12
23
 
13
24
  it 'ensures a query node exists when calling #query' do
14
- query = Stanza::Iq::Query.new
25
+ query = Blather::Stanza::Iq::Query.new
15
26
  query.remove_child :query
16
- query.children.detect { |n| n.element_name == 'query' }.must_be_nil
27
+ query.xpath('query').must_be_empty
17
28
 
18
29
  query.query.wont_be_nil
19
- query.children.detect { |n| n.element_name == 'query' }.wont_be_nil
30
+ query.xpath('query').wont_be_empty
20
31
  end
21
32
 
22
33
  [:get, :set, :result, :error].each do |type|
23
34
  it "can be set as \"#{type}\"" do
24
- query = Stanza::Iq::Query.new type
35
+ query = Blather::Stanza::Iq::Query.new type
25
36
  query.type.must_equal type
26
37
  end
27
38
  end
28
39
 
29
40
  it 'sets type to "result" on reply' do
30
- query = Stanza::Iq::Query.new
41
+ query = Blather::Stanza::Iq::Query.new
31
42
  query.type.must_equal :get
32
43
  reply = query.reply.type.must_equal :result
33
44
  end
34
45
 
35
46
  it 'sets type to "result" on reply!' do
36
- query = Stanza::Iq::Query.new
47
+ query = Blather::Stanza::Iq::Query.new
37
48
  query.type.must_equal :get
38
49
  query.reply!
39
50
  query.type.must_equal :result
40
51
  end
41
- end
52
+
53
+ it 'can be registered under a namespace' do
54
+ class QueryNs < Blather::Stanza::Iq::Query; register :query_ns, nil, 'query:ns'; end
55
+ Blather::XMPPNode.class_from_registration(:query, 'query:ns').must_equal QueryNs
56
+ query_ns = QueryNs.new
57
+ query_ns.xpath('query').must_be_empty
58
+ query_ns.xpath('ns:query', :ns => 'query:ns').size.must_equal 1
59
+
60
+ query_ns.query
61
+ query_ns.query
62
+ query_ns.xpath('ns:query', :ns => 'query:ns').size.must_equal 1
63
+ end
64
+ end
@@ -24,59 +24,76 @@ def roster_xml
24
24
  XML
25
25
  end
26
26
 
27
- describe 'Blather::Stanza::Iq::Roster' do
27
+ describe Blather::Stanza::Iq::Roster do
28
28
  it 'registers itself' do
29
- XMPPNode.class_from_registration(:query, 'jabber:iq:roster').must_equal Stanza::Iq::Roster
29
+ Blather::XMPPNode.class_from_registration(:query, 'jabber:iq:roster').must_equal Blather::Stanza::Iq::Roster
30
30
  end
31
31
 
32
32
  it 'ensures newly inherited items are RosterItem objects' do
33
- n = XML::Document.string roster_xml
34
- r = Stanza::Iq::Roster.new.inherit n.root
35
- r.items.map { |i| i.class }.uniq.must_equal [Stanza::Iq::Roster::RosterItem]
33
+ n = parse_stanza roster_xml
34
+ r = Blather::Stanza::Iq::Roster.new.inherit n.root
35
+ r.items.map { |i| i.class }.uniq.must_equal [Blather::Stanza::Iq::Roster::RosterItem]
36
+ end
37
+
38
+ it 'can be created with #import' do
39
+ doc = parse_stanza roster_xml
40
+ Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Iq::Roster
36
41
  end
37
42
  end
38
43
 
39
- describe 'Blather::Stanza::Iq::Roster::RosterItem' do
40
- it 'can be initialized with just a JID' do
41
- i = Stanza::Iq::Roster::RosterItem.new 'n@d/r'
42
- i.jid.must_equal JID.new('n@d/r')
44
+ describe Blather::Stanza::Iq::Roster::RosterItem do
45
+ it 'can be initialized with just a Blather::JID' do
46
+ i = Blather::Stanza::Iq::Roster::RosterItem.new 'n@d/r'
47
+ i.jid.must_equal Blather::JID.new('n@d/r')
43
48
  end
44
49
 
45
50
  it 'can be initialized with a name' do
46
- i = Stanza::Iq::Roster::RosterItem.new nil, 'foobar'
51
+ i = Blather::Stanza::Iq::Roster::RosterItem.new nil, 'foobar'
47
52
  i.name.must_equal 'foobar'
48
53
  end
49
54
 
50
55
  it 'can be initialized with a subscription' do
51
- i = Stanza::Iq::Roster::RosterItem.new nil, nil, :both
56
+ i = Blather::Stanza::Iq::Roster::RosterItem.new nil, nil, :both
52
57
  i.subscription.must_equal :both
53
58
  end
54
59
 
55
60
  it 'can be initialized with ask (subscription sub-type)' do
56
- i = Stanza::Iq::Roster::RosterItem.new nil, nil, nil, :subscribe
61
+ i = Blather::Stanza::Iq::Roster::RosterItem.new nil, nil, nil, :subscribe
57
62
  i.ask.must_equal :subscribe
58
63
  end
59
64
 
65
+ it 'can be initailized with a hash' do
66
+ control = { :jid => 'j@d/r',
67
+ :name => 'name',
68
+ :subscription => :both,
69
+ :ask => :subscribe }
70
+ i = Blather::Stanza::Iq::Roster::RosterItem.new control
71
+ i.jid.must_equal Blather::JID.new(control[:jid])
72
+ i.name.must_equal control[:name]
73
+ i.subscription.must_equal control[:subscription]
74
+ i.ask.must_equal control[:ask]
75
+ end
76
+
60
77
  it 'inherits a node when initialized with one' do
61
- n = XMPPNode.new 'item'
62
- n['jid'] = 'n@d/r'
63
- n['subscription'] = 'both'
78
+ n = Blather::XMPPNode.new 'item'
79
+ n[:jid] = 'n@d/r'
80
+ n[:subscription] = 'both'
64
81
 
65
- i = Stanza::Iq::Roster::RosterItem.new n
66
- i.jid.must_equal JID.new('n@d/r')
82
+ i = Blather::Stanza::Iq::Roster::RosterItem.new n
83
+ i.jid.must_equal Blather::JID.new('n@d/r')
67
84
  i.subscription.must_equal :both
68
85
  end
69
86
 
70
87
  it 'has a #groups helper that gives an array of groups' do
71
- n = XML::Document.string "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
72
- i = Stanza::Iq::Roster::RosterItem.new n.root
88
+ n = parse_stanza "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
89
+ i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
73
90
  i.must_respond_to :groups
74
91
  i.groups.sort.must_equal %w[bar baz foo]
75
92
  end
76
93
 
77
94
  it 'has a helper to set the groups' do
78
- n = XML::Document.string "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
79
- i = Stanza::Iq::Roster::RosterItem.new n.root
95
+ n = parse_stanza "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
96
+ i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
80
97
  i.must_respond_to :groups=
81
98
  i.groups.sort.must_equal %w[bar baz foo]
82
99
  i.groups = %w[a b c]
@@ -85,38 +102,38 @@ describe 'Blather::Stanza::Iq::Roster::RosterItem' do
85
102
 
86
103
  it 'can be easily converted into a proper stanza' do
87
104
  xml = "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
88
- n = XML::Document.string xml
89
- i = Stanza::Iq::Roster::RosterItem.new n.root
105
+ n = parse_stanza xml
106
+ i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
90
107
  i.must_respond_to :to_stanza
91
108
  s = i.to_stanza
92
- s.must_be_kind_of Stanza::Iq::Roster
93
- s.items.first.jid.must_equal JID.new('romeo@example.net')
109
+ s.must_be_kind_of Blather::Stanza::Iq::Roster
110
+ s.items.first.jid.must_equal Blather::JID.new('romeo@example.net')
94
111
  s.items.first.groups.sort.must_equal %w[bar baz foo]
95
112
  end
96
113
 
97
114
  it 'has an "attr_accessor" for jid' do
98
- i = Stanza::Iq::Roster::RosterItem.new
115
+ i = Blather::Stanza::Iq::Roster::RosterItem.new
99
116
  i.must_respond_to :jid
100
117
  i.jid.must_be_nil
101
118
  i.must_respond_to :jid=
102
119
  i.jid = 'n@d/r'
103
- i.jid.must_equal JID.new('n@d/r')
120
+ i.jid.must_equal Blather::JID.new('n@d/r')
104
121
  end
105
122
 
106
123
  it 'has a name attribute' do
107
- i = Stanza::Iq::Roster::RosterItem.new
124
+ i = Blather::Stanza::Iq::Roster::RosterItem.new
108
125
  i.name = 'name'
109
126
  i.name.must_equal 'name'
110
127
  end
111
128
 
112
129
  it 'has a subscription attribute' do
113
- i = Stanza::Iq::Roster::RosterItem.new
130
+ i = Blather::Stanza::Iq::Roster::RosterItem.new
114
131
  i.subscription = :both
115
132
  i.subscription.must_equal :both
116
133
  end
117
134
 
118
135
  it 'has an ask attribute' do
119
- i = Stanza::Iq::Roster::RosterItem.new
136
+ i = Blather::Stanza::Iq::Roster::RosterItem.new
120
137
  i.ask = :subscribe
121
138
  i.ask.must_equal :subscribe
122
139
  end