social_stream-base 0.19.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,7 +49,7 @@ module SocialStream #:nodoc:
49
49
  a.map{ |e| normalize(e) }
50
50
  else
51
51
  begin
52
- a.supertype!
52
+ a.__send__ "#{ name.underscore }!" # a.actor!
53
53
  rescue
54
54
  raise "Unable to normalize #{ self } #{ a.inspect }"
55
55
  end
@@ -0,0 +1,11 @@
1
+ module SocialStream
2
+ module Routing
3
+ module Constraints
4
+ class Custom
5
+ def matches?(request)
6
+ SocialStream.relation_model == :custom
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SocialStream
2
+ module Routing
3
+ module Constraints
4
+ class Follow
5
+ def matches?(request)
6
+ SocialStream.relation_model == :follow
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SocialStream
2
+ module Routing
3
+ module Constraints
4
+ class Resque
5
+ def matches?(request)
6
+ SocialStream.resque_access
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe FollowersController do
4
+ include SocialStream::TestHelpers::Controllers
5
+
6
+ render_views
7
+
8
+ describe "with followers" do
9
+ before do
10
+ @user = Factory(:user)
11
+
12
+ @follow = Factory(:follow, :contact => Factory(:contact, :sender => @user.actor))
13
+
14
+ sign_in @user
15
+ end
16
+
17
+ it "should render index" do
18
+ get :index
19
+
20
+ response.should be_success
21
+ end
22
+
23
+ describe "with post" do
24
+ before do
25
+ Factory(:self_post, :author_id => @user.actor_id)
26
+ end
27
+
28
+ it "should render index" do
29
+ get :index
30
+
31
+ response.should be_success
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -7,153 +7,149 @@ describe PostsController do
7
7
  render_views
8
8
 
9
9
  describe "authorizing" do
10
- before do
11
- @user = Factory(:user)
12
- sign_in @user
10
+ before :all do
11
+ @ss_relation_model = SocialStream.relation_model
13
12
  end
14
13
 
15
- describe "posts to user" do
16
- describe "with first relation" do
17
- before do
18
- contact = @user.contact_to!(@user)
19
- relation = @user.relation_customs.sort.first
20
- model_assigned_to @user.contact_to!(@user), relation
21
- @current_model = Factory(:post, :author_id => @user.actor_id,
22
- :owner_id => @user.actor_id,
23
- :user_author_id => @user.actor_id,
24
- :_relation_ids => Array(relation.id))
25
- end
26
-
27
- it_should_behave_like "Allow Creating"
28
- it_should_behave_like "Allow Reading"
29
- it_should_behave_like "Allow Destroying"
30
-
31
- it "should destroy with js" do
32
- count = model_count
33
- delete :destroy, :id => @current_model.to_param, :format => :js
34
-
35
- resource = assigns(model_sym)
14
+ after :all do
15
+ SocialStream.relation_model = @ss_relation_model
16
+ end
36
17
 
37
- model_count.should eq(count - 1)
38
- end
18
+ describe "in follow relation model" do
19
+ before :all do
20
+ SocialStream.relation_model = :follow
39
21
  end
40
22
 
41
- describe "with last relation" do
42
- before do
43
- contact = @user.contact_to!(@user)
44
- relation = @user.relation_customs.sort.last
45
- model_assigned_to @user.contact_to!(@user), relation
46
- @current_model = Factory(:post, :author_id => @user.actor_id,
47
- :owner_id => @user.actor_id,
48
- :user_author_id => @user.actor_id,
49
- :_relation_ids => Array(relation.id))
50
- end
51
-
52
- it_should_behave_like "Allow Creating"
53
- it_should_behave_like "Allow Reading"
54
- it_should_behave_like "Allow Destroying"
23
+ before do
24
+ @user = Factory(:user)
25
+ sign_in @user
55
26
  end
56
27
 
57
- describe "with public relation" do
28
+ describe "post from other user" do
58
29
  before do
59
- contact = @user.contact_to!(@user)
60
- relation = Relation::Public.instance
61
- model_assigned_to @user.contact_to!(@user), relation
62
- @current_model = Factory(:post, :author_id => @user.actor_id,
63
- :owner_id => @user.actor_id,
64
- :user_author_id => @user.actor_id)
30
+ @current_model = Factory(:post)
65
31
  end
66
32
 
67
- it_should_behave_like "Allow Creating"
68
33
  it_should_behave_like "Allow Reading"
69
- it_should_behave_like "Allow Destroying"
70
34
  end
