social_stream 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.gitignore +1 -0
  2. data/.yardopts +2 -0
  3. data/Gemfile +2 -3
  4. data/Gemfile.lock +20 -3
  5. data/README.rdoc +2 -3
  6. data/Rakefile +15 -18
  7. data/app/controllers/groups_controller.rb +9 -0
  8. data/app/controllers/likes_controller.rb +47 -0
  9. data/app/controllers/ties_controller.rb +2 -72
  10. data/app/helpers/activities_helper.rb +5 -1
  11. data/app/helpers/ties_helper.rb +21 -10
  12. data/app/models/actor.rb +53 -14
  13. data/app/models/group.rb +13 -0
  14. data/app/models/tie.rb +11 -2
  15. data/app/models/user.rb +6 -0
  16. data/app/views/activities/_activity.html.erb +2 -2
  17. data/app/views/activities/_child.html.erb +23 -0
  18. data/app/views/activities/_jquery.html.erb +0 -2
  19. data/app/views/activities/{_activity_options.html.erb → _options.html.erb} +1 -1
  20. data/app/views/activities/_root.html.erb +32 -0
  21. data/app/views/activity_objects/_activity_object.html.erb +1 -0
  22. data/app/views/groups/_group.html.erb +3 -0
  23. data/app/views/groups/show.html.erb +28 -0
  24. data/app/views/home/_groups.html.erb +14 -0
  25. data/app/views/home/index.html.erb +1 -0
  26. data/app/views/likes/create.js.erb +2 -0
  27. data/app/views/likes/destroy.js.erb +1 -0
  28. data/app/views/ties/_form.html.erb +6 -0
  29. data/app/views/ties/_new.html.erb +26 -0
  30. data/app/views/ties/_pending.html.erb +2 -14
  31. data/app/views/ties/_pendings.html.erb +16 -0
  32. data/app/views/ties/_suggestions.html.erb +7 -3
  33. data/app/views/ties/_tie.html.erb +21 -0
  34. data/app/views/ties/create.js.erb +21 -0
  35. data/app/views/ties/new.html.erb +1 -0
  36. data/app/views/ties/new.js.erb +2 -0
  37. data/config/locales/en.yml +32 -11
  38. data/config/routes.rb +14 -0
  39. data/init.rb +3 -0
  40. data/lib/generators/social_stream/install_generator.rb +8 -4
  41. data/lib/generators/social_stream/templates/initializer.rb +1 -1
  42. data/lib/generators/social_stream/templates/migration.rb +14 -1
  43. data/lib/generators/social_stream/templates/seeds.yml +30 -0
  44. data/lib/paperclip/ext.rb +6 -0
  45. data/lib/social_stream.rb +1 -1
  46. data/lib/social_stream/models/actor.rb +19 -4
  47. data/lib/social_stream/models/supertype.rb +2 -6
  48. data/lib/social_stream/rails.rb +9 -3
  49. data/lib/social_stream/version.rb +1 -1
  50. data/social_stream.gemspec +15 -0
  51. data/spec/dummy/Rakefile +7 -0
  52. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  53. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  54. data/spec/dummy/app/models/ability.rb +23 -0
  55. data/spec/dummy/app/models/post.rb +2 -0
  56. data/spec/dummy/app/models/user.rb +2 -0
  57. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  58. data/spec/dummy/config.ru +4 -0
  59. data/spec/dummy/config/application.rb +46 -0
  60. data/spec/dummy/config/boot.rb +10 -0
  61. data/spec/dummy/config/database.yml +22 -0
  62. data/spec/dummy/config/environment.rb +5 -0
  63. data/spec/dummy/config/environments/development.rb +26 -0
  64. data/spec/dummy/config/environments/production.rb +49 -0
  65. data/spec/dummy/config/environments/test.rb +35 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/devise.rb +142 -0
  68. data/spec/dummy/config/initializers/inflections.rb +10 -0
  69. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  70. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  71. data/spec/dummy/config/initializers/session_store.rb +8 -0
  72. data/spec/dummy/config/initializers/social_stream.rb +5 -0
  73. data/spec/dummy/config/locales/en.yml +5 -0
  74. data/spec/dummy/config/routes.rb +58 -0
  75. data/spec/dummy/db/.gitignore +1 -0
  76. data/spec/dummy/db/migrate/.gitkeep +0 -0
  77. data/spec/dummy/db/schema.rb +116 -0
  78. data/spec/dummy/db/seeds.rb +9 -0
  79. data/spec/dummy/db/seeds/social_stream.yml +54 -0
  80. data/spec/dummy/log/.gitignore +1 -0
  81. data/spec/dummy/public/404.html +26 -0
  82. data/spec/dummy/public/422.html +26 -0
  83. data/spec/dummy/public/500.html +26 -0
  84. data/spec/dummy/public/favicon.ico +0 -0
  85. data/spec/dummy/public/javascripts/application.js +2 -0
  86. data/spec/dummy/public/javascripts/controls.js +965 -0
  87. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  88. data/spec/dummy/public/javascripts/effects.js +1123 -0
  89. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  90. data/spec/dummy/public/javascripts/rails.js +175 -0
  91. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  92. data/spec/dummy/script/rails +6 -0
  93. data/spec/factories/activity.rb +10 -0
  94. data/spec/factories/actor.rb +4 -0
  95. data/spec/factories/group.rb +3 -0
  96. data/spec/factories/post.rb +3 -0
  97. data/spec/factories/tie.rb +38 -0
  98. data/spec/factories/user.rb +4 -0
  99. data/spec/integration/navigation_spec.rb +9 -0
  100. data/spec/models/activity_spec.rb +420 -0
  101. data/spec/models/actor_spec.rb +16 -0
  102. data/spec/models/post_spec.rb +33 -0
  103. data/spec/models/tie_spec.rb +30 -0
  104. data/spec/models/user_space.rb +10 -0
  105. data/spec/social_stream_spec.rb +7 -0
  106. data/spec/spec_helper.rb +45 -0
  107. data/spec/support/cancan.rb +1 -0
  108. data/spec/support/db.rb +4 -0
  109. metadata +155 -45
  110. data/app/views/activities/_root_activity.html.erb +0 -32
  111. data/app/views/activities/_subactivity.html.erb +0 -23
  112. data/app/views/ties/_suggestion.html.erb +0 -20
  113. data/lib/social_stream/rails/routes.rb +0 -19
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,10 @@
1
+ Factory.define :activity do |a|
2
+ a.association :tie
3
+ a.activity_verb { ActivityVerb["post"] }
4
+ end
5
+
6
+ Factory.define :like_activity, :parent => :activity do |a|
7
+ a.association :parent, :factory => :activity
8
+ a.activity_verb { ActivityVerb["like"] }
9
+ a.tie { |tie| tie.association(:tie, :receiver => tie.parent.tie.receiver) }
10
+ end
@@ -0,0 +1,4 @@
1
+ Factory.define :actor do |s|
2
+ s.sequence(:name) { |n| "Actor #{ n }" }
3
+ s.subject_type "Subject"
4
+ end
@@ -0,0 +1,3 @@
1
+ Factory.define :group do |g|
2
+ g.sequence(:name) { |n| "Group #{ n }" }
3
+ end
@@ -0,0 +1,3 @@
1
+ Factory.define :post do |p|
2
+ p._activity_tie_id { |q| q.association(:tie) }
3
+ end
@@ -0,0 +1,38 @@
1
+ Factory.define :tie do |t|
2
+ t.sender { |s| Factory(:user).actor }
3
+ t.receiver { |r| Factory(:user).actor }
4
+ t.relation { |r| Relation.mode('User', 'User').strongest }
5
+ end
6
+
7
+ # UserToUser ties
8
+
9
+ Factory.define :friend_tie, :parent => :tie do |t|
10
+ t.relation { |r| Relation.mode('User', 'User').find_by_name('friend') }
11
+ end
12
+
13
+ Factory.define :fof_tie, :parent => :tie do |t|
14
+ t.relation { |r| Relation.mode('User', 'User').find_by_name('friend_of_friend') }
15
+ end
16
+
17
+ Factory.define :public_tie, :parent => :tie do |t|
18
+ t.relation { |r| Relation.mode('User', 'User').find_by_name('public') }
19
+ end
20
+
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 }
25
+ end
26
+
27
+ Factory.define :admin_tie, :parent => :u2g_tie do |t|
28
+ t.relation { |r| Relation.mode('User', 'Group').find_by_name('admin') }
29
+ end
30
+
31
+ Factory.define :user_tie, :parent => :u2g_tie do |t|
32
+ t.relation { |r| Relation.mode('User', 'Group').find_by_name('user') }
33
+ end
34
+
35
+ Factory.define :follower_tie, :parent => :u2g_tie do |t|
36
+ t.relation { |r| Relation.mode('User', 'Group').find_by_name('follower') }
37
+ end
38
+
@@ -0,0 +1,4 @@
1
+ Factory.define :user do |u|
2
+ u.sequence(:name) { |n| "User #{ n }" }
3
+ u.sequence(:email) { |n| "user#{ n }@example.com" }
4
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Navigation" do
4
+ include Capybara
5
+
6
+ it "should be a valid app" do
7
+ ::Rails.application.should be_a(Dummy::Application)
8
+ end
9
+ end
@@ -0,0 +1,420 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module ActivityTestHelper
4
+ def create_activity_assigned_to(t)
5
+ @tie = t
6
+ @activity = Factory(:activity, :tie => t)
7
+ end
8
+
9
+ def create_ability_accessed_by(tie_type)
10
+ t = Factory(tie_type, :receiver => @tie.receiver)
11
+ u = t.sender.subject
12
+ @ability = Ability.new(u)
13
+ end
14
+
15
+ shared_examples_for "Allows Creating" do
16
+ it "should allow create" do
17
+ @ability.should be_able_to(:create, @activity)
18
+ end
19
+ end
20
+
21
+ shared_examples_for "Allows Reading" do
22
+ it "should allow read" do
23
+ @ability.should be_able_to(:read, @activity)
24
+ end
25
+ end
26
+
27
+ shared_examples_for "Allows Updating" do
28
+ it "should allow update" do
29
+ @ability.should be_able_to(:update, @activity)
30
+ end
31
+ end
32
+
33
+ shared_examples_for "Allows Destroying" do
34
+ it "should allow destroy" do
35
+ @ability.should be_able_to(:destroy, @activity)
36
+ end
37
+ end
38
+
39
+ shared_examples_for "Denies Creating" do
40
+ it "should deny create" do
41
+ @ability.should_not be_able_to(:create, @activity)
42
+ end
43
+ end
44
+
45
+ shared_examples_for "Denies Reading" do
46
+ it "should deny read" do
47
+ @ability.should_not be_able_to(:read, @activity)
48
+ end
49
+ end
50
+
51
+ shared_examples_for "Denies Updating" do
52
+ it "should deny update" do
53
+ @ability.should_not be_able_to(:update, @activity)
54
+ end
55
+ end
56
+
57
+ shared_examples_for "Denies Destroying" do
58
+ it "should deny destroy" do
59
+ @ability.should_not be_able_to(:destroy, @activity)
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ describe Activity do
66
+ include ActivityTestHelper
67
+
68
+ describe "with like subactivity" do
69
+ before do
70
+ @like_activity = Factory(:like_activity)
71
+ @activity = @like_activity.parent
72
+ end
73
+
74
+ it "should recognize the user who likes it" do
75
+ assert @activity.liked_by?(@like_activity.sender)
76
+ end
77
+
78
+ it "should not recognize the user who does not like it" do
79
+ assert ! @activity.liked_by?(Factory(:user))
80
+ end
81
+ end
82
+
83
+ describe "belonging to friend tie" do
84
+ before do
85
+ create_activity_assigned_to(Factory(:friend_tie))
86
+ end
87
+
88
+ describe "accessed by same friend" do
89
+ before do
90
+ u = @tie.sender.subject
91
+ @ability = Ability.new(u)
92
+ end
93
+
94
+ it_should_behave_like "Allows Creating"
95
+ it_should_behave_like "Allows Reading"
96
+ it_should_behave_like "Allows Updating"
97
+ it_should_behave_like "Allows Destroying"
98
+ end
99
+
100
+ describe "accessed by different friend" do
101
+ before do
102
+ create_ability_accessed_by :friend_tie
103
+ end
104
+
105
+ it_should_behave_like "Denies Creating"
106
+ it_should_behave_like "Allows Reading"
107
+ it_should_behave_like "Denies Updating"
108
+ it_should_behave_like "Denies Destroying"
109
+ end
110
+
111
+ describe "accessed by friend of friend" do
112
+ before do
113
+ create_ability_accessed_by :fof_tie
114
+ end
115
+
116
+ it_should_behave_like "Denies Creating"
117
+ it_should_behave_like "Denies Reading"
118
+ it_should_behave_like "Denies Updating"
119
+ it_should_behave_like "Denies Destroying"
120
+ end
121
+
122
+ describe "accessed publicly" do
123
+ before do
124
+ create_ability_accessed_by :public_tie
125
+ end
126
+
127
+ it_should_behave_like "Denies Creating"
128
+ it_should_behave_like "Denies Reading"
129
+ it_should_behave_like "Denies Updating"
130
+ it_should_behave_like "Denies Destroying"
131
+ end
132
+ end
133
+
134
+ describe "belonging to fof tie from a friend" do
135
+ before do
136
+ create_activity_assigned_to(Factory(:friend_tie).related('friend_of_friend'))
137
+ end
138
+
139
+ describe "accessed by a friend" do
140
+ before do
141
+ create_ability_accessed_by :friend_tie
142
+ end
143
+
144
+ it_should_behave_like "Denies Creating"
145
+ it_should_behave_like "Allows Reading"
146
+ it_should_behave_like "Denies Updating"
147
+ it_should_behave_like "Denies Destroying"
148
+ end
149
+
150
+ describe "accessed by same friend" do
151
+ before do
152
+ u = @tie.sender.subject
153
+ @ability = Ability.new(u)
154
+ end
155
+
156
+ it_should_behave_like "Allows Creating"
157
+ it_should_behave_like "Allows Reading"
158
+ it_should_behave_like "Allows Updating"
159
+ it_should_behave_like "Allows Destroying"
160
+ end
161
+
162
+ describe "accessed by different friend of friend" do
163
+ before do
164
+ create_ability_accessed_by :fof_tie
165
+ end
166
+
167
+ it_should_behave_like "Denies Creating"
168
+ it_should_behave_like "Allows Reading"
169
+ it_should_behave_like "Denies Updating"
170
+ it_should_behave_like "Denies Destroying"
171
+ end
172
+
173
+ describe "accessed publicly" do
174
+ before do
175
+ create_ability_accessed_by :public_tie
176
+ end
177
+
178
+ it_should_behave_like "Denies Creating"
179
+ it_should_behave_like "Denies Reading"
180
+ it_should_behave_like "Denies Updating"
181
+ it_should_behave_like "Denies Destroying"
182
+ end
183
+ end
184
+
185
+ describe "belonging to fof tie from a friend of friend" do
186
+ before do
187
+ create_activity_assigned_to(Factory(:fof_tie))
188
+ u = @tie.sender.subject
189
+ @ability = Ability.new(u)
190
+ end
191
+
192
+ it_should_behave_like "Denies Creating"
193
+ end
194
+
195
+
196
+ describe "belonging to public tie" do
197
+ before do
198
+ create_activity_assigned_to(Factory(:friend_tie).related('public'))
199
+ end
200
+
201
+ describe "accessed by a friend" do
202
+ before do
203
+ create_ability_accessed_by :friend_tie
204
+ end
205
+
206
+ it_should_behave_like "Denies Creating"
207
+ it_should_behave_like "Allows Reading"
208
+ it_should_behave_like "Denies Updating"
209
+ it_should_behave_like "Denies Destroying"
210
+ end
211
+
212
+ describe "accessed by friend of friend" do
213
+ before do
214
+ create_ability_accessed_by :fof_tie
215
+ end
216
+
217
+ it_should_behave_like "Denies Creating"
218
+ it_should_behave_like "Allows Reading"
219
+ it_should_behave_like "Denies Updating"
220
+ it_should_behave_like "Denies Destroying"
221
+ end
222
+
223
+ describe "accessed by same public sender" do
224
+ before do
225
+ u = @tie.sender.subject
226
+ @ability = Ability.new(u)
227
+ end
228
+
229
+ it_should_behave_like "Allows Creating"
230
+ it_should_behave_like "Allows Reading"
231
+ it_should_behave_like "Allows Updating"
232
+ it_should_behave_like "Allows Destroying"
233
+ end
234
+
235
+ describe "accessed by different public" do
236
+ before do
237
+ create_ability_accessed_by :public_tie
238
+ end
239
+
240
+ it_should_behave_like "Denies Creating"
241
+ it_should_behave_like "Allows Reading"
242
+ it_should_behave_like "Denies Updating"
243
+ it_should_behave_like "Denies Destroying"
244
+ end
245
+ end
246
+
247
+ describe "belonging to public tie from a public" do
248
+ before do
249
+ create_activity_assigned_to(Factory(:public_tie))
250
+ u = @tie.sender.subject
251
+ @ability = Ability.new(u)
252
+ end
253
+
254
+ it_should_behave_like "Denies Creating"
255
+ end
256
+
257
+ describe "belonging to admin tie" do
258
+ before do
259
+ create_activity_assigned_to(Factory(:admin_tie))
260
+ end
261
+
262
+ describe "accessed by same admin" do
263
+ before do
264
+ u = @tie.sender.subject
265
+ @ability = Ability.new(u)
266
+ end
267
+
268
+ it_should_behave_like "Allows Creating"
269
+ it_should_behave_like "Allows Reading"
270
+ it_should_behave_like "Allows Updating"
271
+ it_should_behave_like "Allows Destroying"
272
+ end
273
+
274
+ describe "accessed by different admin" do
275
+ before do
276
+ create_ability_accessed_by :admin_tie
277
+ end
278
+
279
+ it_should_behave_like "Denies Creating"
280
+ it_should_behave_like "Allows Reading"
281
+ it_should_behave_like "Allows Updating"
282
+ it_should_behave_like "Allows Destroying"
283
+ end
284
+
285
+ describe "accessed by user" do
286
+ before do
287
+ create_ability_accessed_by :user_tie
288
+ end
289
+
290
+ it_should_behave_like "Denies Creating"
291
+ it_should_behave_like "Denies Reading"
292
+ it_should_behave_like "Denies Updating"
293
+ it_should_behave_like "Denies Destroying"
294
+ end
295
+
296
+ describe "accessed by follower" do
297
+ before do
298
+ create_ability_accessed_by :follower_tie
299
+ end
300
+
301
+ it_should_behave_like "Denies Creating"
302
+ it_should_behave_like "Denies Reading"
303
+ it_should_behave_like "Denies Updating"
304
+ it_should_behave_like "Denies Destroying"
305
+ end
306
+ end
307
+
308
+ describe "belonging to user tie from an admin" do
309
+ before do
310
+ create_activity_assigned_to(Factory(:admin_tie).related('user'))
311
+ end
312
+
313
+ describe "accessed by a admin" do
314
+ before do
315
+ create_ability_accessed_by :admin_tie
316
+ end
317
+
318
+ it_should_behave_like "Denies Creating"
319
+ it_should_behave_like "Allows Reading"
320
+ it_should_behave_like "Allows Updating"
321
+ it_should_behave_like "Allows Destroying"
322
+ end
323
+
324
+ describe "accessed by same admin" do
325
+ before do
326
+ u = @tie.sender.subject
327
+ @ability = Ability.new(u)
328
+ end
329
+
330
+ it_should_behave_like "Allows Creating"
331
+ it_should_behave_like "Allows Reading"
332
+ it_should_behave_like "Allows Updating"
333
+ it_should_behave_like "Allows Destroying"
334
+ end
335
+
336
+ describe "accessed by different user" do
337
+ before do
338
+ create_ability_accessed_by :user_tie
339
+ end
340
+
341
+ it_should_behave_like "Denies Creating"
342
+ it_should_behave_like "Allows Reading"
343
+ it_should_behave_like "Allows Updating"
344
+ it_should_behave_like "Allows Destroying"
345
+ end
346
+
347
+ describe "accessed by follower" do
348
+ before do
349
+ create_ability_accessed_by :follower_tie
350
+ end
351
+
352
+ it_should_behave_like "Denies Creating"
353
+ it_should_behave_like "Denies Reading"
354
+ it_should_behave_like "Denies Updating"
355
+ it_should_behave_like "Denies Destroying"
356
+ end
357
+ end
358
+
359
+ describe "belonging to follower tie" do
360
+ before do
361
+ create_activity_assigned_to(Factory(:user_tie).related('follower'))
362
+ end
363
+
364
+ describe "accessed by an admin" do
365
+ before do
366
+ create_ability_accessed_by :admin_tie
367
+ end
368
+
369
+ it_should_behave_like "Denies Creating"
370
+ it_should_behave_like "Allows Reading"
371
+ it_should_behave_like "Allows Updating"
372
+ it_should_behave_like "Allows Destroying"
373
+ end
374
+
375
+ describe "accessed by user" do
376
+ before do
377
+ create_ability_accessed_by :user_tie
378
+ end
379
+
380
+ it_should_behave_like "Denies Creating"
381
+ it_should_behave_like "Allows Reading"
382
+ it_should_behave_like "Allows Updating"
383
+ it_should_behave_like "Allows Destroying"
384
+ end
385
+
386
+ describe "accessed by same sender" do
387
+ before do
388
+ u = @tie.sender.subject
389
+ @ability = Ability.new(u)
390
+ end
391
+
392
+ it_should_behave_like "Allows Creating"
393
+ it_should_behave_like "Allows Reading"
394
+ it_should_behave_like "Allows Updating"
395
+ it_should_behave_like "Allows Destroying"
396
+ end
397
+
398
+ describe "accessed by different follower" do
399
+ before do
400
+ create_ability_accessed_by :follower_tie
401
+ end
402
+
403
+ it_should_behave_like "Denies Creating"
404
+ it_should_behave_like "Allows Reading"
405
+ it_should_behave_like "Denies Updating"
406
+ it_should_behave_like "Denies Destroying"
407
+ end
408
+ end
409
+
410
+ describe "belonging to follower tie from a follower" do
411
+ before do
412
+ create_activity_assigned_to(Factory(:follower_tie))
413
+ u = @tie.sender.subject
414
+ @ability = Ability.new(u)
415
+ end
416
+
417
+ it_should_behave_like "Denies Creating"
418
+ end
419
+
420
+ end