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,459 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::MucConfiguration do
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
458
+
459
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::Muc do
4
+
5
+ describe "instance method" do
6
+
7
+ describe "inspect" do
8
+
9
+ it "should not show connection information" do
10
+ m = Jubjub::Muc.new(Jubjub::Jid.new("hello@conference.foo.com"),nil,"SHHHH CONNECTION OBJECT")
11
+ m.inspect.should_not match 'SHHHH CONNECTION OBJECT'
12
+ end
13
+
14
+ it "should show string version of jid" do
15
+ m = Jubjub::Muc.new(Jubjub::Jid.new("hello@conference.foo.com"),nil,mock)
16
+ m.inspect.should match 'hello@conference.foo.com'
17
+ end
18
+
19
+ it "should show name" do
20
+ m = Jubjub::Muc.new(Jubjub::Jid.new("hello@conference.foo.com"),nil,mock)
21
+ m.inspect.should match '@name=nil'
22
+
23
+ m = Jubjub::Muc.new(Jubjub::Jid.new("hello@conference.foo.com"),"Hey there",mock)
24
+ m.inspect.should match '@name="Hey there"'
25
+ end
26
+
27
+ end
28
+
29
+ describe "jid" do
30
+ it "should return the jid object" do
31
+ Jubjub::Muc.new("hello@conference.foo.com",nil,mock).jid.should == Jubjub::Jid.new("hello@conference.foo.com")
32
+ end
33
+ end
34
+
35
+ describe "name" do
36
+ it "should return the name" do
37
+ Jubjub::Muc.new("hello@conference.foo.com",nil,mock).name.should be_nil
38
+ Jubjub::Muc.new("hello@conference.foo.com","bar",mock).name.should eql("bar")
39
+ end
40
+ end
41
+
42
+ describe "destroy" do
43
+
44
+ it "should call muc.destroy on connection" do
45
+ mock_connection = mock
46
+ mock_connection.stub_chain :muc, :destroy
47
+ mock_connection.muc.should_receive(:destroy).with( Jubjub::Jid.new 'hello@conference.foo.com' )
48
+
49
+ m = Jubjub::Muc.new('hello@conference.foo.com',nil,mock_connection)
50
+ m.destroy
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,17 @@
1
+ $:.unshift File.join(File.dirname(File.dirname(__FILE__)),'lib')
2
+
3
+ require 'jubjub'
4
+ require 'vcr'
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec
8
+ config.mock_with :rspec
9
+ config.extend VCR::RSpec::Macros
10
+ end
11
+
12
+ VCR.config do |config|
13
+ config.cassette_library_dir = File.join(File.dirname(__FILE__),'fixtures','vcr_cassettes')
14
+ config.stub_with :webmock
15
+ config.default_cassette_options = { :record => :none, :match_requests_on => [:uri, :method, :body] }
16
+ end
17
+