social_stream-base 0.9.36 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/app/controllers/groups_controller.rb +3 -2
  2. data/app/controllers/posts_controller.rb +2 -10
  3. data/app/helpers/activities_helper.rb +2 -1
  4. data/app/models/activity_object.rb +28 -0
  5. data/app/models/actor.rb +10 -0
  6. data/app/models/group.rb +7 -3
  7. data/app/models/user.rb +7 -2
  8. data/app/views/activities/_new.html.erb +0 -1
  9. data/app/views/activity_objects/_activity_object.html.erb +3 -3
  10. data/app/views/comments/_new.html.erb +2 -3
  11. data/app/views/groups/_new.html.erb +0 -3
  12. data/app/views/notifications/activities/_like.text.erb +1 -1
  13. data/app/views/objects/_new_activity.html.erb +2 -2
  14. data/app/views/objects/_show.html.erb +1 -1
  15. data/db/migrate/20111124100618_object_actors.rb +50 -0
  16. data/lib/social_stream/ability/base.rb +1 -1
  17. data/lib/social_stream/base/version.rb +1 -1
  18. data/lib/social_stream/controllers/objects.rb +33 -0
  19. data/lib/social_stream/models/object.rb +33 -28
  20. data/lib/social_stream/test_helpers/controllers.rb +3 -1
  21. data/lib/social_stream-base.rb +2 -1
  22. data/lib/tasks/db/populate.rake +9 -2
  23. data/spec/controllers/comments_controller_spec.rb +9 -6
  24. data/spec/controllers/groups_controller_spec.rb +7 -5
  25. data/spec/controllers/posts_controller_spec.rb +45 -9
  26. data/spec/controllers/users_controller_spec.rb +3 -1
  27. data/spec/factories/activity.rb +3 -2
  28. data/spec/factories/comment.rb +3 -2
  29. data/spec/factories/group.rb +2 -1
  30. data/spec/factories/post.rb +5 -4
  31. data/spec/models/activity_authorization_spec.rb +5 -4
  32. data/spec/models/group_spec.rb +5 -2
  33. data/spec/models/post_spec.rb +6 -2
  34. metadata +7 -5
@@ -51,7 +51,8 @@ class GroupsController < InheritedResources::Base
51
51
  private
52
52
 
53
53
  def set_founder
54
- params[:group] ||= {}
55
- params[:group][:_contact_id] ||= current_subject.ego_contact.id
54
+ params[:group] ||= {}
55
+ params[:group][:author_id] ||= current_subject.try(:actor_id)
56
+ params[:group][:user_author_id] ||= current_user.try(:actor_id)
56
57
  end
57
58
  end
@@ -1,11 +1,3 @@
1
- class PostsController < InheritedResources::Base
2
- load_and_authorize_resource
3
-
4
- respond_to :html, :xml, :js
5
-
6
- def destroy
7
- @post_activity = resource.post_activity
8
-
9
- destroy!
10
- end
1
+ class PostsController < ApplicationController
2
+ include SocialStream::Controllers::Objects
11
3
  end
@@ -31,6 +31,7 @@ module ActivitiesHelper
31
31
  def new_post(receiver)
32
32
  return Post.new unless user_signed_in?
33
33
 
34
- Post.new :_contact_id => current_subject.contact_to!(receiver).id
34
+ Post.new :author_id => Actor.normalize_id(current_subject),
35
+ :owner_id => Actor.normalize_id(receiver)
35
36
  end
36
37
  end
@@ -14,9 +14,22 @@ class ActivityObject < ActiveRecord::Base
14
14
 
15
15
  acts_as_taggable
16
16
 
17
+ # Author can be any type of Actor: User, Group, etc.
18
+ belongs_to :author,
19
+ :class_name => "Actor"
20
+ # Owner is the wall's subject this object is posted to
21
+ belongs_to :owner,
22
+ :class_name => "Actor"
23
+
24
+ # UserAuthor is the real user behind the Author
25
+ belongs_to :user_author,
26
+ :class_name => "Actor"
27
+
17
28
  has_many :activity_object_activities, :dependent => :destroy
18
29
  has_many :activities, :through => :activity_object_activities
19
30
 
31
+ validates_presence_of :object_type
32
+
20
33
  # The object of this activity object
21
34
  def object
22
35
  subtype_instance.is_a?(Actor) ?