71
35
  end
72
36
 
73
- describe "post to friend" do
74
- before do
75
- friend = Factory(:friend, :contact => Factory(:contact, :receiver => @user.actor)).sender
37
+ describe "in custom relation mode" do
38
+ before :all do
39
+ SocialStream.relation_model = :custom
40
+ end
76
41
 
77
- model_assigned_to @user.contact_to!(friend), friend.relation_custom('friend')
78
- @current_model = Factory(:post, :author_id => @user.actor_id,
79
- :owner_id => friend.id,
80
- :user_author_id => @user.actor_id)
42
+ before do
43
+ @user = Factory(:user)
44
+ sign_in @user
81
45
  end
82
46
 
83
- it_should_behave_like "Allow Creating"
84
- it_should_behave_like "Allow Reading"
85
- end
47
+ describe "posts to user" do
48
+ describe "with first relation" do
49
+ before do
50
+ contact = @user.contact_to!(@user)
51
+ relation = @user.relation_customs.sort.first
52
+ model_assigned_to @user.contact_to!(@user), relation
53
+ @current_model = Factory(:post, :author_id => @user.actor_id,
54
+ :owner_id => @user.actor_id,
55
+ :user_author_id => @user.actor_id,
56
+ :_relation_ids => Array(relation.id))
57
+ end
86
58
 
87
- describe "post to acquaintance" do
88
- before do
89
- ac = Factory(:acquaintance, :contact => Factory(:contact, :receiver => @user.actor)).sender
59
+ it_should_behave_like "Allow Creating"
60
+ it_should_behave_like "Allow Reading"
61
+ it_should_behave_like "Allow Destroying"
90
62
 
91
- model_assigned_to @user.contact_to!(ac), ac.relation_custom('acquaintance')
92
- end
63
+ it "should destroy with js" do
64
+ count = model_count
65
+ delete :destroy, :id => @current_model.to_param, :format => :js
93
66
 
94
- it_should_behave_like "Deny Creating"
95
- end
67
+ resource = assigns(model_sym)
96
68
 
97
- describe "post from other user" do
98
- before do
99
- @current_model = Factory(:post)
100
- end
69
+ model_count.should eq(count - 1)
70
+ end
71
+ end
101
72
 
102
- it_should_behave_like "Deny Reading"
103
- end
73
+ describe "with last relation" do
74
+ before do
75
+ contact = @user.contact_to!(@user)
76
+ relation = @user.relation_customs.sort.last
77
+ model_assigned_to @user.contact_to!(@user), relation
78
+ @current_model = Factory(:post, :author_id => @user.actor_id,
79
+ :owner_id => @user.actor_id,
80
+ :user_author_id => @user.actor_id,
81
+ :_relation_ids => Array(relation.id))
82
+ end
104
83
 
105
- describe "posts represented group" do
106
- before do
107
- @group = Factory(:member, :contact => Factory(:group_contact, :receiver => @user.actor)).sender_subject
84
+ it_should_behave_like "Allow Creating"
85
+ it_should_behave_like "Allow Reading"
86
+ it_should_behave_like "Allow Destroying"
87
+ end
88
+
89
+ describe "with public relation" do
90
+ before do
91
+ contact = @user.contact_to!(@user)
92
+ relation = Relation::Public.instance
93
+ model_assigned_to @user.contact_to!(@user), relation
94
+ @current_model = Factory(:post, :author_id => @user.actor_id,
95
+ :owner_id => @user.actor_id,
96
+ :user_author_id => @user.actor_id)
97
+ end
98
+
99
+ it_should_behave_like "Allow Creating"
100
+ it_should_behave_like "Allow Reading"
101
+ it_should_behave_like "Allow Destroying"
102
+ end
108
103
  end
109
104
 
110
- describe "with member relation" do
105
+ describe "post to friend" do
111
106
  before do
112
- contact = @user.contact_to!(@group)
113
- relation = @group.relation_custom('member')
114
-
115
- model_assigned_to contact, relation
116
- @current_model = Factory(:post, :author_id => contact.sender.id,
117
- :owner_id => contact.receiver.id,
118
- :user_author_id => contact.sender.id,
119
- :_relation_ids => Array(relation.id))
107
+ friend = Factory(:friend, :contact => Factory(:contact, :receiver => @user.actor)).sender
108
+
109
+ model_assigned_to @user.contact_to!(friend), friend.relation_custom('friend')
110
+ @current_model = Factory(:post, :author_id => @user.actor_id,
111
+ :owner_id => friend.id,
112
+ :user_author_id => @user.actor_id)
120
113
  end
