jubjub 0.0.5 → 0.0.6

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.
Files changed (39) hide show
  1. data/README.mdown +42 -6
  2. data/lib/jubjub/connection/xmpp_gateway/muc.rb +4 -20
  3. data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +194 -13
  4. data/lib/jubjub/data_form.rb +30 -0
  5. data/lib/jubjub/muc.rb +4 -93
  6. data/lib/jubjub/muc/collection.rb +55 -0
  7. data/lib/jubjub/muc/configuration.rb +5 -0
  8. data/lib/jubjub/muc/muc.rb +37 -0
  9. data/lib/jubjub/pubsub.rb +8 -201
  10. data/lib/jubjub/pubsub/affiliation.rb +83 -0
  11. data/lib/jubjub/pubsub/affiliation_collection.rb +38 -0
  12. data/lib/jubjub/pubsub/collection.rb +68 -0
  13. data/lib/jubjub/pubsub/configuration.rb +5 -0
  14. data/lib/jubjub/pubsub/item.rb +35 -0
  15. data/lib/jubjub/pubsub/item_collection.rb +35 -0
  16. data/lib/jubjub/pubsub/pubsub.rb +66 -0
  17. data/lib/jubjub/pubsub/subscription.rb +24 -0
  18. data/lib/jubjub/user.rb +2 -2
  19. data/spec/connection/xmpp_gateway_muc_spec.rb +3 -3
  20. data/spec/connection/xmpp_gateway_pubsub_spec.rb +167 -11
  21. data/spec/fixtures/dataform_1.xml +65 -0
  22. data/spec/fixtures/vcr_cassettes/pubsub_default_configuration.yml +118 -0
  23. data/spec/fixtures/vcr_cassettes/pubsub_modify_affiliations.yml +275 -0
  24. data/spec/fixtures/vcr_cassettes/pubsub_purge.yml +68 -0
  25. data/spec/fixtures/vcr_cassettes/pubsub_retrieve_affiliations.yml +99 -0
  26. data/spec/mixins/user_spec.rb +8 -8
  27. data/spec/models/muc_collection_spec.rb +17 -12
  28. data/spec/models/muc_configuration_spec.rb +1 -1
  29. data/spec/models/pubsub_affiliation_collection_spec.rb +86 -0
  30. data/spec/models/pubsub_affiliation_spec.rb +244 -0
  31. data/spec/models/pubsub_collection_spec.rb +50 -18
  32. data/spec/models/pubsub_item_collection_spec.rb +12 -12
  33. data/spec/models/pubsub_item_spec.rb +9 -2
  34. data/spec/models/pubsub_spec.rb +27 -2
  35. data/spec/models/pubsub_subscription_spec.rb +2 -2
  36. data/spec/spec_helper.rb +1 -1
  37. data/spec/support/helpers.rb +7 -0
  38. data/spec/support/shared_examples.rb +30 -0
  39. metadata +46 -19