@@ -24,6 +37,21 @@ class ActivityObject < ActiveRecord::Base
24
37
  subtype_instance
25
38
  end
26
39
 
40
+ # The {SocialStream::Models::Subject subject} author
41
+ def author_subject
42
+ author.subject
43
+ end
44
+
45
+ # The {SocialStream::Models::Subject subject} owner
46
+ def owner_subject
47
+ owner.subject
48
+ end
49
+
50
+ # The {SocialStream::Models::Subject subject} user actor
51
+ def user_author_subject
52
+ user_author.subject
53
+ end
54
+
27
55
  # The activity in which this activity_object was created
28
56
  def post_activity
29
57
  activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
data/app/models/actor.rb CHANGED
@@ -58,6 +58,16 @@ class Actor < ActiveRecord::Base
58
58
  has_many :relations,
59
59
  :dependent => :destroy
60
60
 
61
+ has_many :authored_objects,
62
+ :class_name => "ActivityObject",
63
+ :foreign_key => :author_id,
64
+ :dependent => :destroy
65
+
66
+ has_many :owned_objects,
67
+ :class_name => "ActivityObject",
68
+ :foreign_key => :owner_id,
69
+ :dependent => :destroy
70
+
61
71
  scope :alphabetic, order('actors.name')
62
72
 
63
73
  scope :letter, lambda { |param|
data/app/models/group.rb CHANGED
@@ -33,13 +33,17 @@ class Group < ActiveRecord::Base
33
33
 
34
34
  # Creates the ties from the founder to the group
35
35
  def create_ties_from_founder
36
- _contact.sender.sent_contacts.create! :receiver_id => actor_id,
37
- :relation_ids => _relation_ids
36
+ author.sent_contacts.create! :receiver_id => actor_id,
37
+ :relation_ids => _relation_ids
38
+
39
+ if represented_author?
40
+ # TODO: create tie with future representation relation
41
+ end
38
42
  end
39
43
 
40
44
  # Creates the ties from the group to the participants
41
45
  def create_ties_to_participants
42
- ([ _contact.sender_id, _contact.receiver_id ] | Array.wrap(@_participants)).uniq.each do |a|
46
+ ([ author_id, user_author_id ].uniq | Array.wrap(@_participants)).uniq.each do |a|
43
47
  sent_contacts.create! :receiver_id => a,
44
48
  :relation_ids => Array(relation_customs.sort.first.id)
45
49
  end
data/app/models/user.rb CHANGED
@@ -3,12 +3,17 @@ require 'devise/orm/active_record'
3
3
  class User < ActiveRecord::Base
4
4
  include SocialStream::Models::Subject
5
5
 
6
- has_many :authentications, :dependent => :destroy
7
6
  devise *SocialStream.devise_modules
8
7
 
8
+ has_many :authentications, :dependent => :destroy
9
+
10
+ has_many :user_authored_objects,
11
+ :class_name => "ActivityObject",
12
+ :foreign_key => :user_author_id
13
+
9
14
  # Setup accessible (or protected) attributes for your model
10
15
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :profile_attributes
11
-
16
+
12
17
  validates_presence_of :email
13
18
 
14
19
  validates_format_of :email, :with => Devise.email_regexp, :allow_blank => true
@@ -1,4 +1,3 @@
1
-
2
1
  <% if can? :create, new_post(receiver) %>
3
2
  <div id="activities_header" class="content_size">
4
3
  <% SocialStream.activity_forms.each do |element| %>
@@ -1,7 +1,7 @@
1
- <% unless activity_object.object.is_a? Actor or activity_object.object.respond_to? :actor %>
2
- <%= render activity_object.object %>
3
- <% else %>
1
+ <% if activity_object.object.is_a?(Actor) || activity_object.object.class.ancestors.include?(SocialStream::Models::Subject) %>
4
2
  <div class="block">
5
3
  <%= model_with_details activity_object.object %>
6
4
  </div>
5
+ <% else %>
6
+ <%= render activity_object.object %>
7
7
  <% end %>
@@ -9,9 +9,8 @@
9
9
  <%= current_subject.name %>
10
10
  </div>
11
11
  <%= form_for Comment.new(:text => t('comment.input'),
12
- :_contact_id =>
13
- current_subject.contact_to!(activity.receiver).id,
14
- :_activity_parent_id => activity.id
12
+ :owner_id => Actor.normalize_id(activity.receiver),
13
+ :_activity_parent_id => activity.id
15
14
  ),
16
15
  :html => { :class => "new_comment", :id => "new_comment"+dom_id(activity) },
17
16
  :remote => true do |f| %>
@@ -19,9 +19,6 @@
19
19
  <div class="space_center"></div>
20
20
 
21
21
  <%= form_for @group do |f| %>
22
- <% f.object._contact_id ||= current_subject.ego_contact.id %>
23
- <%= f.hidden_field :_contact_id %>
24
-
25
22
  <% if @group.errors.any? %>
26
23
  <div id="notice">
27
24
  <h2><%= pluralize(@group.errors.count, "error") %> prohibited this group from being saved:</h2>
@@ -20,4 +20,4 @@
20
20
  <% end %>
21
21
 
22
22
  <%= raw t('notification.look',
23
- :sender => truncate_name(activity.sender.name)) %>: <%=polymorphic_url(activity.sender.subject)%>
23
+ :sender => truncate_name(activity.sender.name)) %>: <%=polymorphic_url(activity.sender.subject)%>
@@ -1,8 +1,8 @@
1
- <% object._contact_id = current_subject.contact_to!(receiver).id %>
1
+ <% object.owner_id = Actor.normalize_id(receiver) %>
2
2
  <% remote = true if remote.nil? %>
