jubjub 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mdown +32 -1
- data/lib/jubjub/connection/xmpp_gateway/muc.rb +2 -10
- data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +153 -1
- data/lib/jubjub/data_form.rb +91 -0
- data/lib/jubjub/muc.rb +15 -70
- data/lib/jubjub/pubsub.rb +95 -0
- data/lib/jubjub/user.rb +3 -0
- data/spec/connection/xmpp_gateway_pubsub_spec.rb +102 -0
- data/spec/fixtures/vcr_cassettes/pubsub_publish_with_dataform_payload.yml +28 -0
- data/spec/fixtures/vcr_cassettes/pubsub_publish_with_id.yml +28 -0
- data/spec/fixtures/vcr_cassettes/pubsub_publish_with_string_payload.yml +28 -0
- data/spec/fixtures/vcr_cassettes/pubsub_retract.yml +122 -0
- data/spec/fixtures/vcr_cassettes/pubsub_retrieve_items.yml +166 -0
- data/spec/fixtures/vcr_cassettes/pubsub_setup_node.yml +47 -0
- data/spec/models/data_form_spec.rb +7 -0
- data/spec/models/muc_collection_spec.rb +32 -3
- data/spec/models/muc_configuration_spec.rb +1 -453
- data/spec/models/pubsub_collection_spec.rb +26 -0
- data/spec/models/pubsub_item_collection_spec.rb +76 -0
- data/spec/models/pubsub_item_spec.rb +87 -0
- data/spec/models/pubsub_spec.rb +53 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples.rb +477 -0
- metadata +46 -25
@@ -85,6 +85,32 @@ describe Jubjub::PubsubCollection do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
describe "[]" do
|
89
|
+
before do
|
90
|
+
@mock_connection = mock
|
91
|
+
@nodes = [
|
92
|
+
Jubjub::Pubsub.new('pubsub.foo.com', 'node_1', @mock_connection),
|
93
|
+
Jubjub::Pubsub.new('pubsub.foo.com', 'node_2', @mock_connection)
|
94
|
+
]
|
95
|
+
@mock_connection.stub_chain( :pubsub, :list ).and_return(@nodes)
|
96
|
+
end
|
97
|
+
|
98
|
+
subject { Jubjub::PubsubCollection.new "pubsub.foo.com", @mock_connection }
|
99
|
+
|
100
|
+
it "should work like a normal array when passed a Fixnum" do
|
101
|
+
subject[1].should == @nodes[1]
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should search by node if a String" do
|
105
|
+
subject["node_1"].should == @nodes[0]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return nil if nothing found" do
|
109
|
+
subject['made-up'].should be_nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
88
114
|
describe "destroy" do
|
89
115
|
it "with redirect should call pubsub.destroy on connection" do
|
90
116
|
@mock_connection = mock
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jubjub::PubsubItemCollection do
|
4
|
+
|
5
|
+
describe "that are proxied like" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@mock_connection = mock
|
9
|
+
@items = [
|
10
|
+
Jubjub::PubsubItem.new('pubsub.foo.com', 'node_1', 'abc', '<foo></foo>', @mock_connection),
|
11
|
+
Jubjub::PubsubItem.new('pubsub.foo.com', 'node_1', 'efg', '<bar></bar>', @mock_connection)
|
12
|
+
]
|
13
|
+
@mock_connection.stub_chain( :pubsub, :retrieve_items ).and_return(@items)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "inspect" do
|
17
|
+
|
18
|
+
it "should show the list of rooms, not MucCollection" do
|
19
|
+
Jubjub::PubsubItemCollection.new('pubsub.foo.com', 'node_1', @mock_connection).inspect.should eql(@items.inspect)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "map" do
|
25
|
+
|
26
|
+
it "should pass the block to the rooms" do
|
27
|
+
c = Jubjub::PubsubItemCollection.new('pubsub.foo.com', 'node_1', @mock_connection)
|
28
|
+
c.map{|r| r.data.to_s }.should eql(['<foo></foo>', '<bar></bar>'])
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "instance method" do
|
36
|
+
|
37
|
+
describe "jid" do
|
38
|
+
it "should return the jid" do
|
39
|
+
Jubjub::PubsubItemCollection.new("pubsub.foo.com", "node", mock).jid.should == Jubjub::Jid.new("pubsub.foo.com")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "node" do
|
44
|
+
it "should return the node" do
|
45
|
+
Jubjub::PubsubItemCollection.new("pubsub.foo.com", "node", mock).node.should == 'node'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "[]" do
|
50
|
+
before do
|
51
|
+
@mock_connection = mock
|
52
|
+
@nodes = [
|
53
|
+
Jubjub::PubsubItem.new('pubsub.foo.com', 'node_1', 'abc', '<foo></foo>', @mock_connection),
|
54
|
+
Jubjub::PubsubItem.new('pubsub.foo.com', 'node_1', 'efg', '<bar></bar>', @mock_connection)
|
55
|
+
]
|
56
|
+
@mock_connection.stub_chain( :pubsub, :retrieve_items ).and_return(@nodes)
|
57
|
+
end
|
58
|
+
|
59
|
+
subject { Jubjub::PubsubItemCollection.new "pubsub.foo.com", "node_1", @mock_connection }
|
60
|
+
|
61
|
+
it "should work like a normal array when passed a Fixnum" do
|
62
|
+
subject[1].should == @nodes[1]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should search by node if a String" do
|
66
|
+
subject["abc"].should == @nodes[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return nil if nothing found" do
|
70
|
+
subject['made-up'].should be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jubjub::PubsubItem do
|
4
|
+
|
5
|
+
def pubsub_item_factory(override = {})
|
6
|
+
options = {
|
7
|
+
:jid => Jubjub::Jid.new("pubsub.foo.com"),
|
8
|
+
:node => 'node',
|
9
|
+
:item_id => '123',
|
10
|
+
:data => 'foo',
|
11
|
+
:connection => "SHHHH CONNECTION OBJECT"
|
12
|
+
}.merge( override )
|
13
|
+
|
14
|
+
Jubjub::PubsubItem.new(
|
15
|
+
options[:jid],
|
16
|
+
options[:node],
|
17
|
+
options[:item_id],
|
18
|
+
options[:data],
|
19
|
+
options[:connection]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "instance method" do
|
24
|
+
|
25
|
+
describe "jid" do
|
26
|
+
it "should return the jid" do
|
27
|
+
p = pubsub_item_factory :jid => 'foo.com'
|
28
|
+
p.jid.should == Jubjub::Jid.new('foo.com')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "node" do
|
33
|
+
it "should return the node" do
|
34
|
+
p = pubsub_item_factory :node => 'node_1'
|
35
|
+
p.node.should == 'node_1'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "data" do
|
40
|
+
it "should return the data" do
|
41
|
+
p = pubsub_item_factory :data => 'hello'
|
42
|
+
p.data.should == 'hello'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "item_id" do
|
47
|
+
it "should return the item_id" do
|
48
|
+
p = pubsub_item_factory :item_id => 'as12'
|
49
|
+
p.item_id.should == 'as12'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "retract" do
|
54
|
+
it "should call pubsub.retract on connection" do
|
55
|
+
@mock_connection = mock
|
56
|
+
@mock_connection.stub_chain :pubsub, :retract
|
57
|
+
@mock_connection.pubsub.should_receive(:retract).with( Jubjub::Jid.new( 'pubsub.foo.com' ), 'node', '123' )
|
58
|
+
|
59
|
+
p = pubsub_item_factory :jid => 'pubsub.foo.com', :node => 'node', :item_id => '123', :connection => @mock_connection
|
60
|
+
p.retract
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "==" do
|
65
|
+
it "should match equivalent objects" do
|
66
|
+
pubsub_item_factory.should == pubsub_item_factory
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not distinguish between connections" do
|
70
|
+
pubsub_item_factory(:connection => 'wibble').should == pubsub_item_factory(:connection => 'wobble')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should still match no matter how jid is initialized" do
|
74
|
+
pubsub_item_factory(:jid => 'foo@bar.com').should == pubsub_item_factory(:jid => Jubjub::Jid.new('foo@bar.com'))
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not match objects with different attributes" do
|
78
|
+
pubsub_item_factory(:jid => 'a.b.com').should_not == pubsub_item_factory
|
79
|
+
pubsub_item_factory(:node => 'adsafsd').should_not == pubsub_item_factory
|
80
|
+
pubsub_item_factory(:item_id => '23').should_not == pubsub_item_factory
|
81
|
+
pubsub_item_factory(:data => '<wibble></wibble').should_not == pubsub_item_factory
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/spec/models/pubsub_spec.rb
CHANGED
@@ -76,6 +76,44 @@ describe Jubjub::Pubsub do
|
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
|
+
describe "publish" do
|
80
|
+
|
81
|
+
before do
|
82
|
+
@mock_connection = mock
|
83
|
+
@mock_connection.stub_chain :pubsub, :publish
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "with item id" do
|
87
|
+
it "should call pubsub.publish on connection" do
|
88
|
+
@mock_connection.pubsub.should_receive(:publish).with( Jubjub::Jid.new( 'pubsub.foo.com' ), 'node', 'data', '123' )
|
89
|
+
|
90
|
+
m = Jubjub::Pubsub.new 'pubsub.foo.com', 'node', @mock_connection
|
91
|
+
m.publish 'data', '123'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "without item id" do
|
96
|
+
it "should call pubsub.publish on connection" do
|
97
|
+
@mock_connection.pubsub.should_receive(:publish).with( Jubjub::Jid.new( 'pubsub.foo.com' ), 'node', 'data', nil )
|
98
|
+
|
99
|
+
m = Jubjub::Pubsub.new 'pubsub.foo.com', 'node', @mock_connection
|
100
|
+
m.publish 'data'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "retract" do
|
107
|
+
it "should call pubsub.retract on connection" do
|
108
|
+
@mock_connection = mock
|
109
|
+
@mock_connection.stub_chain :pubsub, :retract
|
110
|
+
@mock_connection.pubsub.should_receive(:retract).with( Jubjub::Jid.new( 'pubsub.foo.com' ), 'node', '123' )
|
111
|
+
|
112
|
+
m = Jubjub::Pubsub.new 'pubsub.foo.com', 'node', @mock_connection
|
113
|
+
m.retract('123')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
79
117
|
describe "destroy" do
|
80
118
|
|
81
119
|
before do
|
@@ -103,6 +141,21 @@ describe Jubjub::Pubsub do
|
|
103
141
|
|
104
142
|
end
|
105
143
|
|
144
|
+
describe "items" do
|
145
|
+
|
146
|
+
before do
|
147
|
+
@mock_connection = mock
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should return Jubjub::PubsubItemCollection' do
|
151
|
+
@pubsub_node = Jubjub::Pubsub.new 'pubsub.foo.com', 'node', @mock_connection
|
152
|
+
@pubsub_node.items.should be_a Jubjub::PubsubItemCollection
|
153
|
+
@pubsub_node.items.jid.should == Jubjub::Jid.new('pubsub.foo.com')
|
154
|
+
@pubsub_node.items.node.should == 'node'
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
106
159
|
end
|
107
160
|
|
108
161
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,477 @@
|
|
1
|
+
shared_examples_for "any data form" do
|
2
|
+
|
3
|
+
describe "creating" do
|
4
|
+
|
5
|
+
it "should understand hash to build object" do
|
6
|
+
params = {
|
7
|
+
"muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
|
8
|
+
"muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
|
9
|
+
"muc#roomconfig_whois" => {
|
10
|
+
:type => "list-single",
|
11
|
+
:value => "moderators",
|
12
|
+
:label => "Present real Jabber IDs to",
|
13
|
+
:options => [
|
14
|
+
{ :value =>"moderators", :label => "moderators only" },
|
15
|
+
{ :value =>"anyone", :label => "anyone" } ],
|
16
|
+
},
|
17
|
+
"muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
|
18
|
+
}
|
19
|
+
|
20
|
+
config = subject.class.new params
|
21
|
+
|
22
|
+
config.should be_a_kind_of subject.class
|
23
|
+
config.fields.should == params
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should throw an error if :type is missing" do
|
27
|
+
expect{
|
28
|
+
subject.class.new( "foo" => { :value => "1", :label => "Foo" } )
|
29
|
+
}.to raise_error(
|
30
|
+
Jubjub::ArgumentError,
|
31
|
+
":type is missing for foo"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should throw an error if an unknown key is sent" do
|
36
|
+
expect{
|
37
|
+
subject.class.new( "foo" => { :type => "boolean", :value => "1", :label => "Foo", :oh_no => nil } )
|
38
|
+
}.to raise_error(
|
39
|
+
Jubjub::ArgumentError,
|
40
|
+
":oh_no is not a recognised option for foo"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should throw an error if a hash isn't passed in" do
|
45
|
+
expect{
|
46
|
+
subject.class.new( "config" )
|
47
|
+
}.to raise_error(
|
48
|
+
Jubjub::ArgumentError,
|
49
|
+
"please initialize with a hash of the format { 'foo' => {:type => 'boolean', :value => false, :label => 'Fooey'} }"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "instance method" do
|
56
|
+
|
57
|
+
describe "[]" do
|
58
|
+
context "for booleans" do
|
59
|
+
before do
|
60
|
+
@config = subject.class.new(
|
61
|
+
"muc#roomconfig_allowinvites" => {
|
62
|
+
:type => "boolean",
|
63
|
+
:label => "Whether to Allow Occupants to Invite Others",
|
64
|
+
:value => "0"
|
65
|
+
},
|
66
|
+
"muc#roomconfig_moderatedroom" => {
|
67
|
+
:type => "boolean",
|
68
|
+
:label => "Whether to Make Room Moderated",
|
69
|
+
:value => "false"
|
70
|
+
},
|
71
|
+
"muc#roomconfig_changesubject" => {
|
72
|
+
:type => "boolean",
|
73
|
+
:label => "Whether to Allow Occupants to Change Subject",
|
74
|
+
:value => "1"
|
75
|
+
},
|
76
|
+
"muc#roomconfig_publicroom" => {
|
77
|
+
:type => "boolean",
|
78
|
+
:label => "Whether to Allow Public Searching for Room",
|
79
|
+
:value => "true"
|
80
|
+
}
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return false or true" do
|
85
|
+
@config['muc#roomconfig_allowinvites'].should be_false
|
86
|
+
@config['muc#roomconfig_moderatedroom'].should be_false
|
87
|
+
|
88
|
+
@config['muc#roomconfig_changesubject'].should be_true
|
89
|
+
@config['muc#roomconfig_publicroom'].should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "for lists" do
|
94
|
+
before do
|
95
|
+
@config = subject.class.new(
|
96
|
+
"muc#roomconfig_presencebroadcast" => {
|
97
|
+
:type => "list-multi",
|
98
|
+
:label => "Roles for which Presence is Broadcast",
|
99
|
+
:value => ["moderator", "participant", "visitor"],
|
100
|
+
:options => [
|
101
|
+
{ :value => "visitor", :label => "Visitor" },
|
102
|
+
{ :value => "moderators", :label => "Moderator" },
|
103
|
+
{ :value => "participant", :label => "Participant" }
|
104
|
+
]
|
105
|
+
},
|
106
|
+
"muc#roomconfig_maxusers" => {
|
107
|
+
:type => "list-single",
|
108
|
+
:label => "Maximum Number of Occupants",
|
109
|
+
:value => "20",
|
110
|
+
:options => [
|
111
|
+
{ :value => "10", :label => "10" },
|
112
|
+
{ :value => "20", :label => "20" },
|
113
|
+
{ :value => "30", :label => "30" },
|
114
|
+
{ :value => "40", :label => "40" }
|
115
|
+
]
|
116
|
+
}
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return an array for list-multi" do
|
121
|
+
@config["muc#roomconfig_presencebroadcast"].should == ["moderator", "participant", "visitor"]
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return a single item for list-single" do
|
125
|
+
@config["muc#roomconfig_maxusers"].should == "20"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "for jids" do
|
130
|
+
before do
|
131
|
+
@config = subject.class.new(
|
132
|
+
"muc#roomconfig_roomadmins" => {
|
133
|
+
:type => "jid-multi",
|
134
|
+
:label => "Room Admins",
|
135
|
+
:value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
|
136
|
+
},
|
137
|
+
"special_jid" => {
|
138
|
+
:type => "jid-single",
|
139
|
+
:label => "A special jid",
|
140
|
+
:value => "foo@bar.com"
|
141
|
+
}
|
142
|
+
)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should return a Jubjub::Jid" do
|
146
|
+
jids = [Jubjub::Jid.new("wiccarocks@shakespeare.lit"), Jubjub::Jid.new("hecate@shakespeare.lit")]
|
147
|
+
|
148
|
+
@config['muc#roomconfig_roomadmins'].should == jids
|
149
|
+
@config['special_jid'].should == Jubjub::Jid.new("foo@bar.com")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "for non existent options" do
|
154
|
+
before do
|
155
|
+
@config = subject.class.new(
|
156
|
+
"foo" => {
|
157
|
+
:type => "text-single",
|
158
|
+
:label => "Foo",
|
159
|
+
:value => "Blurgh"
|
160
|
+
}
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return nil" do
|
165
|
+
@config['made_up'].should be_nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "[]=" do
|
171
|
+
|
172
|
+
context "for booleans do" do
|
173
|
+
before do
|
174
|
+
@config = subject.class.new(
|
175
|
+
"muc#roomconfig_allowinvites" => {
|
176
|
+
:type => "boolean",
|
177
|
+
:label => "Whether to Allow Occupants to Invite Others",
|
178
|
+
:value => "0"
|
179
|
+
}
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should convert '0' to false" do
|
184
|
+
@config["muc#roomconfig_allowinvites"] = '0'
|
185
|
+
@config["muc#roomconfig_allowinvites"].should be_false
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should convert '1' to true" do
|
189
|
+
@config["muc#roomconfig_allowinvites"] = '1'
|
190
|
+
@config["muc#roomconfig_allowinvites"].should be_true
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should convert 'true' to true" do
|
194
|
+
@config["muc#roomconfig_allowinvites"] = 'true'
|
195
|
+
@config["muc#roomconfig_allowinvites"].should be_true
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should convert 'false' to false" do
|
199
|
+
@config["muc#roomconfig_allowinvites"] = 'false'
|
200
|
+
@config["muc#roomconfig_allowinvites"].should be_false
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return false if something else" do
|
204
|
+
@config["muc#roomconfig_allowinvites"] = 'wibble'
|
205
|
+
@config["muc#roomconfig_allowinvites"].should be_false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "for multi types" do
|
210
|
+
before do
|
211
|
+
@config = subject.class.new(
|
212
|
+
"muc#roomconfig_roomadmins" => {
|
213
|
+
:type => "jid-multi",
|
214
|
+
:label => "Room Admins",
|
215
|
+
:value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
|
216
|
+
}
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should accept an array" do
|
221
|
+
@config['muc#roomconfig_roomadmins'] = ['giraffe@zoo', 'elephant@zoo']
|
222
|
+
|
223
|
+
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo'), Jubjub::Jid.new('elephant@zoo')]
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should convert to an array if it isn't" do
|
227
|
+
@config['muc#roomconfig_roomadmins'] = 'giraffe@zoo'
|
228
|
+
|
229
|
+
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('giraffe@zoo')]
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context "for list types" do
|
234
|
+
before do
|
235
|
+
@config = subject.class.new(
|
236
|
+
"muc#roomconfig_presencebroadcast" => {
|
237
|
+
:type => "list-multi",
|
238
|
+
:label => "Roles for which Presence is Broadcast",
|
239
|
+
:value => ["moderator", "participant", "visitor"],
|
240
|
+
:options => [
|
241
|
+
{ :value => "visitor", :label => "Visitor" },
|
242
|
+
{ :value => "moderators", :label => "Moderator" },
|
243
|
+
{ :value => "participant", :label => "Participant" }
|
244
|
+
]
|
245
|
+
},
|
246
|
+
"muc#roomconfig_maxusers" => {
|
247
|
+
:type => "list-single",
|
248
|
+
:label => "Maximum Number of Occupants",
|
249
|
+
:value => "20",
|
250
|
+
:options => [
|
251
|
+
{ :value => "10", :label => "10" },
|
252
|
+
{ :value => "20", :label => "20" },
|
253
|
+
{ :value => "30", :label => "30" },
|
254
|
+
{ :value => "40", :label => "40" }
|
255
|
+
]
|
256
|
+
}
|
257
|
+
)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should set the value if it is a valid option" do
|
261
|
+
@config['muc#roomconfig_maxusers'] = "10"
|
262
|
+
@config['muc#roomconfig_maxusers'].should eql("10")
|
263
|
+
|
264
|
+
@config['muc#roomconfig_presencebroadcast'] = ["visitor"]
|
265
|
+
@config['muc#roomconfig_presencebroadcast'].should eql(["visitor"])
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should raise an error if the value isn't one of the options" do
|
269
|
+
expect{
|
270
|
+
@config['muc#roomconfig_maxusers'] = "50000"
|
271
|
+
}.to raise_error(
|
272
|
+
Jubjub::ArgumentError,
|
273
|
+
"50000 is not an accepted value please choose from 10, 20, 30, 40"
|
274
|
+
)
|
275
|
+
|
276
|
+
expect{
|
277
|
+
@config['muc#roomconfig_presencebroadcast'] = ["superman", "moderators"]
|
278
|
+
}.to raise_error(
|
279
|
+
Jubjub::ArgumentError,
|
280
|
+
"superman is not an accepted value please choose from visitor, moderators, participant"
|
281
|
+
)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "for jid types" do
|
286
|
+
before do
|
287
|
+
@config = subject.class.new(
|
288
|
+
"muc#roomconfig_roomadmins" => {
|
289
|
+
:type => "jid-multi",
|
290
|
+
:label => "Room Admins",
|
291
|
+
:value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
|
292
|
+
},
|
293
|
+
"special_jid" => {
|
294
|
+
:type => "jid-single",
|
295
|
+
:label => "A special jid",
|
296
|
+
:value => "foo@bar.com"
|
297
|
+
}
|
298
|
+
)
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should convert strings to jids" do
|
302
|
+
@config['muc#roomconfig_roomadmins'] = ["foo@bar.com", "bar@foo.com"]
|
303
|
+
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
304
|
+
|
305
|
+
@config['special_jid'] = "bar@foo.com"
|
306
|
+
@config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should accept jids" do
|
310
|
+
@config['muc#roomconfig_roomadmins'] = [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
311
|
+
@config['muc#roomconfig_roomadmins'].should == [Jubjub::Jid.new('foo@bar.com'), Jubjub::Jid.new('bar@foo.com')]
|
312
|
+
|
313
|
+
@config['special_jid'] = Jubjub::Jid.new('bar@foo.com')
|
314
|
+
@config['special_jid'].should == Jubjub::Jid.new('bar@foo.com')
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context "for non existent fields" do
|
319
|
+
before do
|
320
|
+
@config = subject.class.new(
|
321
|
+
"muc#roomconfig_roomadmins" => {
|
322
|
+
:type => "jid-multi",
|
323
|
+
:label => "Room Admins",
|
324
|
+
:value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
|
325
|
+
}
|
326
|
+
)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should raise an error" do
|
330
|
+
expect{
|
331
|
+
@config['fooey'] = "bar"
|
332
|
+
}.to raise_error(
|
333
|
+
Jubjub::ArgumentError,
|
334
|
+
"fooey is not a valid field"
|
335
|
+
)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
describe "fields" do
|
342
|
+
it "should return all of the types, values, labels and options for each field" do
|
343
|
+
params = {
|
344
|
+
"allow_query_users" => { :type => "boolean", :value => "1", :label => "Allow users to query other users" },
|
345
|
+
"muc#roomconfig_maxusers" => {
|
346
|
+
:type => "list-single",
|
347
|
+
:value => "5",
|
348
|
+
:label => "Maximum Number of Occupants",
|
349
|
+
:options => [
|
350
|
+
{ :value => "5", :label => "5" },
|
351
|
+
{ :value => "10", :label => "10" }
|
352
|
+
]
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
adjusted_params = {
|
357
|
+
"allow_query_users" => { :type => "boolean", :value => false, :label => "Allow users to query other users" },
|
358
|
+
"muc#roomconfig_maxusers" => {
|
359
|
+
:type => "list-single",
|
360
|
+
:value => "5",
|
361
|
+
:label => "Maximum Number of Occupants",
|
362
|
+
:options => [
|
363
|
+
{ :value => "5", :label => "5" },
|
364
|
+
{ :value => "10", :label => "10" }
|
365
|
+
]
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
config = subject.class.new(params)
|
370
|
+
config.fields.should == params
|
371
|
+
|
372
|
+
config['allow_query_users'] = false
|
373
|
+
config.fields.should == adjusted_params
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "==" do
|
378
|
+
it "should match the same room config" do
|
379
|
+
config_1 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
380
|
+
config_2 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
381
|
+
|
382
|
+
config_1.should == config_2
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should not match a different room config" do
|
386
|
+
config_1 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
|
387
|
+
config_2 = subject.class.new("allow_query_users" => { :type => "boolean", :value => "0", :label => "Foo" } )
|
388
|
+
|
389
|
+
config_1.should_not == config_2
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
describe "settings" do
|
394
|
+
before do
|
395
|
+
@config = subject.class.new(
|
396
|
+
"muc#roomconfig_allowvisitornickchange" => { :type => "boolean", :value => "1", :label => "Allow visitors to change nickname" },
|
397
|
+
"muc#roomconfig_roomname" => { :type => "text-single", :value => "", :label => "Room title" },
|
398
|
+
"muc#roomconfig_whois" => {
|
399
|
+
:type => "list-single",
|
400
|
+
:value => "moderators",
|
401
|
+
:label => "Present real Jabber IDs to",
|
402
|
+
:options => [
|
403
|
+
{ :value => "moderators", :label => "moderators only" },
|
404
|
+
{ :value => "anyone", :label => "anyone" } ],
|
405
|
+
},
|
406
|
+
"muc#roomconfig_roomadmins" => {
|
407
|
+
:type => "jid-multi",
|
408
|
+
:label => "Room Admins",
|
409
|
+
:value => ["wiccarocks@shakespeare.lit", "hecate@shakespeare.lit"]
|
410
|
+
},
|
411
|
+
"muc#roomconfig_passwordprotectedroom" => { :type => "boolean", :value => "0", :label => "Make room password protected" }
|
412
|
+
)
|
413
|
+
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should generate hash of name and values" do
|
417
|
+
@config.settings.should == {
|
418
|
+
"muc#roomconfig_allowvisitornickchange" => [true],
|
419
|
+
"muc#roomconfig_roomname" => [""],
|
420
|
+
"muc#roomconfig_whois" => ["moderators"],
|
421
|
+
"muc#roomconfig_roomadmins" => [Jubjub::Jid.new("wiccarocks@shakespeare.lit"), Jubjub::Jid.new("hecate@shakespeare.lit")],
|
422
|
+
"muc#roomconfig_passwordprotectedroom" => [false]
|
423
|
+
}
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
describe "to_builder" do
|
428
|
+
|
429
|
+
it "should return a Nokogiri::XML::Builder" do
|
430
|
+
subject.to_builder.should be_a_kind_of Nokogiri::XML::Builder
|
431
|
+
end
|
432
|
+
|
433
|
+
it "should be possible to merge this into another Nokogiri::Builder" do
|
434
|
+
doc = Nokogiri::XML::Builder.new{|xml|
|
435
|
+
xml.foo {
|
436
|
+
subject.to_builder(xml.parent)
|
437
|
+
}
|
438
|
+
}.to_xml
|
439
|
+
|
440
|
+
expected = "<?xml version=\"1.0\"?>\n<foo>\n <x xmlns=\"jabber:x:data\" type=\"submit\"/>\n</foo>\n"
|
441
|
+
|
442
|
+
doc.should == expected
|
443
|
+
end
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
end
|
448
|
+
|
449
|
+
describe "dynamic methods" do
|
450
|
+
|
451
|
+
describe "<friendly name>= " do
|
452
|
+
it "should return the same as []="
|
453
|
+
end
|
454
|
+
|
455
|
+
describe "<friendly name>" do
|
456
|
+
it "should return the same as []"
|
457
|
+
end
|
458
|
+
|
459
|
+
describe "<friendly name>?" do
|
460
|
+
it "should return label"
|
461
|
+
end
|
462
|
+
|
463
|
+
describe "<name>=" do
|
464
|
+
it "should return the same as []="
|
465
|
+
end
|
466
|
+
|
467
|
+
describe "<name>" do
|
468
|
+
it "should return the same as []"
|
469
|
+
end
|
470
|
+
|
471
|
+
describe "<name>?" do
|
472
|
+
it "should return label"
|
473
|
+
end
|
474
|
+
|
475
|
+
end
|
476
|
+
|
477
|
+
end
|