blather 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +41 -12
- data/examples/echo.rb +1 -1
- data/examples/execute.rb +0 -5
- data/examples/pubsub/cli.rb +64 -0
- data/examples/pubsub/ping_pong.rb +18 -0
- data/examples/rosterprint.rb +14 -0
- data/examples/xmpp4r/echo.rb +35 -0
- data/lib/blather.rb +35 -12
- data/lib/blather/client.rb +1 -1
- data/lib/blather/client/client.rb +19 -13
- data/lib/blather/client/dsl.rb +16 -0
- data/lib/blather/client/dsl/pubsub.rb +133 -0
- data/lib/blather/core_ext/active_support.rb +1 -117
- data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
- data/lib/blather/core_ext/nokogiri.rb +35 -0
- data/lib/blather/errors.rb +3 -20
- data/lib/blather/errors/sasl_error.rb +3 -1
- data/lib/blather/errors/stanza_error.rb +10 -17
- data/lib/blather/errors/stream_error.rb +11 -14
- data/lib/blather/jid.rb +1 -0
- data/lib/blather/roster.rb +9 -0
- data/lib/blather/roster_item.rb +6 -1
- data/lib/blather/stanza.rb +35 -18
- data/lib/blather/stanza/disco.rb +7 -1
- data/lib/blather/stanza/disco/disco_info.rb +45 -33
- data/lib/blather/stanza/disco/disco_items.rb +32 -21
- data/lib/blather/stanza/iq.rb +13 -8
- data/lib/blather/stanza/iq/query.rb +16 -8
- data/lib/blather/stanza/iq/roster.rb +33 -22
- data/lib/blather/stanza/message.rb +20 -31
- data/lib/blather/stanza/presence.rb +3 -5
- data/lib/blather/stanza/presence/status.rb +13 -21
- data/lib/blather/stanza/presence/subscription.rb +11 -16
- data/lib/blather/stanza/pubsub.rb +63 -0
- data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
- data/lib/blather/stanza/pubsub/create.rb +43 -0
- data/lib/blather/stanza/pubsub/errors.rb +9 -0
- data/lib/blather/stanza/pubsub/event.rb +77 -0
- data/lib/blather/stanza/pubsub/items.rb +63 -0
- data/lib/blather/stanza/pubsub/publish.rb +58 -0
- data/lib/blather/stanza/pubsub/retract.rb +53 -0
- data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
- data/lib/blather/stanza/pubsub/subscription.rb +66 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
- data/lib/blather/stanza/pubsub_owner.rb +41 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
- data/lib/blather/stream.rb +76 -168
- data/lib/blather/stream/client.rb +1 -2
- data/lib/blather/stream/component.rb +9 -5
- data/lib/blather/stream/features.rb +53 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
- data/lib/blather/stream/features/session.rb +44 -0
- data/lib/blather/stream/features/tls.rb +28 -0
- data/lib/blather/stream/parser.rb +70 -46
- data/lib/blather/xmpp_node.rb +113 -52
- data/spec/blather/client/client_spec.rb +44 -58
- data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
- data/spec/blather/client/dsl_spec.rb +19 -6
- data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
- data/spec/blather/errors/sasl_error_spec.rb +8 -8
- data/spec/blather/errors/stanza_error_spec.rb +25 -33
- data/spec/blather/errors/stream_error_spec.rb +21 -16
- data/spec/blather/errors_spec.rb +4 -11
- data/spec/blather/jid_spec.rb +31 -30
- data/spec/blather/roster_item_spec.rb +34 -23
- data/spec/blather/roster_spec.rb +27 -12
- data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
- data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
- data/spec/blather/stanza/iq/query_spec.rb +34 -11
- data/spec/blather/stanza/iq/roster_spec.rb +47 -30
- data/spec/blather/stanza/iq_spec.rb +19 -14
- data/spec/blather/stanza/message_spec.rb +30 -17
- data/spec/blather/stanza/presence/status_spec.rb +43 -20
- data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
- data/spec/blather/stanza/presence_spec.rb +34 -21
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
- data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
- data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
- data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
- data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
- data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
- data/spec/blather/stanza/pubsub_spec.rb +62 -0
- data/spec/blather/stanza_spec.rb +53 -38
- data/spec/blather/stream/client_spec.rb +231 -88
- data/spec/blather/stream/component_spec.rb +14 -5
- data/spec/blather/stream/parser_spec.rb +145 -0
- data/spec/blather/xmpp_node_spec.rb +192 -96
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +5 -4
- metadata +54 -18
- data/Rakefile +0 -139
- data/ext/extconf.rb +0 -65
- data/ext/push_parser.c +0 -209
- data/lib/blather/core_ext/libxml.rb +0 -28
- data/lib/blather/stream/resource.rb +0 -48
- data/lib/blather/stream/session.rb +0 -36
- data/lib/blather/stream/stream_handler.rb +0 -39
- data/lib/blather/stream/tls.rb +0 -33
- data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -1,54 +1,65 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
|
2
2
|
|
3
|
-
describe
|
4
|
-
it '
|
5
|
-
jid = JID.new(jid)
|
6
|
-
i = RosterItem.new jid
|
3
|
+
describe Blather::RosterItem do
|
4
|
+
it 'can be initialized with Blather::JID' do
|
5
|
+
jid = Blather::JID.new(jid)
|
6
|
+
i = Blather::RosterItem.new jid
|
7
7
|
i.jid.must_equal jid
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'can be initialized with an Iq::RosterItem' do
|
11
11
|
jid = 'n@d/r'
|
12
|
-
i = RosterItem.new Stanza::Iq::Roster::RosterItem.new(jid)
|
13
|
-
i.jid.must_equal JID.new(jid).stripped
|
12
|
+
i = Blather::RosterItem.new Blather::Stanza::Iq::Roster::RosterItem.new(jid)
|
13
|
+
i.jid.must_equal Blather::JID.new(jid).stripped
|
14
14
|
end
|
15
15
|
|
16
|
-
it '
|
17
|
-
jid =
|
18
|
-
i = RosterItem.new
|
16
|
+
it 'can be initialized with a string' do
|
17
|
+
jid = 'n@d/r'
|
18
|
+
i = Blather::RosterItem.new jid
|
19
|
+
i.jid.must_equal Blather::JID.new(jid).stripped
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns the same object when intialized with a Blather::RosterItem' do
|
23
|
+
control = Blather::RosterItem.new 'n@d/r'
|
24
|
+
Blather::RosterItem.new(control).must_be_same_as control
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has a Blather::JID setter that strips the Blather::JID' do
|
28
|
+
jid = Blather::JID.new('n@d/r')
|
29
|
+
i = Blather::RosterItem.new nil
|
19
30
|
i.jid = jid
|
20
31
|
i.jid.must_equal jid.stripped
|
21
32
|
end
|
22
33
|
|
23
34
|
it 'has a subscription setter that forces a symbol' do
|
24
|
-
i = RosterItem.new nil
|
35
|
+
i = Blather::RosterItem.new nil
|
25
36
|
i.subscription = 'remove'
|
26
37
|
i.subscription.must_equal :remove
|
27
38
|
end
|
28
39
|
|
29
40
|
it 'forces the type of subscription' do
|
30
|
-
proc { RosterItem.new(nil).subscription = 'foo' }.must_raise Blather::ArgumentError
|
41
|
+
proc { Blather::RosterItem.new(nil).subscription = 'foo' }.must_raise Blather::ArgumentError
|
31
42
|
end
|
32
43
|
|
33
44
|
it 'returns :none if the subscription field is blank' do
|
34
|
-
RosterItem.new(nil).subscription.must_equal :none
|
45
|
+
Blather::RosterItem.new(nil).subscription.must_equal :none
|
35
46
|
end
|
36
47
|
|
37
48
|
it 'ensure #ask is a symbol' do
|
38
|
-
i = RosterItem.new(nil)
|
49
|
+
i = Blather::RosterItem.new(nil)
|
39
50
|
i.ask = 'subscribe'
|
40
51
|
i.ask.must_equal :subscribe
|
41
52
|
end
|
42
53
|
|
43
54
|
it 'forces #ask to be :subscribe or nothing at all' do
|
44
|
-
proc { RosterItem.new(nil).ask = 'foo' }.must_raise Blather::ArgumentError
|
55
|
+
proc { Blather::RosterItem.new(nil).ask = 'foo' }.must_raise Blather::ArgumentError
|
45
56
|
end
|
46
57
|
|
47
58
|
it 'generates a stanza with #to_stanza' do
|
48
|
-
jid = JID.new('n@d/r')
|
49
|
-
i = RosterItem.new jid
|
59
|
+
jid = Blather::JID.new('n@d/r')
|
60
|
+
i = Blather::RosterItem.new jid
|
50
61
|
s = i.to_stanza
|
51
|
-
s.must_be_kind_of Stanza::Iq::Roster
|
62
|
+
s.must_be_kind_of Blather::Stanza::Iq::Roster
|
52
63
|
s.items.first.jid.must_equal jid.stripped
|
53
64
|
end
|
54
65
|
|
@@ -63,14 +74,14 @@ describe 'Blather::RosterItem' do
|
|
63
74
|
end
|
64
75
|
|
65
76
|
def setup_item_with_presences
|
66
|
-
@jid = JID.new('n@d/r')
|
67
|
-
@i = RosterItem.new @jid
|
77
|
+
@jid = Blather::JID.new('n@d/r')
|
78
|
+
@i = Blather::RosterItem.new @jid
|
68
79
|
|
69
|
-
@p = Stanza::Presence::Status.new(:away)
|
80
|
+
@p = Blather::Stanza::Presence::Status.new(:away)
|
70
81
|
@p.from = 'n@d/a'
|
71
82
|
@p.priority = 0
|
72
83
|
|
73
|
-
@p2 = Stanza::Presence::Status.new(:dnd)
|
84
|
+
@p2 = Blather::Stanza::Presence::Status.new(:dnd)
|
74
85
|
@p2.from = 'n@d/b'
|
75
86
|
@p2.priority = -1
|
76
87
|
|
@@ -79,7 +90,7 @@ describe 'Blather::RosterItem' do
|
|
79
90
|
end
|
80
91
|
|
81
92
|
it 'initializes groups to [nil] if the item is not part of a group' do
|
82
|
-
i = RosterItem.new 'n@d'
|
93
|
+
i = Blather::RosterItem.new 'n@d'
|
83
94
|
i.groups.must_equal [nil]
|
84
95
|
end
|
85
96
|
end
|
data/spec/blather/roster_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Blather::Roster do
|
4
4
|
before do
|
5
5
|
@stream = mock()
|
6
6
|
@stream.stubs(:send_data)
|
7
7
|
|
8
8
|
@stanza = mock()
|
9
|
-
items = []; 4.times { |n| items << JID.new("n@d/#{n}r") }
|
9
|
+
items = []; 4.times { |n| items << Blather::JID.new("n@d/#{n}r") }
|
10
10
|
@stanza.stubs(:items).returns(items)
|
11
11
|
|
12
|
-
@roster = Roster.new(@stream, @stanza)
|
12
|
+
@roster = Blather::Roster.new(@stream, @stanza)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'initializes with items' do
|
@@ -23,7 +23,7 @@ describe 'Blather::Roster' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'processes @stanzas with add requests' do
|
26
|
-
s = Stanza::Iq::Roster::RosterItem.new('a@b/c').to_stanza
|
26
|
+
s = Blather::Stanza::Iq::Roster::RosterItem.new('a@b/c').to_stanza
|
27
27
|
proc { @roster.process(s) }.must_change('@roster.items.length', :by => 1)
|
28
28
|
end
|
29
29
|
|
@@ -35,16 +35,16 @@ describe 'Blather::Roster' do
|
|
35
35
|
|
36
36
|
it 'allows an item to be pushed' do
|
37
37
|
jid = 'a@b/c'
|
38
|
-
item = RosterItem.new(JID.new(jid))
|
38
|
+
item = Blather::RosterItem.new(Blather::JID.new(jid))
|
39
39
|
proc { @roster.push(item) }.must_change('@roster.items.length', :by => 1)
|
40
40
|
@roster[jid].wont_be_nil
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'aliases #<< to #push and returns self to allow for chaining' do
|
44
44
|
jid = 'a@b/c'
|
45
|
-
item = RosterItem.new(JID.new(jid))
|
45
|
+
item = Blather::RosterItem.new(Blather::JID.new(jid))
|
46
46
|
jid2 = 'd@e/f'
|
47
|
-
item2 = RosterItem.new(JID.new(jid2))
|
47
|
+
item2 = Blather::RosterItem.new(Blather::JID.new(jid2))
|
48
48
|
proc { @roster << item << item2 }.must_change('@roster.items.length', :by => 2)
|
49
49
|
@roster[jid].wont_be_nil
|
50
50
|
@roster[jid2].wont_be_nil
|
@@ -53,24 +53,24 @@ describe 'Blather::Roster' do
|
|
53
53
|
it 'sends a @roster addition over the wire' do
|
54
54
|
stream = mock()
|
55
55
|
stream.expects(:send_data)
|
56
|
-
roster = Roster.new stream, @stanza
|
56
|
+
roster = Blather::Roster.new stream, @stanza
|
57
57
|
roster.push('a@b/c')
|
58
58
|
end
|
59
59
|
|
60
|
-
it 'removes a JID' do
|
60
|
+
it 'removes a Blather::JID' do
|
61
61
|
proc { @roster.delete 'n@d' }.must_change('@roster.items.length', :by => -1)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'sends a @roster removal over the wire' do
|
65
65
|
stream = mock(:send_data => nil)
|
66
|
-
roster = Roster.new stream, @stanza
|
66
|
+
roster = Blather::Roster.new stream, @stanza
|
67
67
|
roster.delete('a@b/c')
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'returns an item through []' do
|
71
71
|
item = @roster['n@d']
|
72
|
-
item.must_be_kind_of RosterItem
|
73
|
-
item.jid.must_equal JID.new('n@d')
|
72
|
+
item.must_be_kind_of Blather::RosterItem
|
73
|
+
item.jid.must_equal Blather::JID.new('n@d')
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'responds to #each' do
|
@@ -86,4 +86,19 @@ describe 'Blather::Roster' do
|
|
86
86
|
items.delete 'n@d'
|
87
87
|
items.wont_equal @roster.items
|
88
88
|
end
|
89
|
+
|
90
|
+
it 'will group roster items' do
|
91
|
+
@roster.delete 'n@d'
|
92
|
+
item1 = Blather::RosterItem.new("n1@d")
|
93
|
+
item1.groups = ['group1', 'group2']
|
94
|
+
item2 = Blather::RosterItem.new("n2@d")
|
95
|
+
item2.groups = ['group1', 'group3']
|
96
|
+
@roster << item1 << item2
|
97
|
+
|
98
|
+
@roster.grouped.must_equal({
|
99
|
+
'group1' => [item1, item2],
|
100
|
+
'group2' => [item1],
|
101
|
+
'group3' => [item2]
|
102
|
+
})
|
103
|
+
end
|
89
104
|
end
|
@@ -18,9 +18,14 @@ def disco_info_xml
|
|
18
18
|
XML
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
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 =
|
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 =
|
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
|
160
|
+
describe Blather::Stanza::Iq::DiscoInfo::Identity do
|
150
161
|
it 'will auto-inherit nodes' do
|
151
|
-
n =
|
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
|
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
|
202
|
+
describe Blather::Stanza::Iq::DiscoInfo::Feature do
|
188
203
|
it 'will auto-inherit nodes' do
|
189
|
-
n =
|
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
|
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
|
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 =
|
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
|
107
|
+
describe Blather::Stanza::Iq::DiscoItems::Item do
|
100
108
|
it 'will auto-inherit nodes' do
|
101
|
-
n =
|
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.
|
133
|
-
a.
|
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
|