social_stream 0.28.4 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/.gitignore +6 -1
  2. data/.travis.yml +0 -2
  3. data/Gemfile +3 -0
  4. data/base/app/controllers/activities_controller.rb +14 -12
  5. data/base/app/controllers/api_controller.rb +0 -13
  6. data/base/app/controllers/frontpage_controller.rb +0 -6
  7. data/base/app/models/activity.rb +21 -61
  8. data/base/app/models/actor.rb +4 -8
  9. data/base/app/models/audience.rb +2 -0
  10. data/base/app/models/comment.rb +2 -1
  11. data/base/app/models/group.rb +0 -2
  12. data/base/app/models/relation/custom.rb +17 -4
  13. data/base/app/models/relation.rb +5 -1
  14. data/base/app/models/tie.rb +0 -2
  15. data/base/app/models/user.rb +0 -2
  16. data/base/app/views/activities/_options.html.erb +1 -1
  17. data/base/app/views/activities/index.atom.builder +48 -0
  18. data/base/app/views/activity_objects/_activity_object.atom.erb +1 -0
  19. data/base/config/locales/en.yml +8 -0
  20. data/base/config/locales/es.yml +8 -0
  21. data/base/config/routes.rb +0 -8
  22. data/base/lib/rails/social_stream.rb +1 -1
  23. data/base/lib/social_stream/ability/base.rb +4 -16
  24. data/base/lib/social_stream/activity_streams/subtype.rb +11 -0
  25. data/base/lib/social_stream/activity_streams/supertype.rb +12 -0
  26. data/base/lib/social_stream/activity_streams.rb +39 -0
  27. data/base/lib/social_stream/base/dependencies.rb +2 -0
  28. data/base/lib/social_stream/base/engine.rb +6 -0
  29. data/base/lib/social_stream/base/version.rb +1 -1
  30. data/base/lib/social_stream/models/object.rb +5 -0
  31. data/base/lib/social_stream/models/subject.rb +1 -1
  32. data/base/lib/social_stream/models/subtype.rb +2 -0
  33. data/base/lib/social_stream/models/supertype.rb +2 -0
  34. data/base/lib/social_stream-base.rb +5 -0
  35. data/base/social_stream-base.gemspec +2 -0
  36. data/base/spec/controllers/activities_controller_spec.rb +18 -0
  37. data/base/spec/controllers/frontpage_controller_spec.rb +0 -5
  38. data/base/spec/models/activity_wall_spec.rb +96 -0
  39. data/base/spec/models/post_authorization_spec.rb +370 -0
  40. data/base/spec/models/post_spec.rb +0 -2
  41. data/base/spec/models/relation_spec.rb +22 -0
  42. data/base/spec/social_stream_activity_streams_spec.rb +16 -0
  43. data/base/spec/social_stream_spec.rb +1 -1
  44. data/documents/app/views/common_documents/_document_info.html.erb +2 -2
  45. data/documents/app/views/common_documents/_index.html.erb +2 -2
  46. data/documents/lib/social_stream/documents/engine.rb +7 -0
  47. data/documents/lib/social_stream/documents/version.rb +1 -1
  48. data/documents/social_stream-documents.gemspec +1 -1
  49. data/events/app/decorators/social_stream/base/actor_decorator.rb +3 -0
  50. data/events/app/decorators/social_stream/base/document_decorator.rb +3 -0
  51. data/events/lib/social_stream/events/engine.rb +2 -10
  52. data/events/lib/social_stream/events/version.rb +1 -1
  53. data/events/social_stream-events.gemspec +1 -1
  54. data/lib/generators/social_stream/install_generator.rb +1 -0
  55. data/lib/social_stream/version.rb +1 -1
  56. data/lib/social_stream.rb +7 -6
  57. data/linkser/lib/social_stream/linkser/engine.rb +3 -0
  58. data/linkser/lib/social_stream/linkser/version.rb +1 -1
  59. data/linkser/social_stream-linkser.gemspec +1 -1
  60. data/ostatus/Gemfile +3 -0
  61. data/ostatus/MIT-LICENSE +20 -0
  62. data/ostatus/README.rdoc +26 -0
  63. data/ostatus/Rakefile +26 -0
  64. data/{base → ostatus}/app/assets/images/logos/actor/remote_subject.png +0 -0
  65. data/ostatus/app/assets/images/logos/contact/remote_subject.png +0 -0
  66. data/ostatus/app/assets/images/logos/original/remote_subject.png +0 -0
  67. data/ostatus/app/assets/images/logos/profile/remote_subject.png +0 -0
  68. data/ostatus/app/controllers/host_meta_controller.rb +9 -0
  69. data/ostatus/app/controllers/pshb_controller.rb +26 -0
  70. data/ostatus/app/controllers/remote_subjects_controller.rb +19 -0
  71. data/ostatus/app/controllers/salmon_controller.rb +15 -0
  72. data/ostatus/app/controllers/subjects_controller.rb +5 -0
  73. data/ostatus/app/controllers/webfinger_controller.rb +24 -0
  74. data/ostatus/app/decorators/social_stream/base/activity_decorator.rb +3 -0
  75. data/ostatus/app/decorators/social_stream/base/actor_decorator.rb +3 -0
  76. data/ostatus/app/decorators/social_stream/base/audience_decorator.rb +3 -0
  77. data/ostatus/app/decorators/social_stream/base/relation/custom_decorator.rb +3 -0
  78. data/ostatus/app/decorators/social_stream/base/tie_decorator.rb +3 -0
  79. data/ostatus/app/models/actor_key.rb +30 -0
  80. data/ostatus/app/models/remote_subject.rb +139 -0
  81. data/ostatus/app/views/remote_subjects/_show.html.erb +6 -0
  82. data/ostatus/app/views/remote_subjects/show.html.erb +5 -0
  83. data/ostatus/config/locales/en.yml +34 -0
  84. data/ostatus/config/routes.rb +13 -0
  85. data/ostatus/db/migrate/20120905145030_create_social_stream_ostatus.rb +20 -0
  86. data/ostatus/db/migrate/20120918194708_create_actor_keys.rb +18 -0
  87. data/ostatus/lib/generators/social_stream/ostatus/install_generator.rb +16 -0
  88. data/ostatus/lib/generators/social_stream/ostatus/templates/initializer.rb +18 -0
  89. data/ostatus/lib/social_stream/migrations/ostatus.rb +9 -0
  90. data/ostatus/lib/social_stream/ostatus/activity_streams.rb +79 -0
  91. data/ostatus/lib/social_stream/ostatus/controllers/debug_requests.rb +24 -0
  92. data/ostatus/lib/social_stream/ostatus/engine.rb +21 -0
  93. data/ostatus/lib/social_stream/ostatus/models/activity.rb +41 -0
  94. data/ostatus/lib/social_stream/ostatus/models/actor.rb +89 -0
  95. data/ostatus/lib/social_stream/ostatus/models/audience.rb +19 -0
  96. data/ostatus/lib/social_stream/ostatus/models/object.rb +28 -0
  97. data/ostatus/lib/social_stream/ostatus/models/relation/custom.rb +22 -0
  98. data/ostatus/lib/social_stream/ostatus/models/tie.rb +24 -0
  99. data/ostatus/lib/social_stream/ostatus/version.rb +5 -0
  100. data/ostatus/lib/social_stream-ostatus.rb +54 -0
  101. data/ostatus/social_stream-ostatus.gemspec +28 -0
  102. data/ostatus/spec/controllers/host_meta_controller_spec.rb +10 -0
  103. data/ostatus/spec/controllers/remote_subjects_controller_spec.rb +37 -0
  104. data/ostatus/spec/controllers/webfinger_controller_spec.rb +13 -0
  105. data/ostatus/spec/dummy/Rakefile +7 -0
  106. data/ostatus/spec/dummy/app/controllers/application_controller.rb +3 -0
  107. data/ostatus/spec/dummy/app/helpers/application_helper.rb +2 -0
  108. data/ostatus/spec/dummy/app/views/layouts/application.html.erb +14 -0
  109. data/ostatus/spec/dummy/config/application.rb +45 -0
  110. data/ostatus/spec/dummy/config/boot.rb +10 -0
  111. data/ostatus/spec/dummy/config/database.yml +22 -0
  112. data/ostatus/spec/dummy/config/environment.rb +5 -0
  113. data/ostatus/spec/dummy/config/environments/development.rb +26 -0
  114. data/ostatus/spec/dummy/config/environments/production.rb +49 -0
  115. data/ostatus/spec/dummy/config/environments/test.rb +35 -0
  116. data/ostatus/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  117. data/ostatus/spec/dummy/config/initializers/inflections.rb +10 -0
  118. data/ostatus/spec/dummy/config/initializers/mime_types.rb +5 -0
  119. data/ostatus/spec/dummy/config/initializers/secret_token.rb +7 -0
  120. data/ostatus/spec/dummy/config/initializers/session_store.rb +8 -0
  121. data/ostatus/spec/dummy/config/locales/en.yml +5 -0
  122. data/ostatus/spec/dummy/config/routes.rb +58 -0
  123. data/ostatus/spec/dummy/config.ru +4 -0
  124. data/ostatus/spec/dummy/public/404.html +26 -0
  125. data/ostatus/spec/dummy/public/422.html +26 -0
  126. data/ostatus/spec/dummy/public/500.html +26 -0
  127. data/ostatus/spec/dummy/public/favicon.ico +0 -0
  128. data/ostatus/spec/dummy/public/javascripts/application.js +2 -0
  129. data/ostatus/spec/dummy/public/javascripts/controls.js +965 -0
  130. data/ostatus/spec/dummy/public/javascripts/dragdrop.js +974 -0
  131. data/ostatus/spec/dummy/public/javascripts/effects.js +1123 -0
  132. data/ostatus/spec/dummy/public/javascripts/prototype.js +6001 -0
  133. data/ostatus/spec/dummy/public/javascripts/rails.js +191 -0
  134. data/ostatus/spec/dummy/public/stylesheets/.gitkeep +0 -0
  135. data/ostatus/spec/dummy/script/rails +6 -0
  136. data/ostatus/spec/factories/remote_subject.rb +39 -0
  137. data/ostatus/spec/integration/navigation_spec.rb +9 -0
  138. data/ostatus/spec/models/actor_key_spec.rb +9 -0
  139. data/ostatus/spec/models/post_spec.rb +25 -0
  140. data/ostatus/spec/models/remote_subject_spec.rb +24 -0
  141. data/ostatus/spec/social_stream_ostatus.spec.rb +9 -0
  142. data/ostatus/spec/social_stream_ostatus_activity_streams.spec.rb +31 -0
  143. data/ostatus/spec/spec_helper.rb +33 -0
  144. data/presence/app/decorators/social_stream/base/models/group_decorator.rb +3 -0
  145. data/presence/app/decorators/social_stream/base/models/tie_decorator.rb +3 -0
  146. data/presence/lib/generators/social_stream/presence/install_generator.rb +1 -1
  147. data/presence/lib/social_stream/presence/engine.rb +0 -12
  148. data/presence/lib/social_stream/presence/version.rb +1 -1
  149. data/presence/social_stream-presence.gemspec +1 -1
  150. data/social_stream.gemspec +6 -5
  151. data/spec/support/db.rb +1 -1
  152. metadata +125 -18
  153. data/base/app/assets/images/logos/actor/remote_user.png +0 -0
  154. data/base/app/controllers/subjects_controller.rb +0 -7
  155. data/base/app/views/api/activity_atom_feed.atom.builder +0 -40
  156. data/base/app/views/frontpage/host_meta.xml.builder +0 -11
  157. data/base/spec/models/activity_authorization_spec.rb +0 -354
