social_stream 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +1 -0
  2. data/README.rdoc +2 -3
  3. data/app/controllers/likes_controller.rb +2 -2
  4. data/app/controllers/messages_controller.rb +3 -0
  5. data/app/controllers/representations_controller.rb +8 -0
  6. data/app/controllers/ties_controller.rb +1 -1
  7. data/app/helpers/activities_helper.rb +2 -2
  8. data/app/helpers/ties_helper.rb +19 -16
  9. data/app/models/activity.rb +42 -7
  10. data/app/models/activity_object.rb +1 -0
  11. data/app/models/activity_verb.rb +5 -1
  12. data/app/models/actor.rb +113 -68
  13. data/app/models/group.rb +15 -1
  14. data/app/models/message.rb +2 -0
  15. data/app/models/permission.rb +20 -41
  16. data/app/models/profile.rb +1 -1
  17. data/app/models/relation.rb +34 -26
  18. data/app/models/representation.rb +35 -0
  19. data/app/models/tie.rb +47 -100
  20. data/app/models/user.rb +12 -17
  21. data/app/views/activities/_activities.html.erb +2 -2
  22. data/app/views/activities/_new.html.erb +6 -3
  23. data/app/views/activities/_options.html.erb +1 -1
  24. data/app/views/comments/_new.html.erb +2 -2
  25. data/app/views/frontpage/index.html.erb +0 -2
  26. data/app/views/groups/_group.html.erb +3 -3
  27. data/app/views/groups/_index.html.erb +3 -4
  28. data/app/views/groups/_middle_show.html.erb +7 -4
  29. data/app/views/groups/_new.html.erb +25 -0
  30. data/app/views/groups/_right_show.html.erb +4 -2
  31. data/app/views/groups/new.html.erb +1 -0
  32. data/app/views/groups/show.html.erb +1 -1
  33. data/app/views/home/_groups.html.erb +7 -5
  34. data/app/views/home/_location.html.erb +1 -1
  35. data/app/views/home/_options.html.erb +2 -2
  36. data/app/views/home/_right.html.erb +2 -2
  37. data/app/views/home/index.html.erb +6 -2
  38. data/app/views/layouts/_footer.html.erb +1 -1
  39. data/app/views/layouts/_header.erb +4 -1
  40. data/app/views/layouts/_representation.html.erb +20 -0
  41. data/app/views/{private_messages → messages}/_form.html.erb +4 -4
  42. data/app/views/{private_messages → messages}/_index.html.erb +1 -1
  43. data/app/views/{private_messages → messages}/_location.html.erb +1 -1
  44. data/app/views/messages/_message.html.erb +17 -0
  45. data/app/views/messages/_messages.html.erb +2 -0
  46. data/app/views/messages/edit.html.erb +6 -0
  47. data/app/views/{private_messages → messages}/index.html.erb +0 -0
  48. data/app/views/{private_messages → messages}/index.js.erb +0 -0
  49. data/app/views/{private_messages → messages}/new.html.erb +2 -2
  50. data/app/views/messages/show.html.erb +21 -0
  51. data/app/views/subjects/_contacts.html.erb +20 -0
  52. data/app/views/ties/_new.html.erb +6 -6
  53. data/app/views/ties/_pendings.html.erb +3 -3
  54. data/app/views/ties/_suggestions.html.erb +3 -3
  55. data/app/views/ties/_tie.html.erb +1 -1
  56. data/app/views/ties/create.js.erb +4 -5
  57. data/app/views/ties/new.js.erb +1 -1
  58. data/app/views/users/_groups.html.erb +5 -5
  59. data/app/views/users/_index.html.erb +3 -1
  60. data/app/views/users/_options.html.erb +1 -1
  61. data/app/views/users/_right_show.html.erb +3 -3
  62. data/app/views/users/show.html.erb +5 -3
  63. data/config/locales/en.yml +13 -19
  64. data/config/routes.rb +11 -4
  65. data/lib/generators/social_stream/install_generator.rb +2 -10
  66. data/lib/generators/social_stream/templates/initializer.rb +1 -1
  67. data/lib/generators/social_stream/templates/migration.rb +19 -24
  68. data/lib/generators/social_stream/templates/public/javascripts/jquery.js +6883 -0
  69. data/lib/generators/social_stream/templates/public/javascripts/rails.js +146 -0
  70. data/lib/generators/social_stream/templates/public/javascripts/ui.dropdownchecklist.js +3 -13
  71. data/lib/generators/social_stream/templates/public/stylesheets/header.css +5 -1
  72. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  73. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_flat_75_ffffff_40x100.png +0 -0
  74. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  75. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_65_ffffff_1x400.png +0 -0
  76. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_75_dadada_1x400.png +0 -0
  77. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  78. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  79. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  80. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_222222_256x240.png +0 -0
  81. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_2e83ff_256x240.png +0 -0
  82. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_454545_256x240.png +0 -0
  83. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_888888_256x240.png +0 -0
  84. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_cd0a0a_256x240.png +0 -0
  85. data/lib/generators/social_stream/templates/relations.yml +42 -0
  86. data/lib/social_stream/ability.rb +7 -6
  87. data/lib/social_stream/controllers/helpers.rb +35 -0
  88. data/lib/social_stream/models/{activity_object.rb → object.rb} +1 -1
  89. data/lib/social_stream/models/{actor.rb → subject.rb} +10 -30
  90. data/lib/social_stream/models/supertype.rb +5 -2
  91. data/lib/social_stream/rails.rb +25 -6
  92. data/lib/social_stream/relations.rb +46 -0
  93. data/lib/social_stream/version.rb +1 -1
  94. data/lib/social_stream.rb +13 -13
  95. data/lib/tasks/db/populate.rake +23 -29
  96. data/spec/controllers/groups_controller_spec.rb +2 -6
  97. data/spec/controllers/ties_controller_spec.rb +19 -0
  98. data/spec/controllers/users_controller_spec.rb +0 -2
  99. data/spec/dummy/config/application.rb +0 -1
  100. data/spec/dummy/config/initializers/social_stream.rb +14 -2
  101. data/spec/dummy/config/relations.yml +42 -0
  102. data/spec/dummy/db/schema.rb +9 -0
  103. data/spec/dummy/db/seeds.rb +0 -1
  104. data/spec/factories/activity.rb +2 -2
  105. data/spec/factories/actor.rb +2 -1
  106. data/spec/factories/group.rb +1 -0
  107. data/spec/factories/post.rb +1 -1
  108. data/spec/factories/tie.rb +16 -22
  109. data/spec/models/activity_spec.rb +27 -24
  110. data/spec/models/actor_spec.rb +3 -0
  111. data/spec/models/representation_spec.rb +16 -0
  112. data/spec/models/tie_spec.rb +49 -57
  113. data/spec/models/user_spec.rb +22 -0
  114. data/spec/support/db.rb +1 -1
  115. metadata +47 -45
  116. data/Gemfile.lock +0 -171
  117. data/app/controllers/private_messages_controller.rb +0 -3
  118. data/app/models/private_message.rb +0 -6
  119. data/app/views/groups/_follow.html.erb +0 -9
  120. data/app/views/groups/_followers.html.erb +0 -16
  121. data/app/views/home/_contacts.html.erb +0 -17
  122. data/app/views/private_messages/_messages.html.erb +0 -2
  123. data/app/views/private_messages/_private_message.html.erb +0 -17
  124. data/app/views/private_messages/edit.html.erb +0 -6
  125. data/app/views/private_messages/show.html.erb +0 -21
  126. data/app/views/ties/_pending.html.erb +0 -21
  127. data/app/views/users/_contacts.html.erb +0 -19
  128. data/init.rb +0 -3
  129. data/lib/generators/social_stream/templates/seeds.yml +0 -64
  130. data/lib/social_stream/rails/common.rb +0 -36
  131. data/lib/social_stream/rails/engine.rb +0 -9
  132. data/lib/social_stream/rails/railtie.rb +0 -9
  133. data/lib/social_stream/seed.rb +0 -49
  134. data/spec/dummy/db/seeds/social_stream.yml +0 -64
  135. data/spec/models/user_space.rb +0 -10