3
3
 
4
4
  <%= form_for object, :remote => remote do |f| %>
5
- <%= f.hidden_field :_contact_id %>
5
+ <%= f.hidden_field :owner_id %>
6
6
 
7
7
  <%= render :partial => object.class.to_s.tableize+'/new_activity_fields' , :locals => {:f => f} %>
8
8
  <% end %>
@@ -1,3 +1,3 @@
1
- <% toolbar :profile => object._owner %>
1
+ <% toolbar :profile => object.owner_subject %>
2
2
 
3
3
  <%= render object.post_activity %>
@@ -0,0 +1,50 @@
1
+ class ObjectActors < ActiveRecord::Migration
2
+ def up
3
+ change_table :activity_objects do |t|
4
+ t.integer :author_id
5
+ t.integer :owner_id
6
+ t.integer :user_author_id
7
+ end
8
+
9
+ add_index "activity_objects", "author_id"
10
+ add_index "activity_objects", "owner_id"
11
+ add_index "activity_objects", "user_author_id"
12
+
13
+ add_foreign_key "activity_objects", "actors", :name => "index_activity_objects_on_author_id", :column => :author_id
14
+ add_foreign_key "activity_objects", "actors", :name => "index_activity_objects_on_owner_id", :column => :owner_id
15
+ add_foreign_key "activity_objects", "actors", :name => "index_activity_objects_on_user_author_id", :column => :user_author_id
16
+
17
+ ActivityObject.record_timestamps = false
18
+
19
+ ActivityObject.all.each do |a|
20
+ if a.object_type == "Actor"
21
+ next if a.object.is_a? User
22
+
23
+ author = user_author = a.object.sent_ties.order(:created_at).first.receiver
24
+
25
+ until user_author.subject_type == "User"
26
+ user_author = user_author.sent_ties.order(:created_at).first.receiver
27
+ end
28
+
29
+ a.author = author
30
+ a.user_author = user_author
31
+ else
32
+ a.author = a.post_activity.sender
33
+ a.owner = a.post_activity.receiver
34
+ a.user_author = (a.author.is_a?(User) ? a.author : a.author.sent_ties.order(:created_at).first.receiver)
35
+ end
36
+
37
+ a.save!
38
+ end
39
+ end
40
+
41
+ def down
42
+ remove_foreign_key "activity_objects", :name => "index_activity_objects_on_author_id"
43
+ remove_foreign_key "activity_objects", :name => "index_activity_objects_on_owner_id"
44
+ remove_foreign_key "activity_objects", :name => "index_activity_objects_on_user_author_id"
45
+
46
+ remove_column :activity_objects, :author_id
47
+ remove_column :activity_objects, :owner_id
48
+ remove_column :activity_objects, :user_author_id
49
+ end
50
+ end
@@ -75,7 +75,7 @@ module SocialStream
75
75
 
76
76
  can :create, Group do |g|
77
77
  subject.present? &&