121
114
 
122
115
  it_should_behave_like "Allow Creating"
123
116
  it_should_behave_like "Allow Reading"
124
- it_should_behave_like "Allow Destroying"
125
117
  end
126
118
 
127
- context "representing the group" do
119
+ describe "post to acquaintance" do
128
120
  before do
129
- represent(@group)
121
+ ac = Factory(:acquaintance, :contact => Factory(:contact, :receiver => @user.actor)).sender
122
+
123
+ model_assigned_to @user.contact_to!(ac), ac.relation_custom('acquaintance')
130
124
  end
131
125
 
132
- describe "with first relation" do
133
- before do
134
- contact = @group.contact_to!(@group)
135
- relation = @group.relation_customs.sort.first
136
- model_assigned_to contact, relation
137
- @current_model = Factory(:post, :author_id => contact.sender.id,
138
- :owner_id => contact.receiver.id,
139
- :user_author_id => contact.sender.id,
140
- :_relation_ids => Array(relation.id))
141
- end
126
+ it_should_behave_like "Deny Creating"
127
+ end
142
128
 
143
- it_should_behave_like "Allow Creating"
144
- it_should_behave_like "Allow Reading"
145
- it_should_behave_like "Allow Destroying"
129
+ describe "post from other user" do
130
+ before do
131
+ @current_model = Factory(:post)
146
132
  end
147
133
 
148
- describe "with last relation" do
134
+
135
+ it_should_behave_like "Deny Reading"
136
+ end
137
+
138
+ describe "posts represented group" do
139
+ before do
140
+ @group = Factory(:member, :contact => Factory(:group_contact, :receiver => @user.actor)).sender_subject
141
+ end
142
+
143
+ describe "with member relation" do
149
144
  before do
150
- contact = @group.contact_to!(@group)
151
- relation = @group.relation_customs.sort.last
145
+ contact = @user.contact_to!(@group)
146
+ relation = @group.relation_custom('member')
147
+
152
148
  model_assigned_to contact, relation
153
149
  @current_model = Factory(:post, :author_id => contact.sender.id,
154
- :owner_id => contact.receiver.id,
155
- :user_author_id => contact.sender.id,
156
- :_relation_ids => Array(relation.id))
150
+ :owner_id => contact.receiver.id,
151
+ :user_author_id => contact.sender.id,
152
+ :_relation_ids => Array(relation.id))
157
153
  end
158
154
 
159
155
  it_should_behave_like "Allow Creating"
@@ -161,91 +157,128 @@ describe PostsController do
161
157
  it_should_behave_like "Allow Destroying"
162
158
  end
163
159
 
164
- describe "with public relation" do
160
+ context "representing the group" do
165
161
  before do
166
- contact = @group.contact_to!(@group)
167
- relation = Relation::Public.instance
168
- model_assigned_to contact, relation
169
- @current_model = Factory(:post, :author_id => contact.sender.id,
170
- :owner_id => contact.receiver.id,
171
- :user_author_id => contact.sender.id,
172
- :_relation_ids => Array(relation.id))
162
+ represent(@group)
173
163
  end
174
164
 
175
- it_should_behave_like "Allow Creating"
176
- it_should_behave_like "Allow Reading"
177
- it_should_behave_like "Allow Destroying"
165
+ describe "with first relation" do
166
+ before do
167
+ contact = @group.contact_to!(@group)
168
+ relation = @group.relation_customs.sort.first
169
+ model_assigned_to contact, relation
170
+ @current_model = Factory(:post, :author_id => contact.sender.id,
171
+ :owner_id => contact.receiver.id,
172
+ :user_author_id => contact.sender.id,
173
+ :_relation_ids => Array(relation.id))
174
+ end
175
+
176
+ it_should_behave_like "Allow Creating"
177
+ it_should_behave_like "Allow Reading"
178
+ it_should_behave_like "Allow Destroying"
179
+ end
180
+
181
+ describe "with last relation" do
182
+ before do
183
+ contact = @group.contact_to!(@group)
184
+ relation = @group.relation_customs.sort.last
185
+ model_assigned_to contact, relation
186
+ @current_model = Factory(:post, :author_id => contact.sender.id,
187
+ :owner_id => contact.receiver.id,
188
+ :user_author_id => contact.sender.id,
189
+ :_relation_ids => Array(relation.id))
190
+ end
191
+
192
+ it_should_behave_like "Allow Creating"
193
+ it_should_behave_like "Allow Reading"
194
+ it_should_behave_like "Allow Destroying"
195
+ end
196
+
197
+ describe "with public relation" do
198
+ before do
199
+ contact = @group.contact_to!(@group)
200
+ relation = Relation::Public.instance
201
+ model_assigned_to contact, relation
202
+ @current_model = Factory(:post, :author_id => contact.sender.id,
203
+ :owner_id => contact.receiver.id,
204
+ :user_author_id => contact.sender.id,
205
+ :_relation_ids => Array(relation.id))
206
+ end
207
+
208
+ it_should_behave_like "Allow Creating"
209
+ it_should_behave_like "Allow Reading"
210
+ it_should_behave_like "Allow Destroying"
211
+ end
178
212
  end