@@ -5,7 +5,7 @@ class ActionDispatch::Http::UploadedFile
5
5
  def initialize_with_magic(*args, &block)
6
6
  initialize_without_magic(*args, &block)
7
7
 
8
- if (unix_file = `which file`.chomp).present? && File.exists?(unix_file)
8
+ if (unix_file = `which file`.try(:chomp)).present? && File.exists?(unix_file)
9
9
  `#{ unix_file } -v 2>&1` =~ /^file-(.*)$/
10
10
  version = $1
11
11
 
@@ -37,40 +37,28 @@ module SocialStream
37
37
  end
38
38
 
39
39
  can :create, Comment do |c|
40
- c._activity_parent.allow?(subject, 'read')
40
+ can? :read, c.parent_post
41
41
  end
42
42
 
43
43
  can :read, Comment do |c|
44
- c.post_activity.allow?(subject, 'read')
44
+ can? :read, c.parent_post
45
45
  end
46
46
 
47
47
  can :update, Comment do |c|
48
- c.post_activity.allow?(subject, 'update')
48
+ can? :update, c.parent_post
49
49
  end
50
50
 
51
51
  can :destroy, Comment do |c|
52
- c.post_activity.allow?(subject, 'destroy')
52
+ can? :destroy, c.parent_post
53
53
  end