78
- g._contact.sender_id == Actor.normalize_id(subject)
78
+ g.author_id == Actor.normalize_id(subject)
79
79
  end
80
80
 
81
81
  can :update, Group do |g|
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.9.36".freeze
3
+ VERSION = "0.10.0".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,33 @@
1
+ module SocialStream
2
+ module Controllers
3
+ module Objects
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ inherit_resources
8
+
9
+ before_filter :set_author_ids, :only => [ :new, :create, :update ]
10
+
11
+ load_and_authorize_resource :except => :index
12
+
13
+ respond_to :html, :js
14
+ end
15
+
16
+ module InstanceMethods
17
+
18
+ def destroy
19
+ @post_activity = resource.post_activity
20
+
21
+ destroy!
22
+ end
23
+
24
+ protected
25
+
26
+ def set_author_ids
27
+ resource_params.first[:author_id] = current_subject.try(:actor_id)
28
+ resource_params.first[:user_author_id] = current_user.try(:actor_id)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,23 +7,20 @@ module SocialStream
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- attr_accessor :_contact_id
11
10
  attr_writer :_relation_ids
12
11
  attr_accessor :_activity_parent_id
13
12
 
14
- belongs_to :activity_object, :dependent => :destroy, :autosave => true
15
- has_many :activity_object_activities, :through => :activity_object
13
+ belongs_to :activity_object,
14
+ :validate => true,
15
+ :autosave => true,
16
+ :dependent => :destroy
16
17
 
17
- delegate :post_activity,
18
- :like_count,
19
- :tag_list, :tag_list=,
20
- :tagged_with, :tag_counts,
21
- :to => :activity_object!
18
+ has_many :activity_object_activities, :through => :activity_object
22
19
 
23
- before_create :create_activity_object_with_type
20
+ # before_create :create_activity_object_with_type
24
21
 
25
22
  unless self == Actor
26
- validates_presence_of :_contact_id, :on => :create
23
+ validates_presence_of :author_id, :owner_id, :user_author_id
27
24
 
28
25
  after_create :create_post_activity
29
26
  after_update :create_update_activity
@@ -35,6 +32,27 @@ module SocialStream
35
32
  activity_object || build_activity_object(:object_type => self.class.to_s)
36
33
  end
37
34
 
35
+ # Delegate missing methods to {ActivityObject}, if they exist there
36
+ def method_missing(method, *args, &block)
37
+ super
38
+ rescue NameError => object_error
39
+ # These methods must be raised to avoid loops (the :activity_object association calls here again)
40
+ exceptions = [ :_activity_object_id ]
41
+ raise object_error if exceptions.include?(method)
42
+
43
+ activity_object!.__send__ method, *args, &block
44
+ end
45
+
46
+ # {ActivityObject} handles some methods
47
+ def respond_to? *args
48
+ super || activity_object!.respond_to?(*args)
49
+ end
50
+
51
+ # Was the author represented with this {SocialStream::Models::Object object} was created?
52
+ def represented_author?
53
+ author_id == user_author_id
54
+ end
55
+
38
56
  # All the activities with this object
39
57
  def activities
40
58
  Activity.
@@ -42,13 +60,6 @@ module SocialStream
42
60
  where("#{ self.class.quoted_table_name }.id" => self.id)
43
61
  end
44
62
 
45
- # The activity in which this object was posted
46
- #
47
- # FIXME: Currently it only supports direct objects
48
- def post_activity
49
- (activities.includes(:activity_verb) & ActivityVerb.verb_name('post')).first
50
- end
51
-
52
63
  # Build the post activity when this object is not saved
53
64
  def build_post_activity
54
65
  Activity.new :contact_id => _contact_id,
@@ -65,7 +76,11 @@ module SocialStream
65
76
  end
66
77
 
67
78
  def _contact
68
- @_contact ||= Contact.find(_contact_id)
79
+ @_contact ||= author && owner && author.contact_to!(owner)
80
+ end
81
+
82
+ def _contact_id
83
+ _contact.try(:id)
69
84
  end
70
85
 
71
86
  def _relation_ids
@@ -90,16 +105,6 @@ module SocialStream
90
105
  @_activity_parent ||= Activity.find(_activity_parent_id)
91
106
  end
92
107
 
