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.
- 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/client/client.rb +19 -13
- data/lib/blather/client/dsl/pubsub.rb +133 -0
- data/lib/blather/client/dsl.rb +16 -0
- data/lib/blather/client.rb +1 -1
- data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
- data/lib/blather/core_ext/active_support.rb +1 -117
- data/lib/blather/core_ext/nokogiri.rb +35 -0
- 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/errors.rb +3 -20
- 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/disco/disco_info.rb +45 -33
- data/lib/blather/stanza/disco/disco_items.rb +32 -21
- data/lib/blather/stanza/disco.rb +7 -1
- data/lib/blather/stanza/iq/query.rb +16 -8
- data/lib/blather/stanza/iq/roster.rb +33 -22
- data/lib/blather/stanza/iq.rb +13 -8
- data/lib/blather/stanza/message.rb +20 -31
- data/lib/blather/stanza/presence/status.rb +13 -21
- data/lib/blather/stanza/presence/subscription.rb +11 -16
- data/lib/blather/stanza/presence.rb +3 -5
- 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.rb +63 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
- data/lib/blather/stanza/pubsub_owner.rb +41 -0
- data/lib/blather/stanza.rb +35 -18
- data/lib/blather/stream/client.rb +1 -2
- data/lib/blather/stream/component.rb +9 -5
- 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/features.rb +53 -0
- data/lib/blather/stream/parser.rb +70 -46
- data/lib/blather/stream.rb +76 -168
- data/lib/blather/xmpp_node.rb +113 -52
- data/lib/blather.rb +35 -12
- 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 +53 -17
- 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,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
|
@@ -1,28 +1,35 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Blather::Stanza::Presence::Subscription do
|
4
4
|
it 'registers itself' do
|
5
|
-
XMPPNode.class_from_registration(:subscription, nil).must_equal Stanza::Presence::Subscription
|
5
|
+
Blather::XMPPNode.class_from_registration(:subscription, nil).must_equal Blather::Stanza::Presence::Subscription
|
6
|
+
end
|
7
|
+
|
8
|
+
[:subscribe, :subscribed, :unsubscribe, :unsubscribed].each do |type|
|
9
|
+
it "must be importable as #{type}" do
|
10
|
+
doc = parse_stanza "<presence type='#{type}'/>"
|
11
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence::Subscription
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
it 'can set to on creation' do
|
9
|
-
sub = Stanza::Presence::Subscription.new 'a@b'
|
16
|
+
sub = Blather::Stanza::Presence::Subscription.new 'a@b'
|
10
17
|
sub.to.to_s.must_equal 'a@b'
|
11
18
|
end
|
12
19
|
|
13
20
|
it 'can set a type on creation' do
|
14
|
-
sub = Stanza::Presence::Subscription.new nil, :subscribed
|
21
|
+
sub = Blather::Stanza::Presence::Subscription.new nil, :subscribed
|
15
22
|
sub.type.must_equal :subscribed
|
16
23
|
end
|
17
24
|
|
18
|
-
it 'strips JIDs when setting #to' do
|
19
|
-
sub = Stanza::Presence::Subscription.new 'a@b/c'
|
25
|
+
it 'strips Blather::JIDs when setting #to' do
|
26
|
+
sub = Blather::Stanza::Presence::Subscription.new 'a@b/c'
|
20
27
|
sub.to.to_s.must_equal 'a@b'
|
21
28
|
end
|
22
29
|
|
23
30
|
it 'generates an approval using #approve!' do
|
24
|
-
jid = JID.new 'a@b'
|
25
|
-
sub = Stanza::Presence::Subscription.new
|
31
|
+
jid = Blather::JID.new 'a@b'
|
32
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
26
33
|
sub.from = jid
|
27
34
|
sub.approve!
|
28
35
|
sub.to.must_equal jid
|
@@ -30,8 +37,8 @@ describe 'Blather::Stanza::Presence::Subscription' do
|
|
30
37
|
end
|
31
38
|
|
32
39
|
it 'generates a refusal using #refuse!' do
|
33
|
-
jid = JID.new 'a@b'
|
34
|
-
sub = Stanza::Presence::Subscription.new
|
40
|
+
jid = Blather::JID.new 'a@b'
|
41
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
35
42
|
sub.from = jid
|
36
43
|
sub.refuse!
|
37
44
|
sub.to.must_equal jid
|
@@ -39,8 +46,8 @@ describe 'Blather::Stanza::Presence::Subscription' do
|
|
39
46
|
end
|
40
47
|
|
41
48
|
it 'generates an unsubscript using #unsubscribe!' do
|
42
|
-
jid = JID.new 'a@b'
|
43
|
-
sub = Stanza::Presence::Subscription.new
|
49
|
+
jid = Blather::JID.new 'a@b'
|
50
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
44
51
|
sub.from = jid
|
45
52
|
sub.unsubscribe!
|
46
53
|
sub.to.must_equal jid
|
@@ -48,8 +55,8 @@ describe 'Blather::Stanza::Presence::Subscription' do
|
|
48
55
|
end
|
49
56
|
|
50
57
|
it 'generates a cancellation using #cancel!' do
|
51
|
-
jid = JID.new 'a@b'
|
52
|
-
sub = Stanza::Presence::Subscription.new
|
58
|
+
jid = Blather::JID.new 'a@b'
|
59
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
53
60
|
sub.from = jid
|
54
61
|
sub.cancel!
|
55
62
|
sub.to.must_equal jid
|
@@ -57,8 +64,8 @@ describe 'Blather::Stanza::Presence::Subscription' do
|
|
57
64
|
end
|
58
65
|
|
59
66
|
it 'generates a request using #request!' do
|
60
|
-
jid = JID.new 'a@b'
|
61
|
-
sub = Stanza::Presence::Subscription.new
|
67
|
+
jid = Blather::JID.new 'a@b'
|
68
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
62
69
|
sub.from = jid
|
63
70
|
sub.request!
|
64
71
|
sub.to.must_equal jid
|
@@ -66,20 +73,33 @@ describe 'Blather::Stanza::Presence::Subscription' do
|
|
66
73
|
end
|
67
74
|
|
68
75
|
it 'has a #request? helper' do
|
69
|
-
sub = Stanza::Presence::Subscription.new
|
76
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
70
77
|
sub.must_respond_to :request?
|
71
78
|
sub.type = :subscribe
|
72
79
|
sub.request?.must_equal true
|
73
80
|
end
|
74
81
|
|
82
|
+
it "successfully routes chained actions" do
|
83
|
+
from = Blather::JID.new("foo@bar.com")
|
84
|
+
to = Blather::JID.new("baz@quux.com")
|
85
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
86
|
+
sub.from = from
|
87
|
+
sub.to = to
|
88
|
+
sub.cancel!
|
89
|
+
sub.unsubscribe!
|
90
|
+
sub.type.must_equal :unsubscribe
|
91
|
+
sub.to.must_equal from
|
92
|
+
sub.from.must_equal to
|
93
|
+
end
|
94
|
+
|
75
95
|
it "will inherit only another node's attributes" do
|
76
|
-
inheritable = XMPPNode.new 'foo'
|
77
|
-
inheritable
|
96
|
+
inheritable = Blather::XMPPNode.new 'foo'
|
97
|
+
inheritable[:bar] = 'baz'
|
78
98
|
|
79
|
-
sub = Stanza::Presence::Subscription.new
|
99
|
+
sub = Blather::Stanza::Presence::Subscription.new
|
80
100
|
sub.must_respond_to :inherit
|
81
101
|
|
82
102
|
sub.inherit inheritable
|
83
|
-
sub
|
103
|
+
sub[:bar].must_equal 'baz'
|
84
104
|
end
|
85
105
|
end
|
@@ -1,53 +1,66 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Blather::Stanza::Presence do
|
4
4
|
it 'registers itself' do
|
5
|
-
XMPPNode.class_from_registration(:presence, nil).must_equal Stanza::Presence
|
5
|
+
Blather::XMPPNode.class_from_registration(:presence, nil).must_equal Blather::Stanza::Presence
|
6
6
|
end
|
7
7
|
|
8
|
-
it '
|
9
|
-
presence =
|
8
|
+
it 'must be importable' do
|
9
|
+
doc = parse_stanza '<presence type="probe"/>'
|
10
|
+
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'ensures type is one of Blather::Stanza::Presence::VALID_TYPES' do
|
14
|
+
presence = Blather::Stanza::Presence.new
|
10
15
|
lambda { presence.type = :invalid_type_name }.must_raise(Blather::ArgumentError)
|
11
16
|
|
12
|
-
Stanza::Presence::VALID_TYPES.each do |valid_type|
|
17
|
+
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
|
13
18
|
presence.type = valid_type
|
14
19
|
presence.type.must_equal valid_type
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
Stanza::Presence::VALID_TYPES.each do |valid_type|
|
23
|
+
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
|
19
24
|
it "provides a helper (#{valid_type}?) for type #{valid_type}" do
|
20
|
-
Stanza::Presence.new.must_respond_to :"#{valid_type}?"
|
25
|
+
Blather::Stanza::Presence.new.must_respond_to :"#{valid_type}?"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns true on call to (#{valid_type}?) if type == #{valid_type}" do
|
29
|
+
method = "#{valid_type}?".to_sym
|
30
|
+
pres = Blather::Stanza::Presence.new
|
31
|
+
pres.type = valid_type
|
32
|
+
pres.must_respond_to method
|
33
|
+
pres.__send__(method).must_equal true
|
21
34
|
end
|
22
35
|
end
|
23
36
|
|
24
37
|
it 'creates a Status object when importing a node with type == nil' do
|
25
|
-
s = Stanza::Presence.import(XMPPNode.new)
|
26
|
-
s.must_be_kind_of Stanza::Presence::Status
|
38
|
+
s = Blather::Stanza::Presence.import(Blather::XMPPNode.new)
|
39
|
+
s.must_be_kind_of Blather::Stanza::Presence::Status
|
27
40
|
s.state.must_equal :available
|
28
41
|
end
|
29
42
|
|
30
43
|
it 'creates a Status object when importing a node with type == "unavailable"' do
|
31
|
-
n = XMPPNode.new
|
32
|
-
n
|
33
|
-
s = Stanza::Presence.import(n)
|
34
|
-
s.must_be_kind_of Stanza::Presence::Status
|
44
|
+
n = Blather::XMPPNode.new
|
45
|
+
n[:type] = :unavailable
|
46
|
+
s = Blather::Stanza::Presence.import(n)
|
47
|
+
s.must_be_kind_of Blather::Stanza::Presence::Status
|
35
48
|
s.state.must_equal :unavailable
|
36
49
|
end
|
37
50
|
|
38
51
|
it 'creates a Subscription object when importing a node with type == "subscribe"' do
|
39
|
-
n = XMPPNode.new
|
40
|
-
n
|
41
|
-
s = Stanza::Presence.import(n)
|
42
|
-
s.must_be_kind_of Stanza::Presence::Subscription
|
52
|
+
n = Blather::XMPPNode.new
|
53
|
+
n[:type] = :subscribe
|
54
|
+
s = Blather::Stanza::Presence.import(n)
|
55
|
+
s.must_be_kind_of Blather::Stanza::Presence::Subscription
|
43
56
|
s.type.must_equal :subscribe
|
44
57
|
end
|
45
58
|
|
46
59
|
it 'creates a Presence object when importing a node with type equal to something unkown' do
|
47
|
-
n = XMPPNode.new
|
48
|
-
n
|
49
|
-
s = Stanza::Presence.import(n)
|
50
|
-
s.must_be_kind_of Stanza::Presence
|
60
|
+
n = Blather::XMPPNode.new
|
61
|
+
n[:type] = :foo
|
62
|
+
s = Blather::Stanza::Presence.import(n)
|
63
|
+
s.must_be_kind_of Blather::Stanza::Presence
|
51
64
|
s.type.must_equal :foo
|
52
65
|
end
|
53
66
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. .. spec_helper])
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. .. fixtures pubsub])
|
3
|
+
|
4
|
+
def control_affiliations
|
5
|
+
{ :owner => ['node1', 'node2'],
|
6
|
+
:publisher => ['node3'],
|
7
|
+
:outcast => ['node4'],
|
8
|
+
:member => ['node5'],
|
9
|
+
:none => ['node6'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Blather::Stanza::PubSub::Affiliations do
|
13
|
+
it 'registers itself' do
|
14
|
+
Blather::XMPPNode.class_from_registration(:affiliations, Blather::Stanza::PubSub.registered_ns).must_equal Blather::Stanza::PubSub::Affiliations
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can be imported' do
|
18
|
+
Blather::XMPPNode.import(parse_stanza(affiliations_xml).root).must_be_instance_of Blather::Stanza::PubSub::Affiliations
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'ensures an affiliations node is present on create' do
|
22
|
+
affiliations = Blather::Stanza::PubSub::Affiliations.new
|
23
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'ensures an affiliations node exists when calling #affiliations' do
|
27
|
+
affiliations = Blather::Stanza::PubSub::Affiliations.new
|
28
|
+
affiliations.pubsub.remove_children :affiliations
|
29
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).must_be_nil
|
30
|
+
|
31
|
+
affiliations.affiliations.wont_be_nil
|
32
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'defaults to a get node' do
|
36
|
+
Blather::Stanza::PubSub::Affiliations.new.type.must_equal :get
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the host if requested' do
|
40
|
+
aff = Blather::Stanza::PubSub::Affiliations.new :get, 'pubsub.jabber.local'
|
41
|
+
aff.to.must_equal Blather::JID.new('pubsub.jabber.local')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can import an affiliates result node' do
|
45
|
+
node = parse_stanza(affiliations_xml).root
|
46
|
+
|
47
|
+
affiliations = Blather::Stanza::PubSub::Affiliations.new.inherit node
|
48
|
+
affiliations.size.must_equal 5
|
49
|
+
affiliations.list.must_equal control_affiliations
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'will iterate over each affiliation' do
|
53
|
+
Blather::XMPPNode.import(parse_stanza(affiliations_xml).root).each do |type, nodes|
|
54
|
+
nodes.must_equal control_affiliations[type]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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::Create do
|
5
|
+
it 'registers itself' do
|
6
|
+
Blather::XMPPNode.class_from_registration(:create, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub::Create
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can be imported' do
|
10
|
+
Blather::XMPPNode.import(parse_stanza(<<-NODE).root).must_be_instance_of Blather::Stanza::PubSub::Create
|
11
|
+
<iq type='set'
|
12
|
+
from='hamlet@denmark.lit/elsinore'
|
13
|
+
to='pubsub.shakespeare.lit'
|
14
|
+
id='create1'>
|
15
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
16
|
+
<create node='princely_musings'/>
|
17
|
+
<configure/>
|
18
|
+
</pubsub>
|
19
|
+
</iq>
|
20
|
+
NODE
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'ensures a create node is present on create' do
|
24
|
+
create = Blather::Stanza::PubSub::Create.new
|
25
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'ensures a configure node is present on create' do
|
29
|
+
create = Blather::Stanza::PubSub::Create.new
|
30
|
+
create.find('//ns:pubsub/ns:configure', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'ensures a create node exists when calling #create_node' do
|
34
|
+
create = Blather::Stanza::PubSub::Create.new
|
35
|
+
create.pubsub.remove_children :create
|
36
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).must_be_empty
|
37
|
+
|
38
|
+
create.create_node.wont_be_nil
|
39
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'defaults to a set node' do
|
43
|
+
create = Blather::Stanza::PubSub::Create.new
|
44
|
+
create.type.must_equal :set
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the host if requested' do
|
48
|
+
create = Blather::Stanza::PubSub::Create.new :set, 'pubsub.jabber.local'
|
49
|
+
create.to.must_equal Blather::JID.new('pubsub.jabber.local')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sets the node' do
|
53
|
+
create = Blather::Stanza::PubSub::Create.new :set, 'host', 'node-name'
|
54
|
+
create.node.must_equal 'node-name'
|
55
|
+
end
|
56
|
+
end
|