@@ -5,16 +5,12 @@ describe GroupsController do
5
5
 
6
6
  describe "when Anonymous" do
7
7
  it "should render index" do
8
- pending
9
-
10
8
  get :index
11
9
 
12
10
  assert_response :success
13
11
  end
14
12
 
15
13
  it "should render show" do
16
- pending
17
-
18
14
  get :show, :id => Factory(:group).to_param
19
15
 
20
16
  assert_response :success
@@ -34,8 +30,8 @@ describe GroupsController do
34
30
  assert_response :success
35
31
  end
36
32
 
37
- it "should render member group" do
38
- @group = Factory(:member, :sender => @user.actor).receiver_subject
33
+ it "should render contact group" do
34
+ @group = Factory(:member, :receiver => @user.actor).sender_subject
39
35
  get :show, :id => @group.to_param
40
36
 
41
37
  assert_response :success
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe TiesController do
4
+ render_views
5
+
6
+ describe "when authenticated" do
7
+ before do
8
+ @user = Factory(:user)
9
+
10
+ sign_in @user
11
+ end
12
+
13
+ it "should render new" do
14
+ get :new, :tie => Factory.attributes_for(:friend, :sender => @user.actor)
15
+
16
+ assert_response :success
17
+ end
18
+ end
19
+ end
@@ -11,8 +11,6 @@ describe UsersController do
11
11
  end