@@ -0,0 +1,68 @@
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_pubsub_purge%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
+ - "346"
19
+ body: |
20
+ <iq type="error" id="blather000f" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/4894272601308145881366110" lang="en">
21
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
22
+ <create node="node_pubsub_purge"/>
23
+ </pubsub>
24
+ <error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></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%3cpurge%20node%3d%22node_pubsub_purge%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
+ - "133"
44
+ body: |
45
+ <iq type="result" id="blather0011" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/4894272601308145881366110"/>
46
+
47
+ http_version: "1.1"
48
+ - !ruby/struct:VCR::HTTPInteraction
49
+ request: !ruby/struct:VCR::Request
50
+ method: :post
51
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
52
+ 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_pubsub_purge%22%2f%3e%0a%20%20%3c%2fpubsub%3e%0a%3c%2fiq%3e%0a
53
+ headers:
54
+ content-type:
55
+ - application/x-www-form-urlencoded
56
+ response: !ruby/struct:VCR::Response
57
+ status: !ruby/struct:VCR::ResponseStatus
58
+ code: 200
59
+ message: ...
60
+ headers:
61
+ content-type:
62
+ - application/xml
63
+ content-length:
64
+ - "133"
65
+ body: |
66
+ <iq type="result" id="blather0013" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/4894272601308145881366110"/>
67
+
68
+ http_version: "1.1"
@@ -0,0 +1,99 @@
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_retrieve_affiliations%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
+ - "252"
19
+ body: |
20
+ <iq type="result" id="blather00a3" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/10916135201308219412692940">
21
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
22
+ <create node="node_retrieve_affiliations"/>
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%22get%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%3caffiliations%20node%3d%22node_retrieve_affiliations%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
+ - "361"
44
+ body: |
45
+ <iq type="result" id="blather00a5" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/10916135201308219412692940">
46
+ <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
47
+ <affiliations node="node_retrieve_affiliations">
48
+ <affiliation jid="theozaurus@theo-template.local" affiliation="owner"/>
49
+ </affiliations>
50
+ </pubsub>
51
+ </iq>
52
+
53
+ http_version: "1.1"
54
+ - !ruby/struct:VCR::HTTPInteraction
55
+ request: !ruby/struct:VCR::Request
56
+ method: :post
57
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
58
+ 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_retrieve_affiliations%22%2f%3e%0a%20%20%3c%2fpubsub%3e%0a%3c%2fiq%3e%0a
59
+ headers:
60
+ content-type:
61
+ - application/x-www-form-urlencoded
62
+ response: !ruby/struct:VCR::Response
63
+ status: !ruby/struct:VCR::ResponseStatus
64
+ code: 200
65
+ message: ...
66
+ headers:
67
+ content-type:
68
+ - application/xml
69
+ content-length:
70
+ - "134"
71
+ body: |
72
+ <iq type="result" id="blather00a7" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/10916135201308219412692940"/>
73
+
74
+ http_version: "1.1"
75
+ - !ruby/struct:VCR::HTTPInteraction
76
+ request: !ruby/struct:VCR::Request
77
+ method: :post
78
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
79
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22get%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%3caffiliations%20node%3d%22made-up%22%2f%3e%0a%20%20%3c%2fpubsub%3e%0a%3c%2fiq%3e%0a
80
+ headers:
81
+ content-type:
82
+ - application/x-www-form-urlencoded
83
+ response: !ruby/struct:VCR::Response
84
+ status: !ruby/struct:VCR::ResponseStatus
85
+ code: 200
86
+ message: ...
87
+ headers:
88
+ content-type:
89
+ - application/xml
90
+ content-length:
91
+ - "355"
92
+ body: |
93
+ <iq type="error" id="blather00a9" from="pubsub.theo-template.local" to="theozaurus@theo-template.local/10916135201308219412692940" lang="en">
94
+ <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
95
+ <affiliations node="made-up"/>
96
+ </pubsub>
97
+ <error code="404" type="cancel"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
98
+
99
+ http_version: "1.1"
@@ -121,13 +121,13 @@ describe Jubjub::User do
121
121
  mock_jubjub_connection
122
122
  end
123
123
 
124
- it 'should return Jubjub::MucCollection for conference.biggles.com when no service specified' do
125
- @user.mucs.should be_a Jubjub::MucCollection
124
+ it 'should return Jubjub::Muc::Collection for conference.biggles.com when no service specified' do
125
+ @user.mucs.should be_a Jubjub::Muc::Collection
126
126
  @user.mucs.jid.should == Jubjub::Jid.new('conference.biggles.com')
127
127
  end
128
128
 
129
- it 'should return Jubjub::MucCollection for service when specified' do
130
- @user.mucs('wibble.com').should be_a Jubjub::MucCollection
129
+ it 'should return Jubjub::Muc::Collection for service when specified' do
130
+ @user.mucs('wibble.com').should be_a Jubjub::Muc::Collection
131
131
  @user.mucs('wibble.com').jid.should == Jubjub::Jid.new('wibble.com')
132
132
  end
133
133
  end
@@ -137,13 +137,13 @@ describe Jubjub::User do
137
137
  mock_jubjub_connection
138
138
  end
139
139
 
140
- it 'should return Jubjub::PubsubCollection for conference.biggles.com when no service specified' do
141
- @user.pubsub.should be_a Jubjub::PubsubCollection
140
+ it 'should return Jubjub::Pubsub::Collection for conference.biggles.com when no service specified' do
141
+ @user.pubsub.should be_a Jubjub::Pubsub::Collection
142
142
  @user.pubsub.jid.should == Jubjub::Jid.new('pubsub.biggles.com')
