sprsquish-blather 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +41 -12
  3. data/examples/echo.rb +1 -1
  4. data/examples/execute.rb +0 -5
  5. data/examples/pubsub/cli.rb +64 -0
  6. data/examples/pubsub/ping_pong.rb +18 -0
  7. data/examples/rosterprint.rb +14 -0
  8. data/examples/xmpp4r/echo.rb +35 -0
  9. data/lib/blather/client/client.rb +19 -13
  10. data/lib/blather/client/dsl/pubsub.rb +133 -0
  11. data/lib/blather/client/dsl.rb +16 -0
  12. data/lib/blather/client.rb +1 -1
  13. data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
  14. data/lib/blather/core_ext/active_support.rb +1 -117
  15. data/lib/blather/core_ext/nokogiri.rb +35 -0
  16. data/lib/blather/errors/sasl_error.rb +3 -1
  17. data/lib/blather/errors/stanza_error.rb +10 -17
  18. data/lib/blather/errors/stream_error.rb +11 -14
  19. data/lib/blather/errors.rb +3 -20
  20. data/lib/blather/jid.rb +1 -0
  21. data/lib/blather/roster.rb +9 -0
  22. data/lib/blather/roster_item.rb +6 -1
  23. data/lib/blather/stanza/disco/disco_info.rb +45 -33
  24. data/lib/blather/stanza/disco/disco_items.rb +32 -21
  25. data/lib/blather/stanza/disco.rb +7 -1
  26. data/lib/blather/stanza/iq/query.rb +16 -8
  27. data/lib/blather/stanza/iq/roster.rb +33 -22
  28. data/lib/blather/stanza/iq.rb +13 -8
  29. data/lib/blather/stanza/message.rb +20 -31
  30. data/lib/blather/stanza/presence/status.rb +13 -21
  31. data/lib/blather/stanza/presence/subscription.rb +11 -16
  32. data/lib/blather/stanza/presence.rb +3 -5
  33. data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
  34. data/lib/blather/stanza/pubsub/create.rb +43 -0
  35. data/lib/blather/stanza/pubsub/errors.rb +9 -0
  36. data/lib/blather/stanza/pubsub/event.rb +77 -0
  37. data/lib/blather/stanza/pubsub/items.rb +63 -0
  38. data/lib/blather/stanza/pubsub/publish.rb +58 -0
  39. data/lib/blather/stanza/pubsub/retract.rb +53 -0
  40. data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
  41. data/lib/blather/stanza/pubsub/subscription.rb +66 -0
  42. data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
  43. data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
  44. data/lib/blather/stanza/pubsub.rb +63 -0
  45. data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
  46. data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
  47. data/lib/blather/stanza/pubsub_owner.rb +41 -0
  48. data/lib/blather/stanza.rb +35 -18
  49. data/lib/blather/stream/client.rb +1 -2
  50. data/lib/blather/stream/component.rb +9 -5
  51. data/lib/blather/stream/features/resource.rb +63 -0
  52. data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
  53. data/lib/blather/stream/features/session.rb +44 -0
  54. data/lib/blather/stream/features/tls.rb +28 -0
  55. data/lib/blather/stream/features.rb +53 -0
  56. data/lib/blather/stream/parser.rb +70 -46
  57. data/lib/blather/stream.rb +76 -168
  58. data/lib/blather/xmpp_node.rb +113 -52
  59. data/lib/blather.rb +35 -12
  60. data/spec/blather/client/client_spec.rb +44 -58
  61. data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
  62. data/spec/blather/client/dsl_spec.rb +19 -6
  63. data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
  64. data/spec/blather/errors/sasl_error_spec.rb +8 -8
  65. data/spec/blather/errors/stanza_error_spec.rb +25 -33
  66. data/spec/blather/errors/stream_error_spec.rb +21 -16
  67. data/spec/blather/errors_spec.rb +4 -11
  68. data/spec/blather/jid_spec.rb +31 -30
  69. data/spec/blather/roster_item_spec.rb +34 -23
  70. data/spec/blather/roster_spec.rb +27 -12
  71. data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
  72. data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
  73. data/spec/blather/stanza/iq/query_spec.rb +34 -11
  74. data/spec/blather/stanza/iq/roster_spec.rb +47 -30
  75. data/spec/blather/stanza/iq_spec.rb +19 -14
  76. data/spec/blather/stanza/message_spec.rb +30 -17
  77. data/spec/blather/stanza/presence/status_spec.rb +43 -20
  78. data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
  79. data/spec/blather/stanza/presence_spec.rb +34 -21
  80. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  81. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  82. data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
  83. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  84. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  85. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  86. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  87. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  88. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  89. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
  90. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  91. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  92. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  93. data/spec/blather/stanza/pubsub_spec.rb +62 -0
  94. data/spec/blather/stanza_spec.rb +53 -38
  95. data/spec/blather/stream/client_spec.rb +231 -88
  96. data/spec/blather/stream/component_spec.rb +14 -5
  97. data/spec/blather/stream/parser_spec.rb +145 -0
  98. data/spec/blather/xmpp_node_spec.rb +192 -96
  99. data/spec/fixtures/pubsub.rb +311 -0
  100. data/spec/spec_helper.rb +5 -4
  101. metadata +53 -17
  102. data/Rakefile +0 -139
  103. data/ext/extconf.rb +0 -65
  104. data/ext/push_parser.c +0 -209
  105. data/lib/blather/core_ext/libxml.rb +0 -28
  106. data/lib/blather/stream/resource.rb +0 -48
  107. data/lib/blather/stream/session.rb +0 -36
  108. data/lib/blather/stream/stream_handler.rb +0 -39
  109. data/lib/blather/stream/tls.rb +0 -33
  110. data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -1,47 +1,42 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