12
12
 
13
13
  it "should render show" do
14
- pending
15
-
16
14
  get :show, :id => Factory(:user).to_param
17
15
 
18
16
  assert_response :success
@@ -21,7 +21,6 @@ module Dummy
21
21
  # Only load the plugins named here, in the order given (default is alphabetical).
22
22
  # :all can be used as a placeholder for all plugins not explicitly named.
23
23
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
- config.paths.vendor.plugins "../../.."
25
24
 
26
25
  # Activate observers that should always be running.
27
26
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
@@ -1,5 +1,17 @@
1
1
  SocialStream.setup do |config|
2
- config.actors = [ :user, :group ]
2
+ # List the models that are social entities. These will have ties between them.
3
+ # Remember you must add an "actor_id" foreign key column to your migration!
4
+ #
5
+ # config.actors = [:user, :group ]
3
6
 
4
- config.activity_objects = [ :post, :comment ]
7
+ # Include devise modules in User. See devise documentation for details.
8
+ # Others available are:
9
+ # :token_authenticatable, :confirmable, :lockable, :timeoutable, :validatable
10
+ # config.devise_modules :database_authenticatable, :registerable,
11
+ # :recoverable, :rememberable, :trackable
12
+
13
+ # Type of activities managed by actors
14
+ # Remember you must add an "activity_object_id" foreign key column to your migration!
15
+ #
16
+ # config.activity_objects = [ :post, :comment, :messages ]
5
17
  end
@@ -0,0 +1,42 @@
1
+ # Relations for Social Stream
2
+ #
3
+ # Define the relations and permissions supported by your application
4
+ #
5
+ user:
6
+ friend:
7
+ name: friend
8
+ permissions:
9
+ - [ create, activity, weak_set ]
10
+ - [ read, activity, star_set ]
11
+ - [ update, activity, weak_set ]
12
+ - [ destroy, activity, weak_set ]
13
+ acquaintance:
14
+ name: acquaintance
15
+ parent: friend
16
+ permissions:
17
+ - [ read, activity, star_set ]
18
+ public:
19
+ name: public
20
+ parent: acquaintance
21
+ permissions:
22
+ - [ read, activity, star_set ]
23
+
24
+ group:
25
+ member:
26
+ name: member
27
+ permissions:
28
+ - [ represent ]
29
+ - [ create, activity, weak_set ]
30
+ - [ read, activity, star_set ]
31
+ - [ update, activity, weak_star_set ]
32
+ - [ destroy, activity, weak_star_set ]
33
+ partner:
34
+ name: partner
35
+ parent: member
36
+ permissions:
37
+ - [ read, activity, star_set ]
38
+ public:
39
+ name: public
40
+ parent: partner
41
+ permissions:
42
+ - [ read, activity, star_set ]
@@ -0,0 +1,9 @@
1
+ # Use migration template
2
+ path = %w( .. .. .. lib generators social_stream templates migration )
3
+ path.unshift File.dirname(__FILE__)
4
+
5
+ require File.join(*path)
6
+
7
+ ActiveRecord::Schema.define(:version => 0) do
8
+ CreateSocialStream.up
9
+ end
@@ -6,4 +6,3 @@
6
6
  # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
