blather 0.6.2 → 0.7.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/.rspec +3 -0
- data/.travis.yml +1 -8
- data/CHANGELOG.md +230 -0
- data/Guardfile +4 -4
- data/README.md +2 -8
- data/Rakefile +14 -27
- data/blather.gemspec +8 -18
- data/lib/blather.rb +1 -0
- data/lib/blather/client/client.rb +8 -0
- data/lib/blather/roster.rb +7 -0
- data/lib/blather/stanza/iq/roster.rb +1 -1
- data/lib/blather/stanza/message/muc_user.rb +2 -0
- data/lib/blather/stanza/muc/muc_user_base.rb +4 -3
- data/lib/blather/stanza/presence.rb +12 -14
- data/lib/blather/stanza/presence/c.rb +58 -62
- data/lib/blather/stanza/presence/muc.rb +14 -10
- data/lib/blather/stanza/presence/muc_user.rb +47 -36
- data/lib/blather/stanza/presence/status.rb +106 -101
- data/lib/blather/stanza/presence/subscription.rb +59 -60
- data/lib/blather/stream.rb +1 -3
- data/lib/blather/stream/features/resource.rb +0 -1
- data/lib/blather/version.rb +1 -2
- data/lib/blather/xmpp_node.rb +24 -3
- data/spec/blather/client/client_spec.rb +64 -64
- data/spec/blather/client/dsl/pubsub_spec.rb +127 -127
- data/spec/blather/client/dsl_spec.rb +11 -11
- data/spec/blather/errors/sasl_error_spec.rb +3 -3
- data/spec/blather/errors/stanza_error_spec.rb +26 -26
- data/spec/blather/errors/stream_error_spec.rb +22 -22
- data/spec/blather/errors_spec.rb +7 -7
- data/spec/blather/file_transfer_spec.rb +16 -18
- data/spec/blather/jid_spec.rb +29 -29
- data/spec/blather/roster_item_spec.rb +18 -18
- data/spec/blather/roster_spec.rb +18 -18
- data/spec/blather/stanza/discos/disco_info_spec.rb +56 -57
- data/spec/blather/stanza/discos/disco_items_spec.rb +33 -33
- data/spec/blather/stanza/iq/command_spec.rb +57 -57
- data/spec/blather/stanza/iq/ibb_spec.rb +27 -39
- data/spec/blather/stanza/iq/ping_spec.rb +13 -9
- data/spec/blather/stanza/iq/query_spec.rb +16 -16
- data/spec/blather/stanza/iq/roster_spec.rb +29 -30
- data/spec/blather/stanza/iq/s5b_spec.rb +10 -13
- data/spec/blather/stanza/iq/si_spec.rb +20 -23
- data/spec/blather/stanza/iq/vcard_spec.rb +22 -25
- data/spec/blather/stanza/iq_spec.rb +12 -12
- data/spec/blather/stanza/message/muc_user_spec.rb +36 -36
- data/spec/blather/stanza/message_spec.rb +56 -56
- data/spec/blather/stanza/presence/c_spec.rb +17 -7
- data/spec/blather/stanza/presence/muc_spec.rb +8 -8
- data/spec/blather/stanza/presence/muc_user_spec.rb +23 -23
- data/spec/blather/stanza/presence/status_spec.rb +42 -30
- data/spec/blather/stanza/presence/subscription_spec.rb +22 -23
- data/spec/blather/stanza/presence_spec.rb +72 -34
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +12 -12
- data/spec/blather/stanza/pubsub/create_spec.rb +10 -10
- data/spec/blather/stanza/pubsub/event_spec.rb +31 -31
- data/spec/blather/stanza/pubsub/items_spec.rb +21 -21
- data/spec/blather/stanza/pubsub/publish_spec.rb +21 -21
- data/spec/blather/stanza/pubsub/retract_spec.rb +20 -20
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +17 -17
- data/spec/blather/stanza/pubsub/subscription_spec.rb +28 -28
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +11 -11
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +22 -22
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +9 -9
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +9 -9
- data/spec/blather/stanza/pubsub_owner_spec.rb +6 -6
- data/spec/blather/stanza/pubsub_spec.rb +16 -16
- data/spec/blather/stanza/x_spec.rb +53 -53
- data/spec/blather/stanza_spec.rb +39 -39
- data/spec/blather/stream/client_spec.rb +133 -133
- data/spec/blather/stream/component_spec.rb +7 -7
- data/spec/blather/stream/parser_spec.rb +24 -24
- data/spec/blather/stream/ssl_spec.rb +7 -7
- data/spec/blather/xmpp_node_spec.rb +17 -7
- data/spec/blather_spec.rb +4 -4
- data/spec/spec_helper.rb +6 -54
- metadata +53 -68
- data/CHANGELOG +0 -220
@@ -2,79 +2,117 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Blather::Stanza::Presence do
|
4
4
|
it 'registers itself' do
|
5
|
-
Blather::XMPPNode.class_from_registration(:presence, nil).
|
5
|
+
Blather::XMPPNode.class_from_registration(:presence, nil).should == Blather::Stanza::Presence
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'must be importable' do
|
9
|
-
|
10
|
-
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence
|
9
|
+
Blather::XMPPNode.parse('<presence type="probe"/>').should be_instance_of Blather::Stanza::Presence
|
11
10
|
end
|
12
11
|
|
13
12
|
it 'ensures type is one of Blather::Stanza::Presence::VALID_TYPES' do
|
14
13
|
presence = Blather::Stanza::Presence.new
|
15
|
-
lambda { presence.type = :invalid_type_name }.
|
14
|
+
lambda { presence.type = :invalid_type_name }.should raise_error(Blather::ArgumentError)
|
16
15
|
|
17
16
|
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
|
18
17
|
presence.type = valid_type
|
19
|
-
presence.type.
|
18
|
+
presence.type.should == valid_type
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
Blather::Stanza::Presence::VALID_TYPES.each do |valid_type|
|
24
23
|
it "provides a helper (#{valid_type}?) for type #{valid_type}" do
|
25
|
-
Blather::Stanza::Presence.new.
|
24
|
+
Blather::Stanza::Presence.new.should respond_to :"#{valid_type}?"
|
26
25
|
end
|
27
26
|
|
28
27
|
it "returns true on call to (#{valid_type}?) if type == #{valid_type}" do
|
29
28
|
method = "#{valid_type}?".to_sym
|
30
29
|
pres = Blather::Stanza::Presence.new
|
31
30
|
pres.type = valid_type
|
32
|
-
pres.
|
33
|
-
pres.__send__(method).
|
31
|
+
pres.should respond_to method
|
32
|
+
pres.__send__(method).should == true
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
36
|
+
it 'creates a C object when importing a node with a c child' do
|
37
|
+
string = <<-XML
|
38
|
+
<presence from='bard@shakespeare.lit/globe'>
|
39
|
+
<c xmlns='http://jabber.org/protocol/caps'
|
40
|
+
hash='sha-1'
|
41
|
+
node='http://www.chatopus.com'
|
42
|
+
ver='zHyEOgxTrkpSdGcQKH8EFPLsriY='/>
|
43
|
+
</presence>
|
44
|
+
XML
|
45
|
+
s = Blather::Stanza::Presence.parse string
|
46
|
+
s.should be_kind_of Blather::Stanza::Presence::C::InstanceMethods
|
47
|
+
s.node.should == 'http://www.chatopus.com'
|
48
|
+
end
|
49
|
+
|
37
50
|
it 'creates a Status object when importing a node with type == nil' do
|
38
|
-
s = Blather::Stanza::Presence.
|
39
|
-
s.
|
40
|
-
s.state.
|
51
|
+
s = Blather::Stanza::Presence.parse('<presence/>')
|
52
|
+
s.should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
|
53
|
+
s.state.should == :available
|
41
54
|
end
|
42
55
|
|
43
56
|
it 'creates a Status object when importing a node with type == "unavailable"' do
|
44
|
-
s = Blather::Stanza::Presence.
|
45
|
-
s.
|
46
|
-
s.state.
|
57
|
+
s = Blather::Stanza::Presence.parse('<presence type="unavailable"/>')
|
58
|
+
s.should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
|
59
|
+
s.state.should == :unavailable
|
47
60
|
end
|
48
61
|
|
49
62
|
it 'creates a Subscription object when importing a node with type == "subscribe"' do
|
50
|
-
s = Blather::Stanza::Presence.
|
51
|
-
s.
|
52
|
-
s.type.
|
63
|
+
s = Blather::Stanza::Presence.parse('<presence type="subscribe"/>')
|
64
|
+
s.should be_kind_of Blather::Stanza::Presence::Subscription::InstanceMethods
|
65
|
+
s.type.should == :subscribe
|
53
66
|
end
|
54
67
|
|
55
68
|
it 'creates a MUC object when importing a node with a form in the MUC namespace' do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
s
|
69
|
+
string = <<-XML
|
70
|
+
<presence from='bard@shakespeare.lit/globe'>
|
71
|
+
<x xmlns='http://jabber.org/protocol/muc'/>
|
72
|
+
</presence>
|
73
|
+
XML
|
74
|
+
s = Blather::Stanza::Presence.parse string
|
75
|
+
s.should be_kind_of Blather::Stanza::Presence::MUC::InstanceMethods
|
62
76
|
end
|
63
77
|
|
64
78
|
it 'creates a MUCUser object when importing a node with a form in the MUC#user namespace' do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
s
|
79
|
+
string = <<-XML
|
80
|
+
<presence from='bard@shakespeare.lit/globe'>
|
81
|
+
<x xmlns='http://jabber.org/protocol/muc#user'/>
|
82
|
+
</presence>
|
83
|
+
XML
|
84
|
+
s = Blather::Stanza::Presence.parse string
|
85
|
+
s.should be_kind_of Blather::Stanza::Presence::MUCUser::InstanceMethods
|
71
86
|
end
|
72
87
|
|
73
88
|
it 'creates a Presence object when importing a node with type equal to something unknown' do
|
74
|
-
|
75
|
-
|
76
|
-
s
|
77
|
-
s.
|
78
|
-
|
89
|
+
string = "<presence from='bard@shakespeare.lit/globe' type='foo'/>"
|
90
|
+
s = Blather::Stanza::Presence.parse string
|
91
|
+
s.should be_kind_of Blather::Stanza::Presence
|
92
|
+
s.type.should == :foo
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'behaves like a C, a Status, and a MUCUser when all types of children are present' do
|
96
|
+
string = <<-XML
|
97
|
+
<presence from='bard@shakespeare.lit/globe'>
|
98
|
+
<show>chat</show>
|
99
|
+
<c xmlns='http://jabber.org/protocol/caps'
|
100
|
+
hash='sha-1'
|
101
|
+
node='http://www.chatopus.com'
|
102
|
+
ver='zHyEOgxTrkpSdGcQKH8EFPLsriY='/>
|
103
|
+
<x xmlns='http://jabber.org/protocol/muc#user'>
|
104
|
+
<item affiliation='none'
|
105
|
+
jid='hag66@shakespeare.lit/pda'
|
106
|
+
role='participant'/>
|
107
|
+
<status code='100'/>
|
108
|
+
<status code='110'/>
|
109
|
+
<password>foobar</password>
|
110
|
+
</x>
|
111
|
+
</presence>
|
112
|
+
XML
|
113
|
+
s = Blather::Stanza::Presence.parse string
|
114
|
+
s.state.should == :chat
|
115
|
+
s.node.should == 'http://www.chatopus.com'
|
116
|
+
s.role.should == :participant
|
79
117
|
end
|
80
118
|
end
|
@@ -11,47 +11,47 @@ end
|
|
11
11
|
|
12
12
|
describe Blather::Stanza::PubSub::Affiliations do
|
13
13
|
it 'registers itself' do
|
14
|
-
Blather::XMPPNode.class_from_registration(:affiliations, Blather::Stanza::PubSub.registered_ns).
|
14
|
+
Blather::XMPPNode.class_from_registration(:affiliations, Blather::Stanza::PubSub.registered_ns).should == Blather::Stanza::PubSub::Affiliations
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can be imported' do
|
18
|
-
Blather::XMPPNode.
|
18
|
+
Blather::XMPPNode.parse(affiliations_xml).should be_instance_of Blather::Stanza::PubSub::Affiliations
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'ensures an affiliations node is present on create' do
|
22
22
|
affiliations = Blather::Stanza::PubSub::Affiliations.new
|
23
|
-
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).
|
23
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'ensures an affiliations node exists when calling #affiliations' do
|
27
27
|
affiliations = Blather::Stanza::PubSub::Affiliations.new
|
28
28
|
affiliations.pubsub.remove_children :affiliations
|
29
|
-
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).
|
29
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should be_nil
|
30
30
|
|
31
|
-
affiliations.affiliations.
|
32
|
-
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).
|
31
|
+
affiliations.affiliations.should_not be_nil
|
32
|
+
affiliations.find_first('//ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_nil
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'defaults to a get node' do
|
36
|
-
Blather::Stanza::PubSub::Affiliations.new.type.
|
36
|
+
Blather::Stanza::PubSub::Affiliations.new.type.should == :get
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'sets the host if requested' do
|
40
40
|
aff = Blather::Stanza::PubSub::Affiliations.new :get, 'pubsub.jabber.local'
|
41
|
-
aff.to.
|
41
|
+
aff.to.should == Blather::JID.new('pubsub.jabber.local')
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'can import an affiliates result node' do
|
45
45
|
node = parse_stanza(affiliations_xml).root
|
46
46
|
|
47
47
|
affiliations = Blather::Stanza::PubSub::Affiliations.new.inherit node
|
48
|
-
affiliations.size.
|
49
|
-
affiliations.list.
|
48
|
+
affiliations.size.should == 5
|
49
|
+
affiliations.list.should == control_affiliations
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'will iterate over each affiliation' do
|
53
|
-
Blather::XMPPNode.
|
54
|
-
nodes.
|
53
|
+
Blather::XMPPNode.parse(affiliations_xml).each do |type, nodes|
|
54
|
+
nodes.should == control_affiliations[type]
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -3,11 +3,11 @@ require 'fixtures/pubsub'
|
|
3
3
|
|
4
4
|
describe Blather::Stanza::PubSub::Create do
|
5
5
|
it 'registers itself' do
|
6
|
-
Blather::XMPPNode.class_from_registration(:create, 'http://jabber.org/protocol/pubsub').
|
6
|
+
Blather::XMPPNode.class_from_registration(:create, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Create
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'can be imported' do
|
10
|
-
Blather::XMPPNode.
|
10
|
+
Blather::XMPPNode.parse(<<-NODE).should be_instance_of Blather::Stanza::PubSub::Create
|
11
11
|
<iq type='set'
|
12
12
|
from='hamlet@denmark.lit/elsinore'
|
13
13
|
to='pubsub.shakespeare.lit'
|
@@ -22,35 +22,35 @@ describe Blather::Stanza::PubSub::Create do
|
|
22
22
|
|
23
23
|
it 'ensures a create node is present on create' do
|
24
24
|
create = Blather::Stanza::PubSub::Create.new
|
25
|
-
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).
|
25
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'ensures a configure node is present on create' do
|
29
29
|
create = Blather::Stanza::PubSub::Create.new
|
30
|
-
create.find('//ns:pubsub/ns:configure', :ns => Blather::Stanza::PubSub.registered_ns).
|
30
|
+
create.find('//ns:pubsub/ns:configure', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'ensures a create node exists when calling #create_node' do
|
34
34
|
create = Blather::Stanza::PubSub::Create.new
|
35
35
|
create.pubsub.remove_children :create
|
36
|
-
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).
|
36
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
|
37
37
|
|
38
|
-
create.create_node.
|
39
|
-
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).
|
38
|
+
create.create_node.should_not be_nil
|
39
|
+
create.find('//ns:pubsub/ns:create', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'defaults to a set node' do
|
43
43
|
create = Blather::Stanza::PubSub::Create.new
|
44
|
-
create.type.
|
44
|
+
create.type.should == :set
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'sets the host if requested' do
|
48
48
|
create = Blather::Stanza::PubSub::Create.new :set, 'pubsub.jabber.local'
|
49
|
-
create.to.
|
49
|
+
create.to.should == Blather::JID.new('pubsub.jabber.local')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'sets the node' do
|
53
53
|
create = Blather::Stanza::PubSub::Create.new :set, 'host', 'node-name'
|
54
|
-
create.node.
|
54
|
+
create.node.should == 'node-name'
|
55
55
|
end
|
56
56
|
end
|
@@ -3,60 +3,60 @@ require 'fixtures/pubsub'
|
|
3
3
|
|
4
4
|
describe Blather::Stanza::PubSub::Event do
|
5
5
|
it 'registers itself' do
|
6
|
-
Blather::XMPPNode.class_from_registration(:event, 'http://jabber.org/protocol/pubsub#event').
|
6
|
+
Blather::XMPPNode.class_from_registration(:event, 'http://jabber.org/protocol/pubsub#event').should == Blather::Stanza::PubSub::Event
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'is importable' do
|
10
|
-
Blather::XMPPNode.
|
10
|
+
Blather::XMPPNode.parse(event_notification_xml).should be_instance_of Blather::Stanza::PubSub::Event
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'ensures a query node is present on create' do
|
14
14
|
evt = Blather::Stanza::PubSub::Event.new
|
15
|
-
evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).
|
15
|
+
evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'ensures an event node exists when calling #event_node' do
|
19
19
|
evt = Blather::Stanza::PubSub::Event.new
|
20
20
|
evt.remove_children :event
|
21
|
-
evt.find('*[local-name()="event"]').
|
21
|
+
evt.find('*[local-name()="event"]').should be_empty
|
22
22
|
|
23
|
-
evt.event_node.
|
24
|
-
evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).
|
23
|
+
evt.event_node.should_not be_nil
|
24
|
+
evt.find('ns:event', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'ensures an items node exists when calling #items_node' do
|
28
28
|
evt = Blather::Stanza::PubSub::Event.new
|
29
29
|
evt.remove_children :items
|
30
|
-
evt.find('*[local-name()="items"]').
|
30
|
+
evt.find('*[local-name()="items"]').should be_empty
|
31
31
|
|
32
|
-
evt.items_node.
|
33
|
-
evt.find('ns:event/ns:items', :ns => Blather::Stanza::PubSub::Event.registered_ns).
|
32
|
+
evt.items_node.should_not be_nil
|
33
|
+
evt.find('ns:event/ns:items', :ns => Blather::Stanza::PubSub::Event.registered_ns).should_not be_empty
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'knows the associated node name' do
|
37
|
-
evt = Blather::XMPPNode.
|
38
|
-
evt.node.
|
37
|
+
evt = Blather::XMPPNode.parse(event_with_payload_xml)
|
38
|
+
evt.node.should == 'princely_musings'
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'ensures newly inherited items are PubSubItem objects' do
|
42
|
-
evt = Blather::XMPPNode.
|
43
|
-
evt.items?.
|
44
|
-
evt.retractions?.
|
45
|
-
evt.items.map { |i| i.class }.uniq.
|
42
|
+
evt = Blather::XMPPNode.parse(event_with_payload_xml)
|
43
|
+
evt.items?.should == true
|
44
|
+
evt.retractions?.should == false
|
45
|
+
evt.items.map { |i| i.class }.uniq.should == [Blather::Stanza::PubSub::PubSubItem]
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'will iterate over each item' do
|
49
|
-
evt = Blather::XMPPNode.
|
50
|
-
evt.items.each { |i| i.class.
|
49
|
+
evt = Blather::XMPPNode.parse(event_with_payload_xml)
|
50
|
+
evt.items.each { |i| i.class.should == Blather::Stanza::PubSub::PubSubItem }
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'handles receiving subscription ids' do
|
54
|
-
evt = Blather::XMPPNode.
|
55
|
-
evt.subscription_ids.
|
54
|
+
evt = Blather::XMPPNode.parse(event_subids_xml)
|
55
|
+
evt.subscription_ids.should == ['123-abc', '004-yyy']
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'can have a list of retractions' do
|
59
|
-
evt = Blather::XMPPNode.
|
59
|
+
evt = Blather::XMPPNode.parse(<<-NODE)
|
60
60
|
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
|
61
61
|
<event xmlns='http://jabber.org/protocol/pubsub#event'>
|
62
62
|
<items node='princely_musings'>
|
@@ -65,34 +65,34 @@ describe Blather::Stanza::PubSub::Event do
|
|
65
65
|
</event>
|
66
66
|
</message>
|
67
67
|
NODE
|
68
|
-
evt.retractions?.
|
69
|
-
evt.items?.
|
70
|
-
evt.retractions.
|
68
|
+
evt.retractions?.should == true
|
69
|
+
evt.items?.should == false
|
70
|
+
evt.retractions.should == %w[ae890ac52d0df67ed7cfdf51b644e901]
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'can be a purge' do
|
74
|
-
evt = Blather::XMPPNode.
|
74
|
+
evt = Blather::XMPPNode.parse(<<-NODE)
|
75
75
|
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
|
76
76
|
<event xmlns='http://jabber.org/protocol/pubsub#event'>
|
77
77
|
<purge node='princely_musings'/>
|
78
78
|
</event>
|
79
79
|
</message>
|
80
80
|
NODE
|
81
|
-
evt.purge?.
|
82
|
-
evt.node.
|
81
|
+
evt.purge?.should_not be_nil
|
82
|
+
evt.node.should == 'princely_musings'
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'can be a subscription notification' do
|
86
|
-
evt = Blather::XMPPNode.
|
86
|
+
evt = Blather::XMPPNode.parse(<<-NODE)
|
87
87
|
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
|
88
88
|
<event xmlns='http://jabber.org/protocol/pubsub#event'>
|
89
89
|
<subscription jid='francisco@denmark.lit' subscription='subscribed' node='/example.com/test'/>
|
90
90
|
</event>
|
91
91
|
</message>
|
92
92
|
NODE
|
93
|
-
evt.subscription?.
|
94
|
-
evt.subscription[:jid].
|
95
|
-
evt.subscription[:subscription].
|
96
|
-
evt.subscription[:node].
|
93
|
+
evt.subscription?.should_not be_nil
|
94
|
+
evt.subscription[:jid].should == 'francisco@denmark.lit'
|
95
|
+
evt.subscription[:subscription].should == 'subscribed'
|
96
|
+
evt.subscription[:node].should == '/example.com/test'
|
97
97
|
end
|
98
98
|
end
|
@@ -3,43 +3,43 @@ require 'fixtures/pubsub'
|
|
3
3
|
|
4
4
|
describe Blather::Stanza::PubSub::Items do
|
5
5
|
it 'registers itself' do
|
6
|
-
Blather::XMPPNode.class_from_registration(:items, 'http://jabber.org/protocol/pubsub').
|
6
|
+
Blather::XMPPNode.class_from_registration(:items, 'http://jabber.org/protocol/pubsub').should == Blather::Stanza::PubSub::Items
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'can be imported' do
|
10
|
-
Blather::XMPPNode.
|
10
|
+
Blather::XMPPNode.parse(items_all_nodes_xml).should be_instance_of Blather::Stanza::PubSub::Items
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'ensures an items node is present on create' do
|
14
14
|
items = Blather::Stanza::PubSub::Items.new
|
15
|
-
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).
|
15
|
+
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'ensures an items node exists when calling #items' do
|
19
19
|
items = Blather::Stanza::PubSub::Items.new
|
20
20
|
items.pubsub.remove_children :items
|
21
|
-
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).
|
21
|
+
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should be_empty
|
22
22
|
|
23
|
-
items.items.
|
24
|
-
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).
|
23
|
+
items.items.should_not be_nil
|
24
|
+
items.find('//ns:pubsub/ns:items', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'defaults to a get node' do
|
28
28
|
aff = Blather::Stanza::PubSub::Items.new
|
29
|
-
aff.type.
|
29
|
+
aff.type.should == :get
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'ensures newly inherited items are PubSubItem objects' do
|
33
|
-
items = Blather::XMPPNode.
|
34
|
-
items.map { |i| i.class }.uniq.
|
33
|
+
items = Blather::XMPPNode.parse(items_all_nodes_xml)
|
34
|
+
items.map { |i| i.class }.uniq.should == [Blather::Stanza::PubSub::PubSubItem]
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'will iterate over each item' do
|
38
38
|
n = parse_stanza items_all_nodes_xml
|
39
39
|
items = Blather::Stanza::PubSub::Items.new.inherit n.root
|
40
40
|
count = 0
|
41
|
-
items.each { |i| i.
|
42
|
-
count.
|
41
|
+
items.each { |i| i.should be_instance_of Blather::Stanza::PubSub::PubSubItem; count += 1 }
|
42
|
+
count.should == 4
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'can create an items request node to request all items' do
|
@@ -47,9 +47,9 @@ describe Blather::Stanza::PubSub::Items do
|
|
47
47
|
node = 'princely_musings'
|
48
48
|
|
49
49
|
items = Blather::Stanza::PubSub::Items.request host, node
|
50
|
-
items.find("//ns:items[@node=\"#{node}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.
|
51
|
-
items.to.
|
52
|
-
items.node.
|
50
|
+
items.find("//ns:items[@node=\"#{node}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 1
|
51
|
+
items.to.should == Blather::JID.new(host)
|
52
|
+
items.node.should == node
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'can create an items request node to request some items' do
|
@@ -60,9 +60,9 @@ describe Blather::Stanza::PubSub::Items do
|
|
60
60
|
items_xpath = items.map { |i| "@id=\"#{i}\"" } * ' or '
|
61
61
|
|
62
62
|
items = Blather::Stanza::PubSub::Items.request host, node, items
|
63
|
-
items.find("//ns:items[@node=\"#{node}\"]/ns:item[#{items_xpath}]", :ns => Blather::Stanza::PubSub.registered_ns).size.
|
64
|
-
items.to.
|
65
|
-
items.node.
|
63
|
+
items.find("//ns:items[@node=\"#{node}\"]/ns:item[#{items_xpath}]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 2
|
64
|
+
items.to.should == Blather::JID.new(host)
|
65
|
+
items.node.should == node
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'can create an items request node to request "max_number" of items' do
|
@@ -71,9 +71,9 @@ describe Blather::Stanza::PubSub::Items do
|
|
71
71
|
max = 3
|
72
72
|
|
73
73
|
items = Blather::Stanza::PubSub::Items.request host, node, nil, max
|
74
|
-
items.find("//ns:pubsub/ns:items[@node=\"#{node}\" and @max_items=\"#{max}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.
|
75
|
-
items.to.
|
76
|
-
items.node.
|
77
|
-
items.max_items.
|
74
|
+
items.find("//ns:pubsub/ns:items[@node=\"#{node}\" and @max_items=\"#{max}\"]", :ns => Blather::Stanza::PubSub.registered_ns).size.should == 1
|
75
|
+
items.to.should == Blather::JID.new(host)
|
76
|
+
items.node.should == node
|
77
|
+
items.max_items.should == max
|
78
78
|
end
|
79
79
|
end
|