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.
- 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,41 +1,64 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
|
|
2
2
|
|
|
3
|
-
describe
|
|
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.
|
|
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.
|
|
27
|
+
query.xpath('query').must_be_empty
|
|
17
28
|
|
|
18
29
|
query.query.wont_be_nil
|
|
19
|
-
query.
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
|
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[
|
|
63
|
-
n[
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
@@ -1,40 +1,45 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe Blather::Stanza::Iq do
|
|
4
4
|
it 'registers itself' do
|
|
5
|
-
XMPPNode.class_from_registration(:iq, nil).must_equal Stanza::Iq
|
|
5
|
+
Blather::XMPPNode.class_from_registration(:iq, nil).must_equal Blather::Stanza::Iq
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'must be importable' do
|
|
9
|
+
doc = parse_stanza "<iq from='juliet@example.com/balcony' type='set' id='roster_4'></iq>"
|
|
10
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Iq
|
|
6
11
|
end
|
|
7
12
|
|
|
8
13
|
it 'creates a new Iq stanza defaulted as a get' do
|
|
9
|
-
Stanza::Iq.new.type.must_equal :get
|
|
14
|
+
Blather::Stanza::Iq.new.type.must_equal :get
|
|
10
15
|
end
|
|
11
16
|
|
|
12
|
-
it '
|
|
13
|
-
|
|
17
|
+
it 'sets the id when created' do
|
|
18
|
+
Blather::Stanza::Iq.new.id.wont_be_nil
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
it 'creates a new Stanza::Iq object on import' do
|
|
17
|
-
Stanza::Iq.import(XMPPNode.new('iq')).must_be_kind_of Stanza::Iq
|
|
22
|
+
Blather::Stanza::Iq.import(Blather::XMPPNode.new('iq')).must_be_kind_of Blather::Stanza::Iq
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
it 'creates a proper object based on its children' do
|
|
21
|
-
n = XMPPNode.new('iq')
|
|
22
|
-
n << XMPPNode.new('query')
|
|
23
|
-
Stanza::Iq.import(n).must_be_kind_of Stanza::Iq::Query
|
|
26
|
+
n = Blather::XMPPNode.new('iq')
|
|
27
|
+
n << Blather::XMPPNode.new('query', n.document)
|
|
28
|
+
Blather::Stanza::Iq.import(n).must_be_kind_of Blather::Stanza::Iq::Query
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
it 'ensures type is one of Stanza::Iq::VALID_TYPES' do
|
|
27
|
-
lambda { Stanza::Iq.new :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
32
|
+
lambda { Blather::Stanza::Iq.new :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
28
33
|
|
|
29
|
-
Stanza::Iq::VALID_TYPES.each do |valid_type|
|
|
30
|
-
n = Stanza::Iq.new valid_type
|
|
34
|
+
Blather::Stanza::Iq::VALID_TYPES.each do |valid_type|
|
|
35
|
+
n = Blather::Stanza::Iq.new valid_type
|
|
31
36
|
n.type.must_equal valid_type
|
|
32
37
|
end
|
|
33
38
|
end
|
|
34
39
|
|
|
35
|
-
Stanza::Iq::VALID_TYPES.each do |valid_type|
|
|
40
|
+
Blather::Stanza::Iq::VALID_TYPES.each do |valid_type|
|
|
36
41
|
it "provides a helper (#{valid_type}?) for type #{valid_type}" do
|
|
37
|
-
Stanza::Iq.new.must_respond_to :"#{valid_type}?"
|
|
42
|
+
Blather::Stanza::Iq.new.must_respond_to :"#{valid_type}?"
|
|
38
43
|
end
|
|
39
44
|
end
|
|
40
45
|
end
|
|
@@ -1,52 +1,65 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe Blather::Stanza::Message do
|
|
4
4
|
it 'registers itself' do
|
|
5
|
-
XMPPNode.class_from_registration(:message, nil).must_equal Stanza::Message
|
|
5
|
+
Blather::XMPPNode.class_from_registration(:message, nil).must_equal Blather::Stanza::Message
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'must be importable' do
|
|
9
|
+
doc = parse_stanza <<-XML
|
|
10
|
+
<message
|
|
11
|
+
to='romeo@example.net'
|
|
12
|
+
from='juliet@example.com/balcony'
|
|
13
|
+
type='chat'
|
|
14
|
+
xml:lang='en'>
|
|
15
|
+
<body>Wherefore art thou, Romeo?</body>
|
|
16
|
+
</message>
|
|
17
|
+
XML
|
|
18
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Message
|
|
6
19
|
end
|
|
7
20
|
|
|
8
21
|
it 'provides "attr_accessor" for body' do
|
|
9
|
-
s = Stanza::Message.new
|
|
22
|
+
s = Blather::Stanza::Message.new
|
|
10
23
|
s.body.must_be_nil
|
|
11
|
-
s.
|
|
24
|
+
s.xpath('body').must_be_empty
|
|
12
25
|
|
|
13
26
|
s.body = 'test message'
|
|
14
27
|
s.body.wont_be_nil
|
|
15
|
-
s.
|
|
28
|
+
s.xpath('body').wont_be_empty
|
|
16
29
|
end
|
|
17
30
|
|
|
18
31
|
it 'provides "attr_accessor" for subject' do
|
|
19
|
-
s = Stanza::Message.new
|
|
32
|
+
s = Blather::Stanza::Message.new
|
|
20
33
|
s.subject.must_be_nil
|
|
21
|
-
s.
|
|
34
|
+
s.xpath('subject').must_be_empty
|
|
22
35
|
|
|
23
36
|
s.subject = 'test subject'
|
|
24
37
|
s.subject.wont_be_nil
|
|
25
|
-
s.
|
|
38
|
+
s.xpath('subject').wont_be_empty
|
|
26
39
|
end
|
|
27
40
|
|
|
28
41
|
it 'provides "attr_accessor" for thread' do
|
|
29
|
-
s = Stanza::Message.new
|
|
42
|
+
s = Blather::Stanza::Message.new
|
|
30
43
|
s.thread.must_be_nil
|
|
31
|
-
s.
|
|
44
|
+
s.xpath('thread').must_be_empty
|
|
32
45
|
|
|
33
46
|
s.thread = 1234
|
|
34
47
|
s.thread.wont_be_nil
|
|
35
|
-
s.
|
|
48
|
+
s.xpath('thread').wont_be_empty
|
|
36
49
|
end
|
|
37
50
|
|
|
38
|
-
it 'ensures type is one of Stanza::Message::VALID_TYPES' do
|
|
39
|
-
lambda { Stanza::Message.new nil, nil, :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
51
|
+
it 'ensures type is one of Blather::Stanza::Message::VALID_TYPES' do
|
|
52
|
+
lambda { Blather::Stanza::Message.new nil, nil, :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
40
53
|
|
|
41
|
-
Stanza::Message::VALID_TYPES.each do |valid_type|
|
|
42
|
-
msg = Stanza::Message.new nil, nil, valid_type
|
|
54
|
+
Blather::Stanza::Message::VALID_TYPES.each do |valid_type|
|
|
55
|
+
msg = Blather::Stanza::Message.new nil, nil, valid_type
|
|
43
56
|
msg.type.must_equal valid_type
|
|
44
57
|
end
|
|
45
58
|
end
|
|
46
59
|
|
|
47
|
-
Stanza::Message::VALID_TYPES.each do |valid_type|
|
|
60
|
+
Blather::Stanza::Message::VALID_TYPES.each do |valid_type|
|
|
48
61
|
it "provides a helper (#{valid_type}?) for type #{valid_type}" do
|
|
49
|
-
Stanza::Message.new.must_respond_to :"#{valid_type}?"
|
|
62
|
+
Blather::Stanza::Message.new.must_respond_to :"#{valid_type}?"
|
|
50
63
|
end
|
|
51
64
|
end
|
|
52
65
|
end
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe Blather::Stanza::Presence::Status do
|
|
4
4
|
it 'registers itself' do
|
|
5
|
-
XMPPNode.class_from_registration(:status, nil).must_equal Stanza::Presence::Status
|
|
5
|
+
Blather::XMPPNode.class_from_registration(:status, nil).must_equal Blather::Stanza::Presence::Status
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'must be importable as unavailable' do
|
|
9
|
+
doc = parse_stanza '<presence type="unavailable"/>'
|
|
10
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence::Status
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'must be importable as nil' do
|
|
14
|
+
doc = parse_stanza '<presence/>'
|
|
15
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence::Status
|
|
6
16
|
end
|
|
7
17
|
|
|
8
18
|
it 'can set state on creation' do
|
|
9
|
-
status = Stanza::Presence::Status.new :away
|
|
19
|
+
status = Blather::Stanza::Presence::Status.new :away
|
|
10
20
|
status.state.must_equal :away
|
|
11
21
|
end
|
|
12
22
|
|
|
13
23
|
it 'can set a message on creation' do
|
|
14
|
-
status = Stanza::Presence::Status.new nil, 'Say hello!'
|
|
24
|
+
status = Blather::Stanza::Presence::Status.new nil, 'Say hello!'
|
|
15
25
|
status.message.must_equal 'Say hello!'
|
|
16
26
|
end
|
|
17
27
|
|
|
18
28
|
it 'ensures type is nil or :unavailable' do
|
|
19
|
-
status = Stanza::Presence::Status.new
|
|
29
|
+
status = Blather::Stanza::Presence::Status.new
|
|
20
30
|
lambda { status.type = :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
21
31
|
|
|
22
32
|
[nil, :unavailable].each do |valid_type|
|
|
@@ -26,35 +36,35 @@ describe 'Blather::Stanza::Presence::Status' do
|
|
|
26
36
|
end
|
|
27
37
|
|
|
28
38
|
it 'ensures state is one of Presence::Status::VALID_STATES' do
|
|
29
|
-
status = Stanza::Presence::Status.new
|
|
39
|
+
status = Blather::Stanza::Presence::Status.new
|
|
30
40
|
lambda { status.state = :invalid_type_name }.must_raise(Blather::ArgumentError)
|
|
31
41
|
|
|
32
|
-
Stanza::Presence::Status::VALID_STATES.each do |valid_state|
|
|
42
|
+
Blather::Stanza::Presence::Status::VALID_STATES.each do |valid_state|
|
|
33
43
|
status.state = valid_state
|
|
34
44
|
status.state.must_equal valid_state
|
|
35
45
|
end
|
|
36
46
|
end
|
|
37
47
|
|
|
38
48
|
it 'returns :available if state is nil' do
|
|
39
|
-
Stanza::Presence::Status.new.state.must_equal :available
|
|
49
|
+
Blather::Stanza::Presence::Status.new.state.must_equal :available
|
|
40
50
|
end
|
|
41
51
|
|
|
42
52
|
it 'returns :unavailable if type is :unavailable' do
|
|
43
|
-
status = Stanza::Presence::Status.new
|
|
53
|
+
status = Blather::Stanza::Presence::Status.new
|
|
44
54
|
status.type = :unavailable
|
|
45
55
|
status.state.must_equal :unavailable
|
|
46
56
|
end
|
|
47
57
|
|
|
48
58
|
it 'ensures priority is not greater than 127' do
|
|
49
|
-
lambda { Stanza::Presence::Status.new.priority = 128 }.must_raise(Blather::ArgumentError)
|
|
59
|
+
lambda { Blather::Stanza::Presence::Status.new.priority = 128 }.must_raise(Blather::ArgumentError)
|
|
50
60
|
end
|
|
51
61
|
|
|
52
62
|
it 'ensures priority is not less than -128' do
|
|
53
|
-
lambda { Stanza::Presence::Status.new.priority = -129 }.must_raise(Blather::ArgumentError)
|
|
63
|
+
lambda { Blather::Stanza::Presence::Status.new.priority = -129 }.must_raise(Blather::ArgumentError)
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
it 'has "attr_accessor" for priority' do
|
|
57
|
-
status = Stanza::Presence::Status.new
|
|
67
|
+
status = Blather::Stanza::Presence::Status.new
|
|
58
68
|
status.priority.must_equal 0
|
|
59
69
|
|
|
60
70
|
status.priority = 10
|
|
@@ -63,7 +73,7 @@ describe 'Blather::Stanza::Presence::Status' do
|
|
|
63
73
|
end
|
|
64
74
|
|
|
65
75
|
it 'has "attr_accessor" for message' do
|
|
66
|
-
status = Stanza::Presence::Status.new
|
|
76
|
+
status = Blather::Stanza::Presence::Status.new
|
|
67
77
|
status.message.must_be_nil
|
|
68
78
|
|
|
69
79
|
status.message = 'new message'
|
|
@@ -72,12 +82,12 @@ describe 'Blather::Stanza::Presence::Status' do
|
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
it 'must be comparable by priority' do
|
|
75
|
-
jid = JID.new 'a@b/c'
|
|
85
|
+
jid = Blather::JID.new 'a@b/c'
|
|
76
86
|
|
|
77
|
-
status1 = Stanza::Presence::Status.new
|
|
87
|
+
status1 = Blather::Stanza::Presence::Status.new
|
|
78
88
|
status1.from = jid
|
|
79
89
|
|
|
80
|
-
status2 = Stanza::Presence::Status.new
|
|
90
|
+
status2 = Blather::Stanza::Presence::Status.new
|
|
81
91
|
status2.from = jid
|
|
82
92
|
|
|
83
93
|
status1.priority = 1
|
|
@@ -89,14 +99,27 @@ describe 'Blather::Stanza::Presence::Status' do
|
|
|
89
99
|
(status1 <=> status2).must_equal 0
|
|
90
100
|
end
|
|
91
101
|
|
|
92
|
-
it 'raises an argument error if compared to a status with a different JID' do
|
|
93
|
-
status1 = Stanza::Presence::Status.new
|
|
102
|
+
it 'raises an argument error if compared to a status with a different Blather::JID' do
|
|
103
|
+
status1 = Blather::Stanza::Presence::Status.new
|
|
94
104
|
status1.from = 'a@b/c'
|
|
95
105
|
|
|
96
|
-
status2 = Stanza::Presence::Status.new
|
|
106
|
+
status2 = Blather::Stanza::Presence::Status.new
|
|
97
107
|
status2.from = 'd@e/f'
|
|
98
108
|
|
|
99
109
|
lambda { status1 <=> status2 }.must_raise(Blather::ArgumentError)
|
|
100
110
|
end
|
|
101
|
-
end
|
|
102
111
|
|
|
112
|
+
Blather::Stanza::Presence::Status::VALID_STATES.each do |valid_state|
|
|
113
|
+
it "provides a helper (#{valid_state}?) for state #{valid_state}" do
|
|
114
|
+
Blather::Stanza::Presence::Status.new.must_respond_to :"#{valid_state}?"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "returns true on call to (#{valid_state}?) if state == #{valid_state}" do
|
|
118
|
+
method = "#{valid_state}?".to_sym
|
|
119
|
+
stat = Blather::Stanza::Presence::Status.new
|
|
120
|
+
stat.state = valid_state
|
|
121
|
+
stat.must_respond_to method
|
|
122
|
+
stat.__send__(method).must_equal true
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|