7
  # Mayor.create(:name => 'Daley', :city => cities.first)
8
8
 
9
- SocialStream.seed!
@@ -1,10 +1,10 @@
1
1
  Factory.define :activity do |a|
2
- a.association :_tie, :factory => :tie
2
+ a.association :_tie, :factory => :friend
3
3
  a.activity_verb { ActivityVerb["post"] }
4
4
  end
5
5
 
6
6
  Factory.define :like_activity, :parent => :activity do |a|
7
7
  a.association :parent, :factory => :activity
8
8
  a.activity_verb { ActivityVerb["like"] }
9
- a._tie { |tie| tie.association(:tie, :receiver => tie.parent.tie.receiver) }
9
+ a._tie { |tie| tie.association(:friend, :sender => tie.parent.tie.sender) }
10
10
  end
@@ -1,4 +1,5 @@
1
1
  Factory.define :actor do |s|
2
2
  s.sequence(:name) { |n| "Actor #{ n }" }
3
- s.subject_type "Subject"
3
+ s.subject_type "User"
4
4
  end
5
+
@@ -1,3 +1,4 @@
1
1
  Factory.define :group do |g|
2
2
  g.sequence(:name) { |n| "Group #{ n }" }
3
+ g._founder { |g| Factory(:user).permalink }
3
4
  end
@@ -1,4 +1,4 @@
1
1
  Factory.define :post do |p|
2
2
  p.sequence(:text) { |n| "Post #{ n }" }
3
- p._activity_tie_id { |q| q.association(:tie) }
3
+ p._activity_tie_id { |q| q.association(:friend) }
4
4
  end
@@ -1,43 +1,37 @@
1
1
  Factory.define :tie do |t|
2
- t.sender { |s| Factory(:user).actor }
2
+ t.sender { |s| Factory(:user).actor }
3
3
  t.receiver { |r| Factory(:user).actor }
4
- t.relation { |r| Relation.mode('User', 'User').strongest }
5
4
  end
6
5
 
7
- # UserToUser ties
6
+ # User ties
8
7
 
9
8
  Factory.define :friend, :parent => :tie do |t|
10
- t.relation { |r| Relation.mode('User', 'User').find_by_name('friend') }
9
+ t.after_build { |u| u.relation = u.sender.relation('friend') }
11
10
  end
12
11
 
13
- Factory.define :friend_request, :parent => :tie do |t|
14
- t.relation { |r| Relation.mode('User', 'User').find_by_name('friend_request') }
12
+ Factory.define :acquaintance, :parent => :tie do |t|
13
+ t.after_build { |u| u.relation = u.sender.relation('acquaintance') }
15
14
  end
16
15
 
17
16
  Factory.define :public, :parent => :tie do |t|
18
- t.relation { |r| Relation.mode('User', 'User').find_by_name('public') }
17
+ t.after_build { |u| u.relation = u.sender.relation('public') }
19
18
  end
20
19
 
21
- # UserToGroup ties
22
- Factory.define :u2g_tie, :parent => :tie do |t|
23
- t.receiver { |r| Factory(:group).actor }
24
- t.relation { |r| Relation.mode('User', 'Group').strongest }
20
+ # Group ties
21
+ Factory.define :g2u_tie, :parent => :tie do |t|
22
+ t.sender { |u| Factory(:group).actor }
25
23
  end
26
24
 
27
- Factory.define :member, :parent => :u2g_tie do |t|
28
- t.relation { |r| Relation.mode('User', 'Group').find_by_name('member') }
25
+ Factory.define :member, :parent => :g2u_tie do |t|
26
+ t.after_build { |u| u.relation = u.sender.relation('member') }
29
27
  end
