jubjub 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
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%3ciq%20type%3d%22set%22%20to%3d%22pubsub.theo-template.local%22%3e%0a%20%20%3cpubsub%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fpubsub%22%3e%0a%20%20%20%20%3ccreate%20node%3d%22node_1%22%2f%3e%0a%20%20%3c%2fpubsub%3e%0a%3c%2fiq%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
+ - "232"
19
+ body: |
20
+ <iq type="result" id="blather0045" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/39957870571305901244463676">
21
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
22
+ <create node="node_1"/>
23
+ </pubsub>
24
+ </iq>
25
+
26
+ http_version: "1.1"
27
+ - !ruby/struct:VCR::HTTPInteraction
28
+ request: !ruby/struct:VCR::Request
29
+ method: :post
30
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
31
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22set%22%20to%3d%22pubsub.theo-template.local%22%3e%0a%20%20%3cpubsub%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fpubsub%23owner%22%3e%0a%20%20%20%20%3cdelete%20node%3d%22node_1%22%2f%3e%0a%20%20%3c%2fpubsub%3e%0a%3c%2fiq%3e%0a
32
+ headers:
33
+ content-type:
34
+ - application/x-www-form-urlencoded
35
+ response: !ruby/struct:VCR::Response
36
+ status: !ruby/struct:VCR::ResponseStatus
37
+ code: 200
38
+ message: ...
39
+ headers:
40
+ content-type:
41
+ - application/xml
42
+ content-length:
43
+ - "134"
44
+ body: |
45
+ <iq type="result" id="blather0049" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/39957870571305901244463676"/>
46
+
47
+ http_version: "1.1"
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::DataForm do
4
+
5
+ it_behaves_like "any data form"
6
+
7
+ end
@@ -37,13 +37,42 @@ describe Jubjub::MucCollection do
37
37
  end
38
38
  end
39
39
 
40
+ describe "[]" do
41
+ before do
42
+ @mock_connection = mock
43
+ @rooms = [
44
+ Jubjub::Muc.new('room_1@conference.foo.com', nil, @mock_connection),
45
+ Jubjub::Muc.new('room_2@conference.foo.com', nil, @mock_connection)
46
+ ]
47
+ @mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
48
+ end
49
+
50
+ subject { Jubjub::MucCollection.new('conference.foo.com', @mock_connection) }
51
+
52
+ it "should work like a normal array when passed a Fixnum" do
53
+ subject[1].should == @rooms[1]
54
+ end
55
+
56
+ it "should search by node if a String" do
57
+ subject["room_1"].should == @rooms[0]
58
+ end
59
+
60
+ it "should search by jid if a Jubjub::Jid" do
61
+ subject[Jubjub::Jid.new("room_1@conference.foo.com")].should == @rooms[0]
62
+ end
63
+
64
+ it "should return nil if nothing found" do
65
+ subject['made-up'].should be_nil
66
+ end
67
+ end
68
+
40
69
  describe "that are proxied like" do
41
70
 
42
71
  before do
43
72
  @mock_connection = mock
44
73
  @rooms = [
45
- Jubjub::Muc.new('room_1', nil, @mock_connection),
46
- Jubjub::Muc.new('room_2', nil, @mock_connection)
74
+ Jubjub::Muc.new('room_1@conference.foo.com', nil, @mock_connection),
75
+ Jubjub::Muc.new('room_2@conference.foo.com', nil, @mock_connection)
47
76
  ]
48
77
  @mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
49
78
  end
@@ -60,7 +89,7 @@ describe Jubjub::MucCollection do
60
89
 
61
90
  it "should pass the block to the rooms" do
62
91
  c = Jubjub::MucCollection.new('conference.foo.com', @mock_connection)
63
- c.map{|r| r.jid.to_s }.should eql(['room_1', 'room_2'])
92
+ c.map{|r| r.jid.to_s }.should eql(['room_1@conference.foo.com', 'room_2@conference.foo.com'])
64
93
  end
65
94
 
66
95
  end
@@ -2,458 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Jubjub::MucConfiguration do
4
4
 