2
2
 
3
3
  def stanza_error_node(type = 'cancel', error = 'internal-server-error', msg = nil)
4
- node = Stanza::Message.new 'error@jabber.local', 'test message', :error
5
- XML::Document.new.root = node
4
+ node = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error
6
5
 
7
- error_node = XMPPNode.new('error')
6
+ node << (error_node = Blather::XMPPNode.new('error'))
8
7
  error_node['type'] = type.to_s
9
8
 
10
- err = XMPPNode.new(error)
9
+ error_node << (err = Blather::XMPPNode.new(error, error_node.document))
11
10
  err.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas'
12
- error_node << err
13
11
 
14
12
  if msg
15
- text = XMPPNode.new('text')
13
+ error_node << (text = Blather::XMPPNode.new('text', error_node.document))
16
14
  text.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas'
17
- text << msg
18
- error_node << text
15
+ text.content = msg
19
16
  end
20
17
 
21
- extra = XMPPNode.new('extra-error')
18
+ error_node << (extra = Blather::XMPPNode.new('extra-error', error_node.document))
22
19
  extra.namespace = 'blather:stanza:error'
23
- extra << 'Blather Error'
24
- error_node << extra
20
+ extra.content = 'Blather Error'
25
21
 
26
- node << error_node
27
22
  node
28
23
  end
29
24
 
30
- describe 'Blather::StanzaError' do
25
+ describe Blather::StanzaError do
31
26
  it 'can import a node' do
32
- StanzaError.must_respond_to :import
33
- e = StanzaError.import stanza_error_node
34
- e.must_be_kind_of StanzaError
27
+ Blather::StanzaError.must_respond_to :import
28
+ e = Blather::StanzaError.import stanza_error_node
29
+ e.must_be_kind_of Blather::StanzaError
35
30
  end
36
31
 
37
32
  describe 'valid types' do
38
- before { @original = Stanza::Message.new 'error@jabber.local', 'test message', :error }
33
+ before { @original = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error }
39
34
 