30
28
 
31
- Factory.define :follower, :parent => :u2g_tie do |t|
32
- t.relation { |r| Relation.mode('User', 'Group').find_by_name('follower') }
29
+ Factory.define :g2g_tie, :parent => :tie do |t|
30
+ t.sender { |u| Factory(:group).actor }
31
+ t.receiver { |u| Factory(:group).actor }
33
32
  end
34
33
 
35
- # GroupToUser ties
36
- Factory.define :g2u_tie, :parent => :tie do |t|
37
- t.sender { |r| Factory(:group).actor }
38
- t.relation { |r| Relation.mode('Group', 'User').strongest }
34
+ Factory.define :partner, :parent => :g2g_tie do |t|
35
+ t.after_build { |u| u.relation = u.sender.relation('partner') }
39
36
  end
40
37
 
41
- Factory.define :g2u_member, :parent => :tie do |t|
42
- t.relation { |r| Relation.mode('Group', 'User').find_by_name('member') }
43
- end
@@ -7,13 +7,13 @@ module ActivityTestHelper
7
7
  end
8
8
 
9
9
  def create_ability_accessed_by(tie_type)
10
- t = Factory(tie_type, :receiver => @tie.receiver)
11
- u = t.sender_subject
10
+ t = Factory(tie_type, :sender => @tie.sender)
11
+ u = t.receiver_subject
12
12
  @ability = Ability.new(u)
13
13
  end
14
14
 
15
- def create_ability_accessed_by_sender
16
- u = @tie.sender_subject
15
+ def create_ability_accessed_by_receiver
16
+ u = @tie.receiver_subject
17
17
  @ability = Ability.new(u)
18
18
  end
19
19
 
@@ -96,7 +96,7 @@ describe Activity do
96
96
 
97
97
  describe "accessed by sender" do
98
98
  before do
99
- create_ability_accessed_by_sender
99
+ create_ability_accessed_by_receiver
100
100
  end
101
101
 
102
102
  it_should_behave_like "Allows Creating"
@@ -116,11 +116,12 @@ describe Activity do
116
116
  it_should_behave_like "Denies Destroying"
117
117
  end
118
118
 
119
- describe "accessed by friend request" do
119
+ describe "accessed by acquaintance" do
120
120
  before do
121
- create_ability_accessed_by :friend_request
121
+ create_ability_accessed_by :acquaintance
122
122
  end
123
123
 
124
+
124
125
  it_should_behave_like "Denies Creating"
125
126
  it_should_behave_like "Denies Reading"
126
127
  it_should_behave_like "Denies Updating"
@@ -139,15 +140,16 @@ describe Activity do
139
140
  end
140
141
  end
141
142
 
142
- describe "belonging to friend reflexive tie" do
143
+ describe "belonging to friend self tie" do
143
144
  before do
144
- tie = Factory(:user).ties.where(:relation_id => Relation.mode('User', 'User').find_by_name('friend')).first
145
+ user = Factory(:user)
146
+ tie = user.ties.where(:relation_id => user.relation('friend')).first
145
147
  create_activity_assigned_to(tie)
146
148
  end
147
149
 
148
150
  describe "accessed by the sender" do
149
151
  before do
150
- create_ability_accessed_by_sender
152
+ create_ability_accessed_by_receiver
151
153
  end
152
154
 
153
155
  it_should_behave_like "Allows Creating"
@@ -167,9 +169,9 @@ describe Activity do
167
169
  it_should_behave_like "Denies Destroying"
168
170
  end
169
171
 
170
- describe "accessed by friend request" do
172
+ describe "accessed by acquaintance" do
171
173
  before do
172
- create_ability_accessed_by :friend_request
174
+ create_ability_accessed_by :acquaintance
173
175
  end
174
176
 
175
177
  it_should_behave_like "Denies Creating"
@@ -193,13 +195,14 @@ describe Activity do
193
195
  describe "belonging to public tie" do
194
196
 
195
197
  before do