5
- describe "creating" do
6
-
7
- it "should understand hash to build object" do
8
- params = {
9
- "muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
10
- "muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
11
- "muc#roomconfig_whois" => {
12
- :type => "list-single",
13
- :value => "moderators",
14
- :label => "Present real Jabber IDs to",
15
- :options => [
16
- { :value =>"moderators", :label => "moderators only" },
17
- { :value =>"anyone", :label => "anyone" } ],
18
- },
19
- "muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
20
- }
21
-
22
- config = Jubjub::MucConfiguration.new params
23
-
24
- config.should be_a_kind_of Jubjub::MucConfiguration
25
- config.fields.should == params
26
- end
27
-
28
- it "should throw an error if :type is missing" do
29
- expect{
30
- Jubjub::MucConfiguration.new( "foo" => { :value => "1", :label => "Foo" } )
31
- }.to raise_error(
32
- Jubjub::ArgumentError,
33
- ":type is missing for foo"
34
- )
35
- end
36
-
37
- it "should throw an error if an unknown key is sent" do
38
- expect{
39
- Jubjub::MucConfiguration.new( "foo" => { :type => "boolean", :value => "1", :label => "Foo", :oh_no => nil } )
40
- }.to raise_error(
41
- Jubjub::ArgumentError,
42
- ":oh_no is not a recognised option for foo"
43
- )
44
- end
45
-
46
- it "should throw an error if a hash isn't passed in" do
47
- expect{
48
- Jubjub::MucConfiguration.new( "config" )
49
- }.to raise_error(
50
- Jubjub::ArgumentError,
51
- "please initialize with a hash of the format { 'foo' => {:type => 'boolean', :value => false, :label => 'Fooey'} }"
52
- )
53
- end
54
-
55
- end
56
-
57
- describe "instance method" do
58
-
59
- describe "[]" do
60
- context "for booleans" do
61
- before do
62
- @config = Jubjub::MucConfiguration.new(
63
- "muc#roomconfig_allowinvites" => {
64
- :type => "boolean",
65
- :label => "Whether to Allow Occupants to Invite Others",
66
- :value => "0"
67
- },
68
- "muc#roomconfig_moderatedroom" => {
69
- :type => "boolean",
70
- :label => "Whether to Make Room Moderated",
71
- :value => "false"
72
- },
73
- "muc#roomconfig_changesubject" => {
74
- :type => "boolean",
75
- :label => "Whether to Allow Occupants to Change Subject",
76
- :value => "1"
77
- },
78
- "muc#roomconfig_publicroom" => {
79
- :type => "boolean",
80
- :label => "Whether to Allow Public Searching for Room",
81
- :value => "true"
82
- }
83
- )
84
- end
85
-
86
- it "should return false or true" do
87
- @config['muc#roomconfig_allowinvites'].should be_false
88
- @config['muc#roomconfig_moderatedroom'].should be_false
89
-
90
- @config['muc#roomconfig_changesubject'].should be_true
91
- @config['muc#roomconfig_publicroom'].should be_true
92
- end
93
- end
94
-
95
- context "for lists" do
96
- before do
97
- @config = Jubjub::MucConfiguration.new(
98
- "muc#roomconfig_presencebroadcast" => {
99
- :type => "list-multi",
100
- :label => "Roles for which Presence is Broadcast",
101
- :value => ["moderator", "participant", "visitor"],
102
- :options => [
103
- { :value => "visitor", :label => "Visitor" },
104
- { :value => "moderators", :label => "Moderator" },
105
- { :value => "participant", :label => "Participant" }
106
- ]
107
- },
108
- "muc#roomconfig_maxusers" => {
109
- :type => "list-single",
110
- :label => "Maximum Number of Occupants",
111
- :value => "20",
112
- :options => [
113
- { :value => "10", :label => "10" },
114
- { :value => "20", :label => "20" },
115
- { :value => "30", :label => "30" },
116
- { :value => "40", :label => "40" }
117
- ]
118
- }
119
- )
120
- end
121
-
122
- it "should return an array for list-multi" do
123
- @config["muc#roomconfig_presencebroadcast"].should == ["moderator", "participant", "visitor"]
124
- end
125
-
126
- it "should return a single item for list-single" do
127
- @config["muc#roomconfig_maxusers"].should == "20"
128
- end
129
- end
130
-
131
- context "for jids" do
132
- before do
133
- @config = Jubjub::MucConfiguration.new(
134
- "muc#roomconfig_roomadmins" => {
135
- :type => "jid-multi",
136
- :label => "Room Admins",
137
- :value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
138
- },
139
- "special_jid" => {
140
- :type => "jid-single",
141
- :label => "A special jid",
142
- :value => "foo@bar.com"
143
- }
144
- )
145
- end
146
-
147
- it "should return a Jubjub::Jid" do
148
- jids = [Jubjub::Jid.new("wiccarocks@shakespeare.lit"), Jubjub::Jid.new("hecate@shakespeare.lit")]
149
-
150
- @config['muc#roomconfig_roomadmins'].should == jids
151
- @config['special_jid'].should == Jubjub::Jid.new("foo@bar.com")
152
- end
153
- end
154
-
155
- context "for non existent options" do
156
- before do
157
- @config = Jubjub::MucConfiguration.new(
158
- "foo" => {
159
- :type => "text-single",
160
- :label => "Foo",
161
- :value => "Blurgh"
162
- }
163
- )
164
- end
165
-
166
- it "should return nil" do
167
- @config['made_up'].should be_nil
168
- end
169
- end
170
- end
171
-
172
- describe "[]=" do
173
-
174
- context "for booleans do" do
175
- before do
176
- @config = Jubjub::MucConfiguration.new(
177
- "muc#roomconfig_allowinvites" => {
178
- :type => "boolean",
179
- :label => "Whether to Allow Occupants to Invite Others",
180
- :value => "0"
181
- }
182
- )
183
- end
184
-
185
- it "should convert '0' to false" do
186
- @config["muc#roomconfig_allowinvites"] = '0'
187
- @config["muc#roomconfig_allowinvites"].should be_false
188
- end
189
-
190
- it "should convert '1' to true" do
191
- @config["muc#roomconfig_allowinvites"] = '1'
192
- @config["muc#roomconfig_allowinvites"].should be_true
193
- end
194
-
195
- it "should convert 'true' to true" do
196
- @config["muc#roomconfig_allowinvites"] = 'true'
197
- @config["muc#roomconfig_allowinvites"].should be_true
198
- end
199
-
200
- it "should convert 'false' to false" do
201
- @config["muc#roomconfig_allowinvites"] = 'false'
202
- @config["muc#roomconfig_allowinvites"].should be_false
203
- end
204
-
205
- it "should return false if something else" do
206
- @config["muc#roomconfig_allowinvites"] = 'wibble'
207
- @config["muc#roomconfig_allowinvites"].should be_false
208
- end
209
- end
210
-
211
- context "for multi types" do
212
- before do
213
- @config = Jubjub::MucConfiguration.new(
214
- "muc#roomconfig_roomadmins" => {
215
- :type => "jid-multi",
216
- :label => "Room Admins",
217
- :value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
218
- }
219
- )
220
- end
221
-
222
- it "should accept an array" do
223
- @config['muc#roomconfig_roomadmins'] = ['giraffe@zoo', 'elephant@zoo']
224
-
225
- @config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo'), Jubjub::Jid.new('elephant@zoo')]
226
- end
227
-
228
- it "should convert to an array if it isn't" do
229
- @config['muc#roomconfig_roomadmins'] = 'giraffe@zoo'
230
-
231
- @config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo')]
232
- end
233
- end
234
-
235
- context "for list types" do
236
- before do
237
- @config = Jubjub::MucConfiguration.new(
238
- "muc#roomconfig_presencebroadcast" => {
239
- :type => "list-multi",
240
- :label => "Roles for which Presence is Broadcast",
241
- :value => ["moderator", "participant", "visitor"],
242
- :options => [
243
- { :value => "visitor", :label => "Visitor" },
244
- { :value => "moderators", :label => "Moderator" },
245
- { :value => "participant", :label => "Participant" }
246
- ]
247
- },
248
- "muc#roomconfig_maxusers" => {
249
- :type => "list-single",
250
- :label => "Maximum Number of Occupants",
251
- :value => "20",
252
- :options => [
253
- { :value => "10", :label => "10" },
254
- { :value => "20", :label => "20" },
255
- { :value => "30", :label => "30" },
256
- { :value => "40", :label => "40" }
257
- ]
258
- }
259
- )
260
- end
261
-
262
- it "should set the value if it is a valid option" do
263
- @config['muc#roomconfig_maxusers'] = "10"
264
- @config['muc#roomconfig_maxusers'].should eql("10")
265
-
266
- @config['muc#roomconfig_presencebroadcast'] = ["visitor"]
267
- @config['muc#roomconfig_presencebroadcast'].should eql(["visitor"])
268
- end
269
-
270
- it "should raise an error if the value isn't one of the options" do
271
- expect{
272
- @config['muc#roomconfig_maxusers'] = "50000"
273
- }.to raise_error(
274
- Jubjub::ArgumentError,
275
- "50000 is not an accepted value please choose from 10, 20, 30, 40"
276
- )
277
-
278
- expect{
279
- @config['muc#roomconfig_presencebroadcast'] = ["superman", "moderators"]
280
- }.to raise_error(
281
- Jubjub::ArgumentError,
282
- "superman is not an accepted value please choose from visitor, moderators, participant"
283
- )
284
- end
285
- end
286
-
287
- context "for jid types" do
288
- before do
289
- @config = Jubjub::MucConfiguration.new(
290
- "muc#roomconfig_roomadmins" => {
291
- :type => "jid-multi",
292
- :label => "Room Admins",
293
- :value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
294
- },
295
- "special_jid" => {
296
- :type => "jid-single",
297
- :label => "A special jid",
298
- :value => "foo@bar.com"
299
- }
300
- )
301
- end
302
-
303
- it "should convert strings to jids" do
304
- @config['muc#roomconfig_roomadmins'] = ["foo@bar.com", "bar@foo.com"]
305
- @config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
306
-
307
- @config['special_jid'] = "bar@foo.com"
308
- @config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
309
- end
310
-
311
- it "should accept jids" do
312
- @config['muc#roomconfig_roomadmins'] = [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
313
- @config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
314
-
315
- @config['special_jid'] = Jubjub::Jid.new('bar@foo.com')
316
- @config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
317
- end
318
- end
319
-
320
- context "for non existent fields" do
321
- before do
322
- @config = Jubjub::MucConfiguration.new(
323
- "muc#roomconfig_roomadmins" => {
324
- :type => "jid-multi",
325
- :label => "Room Admins",
326
- :value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
327
- }
328
- )
329
- end
330
-
331
- it "should raise an error" do
332
- expect{
333
- @config['fooey'] = "bar"
334
- }.to raise_error(
335
- Jubjub::ArgumentError,
336
- "fooey is not a valid field"
337
- )
338
- end
339
- end
340
-
341
- end
342
-
343
- describe "fields" do
344
- it "should return all of the types, values, labels and options for each field" do
345
- params = {
346
- "allow_query_users" => { :type => "boolean", :value => "1", :label => "Allow users to query other users" },
347
- "muc#roomconfig_maxusers" => {
348
- :type => "list-single",
349
- :value => "5",
350
- :label => "Maximum Number of Occupants",
351
- :options => [
352
- { :value => "5", :label => "5" },
353
- { :value => "10", :label => "10" }
354
- ]
355
- }
356
- }
357
-
358
- adjusted_params = {
359
- "allow_query_users" => { :type => "boolean", :value => false, :label => "Allow users to query other users" },
360
- "muc#roomconfig_maxusers" => {
361
- :type => "list-single",
362
- :value => "5",
363
- :label => "Maximum Number of Occupants",
364
- :options => [
365
- { :value => "5", :label => "5" },
366
- { :value => "10", :label => "10" }
367
- ]
368
- }
369
- }
370
-
371
- config = Jubjub::MucConfiguration.new(params)
372
- config.fields.should == params
373
-
374
- config['allow_query_users'] = false
375
- config.fields.should == adjusted_params
376
- end
377
- end
378
-
379
- describe "==" do
380
- it "should match the same room config" do
381
- config_1 = Jubjub::MucConfiguration.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
382
- config_2 = Jubjub::MucConfiguration.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
383
-
384
- config_1.should == config_2
385
- end
386
-
387
- it "should not match a different room config" do
388
- config_1 = Jubjub::MucConfiguration.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
389
- config_2 = Jubjub::MucConfiguration.new("allow_query_users" => { :type => "boolean", :value => "0", :label => "Foo" } )
390
-
391
- config_1.should_not == config_2
392
- end
393
- end
394
-
395
- describe "settings" do
396
- before do
397
- @config = Jubjub::MucConfiguration.new(
398
- "muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
399
- "muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
400
- "muc#roomconfig_whois" => {
401
- :type => "list-single",
402
- :value => "moderators",
403
- :label => "Present real Jabber IDs to",
404
- :options => [
405
- { :value => "moderators", :label => "moderators only" },
406
- { :value => "anyone", :label => "anyone" } ],
407
- },
408
- "muc#roomconfig_roomadmins" => {
409
- :type => "jid-multi",
410
- :label => "Room Admins",
411
- :value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
412
- },
413
- "muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
414
- )
415
-
416
- end
417
-
418
- it "should generate hash of name and values" do
419
- @config.settings.should == {
420
- "muc#roomconfig_allowvisitornickchange" => [true],
421
- "muc#roomconfig_roomname" => [""],
422
- "muc#roomconfig_whois" => ["moderators"],
423
- "muc#roomconfig_roomadmins" => [Jubjub::Jid.new("wiccarocks@shakespeare.lit"), Jubjub::Jid.new("hecate@shakespeare.lit")],
424
- "muc#roomconfig_passwordprotectedroom" => [false]
425
- }
426
- end
427
- end
428
-
429
- end
430
-
431
- describe "dynamic methods" do
432
-
433
- describe "<friendly name>= " do
434
- it "should return the same as []="
435
- end
436
-
437
- describe "<friendly name>" do
438
- it "should return the same as []"
439
- end
440
-
441
- describe "<friendly name>?" do
442
- it "should return label"
443
- end
444
-
445
- describe "<name>=" do
446
- it "should return the same as []="
447
- end
448
-
449
- describe "<name>" do
450
- it "should return the same as []"
451
- end
452
-
453
- describe "<name>?" do
454
- it "should return label"
455
- end
456
-
457
- end
5
+ it_behaves_like "any data form"
458
6
 
459
7
  end