93
- # The {SocialStream::Models::Subject subject} that posted this object
94
- def _author
95
- post_activity.contact.sender_subject
96
- end
97
-
98
- # The owner of the wall where {#_author} posted this object
99
- def _owner
100
- post_activity.contact.receiver_subject
101
- end
102
-
103
108
  private
104
109
 
105
110
  def create_post_activity
@@ -33,7 +33,9 @@ module SocialStream
33
33
  end
34
34
 
35
35
  def model_assigned_to contact, relation_ids
36
- model_attributes[:_contact_id] = contact.id
36
+ model_attributes[:author_id] = contact.sender.id
37
+ model_attributes[:owner_id] = contact.receiver.id
38
+ model_attributes[:user_author_id] = contact.sender.id
37
39
  model_attributes[:_relation_ids] = Array(relation_ids).map(&:id)
38
40
  end
39
41
 
@@ -51,8 +51,9 @@ module SocialStream
51
51
  autoload :TestHelpers, 'social_stream/test_helpers'
52
52
 
53
53
  module Controllers
54
- autoload :Helpers, 'social_stream/controllers/helpers'
55
54
  autoload :CancanDeviseIntegration, 'social_stream/controllers/cancan_devise_integration'
55
+ autoload :Helpers, 'social_stream/controllers/helpers'
56
+ autoload :Objects, 'social_stream/controllers/objects'
56
57
  end
57
58
 
58
59
  module Models
@@ -91,7 +91,8 @@ namespace :db do
91
91
 
92
92
  Group.create! :name => Forgery::Name.company_name,
93
93
  :email => Forgery::Internet.email_address,
94
- :_contact_id => founder.ego_contact.id
94
+ :author_id => founder.id,
95
+ :user_author_id => founder.id
95
96
  end
96
97
 
97
98
  set_tags(Group)
@@ -128,11 +129,17 @@ namespace :db do
128
129
  SocialStream::Populate.power_law(Tie.all) do |t|
129
130
  updated = Time.at(rand(Time.now.to_i))
130
131
 
132
+ author = t.sender
133
+ owner = t.receiver
134
+ user_author = ( t.sender.subject_type == "User" ? t.sender : t.sender.user_author )
135
+
131
136
  p = Post.create :text =>
132
137
  "This post should be for #{ t.relation.name } of #{ t.sender.name }.\n#{ Forgery::LoremIpsum.paragraph(:random => true) }",
133
138
  :created_at => Time.at(rand(updated.to_i)),
134
139
  :updated_at => updated,
135
- :_contact_id => t.contact_id,
140
+ :author_id => author.id,
141
+ :owner_id => owner.id,
142
+ :user_author_id => user_author.id,
136
143
  :_relation_ids => Array(t.relation_id)
137
144
 