196
- tie = Factory(:user).ties.where(:relation_id => Relation.mode('User', 'User').find_by_name('public')).first
198
+ user = Factory(:user)
199
+ tie = user.ties.where(:relation_id => user.relation('public')).first
197
200
  create_activity_assigned_to(tie)
198
201
  end
199
202
 
200
203
  describe "accessed by the sender" do
201
204
  before do
202
- create_ability_accessed_by_sender
205
+ create_ability_accessed_by_receiver
203
206
  end
204
207
 
205
208
  it_should_behave_like "Allows Creating"
@@ -219,9 +222,9 @@ describe Activity do
219
222
  it_should_behave_like "Denies Destroying"
220
223
  end
221
224
 
222
- describe "accessed by friend request" do
225
+ describe "accessed by acquaintance" do
223
226
  before do
224
- create_ability_accessed_by :friend_request
227
+ create_ability_accessed_by :acquaintance
225
228
  end
226
229
 
227
230
  it_should_behave_like "Denies Creating"
@@ -246,7 +249,7 @@ describe Activity do
246
249
 
247
250
  before do
248
251
  create_activity_assigned_to(Factory(:public))
249
- create_ability_accessed_by_sender
252
+ create_ability_accessed_by_receiver
250
253
  end
251
254
 
252
255
  it_should_behave_like "Denies Creating"
@@ -259,7 +262,7 @@ describe Activity do
259
262
 
260
263
  describe "accessed by same member" do
261
264
  before do
262
- create_ability_accessed_by_sender
265
+ create_ability_accessed_by_receiver
263
266
  end
264
267
 
265
268
  it_should_behave_like "Allows Creating"
@@ -279,9 +282,9 @@ describe Activity do
279
282
  it_should_behave_like "Allows Destroying"
280
283
  end
281
284
 
282
- describe "accessed by follower" do
285
+ describe "accessed by partner" do
283
286
  before do
284
- create_ability_accessed_by :follower
287
+ create_ability_accessed_by :partner
285
288
  end
286
289
 
287
290
  it_should_behave_like "Denies Creating"
@@ -302,7 +305,7 @@ describe Activity do
302
305
  end
303
306
  end
304
307
 
305
- describe "belonging to public tie from an admin" do
308
+ describe "belonging to public tie from a member" do
306
309
 
307
310
  before do
308
311
  create_activity_assigned_to(Factory(:member).related('public'))
@@ -310,7 +313,7 @@ describe Activity do
310
313
 
311
314
  describe "accessed by sender" do
312
315
  before do
313
- create_ability_accessed_by_sender
316
+ create_ability_accessed_by_receiver
314
317
  end
315
318
 
316
319
  it_should_behave_like "Allows Creating"
@@ -331,9 +334,9 @@ describe Activity do
331
334
  end
332
335
 
333
336
 
334
- describe "accessed by follower" do
337
+ describe "accessed by partner" do
335
338
  before do
336
- create_ability_accessed_by :follower
339
+ create_ability_accessed_by :partner
337
340
  end
338
341
 
339
342
  it_should_behave_like "Denies Creating"
@@ -13,4 +13,7 @@ describe Actor do
13
13
  a.permalink.should_not == b.permalink
14
14
  end
15
15
 
16
+ it "should generate relations" do
17
+ assert Factory(:actor).relations.present?
18
+ end
16
19
  end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Representation do
4
+ describe "initialized with" do
5
+ describe "valid subject" do
6
+ before do
7
+ @group = Factory(:group)
8
+ @dom_id = ActionController::RecordIdentifier.dom_id(@group)
9
+ end
10
+
11
+ it "should find subject" do
12
+ assert_equal @group, Representation.new(:subject_dom_id => @dom_id).subject
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,30 +1,27 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Tie do
4
- it "should find the relation by its name" do
4
+ it "should create from relation name" do
5
5
  relation = Relation.first
6
6
  sender = Factory(relation.sender_type.underscore)
7
- receiver = Factory(relation.receiver_type.underscore)
7
+
8
+ receiver_type = relation.receiver_type.present? ?
9
+ relation.receiver_type :
10
+ relation.sender_type
11
+
12
+ receiver = Factory(receiver_type.underscore)
8
13
 