40
35
  it 'ensures type is one of Stanza::Message::VALID_TYPES' do
41
- lambda { StanzaError.new @original, :gone, :invalid_type_name }.must_raise(Blather::ArgumentError)
36
+ lambda { Blather::StanzaError.new @original, :gone, :invalid_type_name }.must_raise(Blather::ArgumentError)
42
37
 
43
- StanzaError::VALID_TYPES.each do |valid_type|
44
- msg = StanzaError.new @original, :gone, valid_type
38
+ Blather::StanzaError::VALID_TYPES.each do |valid_type|
39
+ msg = Blather::StanzaError.new @original, :gone, valid_type
45
40
  msg.type.must_equal valid_type
46
41
  end
47
42
  end
@@ -52,7 +47,7 @@ describe 'Blather::StanzaError' do
52
47
  @type = 'cancel'
53
48
  @err_name = 'internal-server-error'
54
49
  @msg = 'the server has experienced a misconfiguration'
55
- @err = StanzaError.import stanza_error_node(@type, @err_name, @msg)
50
+ @err = Blather::StanzaError.import stanza_error_node(@type, @err_name, @msg)
56
51
  end
57
52
 
58
53
  it 'provides a type attribute' do
@@ -72,7 +67,7 @@ describe 'Blather::StanzaError' do
72
67
 
73
68
  it 'provides a reader to the original node' do
74
69
  @err.must_respond_to :original
75
- @err.original.must_be_instance_of Stanza::Message
70
+ @err.original.must_be_instance_of Blather::Stanza::Message
76
71
  end
77
72
 
78
73
  it 'provides an extras attribute' do
@@ -91,14 +86,13 @@ describe 'Blather::StanzaError' do
91
86
 
92
87
  it 'can be turned into xml' do
93
88
  @err.must_respond_to :to_xml
94
- control = "<body>test message</body>\n<error>\n<internal-server-error xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>\n<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">the server has experienced a misconfiguration</text>\n<extra-error xmlns=\"blather:stanza:error\">Blather Error</extra-error>\n</error>\n</message>".split("\n")
95
- test = @err.to_xml.split("\n")
96
- test_msg = test.shift
97
- test.must_equal control
98
-
99
- test_msg.must_match(/<message[^>]*id="#{@err.original.id}"/)
100
- test_msg.must_match(/<message[^>]*from="error@jabber\.local"/)
101
- test_msg.must_match(/<message[^>]*type="error"/)
89
+ doc = parse_stanza @err.to_xml
90
+
91
+ doc.xpath("/message[@from='error@jabber.local' and @type='error']").wont_be_empty
92
+ doc.xpath("/message/error").wont_be_empty
93
+ doc.xpath("/message/error/err_ns:internal-server-error", :err_ns => Blather::StanzaError::STANZA_ERR_NS).wont_be_empty
94
+ doc.xpath("/message/error/err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StanzaError::STANZA_ERR_NS).wont_be_empty
95
+ doc.xpath("/message/error/extra_ns:extra-error[.='Blather Error']", :extra_ns => 'blather:stanza:error').wont_be_empty
102
96
  end
103
97
  end
104
98
 
@@ -127,11 +121,9 @@ describe 'Blather::StanzaError' do
127
121
  unexpected-request
128
122
  ].each do |error_type|
129
123
  it "handles the name for #{error_type}" do
130
- e = StanzaError.import stanza_error_node(:cancel, error_type)
124
+ e = Blather::StanzaError.import stanza_error_node(:cancel, error_type)
131
125
  e.name.must_equal error_type.gsub('-','_').to_sym
132
126
  end
133
127
  end
134
128
  end
135
129
  end
136
-
137
-
@@ -1,33 +1,35 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
2
2
 
3
3
  def stream_error_node(error = 'internal-server-error', msg = nil)