54
54
 
55
55
  # Activities
56
- can :create, Activity do |a|
57
- a.allow?(subject, 'create')
58
- end
59
-
60
56
  can :read, Activity do |a|
61
57
  a.public? ||
62
58
  subject.present? &&
63
59
  a.audience.include?(subject.actor)
64
60
  end
65
61
 
66
- can :update, Activity do |a|
67
- a.allow?(subject, 'update')
68
- end
69
-
70
- can :destroy, Activity do |a|
71
- a.allow?(subject, 'destroy')
72
- end
73
-
74
62
  # Users
75
63
  can :read, User
76
64
 
@@ -0,0 +1,11 @@
1
+ module SocialStream
2
+ module ActivityStreams
3
+ module Subtype
4
+ # The {ActivityStreams}[http://activitystrea.ms/specs/atom/1.0/] object type for
5
+ # this subtype
6
+ def as_object_type
7
+ SocialStream::ActivityStreams.type(self.class)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module SocialStream
2
+ module ActivityStreams
3
+ module Supertype
4
+ # The {ActivityStreams}[http://activitystrea.ms/specs/atom/1.0/] object type for
5
+ # this object
6
+ def as_object_type
7
+ subtype_instance.as_object_type
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ module SocialStream
2
+ # Maintains a list of the equivalences between SocialStream's models
3
+ # and ActivityStreams' object types
4
+ #
5
+ # http://activitystrea.ms/specs/json/schema/activity-schema.html#object-types
6
+ module ActivityStreams
7
+ DEFAULT_TYPE = :note
8
+
9
+ class << self
10
+ @@register = {}
11
+
12
+ # Register a new ActivityStreams type along with the model
13
+ def register(object_type, klass = nil)
14
+ klass ||= object_type
15
+
16
+ @@register[object_type] = klass
17
+ end
18
+
19
+ # Get the SocialStream's model, given a ActivityStreams' object type
20
+ def model(type)
21
+ model = @@register[type]
22
+ model && model.to_s.classify.constantize
23
+ end
24
+
25
+ # Get the SocialStream's model, given a ActivityStreams' object type
26
+ # or the default model
27
+ def model!(type)
28
+ model(type) || model(SocialStream::ActivityStreams::DEFAULT_TYPE)
29
+ end
30
+
31
+ # Get the ActivityStreams' object type, given a SocialStream's model
32
+ def type(klass)
33
+ klass = klass.to_s.underscore.to_sym unless klass.is_a?(Symbol)
34
+
35
+ @@register.invert[klass]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,8 @@
2
2
  require 'deep_merge'