9
14
  tie = Factory(:tie, :sender_id => sender.actor.id,
10
15
  :receiver_id => receiver.actor.id,
11
16
  :relation_name => relation.name)
12
17
  tie.should be_valid
13
-
14
18
  end
15
19
 
16
- describe "with a relation with inverse" do
17
- before do
18
- @relation = Relation.where("inverse_id IS NOT NULL").first
19
- end
20
-
21
- it "should have its inverse tie" do
22
- @tie = Factory(:tie, :relation => @relation)
20
+ it "should create pending" do
21
+ tie = Factory(:friend)
23
22
 
24
- assert Tie.find_by_sender_id_and_receiver_id_and_relation_id(@tie.receiver_id,
25
- @tie.sender_id,
26
- @relation.inverse).present?
27
- end
23
+ assert tie.receiver.pending_ties.present?
24
+ assert tie.receiver.pending_ties.first.relation_set.blank?
28
25
  end
29
26
 
30
27
  describe "friend" do
@@ -32,65 +29,52 @@ describe Tie do
32
29
  @tie = Factory(:friend)
33
30
  end
34
31
 
35
- describe ", sender" do
32
+ describe ", receiver" do
36
33
  before do
37
- @s = @tie.sender
34
+ @s = @tie.receiver
38
35
  end
39
36
 
40
37
  it "creates activity" do
41
- Tie.allowed(@s, 'create', 'activity').should include(@tie)
42
- Tie.allowed(@s, 'create', 'activity').should include(@tie.related('public'))
43
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse)
44
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse.related('public'))
38
+ Tie.allowing(@s, 'create', 'activity').should include(@tie)
39
+ Tie.allowing(@s, 'create', 'activity').should include(@tie.related('public'))
45
40
  end
46
41
 
47
42
  it "reads activity" do
48
- Tie.allowed(@s, 'read', 'activity').should include(@tie)
49
- Tie.allowed(@s, 'read', 'activity').should include(@tie.related('public'))
50
- Tie.allowed(@s, 'read', 'activity').should include(@tie.inverse)
51
- Tie.allowed(@s, 'read', 'activity').should include(@tie.inverse.related('public'))
43
+ Tie.allowing(@s, 'read', 'activity').should include(@tie)
44
+ Tie.allowing(@s, 'read', 'activity').should include(@tie.related('public'))
52
45
  end
53
46
  end
54
47
 
55
48
  describe ", friend" do
56
49
  before do
57
- @s = @tie.receiver
50
+ @s = Factory(:friend, :sender => @tie.sender).receiver
58
51
  end
59
52
 
60
53
  it "creates activity" do
61
- Tie.allowed(@s, 'create', 'activity').should include(@tie.inverse)
62
- Tie.allowed(@s, 'create', 'activity').should include(@tie.inverse.related('public'))
63
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie)
64
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.related('public'))
54
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie)
55
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie.related('public'))
65
56
  end
66
57
 
67
58
  it "reads activity" do
68
- Tie.allowed(@s, 'read', 'activity').should include(@tie)
69
- Tie.allowed(@s, 'read', 'activity').should include(@tie.related('public'))
70
- Tie.allowed(@s, 'read', 'activity').should include(@tie.inverse)
71
- Tie.allowed(@s, 'read', 'activity').should include(@tie.inverse.related('public'))
59
+ Tie.allowing(@s, 'read', 'activity').should include(@tie)
60
+ Tie.allowing(@s, 'read', 'activity').should include(@tie.related('public'))
72
61
  end
73
62
  end
74
63
 
75
- describe ", friend request" do
64
+ describe ", acquaintance" do
76
65
  before do
77
- @s = Factory(:friend_request, :receiver => @tie.receiver).sender
66
+ @s = Factory(:acquaintance, :receiver => @tie.receiver).sender
78
67
  end
79
68
 
80
69
  it "creates activity" do
81
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie)
82
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.related('public'))
83
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse)
84
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse.related('public'))
70
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie)
71
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie.related('public'))
85
72
  end
86
73
 
87
74
  it "reads activity" do