4
- node = XMPPNode.new('stream:error')
5
- XML::Document.new.root = node
4
+ node = Blather::XMPPNode.new('error')
5
+ node.namespace = {'stream' => Blather::Stream::STREAM_NS}
6
6
 
7
- err = XMPPNode.new(error)
7
+ node << (err = Blather::XMPPNode.new(error, node.document))
8
8
  err.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
9
- node << err
10
9
 
11
10
  if msg
12
- text = XMPPNode.new('text')
11
+ node << (text = Blather::XMPPNode.new('text', node.document))
13
12
  text.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
14
- text << msg
15
- node << text
13
+ text.content = msg
16
14
  end
17
15
 
18
- extra = XMPPNode.new('extra-error')
16
+ node << (extra = Blather::XMPPNode.new('extra-error', node.document))
19
17
  extra.namespace = 'blather:stream:error'
20
- extra << 'Blather Error'
18
+ extra.content = 'Blather Error'
21
19
 
22
- node << extra
23
20
  node
24
21
  end
25
22
 
26
23
  describe 'Blather::StreamError' do
27
24
  it 'can import a node' do
28
- StreamError.must_respond_to :import
29
- e = StreamError.import stream_error_node
30
- e.must_be_kind_of StreamError
25
+ err = stream_error_node 'internal-server-error', 'the message'
26
+ Blather::StreamError.must_respond_to :import
27
+ e = Blather::StreamError.import err
28
+ e.must_be_kind_of Blather::StreamError
29
+
30
+ e.name.must_equal :internal_server_error
31
+ e.text.must_equal 'the message'
32
+ e.extras.must_equal err.find('descendant::*[name()="extra-error"]', 'blather:stream:error').map {|n|n}
31
33
  end
32
34
  end
33
35
 
@@ -35,7 +37,7 @@ describe 'Blather::StreamError when instantiated' do
35
37
  before do
36
38
  @err_name = 'internal-server-error'
37
39
  @msg = 'the server has experienced a misconfiguration'
38
- @err = StreamError.import stream_error_node(@err_name, @msg)
40
+ @err = Blather::StreamError.import stream_error_node(@err_name, @msg)
39
41
  end
40
42
 
41
43
  it 'provides a err_name attribute' do
@@ -65,7 +67,10 @@ describe 'Blather::StreamError when instantiated' do
65
67
 
66
68
  it 'can be turned into xml' do
67
69
  @err.must_respond_to :to_xml
