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
data/spec/support/helpers.rb
CHANGED
@@ -4,4 +4,24 @@ end
|
|
4
4
|
|
5
5
|
def fixture_path(location)
|
6
6
|
File.join(File.dirname(File.dirname(__FILE__)),'fixtures',location)
|
7
|
-
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def muc_affiliation_factory(override = {})
|
10
|
+
options = {
|
11
|
+
:muc_jid => Jubjub::Jid.new("borogove@conference.foo.com"),
|
12
|
+
:jid => "mimsy@foo.com",
|
13
|
+
:nick => 'mimsy',
|
14
|
+
:role => 'none',
|
15
|
+
:affiliation => 'none',
|
16
|
+
:connection => 'SHHHH CONNECTION OBJECT'
|
17
|
+
}.merge( override )
|
18
|
+
|
19
|
+
Jubjub::Muc::Affiliation.new(
|
20
|
+
options[:muc_jid],
|
21
|
+
options[:jid],
|
22
|
+
options[:nick],
|
23
|
+
options[:role],
|
24
|
+
options[:affiliation],
|
25
|
+
options[:connection]
|
26
|
+
)
|
27
|
+
end
|
data/spec/support/matchers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
RSpec::Matchers.define :be_a_kind_of_response_proxied do |secondary_class|
|
1
|
+
RSpec::Matchers.define :be_a_kind_of_response_proxied do |secondary_class|
|
2
2
|
match do |proxy|
|
3
|
-
proxy.proxy_class == Jubjub::Response::Proxy &&
|
4
|
-
proxy.proxy_primary.class == Jubjub::Response &&
|
3
|
+
proxy.proxy_class == Jubjub::Response::Proxy &&
|
4
|
+
proxy.proxy_primary.class == Jubjub::Response &&
|
5
5
|
proxy.proxy_secondary.class == secondary_class
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
shared_examples_for "any data form" do
|
2
|
-
|
2
|
+
|
3
3
|
describe "creating" do
|
4
|
-
|
4
|
+
|
5
5
|
it "should understand XML to build object" do
|
6
6
|
dataform_1 = xml_fixture 'dataform_1'
|
7
7
|
dataform = subject.class.new(dataform_1)
|
8
|
-
|
8
|
+
|
9
9
|
expected = {
|
10
10
|
"public" => { :type => "boolean", :value => "", :label => "Public bot?" },
|
11
11
|
"FORM_TYPE" => { :type => "hidden", :value => "jabber:bot", :label => nil},
|
@@ -17,7 +17,7 @@ shared_examples_for "any data form" do
|
|
17
17
|
{:value => "contests", :label=>"Contests"},
|
18
18
|
{:value => "news", :label=>"News"},
|
19
19
|
{:value => "polls", :label=>"Polls"},
|
20
|
-
{:value => "reminders", :label=>"Reminders"},
|
20
|
+
{:value => "reminders", :label=>"Reminders"},
|
21
21
|
{:value => "search", :label=>"Search"}
|
22
22
|
]},
|
23
23
|
"maxsubs" => { :type => "list-single", :value => "20", :label => "Maximum number of subscribers", :options => [
|
@@ -28,15 +28,15 @@ shared_examples_for "any data form" do
|
|
28
28
|
{ :value => "100", :label=>"100"},
|
29
29
|
{ :value => "none", :label=>"None"}]}
|
30
30
|
}
|
31
|
-
|
31
|
+
|
32
32
|
dataform.fields.should == expected
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should understand hash to build object" do
|
36
|
-
params = {
|
36
|
+
params = {
|
37
37
|
"muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
|
38
38
|
"muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
|
39
|
-
"muc#roomconfig_whois" => {
|
39
|
+
"muc#roomconfig_whois" => {
|
40
40
|
:type => "list-single",
|
41
41
|
:value => "moderators",
|
42
42
|
:label => "Present real Jabber IDs to",
|
@@ -46,44 +46,35 @@ shared_examples_for "any data form" do
|
|
46
46
|
},
|
47
47
|
"muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
|
48
48
|
}
|
49
|
-
|
49
|
+
|
50
50
|
config = subject.class.new params
|
51
|
-
|
51
|
+
|
52
52
|
config.should be_a_kind_of subject.class
|
53
53
|
config.fields.should == params
|
54
54
|
end
|
55
|
-
|
56
|
-
it "should throw an error if :type is missing" do
|
57
|
-
expect{
|
58
|
-
subject.class.new( "foo" => { :value => "1", :label => "Foo" } )
|
59
|
-
}.to raise_error(
|
60
|
-
Jubjub::ArgumentError,
|
61
|
-
":type is missing for foo"
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
55
|
+
|
65
56
|
it "should throw an error if an unknown key is sent" do
|
66
|
-
expect{
|
57
|
+
expect{
|
67
58
|
subject.class.new( "foo" => { :type => "boolean", :value => "1", :label => "Foo", :oh_no => nil } )
|
68
|
-
}.to raise_error(
|
59
|
+
}.to raise_error(
|
69
60
|
Jubjub::ArgumentError,
|
70
61
|
":oh_no is not a recognised option for foo"
|
71
62
|
)
|
72
63
|
end
|
73
|
-
|
64
|
+
|
74
65
|
it "should throw an error if a hash isn't passed in" do
|
75
|
-
expect{
|
66
|
+
expect{
|
76
67
|
subject.class.new( "config" )
|
77
|
-
}.to raise_error(
|
68
|
+
}.to raise_error(
|
78
69
|
Jubjub::ArgumentError,
|
79
70
|
"please initialize with a hash of the format { 'foo' => {:type => 'boolean', :value => false, :label => 'Fooey'} }"
|
80
71
|
)
|
81
72
|
end
|
82
|
-
|
73
|
+
|
83
74
|
end
|
84
|
-
|
75
|
+
|
85
76
|
describe "instance method" do
|
86
|
-
|
77
|
+
|
87
78
|
describe "[]" do
|
88
79
|
context "for booleans" do
|
89
80
|
before do
|
@@ -110,16 +101,16 @@ shared_examples_for "any data form" do
|
|
110
101
|
}
|
111
102
|
)
|
112
103
|
end
|
113
|
-
|
104
|
+
|
114
105
|
it "should return false or true" do
|
115
106
|
@config['muc#roomconfig_allowinvites'].should be_false
|
116
107
|
@config['muc#roomconfig_moderatedroom'].should be_false
|
117
|
-
|
108
|
+
|
118
109
|
@config['muc#roomconfig_changesubject'].should be_true
|
119
110
|
@config['muc#roomconfig_publicroom'].should be_true
|
120
111
|
end
|
121
112
|
end
|
122
|
-
|
113
|
+
|
123
114
|
context "for lists" do
|
124
115
|
before do
|
125
116
|
@config = subject.class.new(
|
@@ -146,16 +137,16 @@ shared_examples_for "any data form" do
|
|
146
137
|
}
|
147
138
|
)
|
148
139
|
end
|
149
|
-
|
140
|
+
|
150
141
|
it "should return an array for list-multi" do
|
151
142
|
@config["muc#roomconfig_presencebroadcast"].should == ["moderator", "participant", "visitor"]
|
152
143
|
end
|
153
|
-
|
144
|
+
|
154
145
|
it "should return a single item for list-single" do
|
155
|
-
@config["muc#roomconfig_maxusers"].should == "20"
|
146
|
+
@config["muc#roomconfig_maxusers"].should == "20"
|
156
147
|
end
|
157
148
|
end
|
158
|
-
|
149
|
+
|
159
150
|
context "for jids" do
|
160
151
|
before do
|
161
152
|
@config = subject.class.new(
|
@@ -171,15 +162,15 @@ shared_examples_for "any data form" do
|
|
171
162
|
}
|
172
163
|
)
|
173
164
|
end
|
174
|
-
|
165
|
+
|
175
166
|
it "should return a Jubjub::Jid" do
|
176
167
|
jids = [Jubjub::Jid.new("wiccarocks@shakespeare.lit"), Jubjub::Jid.new("hecate@shakespeare.lit")]
|
177
|
-
|
168
|
+
|
178
169
|
@config['muc#roomconfig_roomadmins'].should == jids
|
179
170
|
@config['special_jid'].should == Jubjub::Jid.new("foo@bar.com")
|
180
171
|
end
|
181
172
|
end
|
182
|
-
|
173
|
+
|
183
174
|
context "for non existent options" do
|
184
175
|
before do
|
185
176
|
@config = subject.class.new(
|
@@ -190,15 +181,15 @@ shared_examples_for "any data form" do
|
|
190
181
|
}
|
191
182
|
)
|
192
183
|
end
|
193
|
-
|
184
|
+
|
194
185
|
it "should return nil" do
|
195
186
|
@config['made_up'].should be_nil
|
196
187
|
end
|
197
188
|
end
|
198
189
|
end
|
199
|
-
|
190
|
+
|
200
191
|
describe "[]=" do
|
201
|
-
|
192
|
+
|
202
193
|
context "for booleans do" do
|
203
194
|
before do
|
204
195
|
@config = subject.class.new(
|
@@ -209,33 +200,33 @@ shared_examples_for "any data form" do
|
|
209
200
|
}
|
210
201
|
)
|
211
202
|
end
|
212
|
-
|
203
|
+
|
213
204
|
it "should convert '0' to false" do
|
214
205
|
@config["muc#roomconfig_allowinvites"] = '0'
|
215
206
|
@config["muc#roomconfig_allowinvites"].should be_false
|
216
207
|
end
|
217
|
-
|
208
|
+
|
218
209
|
it "should convert '1' to true" do
|
219
210
|
@config["muc#roomconfig_allowinvites"] = '1'
|
220
211
|
@config["muc#roomconfig_allowinvites"].should be_true
|
221
212
|
end
|
222
|
-
|
213
|
+
|
223
214
|
it "should convert 'true' to true" do
|
224
215
|
@config["muc#roomconfig_allowinvites"] = 'true'
|
225
216
|
@config["muc#roomconfig_allowinvites"].should be_true
|
226
217
|
end
|
227
|
-
|
218
|
+
|
228
219
|
it "should convert 'false' to false" do
|
229
220
|
@config["muc#roomconfig_allowinvites"] = 'false'
|
230
221
|
@config["muc#roomconfig_allowinvites"].should be_false
|
231
222
|
end
|
232
|
-
|
223
|
+
|
233
224
|
it "should return false if something else" do
|
234
225
|
@config["muc#roomconfig_allowinvites"] = 'wibble'
|
235
226
|
@config["muc#roomconfig_allowinvites"].should be_false
|
236
227
|
end
|
237
228
|
end
|
238
|
-
|
229
|
+
|
239
230
|
context "for multi types" do
|
240
231
|
before do
|
241
232
|
@config = subject.class.new(
|
@@ -246,20 +237,20 @@ shared_examples_for "any data form" do
|
|
246
237
|
}
|
247
238
|
)
|
248
239
|
end
|
249
|
-
|
240
|
+
|
250
241
|
it "should accept an array" do
|
251
242
|
@config['muc#roomconfig_roomadmins'] = ['giraffe@zoo', 'elephant@zoo']
|
252
|
-
|
243
|
+
|
253
244
|
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo'), Jubjub::Jid.new('elephant@zoo')]
|
254
245
|
end
|
255
|
-
|
246
|
+
|
256
247
|
it "should convert to an array if it isn't" do
|
257
248
|
@config['muc#roomconfig_roomadmins'] = 'giraffe@zoo'
|
258
|
-
|
249
|
+
|
259
250
|
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo')]
|
260
251
|
end
|
261
252
|
end
|
262
|
-
|
253
|
+
|
263
254
|
context "for list types" do
|
264
255
|
before do
|
265
256
|
@config = subject.class.new(
|
@@ -286,23 +277,23 @@ shared_examples_for "any data form" do
|
|
286
277
|
}
|
287
278
|
)
|
288
279
|
end
|
289
|
-
|
280
|
+
|
290
281
|
it "should set the value if it is a valid option" do
|
291
282
|
@config['muc#roomconfig_maxusers'] = "10"
|
292
283
|
@config['muc#roomconfig_maxusers'].should eql("10")
|
293
|
-
|
284
|
+
|
294
285
|
@config['muc#roomconfig_presencebroadcast'] = ["visitor"]
|
295
|
-
@config['muc#roomconfig_presencebroadcast'].should eql(["visitor"])
|
286
|
+
@config['muc#roomconfig_presencebroadcast'].should eql(["visitor"])
|
296
287
|
end
|
297
|
-
|
288
|
+
|
298
289
|
it "should raise an error if the value isn't one of the options" do
|
299
290
|
expect{
|
300
|
-
@config['muc#roomconfig_maxusers'] = "50000"
|
291
|
+
@config['muc#roomconfig_maxusers'] = "50000"
|
301
292
|
}.to raise_error(
|
302
293
|
Jubjub::ArgumentError,
|
303
294
|
"50000 is not an accepted value please choose from 10, 20, 30, 40"
|
304
295
|
)
|
305
|
-
|
296
|
+
|
306
297
|
expect{
|
307
298
|
@config['muc#roomconfig_presencebroadcast'] = ["superman", "moderators"]
|
308
299
|
}.to raise_error(
|
@@ -311,7 +302,7 @@ shared_examples_for "any data form" do
|
|
311
302
|
)
|
312
303
|
end
|
313
304
|
end
|
314
|
-
|
305
|
+
|
315
306
|
context "for jid types" do
|
316
307
|
before do
|
317
308
|
@config = subject.class.new(
|
@@ -327,7 +318,7 @@ shared_examples_for "any data form" do
|
|
327
318
|
}
|
328
319
|
)
|
329
320
|
end
|
330
|
-
|
321
|
+
|
331
322
|
it "should convert strings to jids" do
|
332
323
|
@config['muc#roomconfig_roomadmins'] = ["foo@bar.com", "bar@foo.com"]
|
333
324
|
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
@@ -335,7 +326,7 @@ shared_examples_for "any data form" do
|
|
335
326
|
@config['special_jid'] = "bar@foo.com"
|
336
327
|
@config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
|
337
328
|
end
|
338
|
-
|
329
|
+
|
339
330
|
it "should accept jids" do
|
340
331
|
@config['muc#roomconfig_roomadmins'] = [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
341
332
|
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
@@ -344,7 +335,7 @@ shared_examples_for "any data form" do
|
|
344
335
|
@config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
|
345
336
|
end
|
346
337
|
end
|
347
|
-
|
338
|
+
|
348
339
|
context "for non existent fields" do
|
349
340
|
before do
|
350
341
|
@config = subject.class.new(
|
@@ -355,9 +346,9 @@ shared_examples_for "any data form" do
|
|
355
346
|
}
|
356
347
|
)
|
357
348
|
end
|
358
|
-
|
349
|
+
|
359
350
|
it "should raise an error" do
|
360
|
-
expect{
|
351
|
+
expect{
|
361
352
|
@config['fooey'] = "bar"
|
362
353
|
}.to raise_error(
|
363
354
|
Jubjub::ArgumentError,
|
@@ -365,9 +356,9 @@ shared_examples_for "any data form" do
|
|
365
356
|
)
|
366
357
|
end
|
367
358
|
end
|
368
|
-
|
359
|
+
|
369
360
|
end
|
370
|
-
|
361
|
+
|
371
362
|
describe "fields" do
|
372
363
|
it "should return all of the types, values, labels and options for each field" do
|
373
364
|
params = {
|
@@ -382,7 +373,7 @@ shared_examples_for "any data form" do
|
|
382
373
|
]
|
383
374
|
}
|
384
375
|
}
|
385
|
-
|
376
|
+
|
386
377
|
adjusted_params = {
|
387
378
|
"allow_query_users" => { :type => "boolean", :value => false, :label => "Allow users to query other users" },
|
388
379
|
"muc#roomconfig_maxusers" => {
|
@@ -395,37 +386,37 @@ shared_examples_for "any data form" do
|
|
395
386
|
]
|
396
387
|
}
|
397
388
|
}
|
398
|
-
|
389
|
+
|
399
390
|
config = subject.class.new(params)
|
400
391
|
config.fields.should == params
|
401
|
-
|
392
|
+
|
402
393
|
config['allow_query_users'] = false
|
403
394
|
config.fields.should == adjusted_params
|
404
395
|
end
|
405
396
|
end
|
406
|
-
|
397
|
+
|
407
398
|
describe "==" do
|
408
|
-
it "should match the same room config" do
|
399
|
+
it "should match the same room config" do
|
409
400
|
config_1 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
410
401
|
config_2 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
411
|
-
|
402
|
+
|
412
403
|
config_1.should == config_2
|
413
404
|
end
|
414
|
-
|
405
|
+
|
415
406
|
it "should not match a different room config" do
|
416
407
|
config_1 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
417
408
|
config_2 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "0", :label => "Foo" } )
|
418
|
-
|
409
|
+
|
419
410
|
config_1.should_not == config_2
|
420
411
|
end
|
421
412
|
end
|
422
|
-
|
413
|
+
|
423
414
|
describe "settings" do
|
424
415
|
before do
|
425
416
|
@config = subject.class.new(
|
426
417
|
"muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
|
427
418
|
"muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
|
428
|
-
"muc#roomconfig_whois" => {
|
419
|
+
"muc#roomconfig_whois" => {
|
429
420
|
:type => "list-single",
|
430
421
|
:value => "moderators",
|
431
422
|
:label => "Present real Jabber IDs to",
|
@@ -440,9 +431,9 @@ shared_examples_for "any data form" do
|
|
440
431
|
},
|
441
432
|
"muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
|
442
433
|
)
|
443
|
-
|
434
|
+
|
444
435
|
end
|
445
|
-
|
436
|
+
|
446
437
|
it "should generate hash of name and values" do
|
447
438
|
@config.settings.should == {
|
448
439
|
"muc#roomconfig_allowvisitornickchange" => [true],
|
@@ -455,53 +446,100 @@ shared_examples_for "any data form" do
|
|
455
446
|
end
|
456
447
|
|
457
448
|
describe "to_builder" do
|
458
|
-
|
449
|
+
|
459
450
|
it "should return a Nokogiri::XML::Builder" do
|
460
|
-
subject.to_builder.should be_a_kind_of Nokogiri::XML::Builder
|
451
|
+
subject.to_builder.should be_a_kind_of Nokogiri::XML::Builder
|
461
452
|
end
|
462
|
-
|
453
|
+
|
454
|
+
it "should return a valid dataform" do
|
455
|
+
@config = subject.class.new(
|
456
|
+
"boolean_field" => { :type => "boolean", :value => "1", :label => "Boolean Field" },
|
457
|
+
"text_single_field" => { :type => "text-single", :value => "", :label => "Text Single Field" },
|
458
|
+
"list_single_field" => {
|
459
|
+
:type => "list-single",
|
460
|
+
:value => "first",
|
461
|
+
:label => "List Single Field",
|
462
|
+
:options => [
|
463
|
+
{ :value => "first", :label => "The first option" },
|
464
|
+
{ :value => "second", :label => "The second option" } ],
|
465
|
+
},
|
466
|
+
"jid_multi_field" => {
|
467
|
+
:type => "jid-multi",
|
468
|
+
:label => "Jid Multi Field",
|
469
|
+
:value => ["first@jid", "second@jid"]
|
470
|
+
},
|
471
|
+
"unknown_field" => { :value => "0", :label => "Unknown Field" }
|
472
|
+
)
|
473
|
+
|
474
|
+
@xml = @config.to_builder.to_xml
|
475
|
+
|
476
|
+
@expected_xml = <<-EOS
|
477
|
+
<?xml version="1.0"?>
|
478
|
+
<x xmlns="jabber:x:data" type="submit">
|
479
|
+
<field var="boolean_field" type="boolean">
|
480
|
+
<value>true</value>
|
481
|
+
</field>
|
482
|
+
<field var="text_single_field" type="text-single">
|
483
|
+
<value></value>
|
484
|
+
</field>
|
485
|
+
<field var="list_single_field" type="list-single">
|
486
|
+
<value>first</value>
|
487
|
+
</field>
|
488
|
+
<field var="jid_multi_field" type="jid-multi">
|
489
|
+
<value>first@jid</value>
|
490
|
+
<value>second@jid</value>
|
491
|
+
</field>
|
492
|
+
<field var="unknown_field">
|
493
|
+
<value>0</value>
|
494
|
+
</field>
|
495
|
+
</x>
|
496
|
+
EOS
|
497
|
+
|
498
|
+
@xml.should be_equivalent_to( @expected_xml )
|
499
|
+
end
|
500
|
+
|
463
501
|
it "should be possible to merge this into another Nokogiri::Builder" do
|
464
502
|
doc = Nokogiri::XML::Builder.new{|xml|
|
465
503
|
xml.foo {
|
466
504
|
subject.to_builder(xml.parent)
|
467
505
|
}
|
468
506
|
}.to_xml
|
469
|
-
|
507
|
+
|
470
508
|
expected = "<?xml version=\"1.0\"?>\n<foo>\n <x xmlns=\"jabber:x:data\" type=\"submit\"/>\n</foo>\n"
|
471
|
-
|
509
|
+
|
472
510
|
doc.should == expected
|
473
511
|
end
|
474
|
-
|
512
|
+
|
475
513
|
end
|
476
|
-
|
514
|
+
|
477
515
|
end
|
478
|
-
|
516
|
+
|
479
517
|
describe "dynamic methods" do
|
480
|
-
|
518
|
+
|
481
519
|
describe "<friendly name>= " do
|
482
520
|
it "should return the same as []="
|
483
521
|
end
|
484
|
-
|
522
|
+
|
485
523
|
describe "<friendly name>" do
|
486
524
|
it "should return the same as []"
|
487
525
|
end
|
488
|
-
|
526
|
+
|
489
527
|
describe "<friendly name>?" do
|
490
528
|
it "should return label"
|
491
529
|
end
|
492
|
-
|
530
|
+
|
493
531
|
describe "<name>=" do
|
494
532
|
it "should return the same as []="
|
495
533
|
end
|
496
|
-
|
534
|
+
|
497
535
|
describe "<name>" do
|
498
536
|
it "should return the same as []"
|
499
537
|
end
|
500
|
-
|
538
|
+
|
501
539
|
describe "<name>?" do
|
502
540
|
it "should return label"
|
503
541
|
end
|
504
|
-
|
542
|
+
|
505
543
|
end
|
506
|
-
|
544
|
+
|
507
545
|
end
|