88
- Tie.allowed(@s, 'read', 'activity').should_not include(@tie)
89
- # Tie.allowed(@s, 'read', 'activity').should_not include(@tie.related('public'))
90
- Tie.allowed(@s, 'read', 'activity').should_not include(@tie.inverse)
91
- # Tie.allowed(@s, 'read', 'activity').should_not include(@tie.inverse.related('public'))
75
+ Tie.allowing(@s, 'read', 'activity').should_not include(@tie)
76
+ # Tie.allowing(@s, 'read', 'activity').should_not include(@tie.related('public'))
92
77
  end
93
-
94
78
  end
95
79
 
96
80
  describe ", alien" do
@@ -99,15 +83,13 @@ describe Tie do
99
83
  end
100
84
 
101
85
  it "creates activity" do
102
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie)
103
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.related('public'))
104
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse)
105
- Tie.allowed(@s, 'create', 'activity').should_not include(@tie.inverse.related('public'))
86
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie)
87
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie.related('public'))
106
88
  end
107
89
 
108
90
  it "reads activity" do
109
- Tie.allowed(@s, 'read', 'activity').should_not include(@tie)
110
- Tie.allowed(@s, 'read', 'activity').should_not include(@tie.inverse)
91
+ Tie.allowing(@s, 'read', 'activity').should_not include(@tie)
92
+ Tie.allowing(@s, 'read', 'activity').should include(@tie.related('public'))
111
93
  end
112
94
  end
113
95
  end
@@ -117,25 +99,35 @@ describe Tie do
117
99
  @tie = Factory(:member)
118
100
  end
119
101
 
120
- describe ", sender" do
102
+ describe ", receiver" do
121
103
  before do
122
- @s = @tie.sender
104
+ @s = @tie.receiver
123
105
  end
124
106
 
125
107
  it "updates activity" do
126
- Tie.allowed(@s, 'update', 'activity').should include(@tie)
127
- Tie.allowed(@s, 'update', 'activity').should include(@tie.related('public'))
108
+ Tie.allowing(@s, 'update', 'activity').should include(@tie)
109
+ Tie.allowing(@s, 'update', 'activity').should include(@tie.related('public'))
128
110
  end
129
111
  end
130
112
 
131
113
  describe ", member" do
132
114
  before do
133
- @s = Factory(:member, :receiver => @tie.receiver).sender
115
+ @s = Factory(:member, :sender => @tie.sender).receiver
116
+ end
117
+
118
+ it "creates activity" do
119
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie)
120
+ Tie.allowing(@s, 'create', 'activity').should_not include(@tie.related('public'))
121
+ end
122
+
123
+ it "reads activity" do
124
+ Tie.allowing(@s, 'read', 'activity').should include(@tie)
125
+ Tie.allowing(@s, 'read', 'activity').should include(@tie.related('public'))
134
126
  end
135
127
 
136
128
  it "updates activity" do
137
- Tie.allowed(@s, 'update', 'activity').should include(@tie)
138
- Tie.allowed(@s, 'update', 'activity').should include(@tie.related('public'))
129
+ Tie.allowing(@s, 'update', 'activity').should include(@tie)
130
+ Tie.allowing(@s, 'update', 'activity').should include(@tie.related('public'))
139
131
  end
140
132
  end
141
133
  end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe User do
4
+ it "should find by permalink" do
5
+ user = Factory(:user)
6
+
7
+ assert user.should == User.find_by_permalink(user.permalink)
8
+ end
9
+
10
+ it "should represent" do
11
+ tie = Factory(:member)
12
+ group = tie.sender_subject
13
+ user = tie.receiver_subject
14
+
15
+ assert user.represented.should include(group)
16
+
17
+ tie = Factory(:partner, :receiver => user.actor)
18
+
19
+ assert ! user.represented.include?(tie.sender_subject)
20
+ end
21
+ end
22
+
data/spec/support/db.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'lib/generators/social_stream/templates/migration'
1
+ require File.join(Rails.root, '../../lib/generators/social_stream/templates/migration')
2
2
  CreateSocialStream.up
3
3
 
4
4
  require File.expand_path("../../dummy/db/seeds", __FILE__)