3
3
  # Monkey patch Ruby on Rails
4
4
  require 'rails/social_stream'
5
+ # Rails Engine Decorators
6
+ require 'rails_engine_decorators'
5
7
  # Database foreign keys
6
8
  require 'foreigner'
7
9
  # jQuery
@@ -29,6 +29,12 @@ module SocialStream
29
29
  SocialStream.single_relations.each{ |r| "Relation::#{ r.to_s.classify }".constantize }
30
30
  end
31
31
 
32
+ initializer "social_stream-base.model.register_activity_streams" do
33
+ SocialStream::ActivityStreams.register :person, :user
34
+ SocialStream::ActivityStreams.register :group
35
+ SocialStream::ActivityStreams.register :note, :post
36
+ end
37
+
32
38
  initializer "social_stream-base.controller.helpers" do
33
39
  ActiveSupport.on_load(:action_controller) do
34
40
  include SocialStream::Controllers::Helpers
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.22.4".freeze
3
+ VERSION = "0.23.0".freeze
4
4
  end
5
5
  end
@@ -48,6 +48,11 @@ module SocialStream
48
48
  merge(ActivityObject.followed_by(subject))
49
49
  }
50
50
  end
51
+
52
+ module ClassMethods
53
+ # Nothing here by the moment, but methods are added by other
54
+ # SocialStream's components, such as Ostatus
55
+ end
51
56
  end