143
143
  end
144
144
 
145
- it 'should return Jubjub::PubsubCollection for service when specified' do
146
- @user.pubsub('wibble.com').should be_a Jubjub::PubsubCollection
145
+ it 'should return Jubjub::Pubsub::Collection for service when specified' do
146
+ @user.pubsub('wibble.com').should be_a Jubjub::Pubsub::Collection
147
147
  @user.pubsub('wibble.com').jid.should == Jubjub::Jid.new('wibble.com')
148
148
  end
149
149
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jubjub::MucCollection do
3
+ describe Jubjub::Muc::Collection do
4
4
 
5
5
  describe "instance methods" do
6
6
 
@@ -15,16 +15,16 @@ describe Jubjub::MucCollection do
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
- Jubjub::MucCollection.new("conference.foo.com", @mock_connection).create("hello")
18
+ Jubjub::Muc::Collection.new("conference.foo.com", @mock_connection).create("hello")
19
19
  end
20
20
 
21
- it "should yield a MucConfiguration if a block is given" do
22
- @config = Jubjub::MucConfiguration.new( "allow_query_users" => { :type => "boolean", :value => "1", :label => "Foo" } )
21
+ it "should yield a Muc::Configuration if a block is given" do
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
- Jubjub::MucCollection.new("conference.foo.com", @mock_connection).create("hello"){|config|
27
+ Jubjub::Muc::Collection.new("conference.foo.com", @mock_connection).create("hello"){|config|
28
28
  config.should == @config
29
29
  }
30
30
  end
@@ -33,7 +33,7 @@ describe Jubjub::MucCollection do
33
33
 
34
34
  describe "jid" do
35
35
  it "should return the jid" do
36
- Jubjub::MucCollection.new("conference.foo.com", mock).jid.should == Jubjub::Jid.new("conference.foo.com")
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
 
@@ -47,7 +47,7 @@ describe Jubjub::MucCollection do
47
47
  @mock_connection.stub_chain( :muc, :list ).and_return(@rooms)
48
48
  end
49
49
 
50
- subject { Jubjub::MucCollection.new('conference.foo.com', @mock_connection) }
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]
@@ -56,14 +56,19 @@ describe Jubjub::MucCollection do
56
56
  it "should search by node if a String" do
57
57
  subject["room_1"].should == @rooms[0]
58
58
  end
59
+
60
+ it "should return Jubjub::Muc if nothing found for a String as it may still exist" do
61
+ subject['made-up'].should == Jubjub::Muc.new('made-up@conference.foo.com', nil, @mock_connection)
62
+ end
59
63
 
60
64
  it "should search by jid if a Jubjub::Jid" do
61
65
  subject[Jubjub::Jid.new("room_1@conference.foo.com")].should == @rooms[0]
62
66
  end
63
67
 
64
- it "should return nil if nothing found" do
65
- subject['made-up'].should be_nil
68
+ it "should return Jubjub::Muc if nothing found for a Jubjub::Jid as it may still exist" do
69
+ subject[Jubjub::Jid.new("made-up@conference.foo.com")].should == Jubjub::Muc.new('made-up@conference.foo.com', nil, @mock_connection)
66
70
  end
71
+
67
72
  end
68
73
 
69
74
  describe "that are proxied like" do
@@ -79,8 +84,8 @@ describe Jubjub::MucCollection do
79
84
 
80
85
  describe "inspect" do
81
86
 
82
- it "should show the list of rooms, not MucCollection" do
83
- Jubjub::MucCollection.new('conference.foo.com', @mock_connection).inspect.should eql(@rooms.inspect)
87
+ it "should show the list of rooms, not Muc::Collection" do
88
+ Jubjub::Muc::Collection.new('conference.foo.com', @mock_connection).inspect.should eql(@rooms.inspect)
84
89
  end
85
90
 
86
91
  end
@@ -88,7 +93,7 @@ describe Jubjub::MucCollection do
88
93
  describe "map" do
89
94
 
90
95
  it "should pass the block to the rooms" do
91
- c = Jubjub::MucCollection.new('conference.foo.com', @mock_connection)
96
+ c = Jubjub::Muc::Collection.new('conference.foo.com', @mock_connection)
92
97
  c.map{|r| r.jid.to_s }.should eql(['room_1@conference.foo.com', 'room_2@conference.foo.com'])
