jubjub 0.0.1

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.
@@ -0,0 +1,115 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
6
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3cpresence%20to%3d%22test_1%40conference.theo-template.local%2fnick%22%3e%0a%20%20%3cx%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%22%2f%3e%0a%3c%2fpresence%3e%0a
7
+ headers:
8
+ content-type:
9
+ - application/x-www-form-urlencoded
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: ...
14
+ headers:
15
+ content-type:
16
+ - application/xml
17
+ content-length:
18
+ - "40"
19
+ body: |
20
+ #<EventMachine::Timer:0x00000101149900>
21
+
22
+ http_version: "1.1"
23
+ - !ruby/struct:VCR::HTTPInteraction
24
+ request: !ruby/struct:VCR::Request
25
+ method: :post
26
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
27
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22set%22%20to%3d%22test_1%40conference.theo-template.local%22%3e%0a%20%20%3cquery%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%23owner%22%3e%0a%20%20%20%20%3cx%20xmlns%3d%22jabber%3ax%3adata%22%20type%3d%22submit%22%2f%3e%0a%20%20%3c%2fquery%3e%0a%3c%2fiq%3e%0a
28
+ headers:
29
+ content-type:
30
+ - application/x-www-form-urlencoded
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: ...
35
+ headers:
36
+ content-type:
37
+ - application/xml
38
+ content-length:
39
+ - "206"
40
+ body: |
41
+ <iq type="result" id="blather002b" from="test_1@conference.theo-template.local" to="theozaurus@theo-template.local/34112166161296558195646897">
42
+ <query xmlns="http://jabber.org/protocol/muc#owner"/>
43
+ </iq>
44
+
45
+ http_version: "1.1"
46
+ - !ruby/struct:VCR::HTTPInteraction
47
+ request: !ruby/struct:VCR::Request
48
+ method: :post
49
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
50
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3cpresence%20to%3d%22test_2%40conference.theo-template.local%2fnick%22%3e%0a%20%20%3cx%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%22%2f%3e%0a%3c%2fpresence%3e%0a
51
+ headers:
52
+ content-type:
53
+ - application/x-www-form-urlencoded
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: ...
58
+ headers:
59
+ content-type:
60
+ - application/xml
61
+ content-length:
62
+ - "40"
63
+ body: |
64
+ #<EventMachine::Timer:0x00000101123cc8>
65
+
66
+ http_version: "1.1"
67
+ - !ruby/struct:VCR::HTTPInteraction
68
+ request: !ruby/struct:VCR::Request
69
+ method: :post
70
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
71
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22set%22%20to%3d%22test_2%40conference.theo-template.local%22%3e%0a%20%20%3cquery%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%23owner%22%3e%0a%20%20%20%20%3cx%20xmlns%3d%22jabber%3ax%3adata%22%20type%3d%22submit%22%2f%3e%0a%20%20%3c%2fquery%3e%0a%3c%2fiq%3e%0a
72
+ headers:
73
+ content-type:
74
+ - application/x-www-form-urlencoded
75
+ response: !ruby/struct:VCR::Response
76
+ status: !ruby/struct:VCR::ResponseStatus
77
+ code: 200
78
+ message: ...
79
+ headers:
80
+ content-type:
81
+ - application/xml
82
+ content-length:
83
+ - "206"
84
+ body: |
85
+ <iq type="result" id="blather002d" from="test_2@conference.theo-template.local" to="theozaurus@theo-template.local/34112166161296558195646897">
86
+ <query xmlns="http://jabber.org/protocol/muc#owner"/>
87
+ </iq>
88
+
89
+ http_version: "1.1"
90
+ - !ruby/struct:VCR::HTTPInteraction
91
+ request: !ruby/struct:VCR::Request
92
+ method: :post
93
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
94
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22get%22%20to%3d%22conference.theo-template.local%22%3e%0a%20%20%3cquery%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fdisco%23items%22%2f%3e%0a%3c%2fiq%3e%0a
95
+ headers:
96
+ content-type:
97
+ - application/x-www-form-urlencoded
98
+ response: !ruby/struct:VCR::Response
99
+ status: !ruby/struct:VCR::ResponseStatus
100
+ code: 200
101
+ message: ...
102
+ headers:
103
+ content-type:
104
+ - application/xml
105
+ content-length:
106
+ - "359"
107
+ body: |
108
+ <iq type="result" id="blather002f" from="conference.theo-template.local" to="theozaurus@theo-template.local/34112166161296558195646897">
109
+ <query xmlns="http://jabber.org/protocol/disco#items">
110
+ <item jid="test_1@conference.theo-template.local" name="test_1 (1)"/>
111
+ <item jid="test_2@conference.theo-template.local" name="test_2 (1)"/>
112
+ </query>
113
+ </iq>
114
+
115
+ http_version: "1.1"
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ class User
4
+ include Jubjub::User
5
+ end
6
+
7
+ describe Jubjub::User do
8
+
9
+ describe 'class method' do
10
+
11
+ describe 'jubjub' do
12
+
13
+ it 'should require :jid option' do
14
+ expect {
15
+ User.instance_eval{ jubjub_client :password => :foo }
16
+ }.to raise_error(
17
+ Jubjub::ArgumentError,
18
+ 'missing :jid option'
19
+ )
20
+ end
21
+
22
+ it 'should require :password option' do
23
+ expect {
24
+ User.instance_eval{ jubjub_client :jid => :foo }
25
+ }.to raise_error(
26
+ Jubjub::ArgumentError,
27
+ 'missing :password option'
28
+ )
29
+ end
30
+
31
+ it 'should setup jubjub_jid' do
32
+ User.instance_eval{ jubjub_client :jid => :foo, :password => :bar }
33
+
34
+ u = User.new
35
+ u.stub(:foo).and_return('hello@jiggery')
36
+
37
+ u.jubjub_jid.should be_kind_of(Jubjub::Jid)
38
+ u.jubjub_jid.to_s.should eql('hello@jiggery')
39
+ end
40
+
41
+ it 'should setup jubjub_password' do
42
+ User.instance_eval{ jubjub_client :jid => :foo, :password => :bar }
43
+
44
+ u = User.new
45
+ u.stub(:bar).and_return('secr3t')
46
+
47
+ u.jubjub_password.should eql('secr3t')
48
+ end
49
+
50
+ describe 'connection settings' do
51
+ it 'should use sensible defaults' do
52
+ User.instance_eval{ jubjub_client :jid => :jid, :password => :password }
53
+
54
+ u = User.new
55
+ u.jubjub_connection_settings.should eql( :host => '127.0.0.1', :port => '8000' )
56
+ end
57
+
58
+ it 'should have :host overrideable' do
59
+ User.instance_eval{ jubjub_client :jid => :jid, :password => :password, :connection_settings => {:host => '192.168.1.1'} }
60
+
61
+ u = User.new
62
+ u.jubjub_connection_settings.should eql( :host => '192.168.1.1', :port => '8000' )
63
+ end
64
+
65
+ it 'should have :port overrideable' do
66
+ User.instance_eval{ jubjub_client :jid => :jid, :password => :password, :connection_settings => {:port => '7000'} }
67
+
68
+ u = User.new
69
+ u.jubjub_connection_settings.should eql( :host => '127.0.0.1', :port => '7000' )
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ describe 'instance method' do
78
+ def mock_jubjub_connection
79
+ @jubjub_connection = mock
80
+ @user.stub(:jubjub_connection).and_return(@jubjub_connection)
81
+ end
82
+
83
+ before do
84
+ User.instance_eval{ jubjub_client :jid => :jid, :password => :password }
85
+
86
+ @user = User.new
87
+ @user.stub(:jid).and_return('theozaurus@biggles.com')
88
+ @user.stub(:password).and_return('123')
89
+ end
90
+
91
+ describe 'jubjub_connection' do
92
+ it 'should return Jubjub::Connection::XmppGateway instance' do
93
+ @user.jubjub_connection.should be_kind_of(Jubjub::Connection::XmppGateway)
94
+ end
95
+
96
+ it 'should call Jubjub::Connection::XmppGateway with correct options' do
97
+ @user.stub(:jubjub_jid).and_return('theozaurus@biggles.com')
98
+ @user.stub(:jubjub_password).and_return('123')
99
+ @user.stub(:jubjub_connection_settings).and_return(:host => 'zippy', :port => '1234')
100
+
101
+ Jubjub::Connection::XmppGateway.should_receive(:new).with('theozaurus@biggles.com', '123', {:host => 'zippy', :port => '1234'} )
102
+
103
+ @user.jubjub_connection
104
+ end
105
+ end
106
+
107
+ describe 'authenticated?' do
108
+ before do
109
+ mock_jubjub_connection
110
+ end
111
+
112
+ it 'should call authenticated on jubjub_connection' do
113
+ @jubjub_connection.should_receive(:authenticated?)
114
+
115
+ @user.authenticated?
116
+ end
117
+ end
118
+
119
+ describe 'mucs' do
120
+ before do
121
+ mock_jubjub_connection
122
+ end
123
+
124
+ it 'should return Jubjub::MucCollection for conference.biggles.com when no service specified' do
125
+ @user.mucs.should be_a Jubjub::MucCollection
126
+ @user.mucs.jid.should == Jubjub::Jid.new('conference.biggles.com')
127
+ end
128
+
129
+ it 'should return Jubjub::MucCollection for service when specified' do
130
+ @user.mucs('wibble.com').should be_a Jubjub::MucCollection
131
+ @user.mucs('wibble.com').jid.should == Jubjub::Jid.new('wibble.com')
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::Jid do
4
+
5
+ describe "creating" do
6
+
7
+ describe "from a string" do
8
+
9
+ it("should understand 'foo.bar'") do
10
+ j = Jubjub::Jid.new('foo.bar')
11
+
12
+ j.node.should be_nil
13
+ j.domain.should eql('foo.bar')
14
+ j.resource.should be_nil
15
+ end
16
+
17
+ it("should understand 'bob@foo.bar'") do
18
+ j = Jubjub::Jid.new('bob@foo.bar')
19
+
20
+ j.node.should eql('bob')
21
+ j.domain.should eql('foo.bar')
22
+ j.resource.should be_nil
23
+ end
24
+
25
+ it("should understand 'bob@foo.bar/wibble'") do
26
+ j = Jubjub::Jid.new('bob@foo.bar/wibble')
27
+
28
+ j.node.should eql('bob')
29
+ j.domain.should eql('foo.bar')
30
+ j.resource.should eql('wibble')
31
+ end
32
+
33
+ end
34
+
35
+ describe "from components" do
36
+
37
+ it("should understand nil, 'foo.bar', nil") do
38
+ j = Jubjub::Jid.new(nil, 'foo.bar', nil)
39
+
40
+ j.node.should be_nil
41
+ j.domain.should eql('foo.bar')
42
+ j.resource.should be_nil
43
+ end
44
+
45
+ it("should understand 'bob', 'foo.bar', nil") do
46
+ j = Jubjub::Jid.new('bob','foo.bar',nil)
47
+
48
+ j.node.should eql('bob')
49
+ j.domain.should eql('foo.bar')
50
+ j.resource.should be_nil
51
+ end
52
+
53
+ it("should understand 'bob','foo.bar','wibble'") do
54
+ j = Jubjub::Jid.new('bob','foo.bar','wibble')
55
+
56
+ j.node.should eql('bob')
57
+ j.domain.should eql('foo.bar')
58
+ j.resource.should eql('wibble')
59
+ end
60
+
61
+ end
62
+
63
+ describe "from a Jubjub::Jid" do
64
+ it("should understand Jid.new('foo.bar')") do
65
+ j = Jubjub::Jid.new( Jubjub::Jid.new('foo.bar') )
66
+
67
+ j.node.should be_nil
68
+ j.domain.should eql('foo.bar')
69
+ j.resource.should be_nil
70
+ end
71
+
72
+ it("should understand Jid.new('bob@foo.bar')") do
73
+ j = Jubjub::Jid.new( Jubjub::Jid.new('bob@foo.bar') )
74
+
75
+ j.node.should eql('bob')
76
+ j.domain.should eql('foo.bar')
77
+ j.resource.should be_nil
78
+ end
79
+
80
+ it("should understand Jid.new('bob@foo.bar/wibble')") do
81
+ j = Jubjub::Jid.new( Jubjub::Jid.new('bob@foo.bar/wibble') )
82
+
83
+ j.node.should eql('bob')
84
+ j.domain.should eql('foo.bar')
85
+ j.resource.should eql('wibble')
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ describe "instance method" do
92
+
93
+ describe "to_s" do
94
+
95
+ it "should support just a domain" do
96
+ j = Jubjub::Jid.new nil, 'biggles.com'
97
+
98
+ j.to_s.should eql('biggles.com')
99
+ end
100
+
101
+ it "should support a node and a domain" do
102
+ j = Jubjub::Jid.new 'theozaurus', 'biggles.com'
103
+
104
+ j.to_s.should eql('theozaurus@biggles.com')
105
+ end
106
+
107
+ it "should support a node, domain and resource" do
108
+ j = Jubjub::Jid.new 'theozaurus', 'biggles.com', 'rocket'
109
+
110
+ j.to_s.should eql('theozaurus@biggles.com/rocket')
111
+ end
112
+
113
+ it "should support a domain and resource" do
114
+ j = Jubjub::Jid.new nil, 'biggles.com', 'bingo'
115
+
116
+ j.to_s.should eql('biggles.com/bingo')
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::MucCollection do
4
+
5
+ describe "instance methods" do
6
+
7
+ describe "create" do
8
+
9
+ before do
10
+ @mock_connection = mock
11
+ @mock_connection.stub(:jid).and_return( Jubjub::Jid.new 'admin@foo.com' )
12
+ @mock_connection.stub_chain :muc, :create
13
+ end
14
+
15
+ it "should call muc.create on connection" do
16
+ @mock_connection.muc.should_receive(:create).with( Jubjub::Jid.new 'hello@conference.foo.com/admin' )
17
+
18
+ Jubjub::MucCollection.new("conference.foo.com", @mock_connection).create("hello")
19
+ end
20
+
21
+ it "should yield a MucConfiguration if a block is given" do
22
+ @config = Jubjub::MucConfiguration.new( "allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
23
+
24
+ @mock_connection.muc.should_receive( :configuration ).with( Jubjub::Jid.new( 'hello@conference.foo.com/admin' )).and_return( @config )
25
+ @mock_connection.muc.should_receive( :create ).with( Jubjub::Jid.new( 'hello@conference.foo.com/admin' ), @config )
26
+
27
+ Jubjub::MucCollection.new("conference.foo.com", @mock_connection).create("hello"){|config|
28
+ config.should == @config
29
+ }
30
+ end
31
+
32
+ end
33
+
34
+ describe "jid" do
35
+ it "should return the jid" do
36
+ Jubjub::MucCollection.new("conference.foo.com", mock).jid.should == Jubjub::Jid.new("conference.foo.com")
37
+ end
38
+ end
39
+
40
+ describe "that are proxied like" do
41
+
42
+ before do
43
+ @mock_connection = mock
44
+ @rooms = [
45
+ Jubjub::Muc.new('room_1', nil, @mock_connection),
46
+ Jubjub::Muc.new('room_2', nil, @mock_connection)
47
+ ]
48
+ @mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
49
+ end
50
+
51
+ describe "inspect" do
52
+
53
+ it "should show the list of rooms, not MucCollection" do
54
+ Jubjub::MucCollection.new('conference.foo.com', @mock_connection).inspect.should eql(@rooms.inspect)
55
+ end
56
+
57
+ end
58
+
59
+ describe "map" do
60
+
61
+ it "should pass the block to the rooms" do
62
+ c = Jubjub::MucCollection.new('conference.foo.com', @mock_connection)
63
+ c.map{|r| r.jid.to_s }.should eql(['room_1', 'room_2'])
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end