jubjub 0.0.7 → 0.0.8
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/README.mdown +27 -1
- data/lib/jubjub.rb +1 -1
- data/lib/jubjub/connection/xmpp_gateway.rb +9 -9
- data/lib/jubjub/connection/xmpp_gateway/helper.rb +5 -5
- data/lib/jubjub/connection/xmpp_gateway/muc.rb +127 -32
- data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +64 -64
- data/lib/jubjub/data_form.rb +16 -13
- data/lib/jubjub/errors.rb +2 -2
- data/lib/jubjub/helpers.rb +32 -0
- data/lib/jubjub/jid.rb +8 -8
- data/lib/jubjub/muc.rb +3 -1
- data/lib/jubjub/muc/affiliation.rb +77 -0
- data/lib/jubjub/muc/affiliations_collection.rb +31 -0
- data/lib/jubjub/muc/collection.rb +12 -19
- data/lib/jubjub/muc/configuration.rb +2 -2
- data/lib/jubjub/muc/muc.rb +24 -11
- data/lib/jubjub/pubsub.rb +1 -1
- data/lib/jubjub/pubsub/affiliation.rb +20 -20
- data/lib/jubjub/pubsub/affiliation_collection.rb +11 -18
- data/lib/jubjub/pubsub/collection.rb +14 -21
- data/lib/jubjub/pubsub/configuration.rb +2 -2
- data/lib/jubjub/pubsub/item.rb +8 -8
- data/lib/jubjub/pubsub/item_collection.rb +10 -17
- data/lib/jubjub/pubsub/pubsub.rb +17 -17
- data/lib/jubjub/pubsub/subscription.rb +6 -6
- data/lib/jubjub/response.rb +1 -1
- data/lib/jubjub/response/error.rb +6 -6
- data/lib/jubjub/response/proxy.rb +8 -8
- data/lib/jubjub/response/response.rb +10 -10
- data/lib/jubjub/user.rb +16 -15
- data/spec/connection/xmpp_gateway_muc_spec.rb +174 -40
- data/spec/connection/xmpp_gateway_pubsub_spec.rb +100 -104
- data/spec/fixtures/vcr_cassettes/muc_configuration.yml +73 -6
- data/spec/fixtures/vcr_cassettes/muc_create_with_configuration.yml +8 -8
- data/spec/fixtures/vcr_cassettes/muc_message.yml +89 -0
- data/spec/fixtures/vcr_cassettes/muc_modify_affiliations.yml +367 -0
- data/spec/fixtures/vcr_cassettes/muc_retrieve_affiliations.yml +93 -0
- data/spec/fixtures/vcr_cassettes/pubsub_publish_with_dataform_payload.yml +3 -3
- data/spec/fixtures/vcr_cassettes/pubsub_retrieve_items.yml +24 -18
- data/spec/mixins/user_spec.rb +37 -37
- data/spec/models/data_form_spec.rb +3 -3
- data/spec/models/jid_spec.rb +41 -41
- data/spec/models/muc_affiliation_collection_spec.rb +146 -0
- data/spec/models/muc_affiliation_spec.rb +215 -0
- data/spec/models/muc_collection_spec.rb +64 -32
- data/spec/models/muc_configuration_spec.rb +3 -3
- data/spec/models/muc_spec.rb +44 -23
- data/spec/models/pubsub_affiliation_collection_spec.rb +65 -30
- data/spec/models/pubsub_affiliation_spec.rb +50 -50
- data/spec/models/pubsub_collection_spec.rb +65 -49
- data/spec/models/pubsub_item_collection_spec.rb +17 -17
- data/spec/models/pubsub_item_spec.rb +18 -18
- data/spec/models/pubsub_spec.rb +41 -41
- data/spec/models/pubsub_subscription_spec.rb +23 -23
- data/spec/models/response_error_spec.rb +19 -19
- data/spec/models/response_proxy_spec.rb +51 -49
- data/spec/models/response_spec.rb +33 -33
- data/spec/support/helpers.rb +21 -1
- data/spec/support/matchers.rb +4 -4
- data/spec/support/shared_examples.rb +132 -94
- data/spec/support/webmock_stanza_matching.rb +43 -0
- metadata +45 -16
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jubjub::Muc::AffiliationCollection do
|
4
|
+
|
5
|
+
describe "that are proxied like" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@mock_connection = mock
|
9
|
+
@affiliations = [
|
10
|
+
muc_affiliation_factory( :affiliation => 'owner' ),
|
11
|
+
muc_affiliation_factory( :affiliation => 'admin' )
|
12
|
+
]
|
13
|
+
# Hack to get around the fact that [] calls retrieve_affiliations several times with different affiliations
|
14
|
+
@mock_connection.stub_chain( :muc, :retrieve_affiliations ).with{|jid,affiliation| affiliation == "owner" }.and_return(@affiliations)
|
15
|
+
@mock_connection.stub_chain( :muc, :retrieve_affiliations ).with{|jid,affiliation| affiliation != "owner" }.and_return([])
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "inspect" do
|
19
|
+
|
20
|
+
it "should show the list of affiliations, not Muc::AffiliationCollection" do
|
21
|
+
Jubjub::Muc::AffiliationCollection.new('conference.foo.com', @mock_connection).inspect.should eql(@affiliations.inspect)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "map" do
|
27
|
+
|
28
|
+
it "should pass the block to the rooms" do
|
29
|
+
c = Jubjub::Muc::AffiliationCollection.new('conference.foo.com', @mock_connection)
|
30
|
+
c.map{|r| r.affiliation.to_s }.should eql(['owner', 'admin'])
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "instance method" do
|
38
|
+
|
39
|
+
describe "jid" do
|
40
|
+
it "should return the jid" do
|
41
|
+
Jubjub::Muc::AffiliationCollection.new("conference.foo.com", mock).jid.should == Jubjub::Jid.new("conference.foo.com")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "[]" do
|
46
|
+
before do
|
47
|
+
@mock_connection = mock
|
48
|
+
@affiliations = [
|
49
|
+
muc_affiliation_factory( :jid => 'theozaurus@foo.com', :affiliation => 'owner' ),
|
50
|
+
muc_affiliation_factory( :jid => 'dragonzaurus@foo.com', :affiliation => 'member' )
|
51
|
+
]
|
52
|
+
# Hack to get around the fact that [] calls retrieve_affiliations several times with different affiliations
|
53
|
+
@mock_connection.stub_chain( :muc, :retrieve_affiliations ).with{|jid,affiliation| affiliation == "owner" }.and_return(@affiliations)
|
54
|
+
@mock_connection.stub_chain( :muc, :retrieve_affiliations ).with{|jid,affiliation| affiliation != "owner" }.and_return([])
|
55
|
+
end
|
56
|
+
|
57
|
+
subject { Jubjub::Muc::AffiliationCollection.new "conference.foo.com", @mock_connection }
|
58
|
+
|
59
|
+
it "should call retrieve_affiliations with owner, outcast, member, admin" do
|
60
|
+
muc_mock = mock
|
61
|
+
@mock_connection.stub(:muc).and_return(muc_mock)
|
62
|
+
muc_mock.should_receive(:retrieve_affiliations).with(subject.jid, 'owner')
|
63
|
+
muc_mock.should_receive(:retrieve_affiliations).with(subject.jid, 'outcast')
|
64
|
+
muc_mock.should_receive(:retrieve_affiliations).with(subject.jid, 'member')
|
65
|
+
muc_mock.should_receive(:retrieve_affiliations).with(subject.jid, 'admin')
|
66
|
+
|
67
|
+
subject[0]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should work like a normal array when passed a Fixnum" do
|
71
|
+
subject[1].should == @affiliations[1]
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "searching by jid if a String" do
|
75
|
+
|
76
|
+
it "should return cached result if it has already searched" do
|
77
|
+
# Trigger lookup
|
78
|
+
@mock_connection.muc.should_receive(:retrieve_affiliations)
|
79
|
+
subject.first
|
80
|
+
subject["theozaurus@foo.com"].should == @affiliations[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return default result if it has already searched and does not exist" do
|
84
|
+
# Trigger lookup
|
85
|
+
@mock_connection.muc.should_receive(:retrieve_affiliations)
|
86
|
+
subject.first
|
87
|
+
subject['blogozaurus@foo.com'].should ==
|
88
|
+
muc_affiliation_factory( :muc_jid => 'conference.foo.com',
|
89
|
+
:jid => 'blogozaurus@foo.com',
|
90
|
+
:affiliation => 'none',
|
91
|
+
:role => nil,
|
92
|
+
:nick => nil )
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return default result if it has not already searched" do
|
96
|
+
@mock_connection.muc.should_not_receive(:retrieve_affiliations)
|
97
|
+
subject["theozaurus@foo.com"].should_not equal @affiliations[0]
|
98
|
+
subject["theozaurus@foo.com"].should ==
|
99
|
+
muc_affiliation_factory( :muc_jid => 'conference.foo.com',
|
100
|
+
:jid => 'theozaurus@foo.com',
|
101
|
+
:affiliation => 'none',
|
102
|
+
:role => nil,
|
103
|
+
:nick => nil )
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "searching by Jid if a Jubjub::Jid" do
|
109
|
+
|
110
|
+
it "should return cached result if it has already searched" do
|
111
|
+
# Trigger lookup
|
112
|
+
@mock_connection.muc.should_receive(:retrieve_affiliations)
|
113
|
+
subject.first
|
114
|
+
subject[Jubjub::Jid.new "theozaurus@foo.com"].should == @affiliations[0]
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return default result if it has already searched and does not exist" do
|
118
|
+
# Trigger lookup
|
119
|
+
@mock_connection.muc.should_receive(:retrieve_affiliations)
|
120
|
+
subject.first
|
121
|
+
subject[Jubjub::Jid.new 'blogozaurus@foo.com'].should ==
|
122
|
+
muc_affiliation_factory( :muc_jid => 'conference.foo.com',
|
123
|
+
:jid => 'blogozaurus@foo.com',
|
124
|
+
:affiliation => 'none',
|
125
|
+
:role => nil,
|
126
|
+
:nick => nil )
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return default result if it has not already searched" do
|
130
|
+
@mock_connection.muc.should_not_receive(:retrieve_affiliations)
|
131
|
+
subject[Jubjub::Jid.new "theozaurus@foo.com"].should_not equal @affiliations[0]
|
132
|
+
subject[Jubjub::Jid.new "theozaurus@foo.com"].should ==
|
133
|
+
muc_affiliation_factory( :muc_jid => 'conference.foo.com',
|
134
|
+
:jid => 'theozaurus@foo.com',
|
135
|
+
:affiliation => 'none',
|
136
|
+
:role => nil,
|
137
|
+
:nick => nil )
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jubjub::Muc::Affiliation do
|
4
|
+
|
5
|
+
describe "instance method" do
|
6
|
+
|
7
|
+
describe "muc_jid" do
|
8
|
+
it "should return the muc_jid" do
|
9
|
+
p = muc_affiliation_factory :muc_jid => 'muc.foo.com'
|
10
|
+
p.muc_jid.should == Jubjub::Jid.new('muc.foo.com')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "jid" do
|
15
|
+
it "should return the jid" do
|
16
|
+
p = muc_affiliation_factory :jid => 'bob@foo.com'
|
17
|
+
p.jid.should == Jubjub::Jid.new('bob@foo.com')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "nick" do
|
22
|
+
it "should return the nick" do
|
23
|
+
p = muc_affiliation_factory :nick => 'bob'
|
24
|
+
p.nick.should == 'bob'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "role" do
|
29
|
+
it "should return the role" do
|
30
|
+
p = muc_affiliation_factory :role => 'moderator'
|
31
|
+
p.role.should == 'moderator'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "affiliation" do
|
36
|
+
it "should return the affiliation" do
|
37
|
+
p = muc_affiliation_factory :affiliation => 'admin'
|
38
|
+
p.affiliation.should == 'admin'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "owner?" do
|
43
|
+
it "should return true when affiliation is 'owner'" do
|
44
|
+
muc_affiliation_factory( :affiliation => 'owner' ).owner?.should equal(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return false when affiliation is not 'owner'" do
|
48
|
+
muc_affiliation_factory( :affiliation => 'admin' ).owner?.should equal(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "admin?" do
|
53
|
+
it "should return true when affiliation is 'admin'" do
|
54
|
+
muc_affiliation_factory( :affiliation => 'admin' ).admin?.should equal(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false when affiliation is not 'admin'" do
|
58
|
+
muc_affiliation_factory( :affiliation => 'owner' ).admin?.should equal(false)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "member?" do
|
63
|
+
it "should return true when affiliation is 'member'" do
|
64
|
+
muc_affiliation_factory( :affiliation => 'member' ).member?.should equal(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return false when affiliation is not 'member'" do
|
68
|
+
muc_affiliation_factory( :affiliation => 'publisher' ).member?.should equal(false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "none?" do
|
73
|
+
it "should return true when affiliation is 'none'" do
|
74
|
+
muc_affiliation_factory( :affiliation => 'none' ).none?.should equal(true)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return false when affiliation is not 'none'" do
|
78
|
+
muc_affiliation_factory( :affiliation => 'publisher' ).none?.should equal(false)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "outcast?" do
|
83
|
+
it "should return true when affiliation is 'outcast'" do
|
84
|
+
muc_affiliation_factory( :affiliation => 'outcast' ).outcast?.should equal(true)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return false when affiliation is not 'outcast'" do
|
88
|
+
muc_affiliation_factory( :affiliation => 'publisher' ).outcast?.should equal(false)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "set" do
|
93
|
+
it "should redirect call to muc.modify_affiliations" do
|
94
|
+
@mock_connection = mock
|
95
|
+
@mock_connection.stub_chain :muc, :modify_affiliations
|
96
|
+
|
97
|
+
affiliation = muc_affiliation_factory :connection => @mock_connection
|
98
|
+
|
99
|
+
@mock_connection.muc.should_receive(:modify_affiliations).with( affiliation.muc_jid, affiliation )
|
100
|
+
|
101
|
+
affiliation.set 'admin'
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "when succesful" do
|
105
|
+
before do
|
106
|
+
@mock_connection = mock
|
107
|
+
@mock_connection.stub_chain( :muc, :modify_affiliations ).and_return( true )
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return true" do
|
111
|
+
@affiliation = muc_affiliation_factory :connection => @mock_connection
|
112
|
+
@affiliation.set( 'admin' ).should equal( true )
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should have affiliaton set to new value" do
|
116
|
+
@affiliation = muc_affiliation_factory :connection => @mock_connection, :affiliation => 'owner'
|
117
|
+
@affiliation.set 'admin'
|
118
|
+
@affiliation.affiliation.should == 'admin'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "when unsuccesful" do
|
123
|
+
before do
|
124
|
+
@mock_connection = mock
|
125
|
+
@mock_connection.stub_chain( :muc, :modify_affiliations ).and_return( false )
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return false" do
|
129
|
+
@affiliation = muc_affiliation_factory :connection => @mock_connection
|
130
|
+
@affiliation.set( 'admin' ).should equal( false )
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have affiliaton set to original value" do
|
134
|
+
@affiliation = muc_affiliation_factory :connection => @mock_connection, :affiliation => 'owner'
|
135
|
+
@affiliation.set 'admin'
|
136
|
+
@affiliation.affiliation.should == 'owner'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "set_owner" do
|
142
|
+
it "should redirect call to set" do
|
143
|
+
affiliation = muc_affiliation_factory
|
144
|
+
affiliation.should_receive(:set).with('owner').and_return( 'from-set' )
|
145
|
+
|
146
|
+
affiliation.set_owner.should == 'from-set'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "set_admin" do
|
151
|
+
it "should redirect call to set" do
|
152
|
+
affiliation = muc_affiliation_factory
|
153
|
+
affiliation.should_receive(:set).with('admin').and_return( 'from-set' )
|
154
|
+
|
155
|
+
affiliation.set_admin.should == 'from-set'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "set_member" do
|
160
|
+
it "should redirect call to set" do
|
161
|
+
affiliation = muc_affiliation_factory
|
162
|
+
affiliation.should_receive(:set).with('member').and_return( 'from-set' )
|
163
|
+
|
164
|
+
affiliation.set_member.should == 'from-set'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "set_none" do
|
169
|
+
it "should redirect call to set" do
|
170
|
+
affiliation = muc_affiliation_factory
|
171
|
+
affiliation.should_receive(:set).with('none').and_return( 'from-set' )
|
172
|
+
|
173
|
+
affiliation.set_none.should == 'from-set'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "set_outcast" do
|
178
|
+
it "should redirect call to set" do
|
179
|
+
affiliation = muc_affiliation_factory
|
180
|
+
affiliation.should_receive(:set).with('outcast').and_return( 'from-set' )
|
181
|
+
|
182
|
+
affiliation.set_outcast.should == 'from-set'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "==" do
|
187
|
+
it "should match equivalent objects" do
|
188
|
+
muc_affiliation_factory.should == muc_affiliation_factory
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should not distinguish between connections" do
|
192
|
+
muc_affiliation_factory(:connection => 'wibble').should == muc_affiliation_factory(:connection => 'wobble')
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should still match no matter how jid is initialized" do
|
196
|
+
muc_affiliation_factory(:jid => 'foo@bar.com').should == muc_affiliation_factory(:jid => Jubjub::Jid.new('foo@bar.com'))
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should still match no matter how muc_jid is initialized" do
|
200
|
+
muc_affiliation_factory(:muc_jid => 'muc.bar.com').should ==
|
201
|
+
muc_affiliation_factory(:muc_jid => Jubjub::Jid.new('muc.bar.com'))
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should not match objects with different attributes" do
|
205
|
+
muc_affiliation_factory(:muc_jid => 'a.b.com').should_not == muc_affiliation_factory
|
206
|
+
muc_affiliation_factory(:jid => 'a.b.com').should_not == muc_affiliation_factory
|
207
|
+
muc_affiliation_factory(:nick => 'snicker-snack').should_not == muc_affiliation_factory
|
208
|
+
muc_affiliation_factory(:role => 'owner').should_not == muc_affiliation_factory
|
209
|
+
muc_affiliation_factory(:affiliation => 'member').should_not == muc_affiliation_factory
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Jubjub::Muc::Collection do
|
4
|
-
|
4
|
+
|
5
5
|
describe "instance methods" do
|
6
|
-
|
6
|
+
|
7
7
|
describe "create" do
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@mock_connection = mock
|
11
11
|
@mock_connection.stub(:jid).and_return( Jubjub::Jid.new 'admin@foo.com' )
|
12
12
|
@mock_connection.stub_chain :muc, :create
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should call muc.create on connection" do
|
16
16
|
@mock_connection.muc.should_receive(:create).with( Jubjub::Jid.new 'hello@conference.foo.com/admin' )
|
17
|
-
|
17
|
+
|
18
18
|
Jubjub::Muc::Collection.new("conference.foo.com", @mock_connection).create("hello")
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should yield a Muc::Configuration if a block is given" do
|
22
22
|
@config = Jubjub::Muc::Configuration.new( "allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
23
|
-
|
23
|
+
|
24
24
|
@mock_connection.muc.should_receive( :configuration ).with( Jubjub::Jid.new( 'hello@conference.foo.com/admin' )).and_return( @config )
|
25
25
|
@mock_connection.muc.should_receive( :create ).with( Jubjub::Jid.new( 'hello@conference.foo.com/admin' ), @config )
|
26
|
-
|
26
|
+
|
27
27
|
Jubjub::Muc::Collection.new("conference.foo.com", @mock_connection).create("hello"){|config|
|
28
28
|
config.should == @config
|
29
29
|
}
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
describe "jid" do
|
35
35
|
it "should return the jid" do
|
36
36
|
Jubjub::Muc::Collection.new("conference.foo.com", mock).jid.should == Jubjub::Jid.new("conference.foo.com")
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
describe "[]" do
|
41
41
|
before do
|
42
42
|
@mock_connection = mock
|
@@ -46,33 +46,65 @@ describe Jubjub::Muc::Collection do
|
|
46
46
|
]
|
47
47
|
@mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
subject { Jubjub::Muc::Collection.new('conference.foo.com', @mock_connection) }
|
51
|
-
|
51
|
+
|
52
52
|
it "should work like a normal array when passed a Fixnum" do
|
53
53
|
subject[1].should == @rooms[1]
|
54
54
|
end
|
55
|
-
|
56
|
-
it "should search by node if a String" do
|
57
|
-
subject["room_1"].should == @rooms[0]
|
58
|
-
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
describe "searching by node if a String" do
|
57
|
+
|
58
|
+
it "should return cached result if it has already searched" do
|
59
|
+
# Trigger lookup
|
60
|
+
@mock_connection.muc.should_receive(:list)
|
61
|
+
subject.first
|
62
|
+
subject["room_1"].should == @rooms[0]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return default result if it has already searched and does not exist" do
|
66
|
+
# Trigger lookup
|
67
|
+
@mock_connection.muc.should_receive(:list)
|
68
|
+
subject.first
|
69
|
+
subject['made-up'].should == Jubjub::Muc.new('made-up@conference.foo.com', nil, @mock_connection)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return default result if it has not already searched" do
|
73
|
+
@mock_connection.muc.should_not_receive(:list)
|
74
|
+
subject["room_1"].should_not equal @rooms[0]
|
75
|
+
subject["room_1"].should == Jubjub::Muc.new('room_1@conference.foo.com', nil, @mock_connection)
|
76
|
+
end
|
77
|
+
|
66
78
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
79
|
+
|
80
|
+
describe "searching by jid if a Jubjub::Jid" do
|
81
|
+
|
82
|
+
it "should return cached result if it has already searched" do
|
83
|
+
# Trigger lookup
|
84
|
+
@mock_connection.muc.should_receive(:list)
|
85
|
+
subject.first
|
86
|
+
subject[Jubjub::Jid.new("room_1@conference.foo.com")].should == @rooms[0]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return default result if it has already searched and does not exist" do
|
90
|
+
# Trigger lookup
|
91
|
+
@mock_connection.muc.should_receive(:list)
|
92
|
+
subject.first
|
93
|
+
subject[Jubjub::Jid.new("made-up@conference.foo.com")].should == Jubjub::Muc.new('made-up@conference.foo.com', nil, @mock_connection)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return default result if it has not already searched" do
|
97
|
+
@mock_connection.muc.should_not_receive(:list)
|
98
|
+
subject[Jubjub::Jid.new("room_1@conference.foo.com")].should_not equal @rooms[0]
|
99
|
+
subject[Jubjub::Jid.new("room_1@conference.foo.com")].should == Jubjub::Muc.new('room_1@conference.foo.com', nil, @mock_connection)
|
100
|
+
end
|
101
|
+
|
70
102
|
end
|
71
103
|
|
72
104
|
end
|
73
|
-
|
105
|
+
|
74
106
|
describe "that are proxied like" do
|
75
|
-
|
107
|
+
|
76
108
|
before do
|
77
109
|
@mock_connection = mock
|
78
110
|
@rooms = [
|
@@ -81,7 +113,7 @@ describe Jubjub::Muc::Collection do
|
|
81
113
|
]
|
82
114
|
@mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
|
83
115
|
end
|
84
|
-
|
116
|
+
|
85
117
|
describe "inspect" do
|
86
118
|
|
87
119
|
it "should show the list of rooms, not Muc::Collection" do
|
@@ -99,7 +131,7 @@ describe Jubjub::Muc::Collection do
|
|
99
131
|
|
100
132
|
end
|
101
133
|
end
|
102
|
-
|
134
|
+
|
103
135
|
end
|
104
|
-
|
105
|
-
end
|
136
|
+
|
137
|
+
end
|