138
145
  p.post_activity.update_attributes(:created_at => p.created_at,
@@ -14,9 +14,10 @@ describe CommentsController do
14
14
  describe "comment from user" do
15
15
  before do
16
16
  activity = Factory(:self_activity, :contact => Factory(:self_contact, :sender => @user.actor))
17
- contact = @user.contact_to!(@user)
18
17
 
19
- model_attributes[:_contact_id] = contact.id
18
+ model_attributes[:author_id] = @user.actor_id
19
+ model_attributes[:owner_id] = @user.actor_id
20
+ model_attributes[:user_author_id] = @user.actor_id
20
21
  model_attributes[:_activity_parent_id] = activity.id
21
22
  end
22
23
 
@@ -38,9 +39,10 @@ describe CommentsController do
38
39
  before do
39
40
  f = Factory(:friend, :contact => Factory(:contact, :receiver => @user.actor)).sender
40
41
  activity = Factory(:self_activity, :contact => f.contact_to!(f))
41
- contact = @user.contact_to!(f)
42
42
 
43
- model_attributes[:_contact_id] = contact.id
43
+ model_attributes[:author_id] = @user.actor_id
44
+ model_attributes[:owner_id] = f.id
45
+ model_attributes[:user_author_id] = @user.actor_id
44
46
  model_attributes[:_activity_parent_id] = activity.id
45
47
  end
46
48
 
@@ -51,9 +53,10 @@ describe CommentsController do
51
53
  before do
52
54
  a = Factory(:acquaintance, :contact => Factory(:contact, :receiver => @user.actor)).sender
53
55
  activity = Factory(:self_activity, :contact => a.contact_to!(a))
54
- contact = @user.contact_to!(a)
55
56
 
56
- model_attributes[:_contact_id] = contact.id
57
+ model_attributes[:author_id] = @user.actor_id
58
+ model_attributes[:owner_id] = a.id
59
+ model_attributes[:user_author_id] = @user.actor_id
57
60
  model_attributes[:_activity_parent_id] = activity.id
58
61
  end
59
62
 
@@ -26,9 +26,7 @@ describe GroupsController do
26
26
 
27
27
  context "faking a new group" do
28
28
  it "should deny creating" do
29
- post :create, :group => { :name => "Test",
30
- :_contact_id => Factory(:user).ego_contact.id
31
- }
29
+ post :create, :group => { :name => "Test" }
32
30
 
33
31
  response.should redirect_to(new_user_session_path)
34
32
  end
@@ -79,7 +77,8 @@ describe GroupsController do
79
77
 
80
78
  context "a new own group" do
81
79
  before do
82
- model_attributes[:_contact_id] = @user.ego_contact.id
80
+ model_attributes[:author_id] = @user.actor_id
81
+ model_attributes[:user_author_id] = @user.actor_id
83
82
  end
84
83
 
85
84
  it "should allow creating" do
@@ -125,7 +124,10 @@ describe GroupsController do
125
124
 
126
125
  context "a new fake group" do
127
126
  before do
128
- model_attributes[:_contact_id] = Factory(:user).ego_contact.id
127
+ user = Factory(:user)
128
+
129
+ model_attributes[:author_id] = user.actor_id
130
+ model_attributes[:user_author_id] = user.actor_id
129
131
  end
130
132
 
131
133
  it_should_behave_like "Deny Creating"
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  describe PostsController do
5
4
  include SocialStream::TestHelpers
6
5
  include SocialStream::TestHelpers::Controllers
@@ -19,7 +18,10 @@ describe PostsController do
19
18
  contact = @user.contact_to!(@user)
20
19
  relation = @user.relation_customs.sort.first
21
20
  model_assigned_to @user.contact_to!(@user), relation
22
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
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))
23
25
  end
24
26
 
25
27
  it_should_behave_like "Allow Creating"
@@ -31,7 +33,10 @@ describe PostsController do
31
33
  contact = @user.contact_to!(@user)
32
34
  relation = @user.relation_customs.sort.last
33
35
  model_assigned_to @user.contact_to!(@user), relation
34
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
36
+ @current_model = Factory(:post, :author_id => @user.actor_id,
37
+ :owner_id => @user.actor_id,
38
+ :user_author_id => @user.actor_id,
39
+ :_relation_ids => Array(relation.id))
35
40
  end
36
41
 
37
42
  it_should_behave_like "Allow Creating"
@@ -43,7 +48,9 @@ describe PostsController do
43
48
  contact = @user.contact_to!(@user)
44
49
  relation = @user.relation_public
45
50
  model_assigned_to @user.contact_to!(@user), relation
46
- @current_model = Factory(:post, :_contact_id => contact.id)
51
+ @current_model = Factory(:post, :author_id => @user.actor_id,
52
+ :owner_id => @user.actor_id,
53
+ :user_author_id => @user.actor_id)
47
54
  end
48
55
 
49
56
  it_should_behave_like "Allow Creating"
@@ -82,7 +89,10 @@ describe PostsController do
82
89
  relation = @group.relation_custom('member')
83
90
 
84
91
  model_assigned_to contact, relation
85
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
92
+ @current_model = Factory(:post, :author_id => contact.sender.id,
93
+ :owner_id => contact.receiver.id,
94
+ :user_author_id => contact.sender.id,
95
+ :_relation_ids => Array(relation.id))
86
96
  end
87
97
 
88
98
  it_should_behave_like "Allow Creating"
@@ -99,7 +109,10 @@ describe PostsController do
99
109
  contact = @group.contact_to!(@group)
100
110
  relation = @group.relation_customs.sort.first
101
111
  model_assigned_to contact, relation
102
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
112
+ @current_model = Factory(:post, :author_id => contact.sender.id,
113
+ :owner_id => contact.receiver.id,
114
+ :user_author_id => contact.sender.id,
115
+ :_relation_ids => Array(relation.id))
103
116
  end
104
117
 
105
118
  it_should_behave_like "Allow Creating"