179
213
  end
180
214
  end
181
- end
182
215
 
183
- context "creating post in group's wall" do
184
- before do
185
- @tie = Factory(:member)
186
- end
216
+ context "creating post in group's wall" do
217
+ before do
218
+ @tie = Factory(:member)
219
+ end
187
220
 
188
- it "should assign activity to member" do
189
- sign_in @tie.receiver_subject
221
+ it "should assign activity to member" do
222
+ sign_in @tie.receiver_subject
190
223
 
191
- post :create, :post => { :text => "Test",
192
- :owner_id => @tie.contact.sender.id
193
- }
224
+ post :create, :post => { :text => "Test",
225
+ :owner_id => @tie.contact.sender.id
226
+ }
194
227
 
195
- post = assigns(:post)
228
+ post = assigns(:post)
196
229
 
197
- post.should be_valid
198
- post.post_activity.relations.should include(@tie.relation)
199
- end
230
+ post.should be_valid
231
+ post.post_activity.relations.should include(@tie.relation)
232
+ end
200
233
 
201
- it "should assign activity to member" do
202
- sign_in @tie.receiver_subject
234
+ it "should assign activity to member" do
235
+ sign_in @tie.receiver_subject
203
236
 
204
- post :create, :post => { :text => "Test",
205
- :owner_id => @tie.contact.sender.id
206
- },
207
- :format => :js
208
-
237
+ post :create, :post => { :text => "Test",
238
+ :owner_id => @tie.contact.sender.id
239
+ },
240
+ :format => :js
209
241
 
210
- post = assigns(:post)
211
242
 
212
- post.should be_valid
213
- post.post_activity.relations.should include(@tie.relation)
243
+ post = assigns(:post)
214
244
 
215
- response.should be_success
216
- end
217
- end
245
+ post.should be_valid
246
+ post.post_activity.relations.should include(@tie.relation)
218
247
 
219
- context "creating public post" do
220
- before do
221
- @post = Factory(:public_post)
248
+ response.should be_success
249
+ end
222
250
  end
223
251
 
224
- it "should render" do
225
- get :show, :id => @post.to_param
252
+ context "creating public post" do
253
+ before do
254
+ @post = Factory(:public_post)
255
+ end
256
+
257
+ it "should render" do
258
+ get :show, :id => @post.to_param
226
259
 
227
- response.should be_success
260
+ response.should be_success
261
+ end
228
262
  end
229
- end
230
263
 
231
- describe "to friend on representation change" do
232
- before do
233
- @post = Factory(:post)
264
+ describe "to friend on representation change" do
265
+ before do
266
+ @post = Factory(:post)
234
267
 
235
- @user = @post.post_activity.sender_subject
268
+ @user = @post.post_activity.sender_subject
236
269
 
237
- @group = Factory(:member, :contact => Factory(:g2g_contact, :receiver => @user.actor)).sender_subject
270
+ @group = Factory(:member, :contact => Factory(:g2g_contact, :receiver => @user.actor)).sender_subject
238
271
 
239
- Factory(:friend, :contact => Factory(:g2g_contact, :sender => @user.actor))
272
+ Factory(:friend, :contact => Factory(:g2g_contact, :sender => @user.actor))
240
273
 
241
- sign_in @user
242
- end
274
+ sign_in @user
275
+ end
243
276
 
244
- it "should redirect show to home" do
245
- get :show, :id => @post.to_param, :s => @group.slug
277
+ it "should redirect show to home" do
278
+ get :show, :id => @post.to_param, :s => @group.slug
246
279
 
247
- response.should redirect_to(:home)
280
+ response.should redirect_to(:home)
281
+ end
248
282
  end
249
283
  end
250
284
  end
251
-