93
98
  end
94
99
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jubjub::MucConfiguration do
3
+ describe Jubjub::Muc::Configuration do
4
4
 
5
5
  it_behaves_like "any data form"
6
6
 
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::Pubsub::AffiliationCollection do
4
+
5
+ describe "that are proxied like" do
6
+
7
+ before do
8
+ @mock_connection = mock
9
+ @affiliations = [
10
+ Jubjub::Pubsub::Affiliation.new('pubsub.foo.com', 'node', 'theozaurus@foo.com', 'owner', @mock_connection),
11
+ Jubjub::Pubsub::Affiliation.new('pubsub.foo.com', 'node', 'dragonzaurus@foo.com', 'publisher', @mock_connection)
12
+ ]
13
+ @mock_connection.stub_chain( :pubsub, :retrieve_affiliations ).and_return(@affiliations)
14
+ end
15
+
16
+ describe "inspect" do
17
+
18
+ it "should show the list of affiliations, not Pubsub::AffiliationCollection" do
19
+ Jubjub::Pubsub::AffiliationCollection.new('pubsub.foo.com', 'node_1', @mock_connection).inspect.should eql(@affiliations.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::Pubsub::AffiliationCollection.new('pubsub.foo.com', 'node_1', @mock_connection)
28
+ c.map{|r| r.affiliation.to_s }.should eql(['owner', 'publisher'])
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::Pubsub::AffiliationCollection.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::Pubsub::AffiliationCollection.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::Pubsub::Affiliation.new('pubsub.foo.com', 'node_1', 'theozaurus@foo.com', 'owner', @mock_connection),
54
+ Jubjub::Pubsub::Affiliation.new('pubsub.foo.com', 'node_1', 'dragonzaurus@foo.com', 'member', @mock_connection)
55
+ ]
56
+ @mock_connection.stub_chain( :pubsub, :retrieve_affiliations ).and_return(@nodes)
57
+ end
58
+
59
+ subject { Jubjub::Pubsub::AffiliationCollection.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 jid if a String" do
66
+ subject["theozaurus@foo.com"].should == @nodes[0]
67
+ end
68
+
69
+ it "should return affiliation of 'none' if not found when searching by String" do
70
+ subject['blogozaurus@foo.com'].should ==
71
+ Jubjub::Pubsub::Affiliation.new('pubsub.foo.com', 'node_1', 'blogozaurus@foo.com', 'none', @mock_connection)
72
+ end
73
+
74
+ it "should search by Jid if Jubjub::Jid" do
75
+ subject[Jubjub::Jid.new 'dragonzaurus@foo.com'].should == @nodes[1]
76
+ end
77
+
78
+ it "should return afiliation of 'none' if not found when searching by Jubjub::Jid" do
79
+ subject[Jubjub::Jid.new 'blogozaurus@foo.com'].should ==
80
+ Jubjub::Pubsub::Affiliation.new('pubsub.foo.com', 'node_1', 'blogozaurus@foo.com', 'none', @mock_connection)
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,244 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jubjub::Pubsub::Affiliation do
4
+
5
+ def pubsub_affiliation_factory(override = {})
6
+ options = {
7
+ :pubsub_jid => Jubjub::Jid.new("pubsub.foo.com"),
8
+ :pubsub_node => "node_1",
9
+ :jid => Jubjub::Jid.new("theozaurus@foo.com"),
10
+ :affiliation => 'owner',
11
+ :connection => "SHHHH CONNECTION OBJECT"
12
+ }.merge( override )
13
+
14
+ Jubjub::Pubsub::Affiliation.new(
15
+ options[:pubsub_jid],
16
+ options[:pubsub_node],
17
+ options[:jid],
18
+ options[:affiliation],
19
+ options[:connection]
20
+ )
21
+ end
22
+
23
+ describe "instance method" do
24
+
25
+ describe "pubsub_jid" do
26
+ it "should return the pubsub_jid" do
27
+ p = pubsub_affiliation_factory :pubsub_jid => 'pubsub.foo.com'
28
+ p.pubsub_jid.should == Jubjub::Jid.new('pubsub.foo.com')
29
+ end
30
+ end
31
+
32
+ describe "pubsub_node" do
33
+ it "should return the node" do
34
+ p = pubsub_affiliation_factory :pubsub_node => 'node_1'
35
+ p.pubsub_node.should == 'node_1'
36
+ end
37
+ end
38
+
39
+ describe "jid" do
40
+ it "should return the jid" do
41
+ p = pubsub_affiliation_factory :jid => 'bob@foo.com'
42
+ p.jid.should == Jubjub::Jid.new('bob@foo.com')
43
+ end
44
+ end
45
+
46
+ describe "affiliation" do
47
+ it "should return the affiliation" do
48
+ p = pubsub_affiliation_factory :affiliation => 'publisher'
49
+ p.affiliation.should == 'publisher'
50
+ end
51
+ end
52
+
53
+ describe "owner?" do
54
+ it "should return true when affiliation is 'owner'" do
55
+ pubsub_affiliation_factory( :affiliation => 'owner' ).owner?.should equal(true)
56
+ end
57
+
58
+ it "should return false when affiliation is not 'owner'" do
59
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).owner?.should equal(false)
60
+ end
61
+ end
62
+
63
+ describe "publisher?" do
64
+ it "should return true when affiliation is 'publisher'" do
65
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).publisher?.should equal(true)
66
+ end
67
+
68
+ it "should return false when affiliation is not 'publisher'" do
69
+ pubsub_affiliation_factory( :affiliation => 'owner' ).publisher?.should equal(false)
70
+ end
71
+ end
72
+
73
+ describe "publish_only?" do
74
+ it "should return true when affiliation is 'publish-only'" do
75
+ pubsub_affiliation_factory( :affiliation => 'publish-only' ).publish_only?.should equal(true)
76
+ end
77
+
78
+ it "should return false when affiliation is not 'publish-only'" do
79
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).publish_only?.should equal(false)
80
+ end
81
+ end
82
+
83
+ describe "member?" do
84
+ it "should return true when affiliation is 'member'" do
85
+ pubsub_affiliation_factory( :affiliation => 'member' ).member?.should equal(true)
86
+ end
87
+
88
+ it "should return false when affiliation is not 'member'" do
89
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).member?.should equal(false)
90
+ end
91
+ end
92
+
93
+ describe "none?" do
94
+ it "should return true when affiliation is 'none'" do
95
+ pubsub_affiliation_factory( :affiliation => 'none' ).none?.should equal(true)
96
+ end
97
+
98
+ it "should return false when affiliation is not 'none'" do
99
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).none?.should equal(false)
100
+ end
101
+ end
102
+
103
+ describe "outcast?" do
104
+ it "should return true when affiliation is 'outcast'" do
105
+ pubsub_affiliation_factory( :affiliation => 'outcast' ).outcast?.should equal(true)
106
+ end
107
+
108
+ it "should return false when affiliation is not 'outcast'" do
109
+ pubsub_affiliation_factory( :affiliation => 'publisher' ).outcast?.should equal(false)
110
+ end
111
+ end
112
+
113
+ describe "set" do
114
+ it "should redirect call to pubsub.modify_affiliation" do
115
+ @mock_connection = mock
116
+ @mock_connection.stub_chain :pubsub, :modify_affiliations
117
+
118
+ affiliation = pubsub_affiliation_factory :connection => @mock_connection
119
+
120
+ @mock_connection.pubsub.should_receive(:modify_affiliations).with( affiliation.pubsub_jid, affiliation.pubsub_node, affiliation )
121
+
122
+ affiliation.set 'publisher'
123
+ end
124
+
125
+ describe "when succesful" do
126
+ before do
127
+ @mock_connection = mock
128
+ @mock_connection.stub_chain( :pubsub, :modify_affiliations ).and_return( true )
129
+ end
130
+
131
+ it "should return true" do
132
+ @affiliation = pubsub_affiliation_factory :connection => @mock_connection
133
+ @affiliation.set( 'publisher' ).should equal( true )
134
+ end
135
+
136
+ it "should have affiliaton set to new value" do
137
+ @affiliation = pubsub_affiliation_factory :connection => @mock_connection, :affiliation => 'owner'
138
+ @affiliation.set 'publisher'
139
+ @affiliation.affiliation.should == 'publisher'
140
+ end
141
+ end
142
+
143
+ describe "when unsuccesful" do
144
+ before do
145
+ @mock_connection = mock
146
+ @mock_connection.stub_chain( :pubsub, :modify_affiliations ).and_return( false )
147
+ end
148
+
149
+ it "should return false" do
150
+ @affiliation = pubsub_affiliation_factory :connection => @mock_connection
151
+ @affiliation.set( 'publisher' ).should equal( false )
152
+ end
153
+
154
+ it "should have affiliaton set to original value" do
155
+ @affiliation = pubsub_affiliation_factory :connection => @mock_connection, :affiliation => 'owner'
156
+ @affiliation.set 'publisher'
157
+ @affiliation.affiliation.should == 'owner'
158
+ end
159
+ end
160
+ end
161
+
162
+ describe "set_owner" do
163
+ it "should redirect call to set" do
164
+ affiliation = pubsub_affiliation_factory
165
+ affiliation.should_receive(:set).with('owner').and_return( 'from-set' )
166
+
167
+ affiliation.set_owner.should == 'from-set'
168
+ end
169
+ end
170
+
171
+ describe "set_publisher" do
172
+ it "should redirect call to set" do
173
+ affiliation = pubsub_affiliation_factory
174
+ affiliation.should_receive(:set).with('publisher').and_return( 'from-set' )
175
+
176
+ affiliation.set_publisher.should == 'from-set'
177
+ end
178
+ end
179
+
180
+ describe "set_publish_only" do
181
+ it "should redirect call to set" do
182
+ affiliation = pubsub_affiliation_factory
183
+ affiliation.should_receive(:set).with('publish-only').and_return( 'from-set' )
184
+
185
+ affiliation.set_publish_only.should == 'from-set'
186
+ end
187
+ end
188
+
189
+ describe "set_member" do
190
+ it "should redirect call to set" do
191
+ affiliation = pubsub_affiliation_factory
192
+ affiliation.should_receive(:set).with('member').and_return( 'from-set' )
193
+
194
+ affiliation.set_member.should == 'from-set'
195
+ end
196
+ end
197
+
198
+ describe "set_none" do
199
+ it "should redirect call to set" do
200
+ affiliation = pubsub_affiliation_factory
201
+ affiliation.should_receive(:set).with('none').and_return( 'from-set' )
202
+
203
+ affiliation.set_none.should == 'from-set'
204
+ end
205
+ end
206
+
207
+ describe "set_outcast" do
208
+ it "should redirect call to set" do
209
+ affiliation = pubsub_affiliation_factory
210
+ affiliation.should_receive(:set).with('outcast').and_return( 'from-set' )
211
+
212
+ affiliation.set_outcast.should == 'from-set'
213
+ end
214
+ end
215
+
216
+ describe "==" do
217
+ it "should match equivalent objects" do
218
+ pubsub_affiliation_factory.should == pubsub_affiliation_factory
219
+ end
220
+
221
+ it "should not distinguish between connections" do
222
+ pubsub_affiliation_factory(:connection => 'wibble').should == pubsub_affiliation_factory(:connection => 'wobble')
223
+ end
224
+
225
+ it "should still match no matter how jid is initialized" do
226
+ pubsub_affiliation_factory(:jid => 'foo@bar.com').should == pubsub_affiliation_factory(:jid => Jubjub::Jid.new('foo@bar.com'))
227
+ end
228
+
229
+ it "should still match no matter how pubsub_jid is initialized" do
230
+ pubsub_affiliation_factory(:pubsub_jid => 'pubsub.bar.com').should ==
231
+ pubsub_affiliation_factory(:pubsub_jid => Jubjub::Jid.new('pubsub.bar.com'))
232
+ end
233
+
234
+ it "should not match objects with different attributes" do
235
+ pubsub_affiliation_factory(:pubsub_jid => 'a.b.com').should_not == pubsub_affiliation_factory
236
+ pubsub_affiliation_factory(:pubsub_node => 'waggle').should_not == pubsub_affiliation_factory
237
+ pubsub_affiliation_factory(:jid => 'a.b.com').should_not == pubsub_affiliation_factory
238
+ pubsub_affiliation_factory(:affiliation => 'member').should_not == pubsub_affiliation_factory
239
+ end
240
+ end
241
+
242
+ end
243
+
244
+ end