@@ -111,7 +124,10 @@ describe PostsController do
111
124
  contact = @group.contact_to!(@group)
112
125
  relation = @group.relation_customs.sort.last
113
126
  model_assigned_to contact, relation
114
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
127
+ @current_model = Factory(:post, :author_id => contact.sender.id,
128
+ :owner_id => contact.receiver.id,
129
+ :user_author_id => contact.sender.id,
130
+ :_relation_ids => Array(relation.id))
115
131
  end
116
132
 
117
133
  it_should_behave_like "Allow Creating"
@@ -123,7 +139,10 @@ describe PostsController do
123
139
  contact = @group.contact_to!(@group)
124
140
  relation = @group.relation_public
125
141
  model_assigned_to contact, relation
126
- @current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
142
+ @current_model = Factory(:post, :author_id => contact.sender.id,
143
+ :owner_id => contact.receiver.id,
144
+ :user_author_id => contact.sender.id,
145
+ :_relation_ids => Array(relation.id))
127
146
  end
128
147
 
129
148
  it_should_behave_like "Allow Creating"
@@ -143,7 +162,7 @@ describe PostsController do
143
162
  sign_in @tie.receiver_subject
144
163
 
145
164
  post :create, :post => { :text => "Test",
146
- :_contact_id => @tie.contact.inverse!.id,
165
+ :owner_id => @tie.contact.sender.id
147
166
  }
148
167
 
149
168
  post = assigns(:post)
@@ -151,6 +170,23 @@ describe PostsController do
151
170
  post.should be_valid
152
171
  post.post_activity.relations.should include(@tie.relation)
153
172
  end
173
+
174
+ it "should assign activity to member" do
175
+ sign_in @tie.receiver_subject
176
+
177
+ post :create, :post => { :text => "Test",
178
+ :owner_id => @tie.contact.sender.id
179
+ },
180
+ :format => :js
181
+
182
+
183
+ post = assigns(:post)
184
+
185
+ post.should be_valid
186
+ post.post_activity.relations.should include(@tie.relation)
187
+
188
+ response.should be_success
189
+ end
154
190
  end
155
191
 
156
192
  context "creating public post" do
@@ -74,7 +74,9 @@ describe UsersController do
74
74
  it "should render other's page with activity" do
75
75
  tie = Factory(:friend, :receiver => @user.actor)
76
76
  friend = tie.sender