52
57
  end
53
58
  end
@@ -17,7 +17,7 @@ module SocialStream
17
17
  #
18
18
  module Subject
19
19
  extend ActiveSupport::Concern
20
-
20
+
21
21
  included do
22
22
  subtype_of :actor,
23
23
  :build => { :subject_type => to_s }
@@ -9,6 +9,8 @@ module SocialStream #:nodoc:
9
9
  module Subtype
10
10
  extend ActiveSupport::Concern
11
11
 
12
+ include SocialStream::ActivityStreams::Subtype
13
+
12
14
  included do
13
15
  class << self
14
16
  attr_reader :supertype_name, :supertype_options
@@ -11,6 +11,8 @@ module SocialStream #:nodoc:
11
11
  module Supertype
12
12
  extend ActiveSupport::Concern
13
13
 
14
+ include SocialStream::ActivityStreams::Supertype
15
+
14
16
  included do
15
17
  subtypes.each do |s| # [ :user, :group ].each do |s|
16
18
  has_one s, :dependent => :destroy # has_one s, :dependent => :destroy
@@ -4,6 +4,11 @@ require 'social_stream/base/dependencies'
4
4
  # Provides your Rails application with social network and activity stream support
5
5
  module SocialStream
6
6
  autoload :Ability, 'social_stream/ability'
7
+ autoload :ActivityStreams, 'social_stream/activity_streams'
8
+ module ActivityStreams
9
+ autoload :Supertype, 'social_stream/activity_streams/supertype'
10
+ autoload :Subtype, 'social_stream/activity_streams/subtype'
11
+ end
7
12
  autoload :D3, 'social_stream/d3'
8
13
  autoload :Populate, 'social_stream/populate'
9
14
  autoload :Relations, 'social_stream/relations'
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency('deep_merge')
20
20
  # Rails
21
21
  s.add_runtime_dependency('rails', '>= 3.1.0')
22
+ # Rails Engine Decorators
23
+ s.add_runtime_dependency('rails_engine_decorators')
22
24
  # Activity and Relation hierarchies
23
25
  s.add_runtime_dependency('ancestry', '~> 1.2.3')
24
26
  # SQL foreign keys
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActivitiesController do
4
+ describe "show" do
5
+ it "should redirecto to activity object" do
6
+ id = 3
7
+ activity = double("activity")
8
+ post = Factory(:post)
9
+
10
+ activity.should_receive(:direct_object) { post }
11
+
12
+ Activity.should_receive(:find).with(id.to_s) { activity }
13
+
14
+ get :show, id: id
15
+ end
16
+ end
17
+ end
18
+
@@ -7,10 +7,5 @@ describe FrontpageController do
7
7
  get :index
8
8
  assert_response :success
9
9
  end
10
-
11
- it "should render host_meta" do
12
- get :host_meta, :format => :all
13
- assert_response :success
14
- end
15
10
  end