68
- @err.to_xml.must_equal "<stream:error>\n<internal-server-error xmlns=\"urn:ietf:params:xml:ns:xmpp-streams\"/>\n<text xmlns=\"urn:ietf:params:xml:ns:xmpp-streams\">the server has experienced a misconfiguration</text>\n<extra-error xmlns=\"blather:stream:error\">Blather Error</extra-error>\n</stream:error>"
70
+ doc = parse_stanza @err.to_xml
71
+ doc.xpath("//err_ns:internal-server-error", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
72
+ doc.xpath("//err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
73
+ doc.xpath("//err_ns:extra-error[.='Blather Error']", :err_ns => 'blather:stream:error').wont_be_empty
69
74
  end
70
75
  end
71
76
 
@@ -96,7 +101,7 @@ describe 'Each XMPP stream error type' do
96
101
  xml-not-well-formed
97
102
  ].each do |error_type|
98
103
  it "handles the name for #{error_type}" do
99
- e = StreamError.import stream_error_node(error_type)
104
+ e = Blather::StreamError.import stream_error_node(error_type)
100
105
  e.name.must_equal error_type.gsub('-','_').to_sym
101
106
  end
102
107
  end
@@ -1,13 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
- describe 'Blather::BlatherError' do
3
+ describe Blather::BlatherError do
4
4
  it 'is handled by :error' do
5
- BlatherError.new.handler_heirarchy.must_equal [:error]
5
+ Blather::BlatherError.new.handler_heirarchy.must_equal [:error]
6
6
  end
7
7
  end
8
8
 
9
9
  describe 'Blather::ParseError' do
10
- before { @error = ParseError.new('</generate-parse-error>"') }
10
+ before { @error = Blather::ParseError.new('</generate-parse-error>"') }
11
11
 
12
12
  it 'is registers with the handler heirarchy' do
13
13
  @error.handler_heirarchy.must_equal [:parse_error, :error]
@@ -19,14 +19,8 @@ describe 'Blather::ParseError' do
19
19
  end
20
20
  end
21
21
 
22
- describe 'Blather::TLSFailure' do
23
- it 'is registers with the handler heirarchy' do
24
- TLSFailure.new.handler_heirarchy.must_equal [:tls_failure, :error]
25
- end
26
- end
27
-
28
22
  describe 'Blather::UnknownResponse' do
29
- before { @error = UnknownResponse.new(XMPPNode.new('foo-bar')) }
23
+ before { @error = Blather::UnknownResponse.new(Blather::XMPPNode.new('foo-bar')) }
30
24
 
31
25
  it 'is registers with the handler heirarchy' do
32
26
  @error.handler_heirarchy.must_equal [:unknown_response_error, :error]
@@ -37,4 +31,3 @@ describe 'Blather::UnknownResponse' do
37
31
  @error.node.element_name.must_equal 'foo-bar'
38
32
  end
39
33
  end
40
-
@@ -1,83 +1,84 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
- describe 'Blather::JID' do
4
- it 'does nothing if creaded from JID' do
5
- jid = JID.new 'n@d/r'
6
- JID.new(jid).object_id.must_equal jid.object_id
3
+ describe Blather::JID do
4
+ it 'does nothing if creaded from Blather::JID' do
5
+ jid = Blather::JID.new 'n@d/r'
6
+ Blather::JID.new(jid).object_id.must_equal jid.object_id
7
7
  end
8
8
 
9
- it 'creates a new JID from (n,d,r)' do
10
- jid = JID.new('n', 'd', 'r')
9
+ it 'creates a new Blather::JID from (n,d,r)' do
10
+ jid = Blather::JID.new('n', 'd', 'r')
11
11
  jid.node.must_equal 'n'
12
12
  jid.domain.must_equal 'd'
13
13
  jid.resource.must_equal 'r'
14
14
  end
15
15
 
16
- it 'creates a new JID from (n,d)' do
17
- jid = JID.new('n', 'd')
16
+ it 'creates a new Blather::JID from (n,d)' do
17
+ jid = Blather::JID.new('n', 'd')
18
18
  jid.node.must_equal 'n'
19
19
  jid.domain.must_equal 'd'
20
20
  end
21
21
 
22
- it 'creates a new JID from (n@d)' do
23
- jid = JID.new('n@d')
22
+ it 'creates a new Blather::JID from (n@d)' do
23
+ jid = Blather::JID.new('n@d')
24
24
  jid.node.must_equal 'n'
25
25
  jid.domain.must_equal 'd'
26
26
  end
27
27
 
28
- it 'creates a new JID from (n@d/r)' do
29
- jid = JID.new('n@d/r')
28
+ it 'creates a new Blather::JID from (n@d/r)' do
29
+ jid = Blather::JID.new('n@d/r')
30
30
  jid.node.must_equal 'n'
31
31
  jid.domain.must_equal 'd'
32
32
  jid.resource.must_equal 'r'
33
33
  end
34
34
 
35
35
  it 'requires at least a node' do
36
- proc { JID.new }.must_raise ArgumentError
36
+ proc { Blather::JID.new }.must_raise ::ArgumentError
37
37
  end
38
38
 
39
39
  it 'ensures length of node is no more than 1023 characters' do
40
- proc { JID.new('n'*1024) }.must_raise Blather::ArgumentError
40
+ proc { Blather::JID.new('n'*1024) }.must_raise Blather::ArgumentError
41
41
  end
42
42
 
43
43
  it 'ensures length of domain is no more than 1023 characters' do
44
- proc { JID.new('n', 'd'*1024) }.must_raise Blather::ArgumentError
44
+ proc { Blather::JID.new('n', 'd'*1024) }.must_raise Blather::ArgumentError
45
45
  end
46
46
 
47
47
  it 'ensures length of resource is no more than 1023 characters' do
48
- proc { JID.new('n', 'd', 'r'*1024) }.must_raise Blather::ArgumentError
48
+ proc { Blather::JID.new('n', 'd', 'r'*1024) }.must_raise Blather::ArgumentError
49
49
  end
50
50
 
51
- it 'compares JIDs' do
52
- (JID.new('a@b/c') <=> JID.new('d@e/f')).must_equal -1
53
- (JID.new('a@b/c') <=> JID.new('a@b/c')).must_equal 0
54
- (JID.new('d@e/f') <=> JID.new('a@b/c')).must_equal 1
51
+ it 'compares Blather::JIDs' do
52
+ (Blather::JID.new('a@b/c') <=> Blather::JID.new('d@e/f')).must_equal -1
53
+ (Blather::JID.new('a@b/c') <=> Blather::JID.new('a@b/c')).must_equal 0
54
+ (Blather::JID.new('d@e/f') <=> Blather::JID.new('a@b/c')).must_equal 1
55
55
  end
56
56
 
57
57
  it 'checks for equality' do
58
- (JID.new('n@d/r') == JID.new('n@d/r')).must_equal true
58
+ (Blather::JID.new('n@d/r') == Blather::JID.new('n@d/r')).must_equal true
59
+ Blather::JID.new('n@d/r').eql?(Blather::JID.new('n@d/r')).must_equal true
59
60
  end
60
61
 
61
62
  it 'will strip' do
62
- jid = JID.new('n@d/r')
63
- jid.stripped.must_equal JID.new('n@d')
64
- jid.must_equal JID.new('n@d/r')
63
+ jid = Blather::JID.new('n@d/r')
64
+ jid.stripped.must_equal Blather::JID.new('n@d')
65
+ jid.must_equal Blather::JID.new('n@d/r')
65
66
  end
66
67
 
67
68
  it 'will strip itself' do
68
- jid = JID.new('n@d/r')
69
+ jid = Blather::JID.new('n@d/r')
69
70
  jid.strip!
70
- jid.must_equal JID.new('n@d')
71
+ jid.must_equal Blather::JID.new('n@d')
71
72
  end
72
73
 
73
74
  it 'has a string representation' do
74
- JID.new('n@d/r').to_s.must_equal 'n@d/r'
75
- JID.new('n', 'd', 'r').to_s.must_equal 'n@d/r'
76
- JID.new('n', 'd').to_s.must_equal 'n@d'
75
+ Blather::JID.new('n@d/r').to_s.must_equal 'n@d/r'
76
+ Blather::JID.new('n', 'd', 'r').to_s.must_equal 'n@d/r'
77
+ Blather::JID.new('n', 'd').to_s.must_equal 'n@d'
77
78
  end
78
79
 
79
80
  it 'provides a #stripped? helper' do
80
- jid = JID.new 'a@b/c'
81
+ jid = Blather::JID.new 'a@b/c'
81
82
  jid.must_respond_to :stripped?
82
83
  jid.stripped?.wont_equal true
83
84
  jid.strip!
@@ -1,54 +1,65 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
- describe 'Blather::RosterItem' do
4
- it 'initializes with JID' do
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 'initializes with an Iq::RosterItem' do
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 'has a JID setter that strips the JID' do
17
- jid = JID.new('n@d/r')
18
- i = RosterItem.new nil
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
@@ -1,15 +1,15 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
- describe 'Blather::Roster' do
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