77
- Factory(:post, :_contact_id => tie.contact_id,
77
+ Factory(:post, :author_id => tie.sender.id,
78
+ :owner_id => tie.receiver.id,
79
+ :user_author_id => tie.sender.id,
78
80
  :_relation_ids => Array(tie.relation_id))
79
81
 
80
82
  get :show, :id => friend.to_param
@@ -38,11 +38,12 @@ Factory.define :public_activity, :parent => :activity do |a|
38
38
  a.relation_ids { |b| Array(b.sender.relation_public.id) }
39
39
  end
40
40
 
41
- Factory.define :like_activity, :parent => :activity do |a|
41
+ Factory.define :like_activity, :class => 'Activity' do |a|
42
42
  a.association :parent, :factory => :activity
43
43
  a.contact { |b| Factory(:friend, :sender => b.parent.sender).receiver.contact_to!(b.parent.sender) }
44
44
  a.activity_verb { ActivityVerb["like"] }
45
- a.relation_ids { |b| Array(b.parent.contact.ties.first.relation.id) }
45
+ a.relation_ids { |b| b.parent.relation_ids }
46
+ a.after_build{ |b| b.activity_object_ids = b.parent.activity_object_ids }
46
47
  end
47
48
 
48
49
 
@@ -1,5 +1,6 @@
1
1
  Factory.define :comment do |p|
2
2
  p.sequence(:text) { |n| "Comment #{ n }" }
3
- p._contact_id { Factory(:friend).contact_id }
4
- p._relation_ids { |q| Array(Contact.find(q._contact_id).sender.relation_customs.sort.first.id) }
3
+ p.author_id { Factory(:friend).receiver.id }
4
+ p.owner_id { |q| Actor.find(q.author_id).received_ties.first.sender.id }
5
+ p.user_author_id { |q| q.author_id }
5
6
  end
@@ -1,4 +1,5 @@
1
1
  Factory.define :group do |g|
2
2
  g.sequence(:name) { |n| "Group #{ n }" }
3
- g._contact_id { |g| Factory(:user).ego_contact.id }
3
+ g.author_id { |h| Factory(:user).actor_id }
4
+ g.user_author_id { |h| h.author_id }
4
5
  end
@@ -1,10 +1,11 @@
1
1
  Factory.define :post do |p|
2
2
  p.sequence(:text) { |n| "Post #{ n }" }
3
- p._contact_id { Factory(:friend).contact_id }
4
- p._relation_ids { |q| Array(Contact.find(q._contact_id).sender.relation_customs.sort.first.id) }
3
+ p.author_id { Factory(:friend).receiver.id }
4
+ p.owner_id { |q| Actor.find(q.author_id).received_ties.first.sender.id }
5
+ p.user_author_id { |q| q.author_id }
5
6
  end
6
7
 
7
8
  Factory.define :public_post, :parent => :post do |p|
8
- p._contact_id { Factory(:self_contact).id }
9
- p._relation_ids { |q| Array(Contact.find(q._contact_id).sender.relation_public.id) }
9
+ p.owner_id { |q| q.author_id }
10
+ p._relation_ids { |q| Array(q.author.relation_public.id) }
10
11
  end
@@ -2,10 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  module ActivityTestHelper
4
4
  def create_activity(contact, relations)
5
- @activity = Factory(:activity,
6
- :contact_id => contact.id,
7
- :relation_ids => Array(Relation.normalize_id(relations)))
8
-
5
+ @activity = Factory(:post,
6
+ :author_id => contact.sender.id,
7
+ :owner_id => contact.receiver.id,
8
+ :user_author_id => contact.sender.id,
9
+ :_relation_ids => Array(Relation.normalize_id(relations))).post_activity
9
10
  end
10
11
 
11
12
  def create_ability_accessed_by(subject)
@@ -2,9 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Group do
4
4
  it "should save description" do
5
- g = Group.create(:name => "Test",
5
+ user = Factory(:user)
6
+
7
+ g = Group.create :name => "Test",
6
8
  :description => "Testing description",
7
- :_contact_id => Factory(:user).ego_contact.id)
9
+ :author_id => user.actor.id,
10
+ :user_author_id => user.actor.id
8
11
 
9
12
  g.reload.description.should be_present
10
13
  end
@@ -36,7 +36,9 @@ describe Post do
36
36
  tie = Factory(:friend)
37
37
 
38
38
  post = Post.new :text => "testing",
39
- :_contact_id => tie.contact.inverse!.id
39
+ :author_id => tie.receiver.id,
40
+ :owner_id => tie.sender.id,
41
+ :user_author_id => tie.receiver.id
40
42
 
41
43
  assert post.build_post_activity.allow? tie.receiver_subject, 'create'
42
44
 
@@ -49,7 +51,9 @@ describe Post do
49
51
  tie = Factory(:friend)
50
52
 
51
53
  post = Post.new :text => "testing",
52
- :_contact_id => tie.contact.inverse!.id
54
+ :author_id => tie.receiver.id,
55
+ :owner_id => tie.sender.id,
56
+ :user_author_id => tie.receiver.id
53
57
 
54
58
  post.save!
55
59
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream-base
3
3
  version: !ruby/object:Gem::Version
4
- hash: 115
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 9
9
- - 36
10
- version: 0.9.36
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - GING - DIT - UPM
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-21 00:00:00 +01:00
19
+ date: 2011-11-28 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -958,6 +958,7 @@ files:
958
958
  - db/migrate/20110712090343_remove_spheres.rb
959
959
  - db/migrate/20110712142140_remove_permission_function.rb
960
960
  - db/migrate/20110912074426_add_reject_relation.rb
961
+ - db/migrate/20111124100618_object_actors.rb
961
962
  - lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
962
963
  - lib/acts_as_taggable_on/social_stream.rb
963
964
  - lib/generators/social_stream/base/install_generator.rb
@@ -973,6 +974,7 @@ files:
973
974
  - lib/social_stream/base/version.rb
974
975
  - lib/social_stream/controllers/cancan_devise_integration.rb
975
976
  - lib/social_stream/controllers/helpers.rb
977
+ - lib/social_stream/controllers/objects.rb
976
978
  - lib/social_stream/d3.rb
977
979
  - lib/social_stream/migrations/base.rb
978
980
  - lib/social_stream/migrations/components.rb