16
11
 
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe Activity do
4
+
5
+ context "user" do
6
+ before(:all) do
7
+ @subject = @user = Factory(:user)
8
+ end
9
+
10
+ context "with public activity" do
11
+ before do
12
+ @activity = Factory(:self_activity, :relation_ids => [Relation::Public.instance.id])
13
+ end
14
+
15
+ describe "sender home" do
16
+ it "should include activity" do
17
+ @activity.sender.wall(:home).should include(@activity)
18
+ end
19
+ end
20
+
21
+ describe "sender profile" do
22
+ context "accessed by alien" do
23
+ it "should include activity" do
24
+ @activity.sender.wall(:profile,
25
+ :for => Factory(:user)).should include(@activity)
26
+ end
27
+ end
28
+
29
+ context "accessed by anonymous" do
30
+ it "should include activity" do
31
+ @activity.sender.wall(:profile,
32
+ :for => nil).should include(@activity)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "belonging to friend" do
39
+ before do
40
+ @activity = Factory(:activity)
41
+ end
42
+
43
+ describe "sender home" do
44
+ it "should include activity" do
45
+ @activity.sender.wall(:home).should include(@activity)
46
+ end
47
+ end
48
+
49
+ describe "sender profile" do
50
+ context "accessed by friend" do
51
+ it "should include activity" do
52
+ @activity.sender.wall(:profile,
53
+ :for => @activity.receiver).should include(@activity)
54
+ end
55
+ end
56
+
57
+ context "accessed by alien" do
58
+ it "should not include activity" do
59
+ @activity.sender.wall(:profile,
60
+ :for => Factory(:user)).should_not include(@activity)
61
+ end
62
+ end
63
+
64
+ context "accessed by anonymous" do
65
+ it "should not include activity" do
66
+ @activity.sender.wall(:profile,
67
+ :for => nil).should_not include(@activity)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "receiver profile" do
73
+ context "accessed by receiver" do
74
+ it "should include activity" do
75
+ @activity.receiver.wall(:profile,
76
+ :for => @activity.receiver).should include(@activity)
77
+ end
78
+ end
79
+
80
+ context "accessed by alien" do
81
+ it "should not include activity" do
82
+ @activity.receiver.wall(:profile,
83
+ :for => Factory(:user)).should_not include(@activity)
84
+ end
85
+ end
86
+
87
+ context "accessed by anonymous" do
88
+ it "should not include activity" do
89
+ @activity.receiver.wall(:profile,
90
+ :for => nil).should_not include(@activity)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,370 @@
1
+ require 'spec_helper'
2
+
3
+ module PostAuthorizationTestHelper
4
+ def create_ability_accessed_by(subject)
5
+ @ability = Ability.new(subject)
6
+ end
7
+
8
+ def create_ability_accessed_by_related(tie_type)
9
+ @tie = create_related_tie(tie_type)
10
+ @related = @tie.receiver_subject
11
+ @ability = Ability.new(@related)
12
+ end
13
+
14
+ def create_ability_accessed_publicly
15
+ u = Factory(:user)
16
+ @ability = Ability.new(u)
17
+ end
18
+
19
+ def create_related_tie(tie_type)
20
+ Factory(tie_type, :contact => Factory(:contact, :sender => Actor.normalize(@subject)))
21
+ end
22
+
23
+ shared_examples_for "Allows Creating" do
24
+ it "should allow create" do
25
+ @ability.should be_able_to(:create, @post)
26
+ end
27
+ end
28
+
29
+ shared_examples_for "Allows Reading" do
30
+ it "should allow read" do
31
+ @ability.should be_able_to(:read, @post)
32
+ end
33
+ end
34
+
35
+ shared_examples_for "Allows Updating" do
36
+ it "should allow update" do
37
+ @ability.should be_able_to(:update, @post)
38
+ end
39
+ end
40
+
41
+ shared_examples_for "Allows Destroying" do
42
+ it "should allow destroy" do
43
+ @ability.should be_able_to(:destroy, @post)
44
+ end
45
+ end
46
+
47
+ shared_examples_for "Denies Creating" do
48
+ it "should deny create" do
49
+ @ability.should_not be_able_to(:create, @post)
50
+ end
51
+ end
52
+
53
+ shared_examples_for "Denies Reading" do
54
+ it "should deny read" do
55
+ @ability.should_not be_able_to(:read, @post)
56
+ end
57
+ end
58
+
59
+ shared_examples_for "Denies Updating" do
60
+ it "should deny update" do
61
+ @ability.should_not be_able_to(:update, @post)
62
+ end
63
+ end
64
+
65
+ shared_examples_for "Denies Destroying" do
66
+ it "should deny destroy" do
67
+ @ability.should_not be_able_to(:destroy, @post)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe Post do
73
+ include PostAuthorizationTestHelper
74
+
75
+ before :all do
76
+ @ss_relation_model = SocialStream.relation_model
77
+ end
78
+
79
+ after :all do
80
+ SocialStream.relation_model = @ss_relation_model
81
+ end
82
+
83
+ context "in custom relation model" do
84
+ before :all do
85
+ SocialStream.relation_model = :custom
86
+ end
87
+
88
+ before :all do
89
+ @subject = @user = Factory(:user)
90
+ end
91
+
92
+ context "with friend tie" do
93
+ before :all do
94
+ @tie = create_related_tie(:friend)
95
+ end
96
+
97
+ describe "posting for all contacts" do
98
+ before :all do
99
+ @post = Factory(:post,
100
+ :author => @tie.receiver,
101
+ :owner => @tie.sender)
102
+ end
103
+
104
+ describe "accesed by author" do
105
+ before do
106
+ create_ability_accessed_by(@post.author_subject)
107
+ end
108
+
109
+ it_should_behave_like "Allows Creating"
110
+ it_should_behave_like "Allows Reading"
111
+ it_should_behave_like "Allows Updating"
112
+ it_should_behave_like "Allows Destroying"
113
+ end
114
+
115
+ describe "accesed by owner" do
116
+ before do
117
+ create_ability_accessed_by(@post.owner_subject)
118
+ end
119
+
120
+ it_should_behave_like "Denies Creating"
121
+ it_should_behave_like "Allows Reading"
122
+ it_should_behave_like "Allows Updating"
123
+ it_should_behave_like "Allows Destroying"
124
+ end
125
+
126
+ describe "accessed by different friend" do
127
+ before do
128
+ create_ability_accessed_by_related :friend
129
+ end
130
+
131
+ it_should_behave_like "Denies Creating"
132
+ it_should_behave_like "Allows Reading"
133
+ it_should_behave_like "Denies Updating"
134
+ it_should_behave_like "Denies Destroying"
135
+ end
136
+
137
+ describe "accessed by acquaintance" do
138
+ before do
139
+ create_ability_accessed_by_related :acquaintance
140
+ end
141
+ it_should_behave_like "Denies Creating"
142
+ it_should_behave_like "Allows Reading"
143
+ it_should_behave_like "Denies Updating"
144
+ it_should_behave_like "Denies Destroying"
145
+ end
146
+
147
+ describe "accessed publicly" do
148
+ before do
149
+ create_ability_accessed_publicly
150
+ end
151
+
152
+ it_should_behave_like "Denies Creating"
153
+ it_should_behave_like "Denies Reading"
154
+ it_should_behave_like "Denies Updating"
155
+ it_should_behave_like "Denies Destroying"
156
+ end
157
+ end
158
+
159
+ describe "posting only to friends" do
160
+ before :all do
161
+ @post = Factory(:post,
162
+ :author => @tie.receiver,
163
+ :owner => @tie.sender,
164
+ :relation_ids => [@tie.relation_id])
165
+
166
+ end
167
+
168
+ describe "accessed by author" do
169
+ before do
170
+ create_ability_accessed_by(@post.author_subject)
171
+ end
172
+
173
+ it_should_behave_like "Allows Creating"
174
+ it_should_behave_like "Allows Reading"
175
+ it_should_behave_like "Allows Updating"
176
+ it_should_behave_like "Allows Destroying"
177
+ end
178
+
179
+ describe "accesed by owner" do
180
+ before do
181
+ create_ability_accessed_by(@post.owner_subject)
182
+ end
183
+
184
+ it_should_behave_like "Denies Creating"
185
+ it_should_behave_like "Allows Reading"
186
+ it_should_behave_like "Allows Updating"
187
+ it_should_behave_like "Allows Destroying"
188
+ end
189
+
190
+ describe "accessed by a friend" do
191
+ before do
192
+ create_ability_accessed_by_related :friend
193
+ end
194
+
195
+ it_should_behave_like "Denies Creating"
196
+ it_should_behave_like "Allows Reading"
197
+ it_should_behave_like "Denies Updating"
198
+ it_should_behave_like "Denies Destroying"
199
+ end
200
+
201
+ describe "accessed by acquaintance" do
202
+ before do
203
+ create_ability_accessed_by_related :acquaintance
204
+ end
205
+
206
+ it_should_behave_like "Denies Creating"
207
+ it_should_behave_like "Denies Reading"
208
+ it_should_behave_like "Denies Updating"
209
+ it_should_behave_like "Denies Destroying"
210
+ end
211
+
212
+ describe "accessed publicly" do
213
+ before do
214
+ create_ability_accessed_publicly
215
+ end
216
+
217
+ it_should_behave_like "Denies Creating"
218
+ it_should_behave_like "Denies Reading"
219
+ it_should_behave_like "Denies Updating"
220
+ it_should_behave_like "Denies Destroying"
221
+ end
222
+ end
223
+
224
+ describe "posting to public relation" do
225
+
226
+ before do
227
+ @post = Factory(:post,
228
+ :author => @tie.receiver,
229
+ :owner => @tie.sender,
230
+ :relation_ids => [Relation::Public.instance.id])
231
+ end
232
+
233
+ describe "accessed by author" do
234
+ before do
235
+ create_ability_accessed_by(@post.author_subject)
236
+ end
237
+
238
+ it_should_behave_like "Allows Creating"
239
+ it_should_behave_like "Allows Reading"
240
+ it_should_behave_like "Allows Updating"
241
+ it_should_behave_like "Allows Destroying"
242
+ end
243
+
244
+ describe "accessed by owner" do
245
+ before do
246
+ create_ability_accessed_by(@post.owner_subject)
247
+ end
248
+
249
+ it_should_behave_like "Denies Creating"
250
+ it_should_behave_like "Allows Reading"
251
+ it_should_behave_like "Allows Updating"
252
+ it_should_behave_like "Allows Destroying"
253
+ end
254
+
255
+ describe "accessed by a friend" do
256
+ before do
257
+ create_ability_accessed_by_related :friend
258
+ end
259
+
260
+ it_should_behave_like "Denies Creating"
261
+ it_should_behave_like "Allows Reading"
262
+ it_should_behave_like "Denies Updating"
263
+ it_should_behave_like "Denies Destroying"
264
+ end
265
+
266
+ describe "accessed by acquaintance" do
267
+ before do
268
+ create_ability_accessed_by_related :acquaintance
269
+ end
270
+
271
+ it_should_behave_like "Denies Creating"
272
+ it_should_behave_like "Allows Reading"
273
+ it_should_behave_like "Denies Updating"
274
+ it_should_behave_like "Denies Destroying"
275
+ end
276
+
277
+ describe "accessed publicly" do
278
+ before do
279
+ create_ability_accessed_publicly
280
+ end
281
+
282
+ it_should_behave_like "Denies Creating"
283
+ it_should_behave_like "Allows Reading"
284
+ it_should_behave_like "Denies Updating"
285
+ it_should_behave_like "Denies Destroying"
286
+ end
287
+ end
288
+
289
+ describe "posting by not replied" do
290
+ before :all do
291
+ @post = Factory(:post,
292
+ :author => @tie.sender,
293
+ :owner => @tie.receiver)
294
+ end
295
+
296
+ describe "accessed by author" do
297
+ before do
298
+ create_ability_accessed_by(@post.author_subject)
299
+ end
300
+
301
+ it_should_behave_like "Denies Creating"
302
+ end
303
+ end
304
+ end
305
+
306
+ context "group" do
307
+ before(:all) do
308
+ @subject = @group = Factory(:group)
309
+ end
310
+
311
+ describe "with member tie" do
312
+ before :all do
313
+ @tie = create_related_tie(:member)
314
+ end
315
+
316
+ describe "posting from member all contacts" do
317
+ before :all do
318
+ @post = Factory(:post,
319
+ :author => @tie.receiver,
320
+ :owner => @tie.sender)
321
+ end
322
+
323
+ describe "accessed by author" do
324
+ before do
325
+ create_ability_accessed_by @post.author_subject
326
+ end
327
+
328
+ it_should_behave_like "Allows Creating"
329
+ it_should_behave_like "Allows Reading"
330
+ it_should_behave_like "Allows Updating"
331
+ it_should_behave_like "Allows Destroying"
332
+ end
333
+
334
+ describe "accessed by different member" do
335
+ before do
336
+ create_ability_accessed_by_related :member
337
+ end
338
+
339
+ it_should_behave_like "Denies Creating"
340
+ it_should_behave_like "Allows Reading"
341
+ it_should_behave_like "Denies Updating"
342
+ it_should_behave_like "Denies Destroying"
343
+ end
344
+
345
+ describe "accessed by partner" do
346
+ before do
347
+ create_ability_accessed_by_related :partner
348
+ end
349
+
350
+ it_should_behave_like "Denies Creating"
351
+ it_should_behave_like "Allows Reading"
352
+ it_should_behave_like "Denies Updating"
353
+ it_should_behave_like "Denies Destroying"
354
+ end
355
+
356
+ describe "accessed publicly" do
357
+ before do
358
+ create_ability_accessed_publicly
359
+ end
360
+
361
+ it_should_behave_like "Denies Creating"
362
+ it_should_behave_like "Denies Reading"
363
+ it_should_behave_like "Denies Updating"
364
+ it_should_behave_like "Denies Destroying"
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end