commontator 1.1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/app/controllers/commontator/comments_controller.rb +3 -2
  2. data/app/controllers/commontator/comments_controller.rb~ +136 -0
  3. data/app/models/commontator/comment.rb +53 -36
  4. data/app/models/commontator/comment.rb~ +108 -0
  5. data/app/models/commontator/subscription.rb +8 -6
  6. data/app/models/commontator/subscription.rb~ +21 -0
  7. data/app/models/commontator/thread.rb +48 -44
  8. data/app/models/commontator/thread.rb~ +48 -47
  9. data/app/views/commontator/comments/_body.html.erb +1 -1
  10. data/app/views/commontator/comments/_body.html.erb~ +8 -0
  11. data/app/views/commontator/comments/_form.html.erb +1 -1
  12. data/app/views/commontator/comments/_form.html.erb~ +38 -0
  13. data/app/views/commontator/comments/_show.html.erb +1 -1
  14. data/app/views/commontator/comments/_show.html.erb~ +44 -0
  15. data/app/views/commontator/comments/_votes.html.erb +1 -1
  16. data/app/views/commontator/comments/_votes.html.erb~ +57 -0
  17. data/app/views/commontator/comments/delete.js.erb +1 -1
  18. data/app/views/commontator/comments/delete.js.erb~ +17 -0
  19. data/config/initializers/commontator.rb +11 -4
  20. data/config/initializers/commontator.rb~ +171 -0
  21. data/db/migrate/0_install.rb +23 -21
  22. data/db/migrate/0_install.rb~ +23 -21
  23. data/lib/commontator.rb +2 -0
  24. data/lib/commontator.rb~ +1 -1
  25. data/lib/commontator/acts_as_commontable.rb +7 -6
  26. data/lib/commontator/acts_as_commontable.rb~ +8 -6
  27. data/lib/commontator/acts_as_commontator.rb +4 -3
  28. data/lib/commontator/acts_as_commontator.rb~ +31 -0
  29. data/lib/commontator/version.rb +1 -1
  30. data/lib/commontator/version.rb~ +1 -1
  31. data/spec/app/controllers/commontator/comments_controller_spec.rb +61 -20
  32. data/spec/app/controllers/commontator/comments_controller_spec.rb~ +58 -21
  33. data/spec/app/models/commontator/comment_spec.rb +8 -7
  34. data/spec/app/models/commontator/comment_spec.rb~ +9 -8
  35. data/spec/app/models/commontator/thread_spec.rb +1 -1
  36. data/spec/app/models/commontator/thread_spec.rb~ +1 -1
  37. data/spec/dummy/db/development.sqlite3 +0 -0
  38. data/spec/dummy/db/schema.rb +16 -16
  39. data/spec/dummy/db/test.sqlite3 +0 -0
  40. data/spec/dummy/log/development.log +724 -0
  41. data/spec/dummy/log/test.log +41005 -0
  42. metadata +12 -2
data/lib/commontator.rb CHANGED
@@ -25,6 +25,8 @@ module Commontator
25
25
  :comment_name,
26
26
  :comment_create_verb_present,
27
27
  :comment_create_verb_past,
28
+ :comment_edit_verb_present,
29
+ :comment_edit_verb_past,
28
30
  :commontable_name,
29
31
  :timestamp_format,
30
32
  :admin_can_edit_comments,
data/lib/commontator.rb~ CHANGED
@@ -25,6 +25,7 @@ module Commontator
25
25
  :comment_name,
26
26
  :comment_create_verb_present,
27
27
  :comment_create_verb_past,
28
+ :comment_edit_verb_past,
28
29
  :commontable_name,
29
30
  :timestamp_format,
30
31
  :admin_can_edit_comments,
@@ -58,4 +59,3 @@ end
58
59
 
59
60
  require 'commontator/acts_as_commontator'
60
61
  require 'commontator/acts_as_commontable'
61
-
@@ -11,23 +11,24 @@ module Commontator
11
11
  module ClassMethods
12
12
  def acts_as_commontable(options = {})
13
13
  class_eval do
14
+ cattr_accessor :commontable_config
15
+ self.commontable_config = Commontator::CommontableConfig.new(options)
16
+ self.is_commontable = true
17
+
14
18
  has_one :thread, :as => :commontable, :class_name => 'Commontator::Thread'
15
19
  has_many :comments, :class_name => 'Commontator::Comment', :through => :thread
20
+
16
21
  has_many :subscriptions, :class_name => 'Commontator::Subscription', :through => :thread
17
22
 
18
23
  validates_presence_of :thread
19
24
 
20
- cattr_accessor :commontable_config
21
- self.commontable_config = Commontator::CommontableConfig.new(options)
22
- self.is_commontable = true
23
-
24
25
  alias_method :thread_raw, :thread
25
26
 
26
27
  def thread
27
28
  raw = thread_raw
28
29
  return raw unless raw.nil?
29
- return Commontator::Thread.find_or_create_by_commontable_id_and_commontable_type(self.id, self.class.name) \
30
- unless self.id.nil?
30
+ return Commontator::Thread.find_or_create_by_commontable_type_and_commontable_id(self.class.name, id) \
31
+ unless id.nil?
31
32
  self.thread = Commontator::Thread.new
32
33
  self.thread.commontable = self
33
34
  self.thread
@@ -11,23 +11,25 @@ module Commontator
11
11
  module ClassMethods
12
12
  def acts_as_commontable(options = {})
13
13
  class_eval do
14
+ cattr_accessor :commontable_config
15
+ self.commontable_config = Commontator::CommontableConfig.new(options)
16
+ self.is_commontable = true
17
+
14
18
  has_one :thread, :as => :commontable, :class_name => 'Commontator::Thread'
15
19
  has_many :comments, :class_name => 'Commontator::Comment', :through => :thread
20
+
16
21
  has_many :subscriptions, :class_name => 'Commontator::Subscription', :through => :thread
22
+ has_many :subscribers, :through => :subscriptions
17
23
 
18
24
  validates_presence_of :thread
19
25
 
20
- cattr_accessor :commontable_config
21
- self.commontable_config = Commontator::CommontableConfig.new
22
- self.is_commontable = true
23
-
24
26
  alias_method :thread_raw, :thread
25
27
 
26
28
  def thread
27
29
  raw = thread_raw
28
30
  return raw unless raw.nil?
29
- return Commontator::Thread.find_or_create_by_commontable_id_and_commontable_type(self.id, self.class.name) \
30
- unless self.id.nil?
31
+ return Commontator::Thread.find_or_create_by_commontable_type_and_commontable_id(self.class.name, id) \
32
+ unless id.nil?
31
33
  self.thread = Commontator::Thread.new
32
34
  self.thread.commontable = self
33
35
  self.thread
@@ -11,12 +11,13 @@ module Commontator
11
11
  module ClassMethods
12
12
  def acts_as_commontator(options = {})
13
13
  class_eval do
14
- has_many :comments, :as => :commontator, :class_name => 'Commontator::Comment'
15
- has_many :subscriptions, :as => :subscriber, :class_name => 'Commontator::Subscription', :dependent => :destroy
16
-
17
14
  cattr_accessor :commontator_config
18
15
  self.commontator_config = Commontator::CommontatorConfig.new(options)
19
16
  self.is_commontator = true
17
+
18
+ has_many :comments, :as => :commontator, :class_name => 'Commontator::Comment'
19
+
20
+ has_many :subscriptions, :as => :subscriber, :class_name => 'Commontator::Subscription', :dependent => :destroy
20
21
  end
21
22
  end
22
23
 
@@ -0,0 +1,31 @@
1
+ require 'commontator/commontator_config'
2
+
3
+ module Commontator
4
+ module ActsAsCommontator
5
+ def self.included(base)
6
+ base.class_attribute :is_commontator
7
+ base.is_commontator = false
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def acts_as_commontator(options = {})
13
+ class_eval do
14
+ has_many :comments, :as => :commontator, :class_name => 'Commontator::Comment'
15
+
16
+ has_many :subscriptions, :as => :subscriber, :class_name => 'Commontator::Subscription', :dependent => :destroy
17
+
18
+ cattr_accessor :commontator_config
19
+ self.commontator_config = Commontator::CommontatorConfig.new(options)
20
+ self.is_commontator = true
21
+ end
22
+ end
23
+
24
+ alias_method :acts_as_commonter, :acts_as_commontator
25
+ alias_method :acts_as_commentator, :acts_as_commontator
26
+ alias_method :acts_as_commenter, :acts_as_commontator
27
+ end
28
+ end
29
+ end
30
+
31
+ ActiveRecord::Base.send :include, Commontator::ActsAsCommontator
@@ -1,3 +1,3 @@
1
1
  module Commontator
2
- VERSION = "1.1.3"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Commontator
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -45,7 +45,7 @@ module Commontator
45
45
 
46
46
  it 'wont create unless authorized' do
47
47
  attributes = Hash.new
48
- attributes[:body] = 'Something'
48
+ attributes[:body] = 'Something else'
49
49
 
50
50
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
51
51
  assert_response 403
@@ -65,35 +65,65 @@ module Commontator
65
65
  it 'must create if authorized' do
66
66
  sign_in @user
67
67
  attributes = Hash.new
68
- attributes[:body] = 'Something'
69
68
 
69
+ attributes[:body] = 'Something else'
70
70
  @user.can_read = true
71
71
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
72
72
  assert_redirected_to @thread
73
73
  assigns(:comment).errors.must_be_empty
74
- assigns(:comment).body.must_equal 'Something'
74
+ assigns(:comment).body.must_equal 'Something else'
75
75
  assigns(:comment).creator.must_equal @user
76
+ assigns(:comment).editor.must_be_nil
76
77
  assigns(:comment).thread.must_equal @thread
77
78
 
79
+ attributes[:body] = 'Another thing'
78
80
  @user.can_read = false
79
81
  @user.can_edit = true
80
82
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
81
83
  assert_redirected_to @thread
82
84
  assigns(:comment).errors.must_be_empty
83
- assigns(:comment).body.must_equal 'Something'
85
+ assigns(:comment).body.must_equal 'Another thing'
84
86
  assigns(:comment).creator.must_equal @user
87
+ assigns(:comment).editor.must_be_nil
85
88
  assigns(:comment).thread.must_equal @thread
86
89
 
90
+ attributes[:body] = 'And this too'
87
91
  @user.can_edit = false
88
92
  @user.is_admin = true
89
93
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
90
94
  assert_redirected_to @thread
91
95
  assigns(:comment).errors.must_be_empty
92
- assigns(:comment).body.must_equal 'Something'
96
+ assigns(:comment).body.must_equal 'And this too'
93
97
  assigns(:comment).creator.must_equal @user
98
+ assigns(:comment).editor.must_be_nil
94
99
  assigns(:comment).thread.must_equal @thread
95
100
  end
96
101
 
102
+ it 'wont create if double posting' do
103
+ sign_in @user
104
+ @user.can_read = true
105
+ attributes = Hash.new
106
+
107
+ attributes[:body] = 'Something'
108
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
109
+ assert_redirected_to @thread
110
+ assigns(:comment).errors.wont_be_empty
111
+
112
+ attributes[:body] = 'Something else'
113
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
114
+ assert_redirected_to @thread
115
+ assigns(:comment).errors.must_be_empty
116
+ assigns(:comment).body.must_equal 'Something else'
117
+ assigns(:comment).creator.must_equal @user
118
+ assigns(:comment).editor.must_be_nil
119
+ assigns(:comment).thread.must_equal @thread
120
+
121
+ attributes[:body] = 'Something else'
122
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
123
+ assert_redirected_to @thread
124
+ assigns(:comment).errors.wont_be_empty
125
+ end
126
+
97
127
  it 'wont edit unless authorized' do
98
128
  get :edit, :id => @comment.id, :use_route => :commontator
99
129
  assert_response 403
@@ -151,11 +181,13 @@ module Commontator
151
181
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
152
182
  assert_response 403
153
183
  assigns(:comment).body.must_equal 'Something'
184
+ assigns(:comment).editor.must_be_nil
154
185
 
155
186
  sign_in @user
156
187
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
157
188
  assert_response 403
158
189
  assigns(:comment).body.must_equal 'Something'
190
+ assigns(:comment).editor.must_be_nil
159
191
 
160
192
  user2 = DummyUser.create
161
193
  user2.can_read = true
@@ -165,6 +197,7 @@ module Commontator
165
197
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
166
198
  assert_response 403
167
199
  assigns(:comment).body.must_equal 'Something'
200
+ assigns(:comment).editor.must_be_nil
168
201
 
169
202
  @user.can_read = true
170
203
  @user.can_edit = true
@@ -178,6 +211,7 @@ module Commontator
178
211
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
179
212
  assert_response 403
180
213
  assigns(:comment).body.must_equal 'Something'
214
+ assigns(:comment).editor.must_be_nil
181
215
  end
182
216
 
183
217
  it 'must update if authorized' do
@@ -189,18 +223,21 @@ module Commontator
189
223
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
190
224
  assert_redirected_to @thread
191
225
  assigns(:comment).errors.must_be_empty
226
+ assigns(:comment).editor.must_equal @user
192
227
 
193
228
  @user.can_read = false
194
229
  @user.can_edit = true
195
230
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
196
231
  assert_redirected_to @thread
197
232
  assigns(:comment).errors.must_be_empty
233
+ assigns(:comment).editor.must_equal @user
198
234
 
199
235
  @user.can_edit = false
200
236
  @user.is_admin = true
201
237
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
202
238
  assert_redirected_to @thread
203
239
  assigns(:comment).errors.must_be_empty
240
+ assigns(:comment).editor.must_equal @user
204
241
  end
205
242
 
206
243
  it 'wont delete unless authorized and not deleted' do
@@ -215,7 +252,7 @@ module Commontator
215
252
  assigns(:comment).is_deleted?.must_equal false
216
253
 
217
254
  @user.can_read = true
218
- @comment.delete(@user).must_equal true
255
+ @comment.delete_by(@user).must_equal true
219
256
  put :delete, :id => @comment.id, :use_route => :commontator
220
257
  assert_redirected_to @thread
221
258
  assigns(:comment).errors.wont_be_empty
@@ -225,7 +262,7 @@ module Commontator
225
262
  comment2.creator = @user
226
263
  comment2.body = 'Something else'
227
264
  comment2.save!
228
- @comment.undelete.must_equal true
265
+ @comment.undelete_by(@user).must_equal true
229
266
  put :delete, :id => @comment.id, :use_route => :commontator
230
267
  assert_response 403
231
268
  assigns(:comment).is_deleted?.must_equal false
@@ -239,7 +276,7 @@ module Commontator
239
276
  assert_redirected_to @thread
240
277
  assigns(:comment).errors.must_be_empty
241
278
  assigns(:comment).is_deleted?.must_equal true
242
- assigns(:comment).deleter.must_equal @user
279
+ assigns(:comment).editor.must_equal @user
243
280
 
244
281
  user2 = DummyUser.create
245
282
  sign_in user2
@@ -249,26 +286,26 @@ module Commontator
249
286
  comment2.body = 'Something else'
250
287
  comment2.save!
251
288
 
252
- assigns(:comment).undelete.must_equal true
289
+ assigns(:comment).undelete_by(@user).must_equal true
253
290
  user2.can_edit = true
254
291
  put :delete, :id => @comment.id, :use_route => :commontator
255
292
  assert_redirected_to @thread
256
293
  assigns(:comment).errors.must_be_empty
257
294
  assigns(:comment).is_deleted?.must_equal true
258
- assigns(:comment).deleter.must_equal user2
295
+ assigns(:comment).editor.must_equal user2
259
296
 
260
- assigns(:comment).undelete.must_equal true
297
+ assigns(:comment).undelete_by(@user).must_equal true
261
298
  user2.can_edit = false
262
299
  user2.is_admin = true
263
300
  put :delete, :id => @comment.id, :use_route => :commontator
264
301
  assert_redirected_to @thread
265
302
  assigns(:comment).errors.must_be_empty
266
303
  assigns(:comment).is_deleted?.must_equal true
267
- assigns(:comment).deleter.must_equal user2
304
+ assigns(:comment).editor.must_equal user2
268
305
  end
269
306
 
270
307
  it 'wont undelete unless authorized and deleted' do
271
- @comment.delete(@user).must_equal true
308
+ @comment.delete_by(@user).must_equal true
272
309
  put :undelete, :id => @comment.id, :use_route => :commontator
273
310
  assert_response 403
274
311
  assigns(:comment).is_deleted?.must_equal true
@@ -280,12 +317,16 @@ module Commontator
280
317
  assigns(:comment).is_deleted?.must_equal true
281
318
 
282
319
  @user.can_read = true
283
- @comment.undelete.must_equal true
320
+ @comment.undelete_by(@user).must_equal true
284
321
  put :undelete, :id => @comment.id, :use_route => :commontator
285
322
  assert_redirected_to @thread
286
323
  assigns(:comment).errors.wont_be_empty
287
324
 
288
- @comment.delete.must_equal true
325
+ user2 = DummyUser.create
326
+ user2.can_read = true
327
+ user2.can_edit = true
328
+ user2.is_admin = true
329
+ @comment.delete_by(user2).must_equal true
289
330
  put :undelete, :id => @comment.id, :use_route => :commontator
290
331
  assert_response 403
291
332
  assigns(:comment).is_deleted?.must_equal true
@@ -295,8 +336,8 @@ module Commontator
295
336
  comment2.creator = @user
296
337
  comment2.body = 'Something else'
297
338
  comment2.save!
298
- @comment.undelete.must_equal true
299
- @comment.delete(@user).must_equal true
339
+ @comment.undelete_by(@user).must_equal true
340
+ @comment.delete_by(@user).must_equal true
300
341
  put :undelete, :id => @comment.id, :use_route => :commontator
301
342
  assert_response 403
302
343
  assigns(:comment).is_deleted?.must_equal true
@@ -305,7 +346,7 @@ module Commontator
305
346
  it 'must undelete if authorized and deleted' do
306
347
  sign_in @user
307
348
 
308
- @comment.delete(@user).must_equal true
349
+ @comment.delete_by(@user).must_equal true
309
350
  @user.can_read = true
310
351
  put :undelete, :id => @comment.id, :use_route => :commontator
311
352
  assert_redirected_to @thread
@@ -320,14 +361,14 @@ module Commontator
320
361
  comment2.body = 'Something else'
321
362
  comment2.save!
322
363
 
323
- assigns(:comment).delete(@user).must_equal true
364
+ assigns(:comment).delete_by(@user).must_equal true
324
365
  user2.can_edit = true
325
366
  put :undelete, :id => @comment.id, :use_route => :commontator
326
367
  assert_redirected_to @thread
327
368
  assigns(:comment).errors.must_be_empty
328
369
  assigns(:comment).is_deleted?.must_equal false
329
370
 
330
- assigns(:comment).delete(@user).must_equal true
371
+ assigns(:comment).delete_by(@user).must_equal true
331
372
  user2.can_edit = false
332
373
  user2.is_admin = true
333
374
  put :undelete, :id => @comment.id, :use_route => :commontator
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'minitest_helper'
2
2
  require 'acts_as_votable'
3
3
 
4
4
  module Commontator
@@ -45,7 +45,7 @@ module Commontator
45
45
 
46
46
  it 'wont create unless authorized' do
47
47
  attributes = Hash.new
48
- attributes[:body] = 'Something'
48
+ attributes[:body] = 'Something else'
49
49
 
50
50
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
51
51
  assert_response 403
@@ -65,35 +65,65 @@ module Commontator
65
65
  it 'must create if authorized' do
66
66
  sign_in @user
67
67
  attributes = Hash.new
68
- attributes[:body] = 'Something'
69
68
 
69
+ attributes[:body] = 'Something else'
70
70
  @user.can_read = true
71
71
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
72
72
  assert_redirected_to @thread
73
73
  assigns(:comment).errors.must_be_empty
74
- assigns(:comment).body.must_equal 'Something'
74
+ assigns(:comment).body.must_equal 'Something else'
75
75
  assigns(:comment).creator.must_equal @user
76
+ assigns(:comment).editor.must_be_nil
76
77
  assigns(:comment).thread.must_equal @thread
77
78
 
79
+ attributes[:body] = 'Another thing'
78
80
  @user.can_read = false
79
81
  @user.can_edit = true
80
82
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
81
83
  assert_redirected_to @thread
82
84
  assigns(:comment).errors.must_be_empty
83
- assigns(:comment).body.must_equal 'Something'
85
+ assigns(:comment).body.must_equal 'Another thing'
84
86
  assigns(:comment).creator.must_equal @user
87
+ assigns(:comment).editor.must_be_nil
85
88
  assigns(:comment).thread.must_equal @thread
86
89
 
90
+ attributes[:body] = 'And this too'
87
91
  @user.can_edit = false
88
92
  @user.is_admin = true
89
93
  post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
90
94
  assert_redirected_to @thread
91
95
  assigns(:comment).errors.must_be_empty
92
- assigns(:comment).body.must_equal 'Something'
96
+ assigns(:comment).body.must_equal 'And this too'
93
97
  assigns(:comment).creator.must_equal @user
98
+ assigns(:comment).editor.must_be_nil
94
99
  assigns(:comment).thread.must_equal @thread
95
100
  end
96
101
 
102
+ it 'wont create if double posting' do
103
+ sign_in @user
104
+ @user.can_read = true
105
+ attributes = Hash.new
106
+
107
+ attributes[:body] = 'Something'
108
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
109
+ assert_redirected_to @thread
110
+ assigns(:comment).errors.wont_be_empty
111
+
112
+ attributes[:body] = 'Something else'
113
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
114
+ assert_redirected_to @thread
115
+ assigns(:comment).errors.must_be_empty
116
+ assigns(:comment).body.must_equal 'Something else'
117
+ assigns(:comment).creator.must_equal @user
118
+ assigns(:comment).editor.must_be_nil
119
+ assigns(:comment).thread.must_equal @thread
120
+
121
+ attributes[:body] = 'Something else'
122
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
123
+ assert_redirected_to @thread
124
+ assigns(:comment).errors.wont_be_empty
125
+ end
126
+
97
127
  it 'wont edit unless authorized' do
98
128
  get :edit, :id => @comment.id, :use_route => :commontator
99
129
  assert_response 403
@@ -151,11 +181,13 @@ module Commontator
151
181
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
152
182
  assert_response 403
153
183
  assigns(:comment).body.must_equal 'Something'
184
+ assigns(:comment).editor.must_be_nil
154
185
 
155
186
  sign_in @user
156
187
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
157
188
  assert_response 403
158
189
  assigns(:comment).body.must_equal 'Something'
190
+ assigns(:comment).editor.must_be_nil
159
191
 
160
192
  user2 = DummyUser.create
161
193
  user2.can_read = true
@@ -165,6 +197,7 @@ module Commontator
165
197
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
166
198
  assert_response 403
167
199
  assigns(:comment).body.must_equal 'Something'
200
+ assigns(:comment).editor.must_be_nil
168
201
 
169
202
  @user.can_read = true
170
203
  @user.can_edit = true
@@ -178,6 +211,7 @@ module Commontator
178
211
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
179
212
  assert_response 403
180
213
  assigns(:comment).body.must_equal 'Something'
214
+ assigns(:comment).editor.must_be_nil
181
215
  end
182
216
 
183
217
  it 'must update if authorized' do
@@ -189,18 +223,21 @@ module Commontator
189
223
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
190
224
  assert_redirected_to @thread
191
225
  assigns(:comment).errors.must_be_empty
226
+ assigns(:comment).editor.must_equal @user
192
227
 
193
228
  @user.can_read = false
194
229
  @user.can_edit = true
195
230
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
196
231
  assert_redirected_to @thread
197
232
  assigns(:comment).errors.must_be_empty
233
+ assigns(:comment).editor.must_equal @user
198
234
 
199
235
  @user.can_edit = false
200
236
  @user.is_admin = true
201
237
  put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
202
238
  assert_redirected_to @thread
203
239
  assigns(:comment).errors.must_be_empty
240
+ assigns(:comment).editor.must_equal @user
204
241
  end
205
242
 
206
243
  it 'wont delete unless authorized and not deleted' do
@@ -215,7 +252,7 @@ module Commontator
215
252
  assigns(:comment).is_deleted?.must_equal false
216
253
 
217
254
  @user.can_read = true
218
- @comment.delete(@user).must_equal true
255
+ @comment.delete_by(@user).must_equal true
219
256
  put :delete, :id => @comment.id, :use_route => :commontator
220
257
  assert_redirected_to @thread
221
258
  assigns(:comment).errors.wont_be_empty
@@ -225,7 +262,7 @@ module Commontator
225
262
  comment2.creator = @user
226
263
  comment2.body = 'Something else'
227
264
  comment2.save!
228
- @comment.undelete.must_equal true
265
+ @comment.undelete_by(@user).must_equal true
229
266
  put :delete, :id => @comment.id, :use_route => :commontator
230
267
  assert_response 403
231
268
  assigns(:comment).is_deleted?.must_equal false
@@ -239,7 +276,7 @@ module Commontator
239
276
  assert_redirected_to @thread
240
277
  assigns(:comment).errors.must_be_empty
241
278
  assigns(:comment).is_deleted?.must_equal true
242
- assigns(:comment).deleter.must_equal @user
279
+ assigns(:comment).editor.must_equal @user
243
280
 
244
281
  user2 = DummyUser.create
245
282
  sign_in user2
@@ -249,26 +286,26 @@ module Commontator
249
286
  comment2.body = 'Something else'
250
287
  comment2.save!
251
288
 
252
- assigns(:comment).undelete.must_equal true
289
+ assigns(:comment).undelete_by(@user).must_equal true
253
290
  user2.can_edit = true
254
291
  put :delete, :id => @comment.id, :use_route => :commontator
255
292
  assert_redirected_to @thread
256
293
  assigns(:comment).errors.must_be_empty
257
294
  assigns(:comment).is_deleted?.must_equal true
258
- assigns(:comment).deleter.must_equal user2
295
+ assigns(:comment).editor.must_equal user2
259
296
 
260
- assigns(:comment).undelete.must_equal true
297
+ assigns(:comment).undelete_by(@user).must_equal true
261
298
  user2.can_edit = false
262
299
  user2.is_admin = true
263
300
  put :delete, :id => @comment.id, :use_route => :commontator
264
301
  assert_redirected_to @thread
265
302
  assigns(:comment).errors.must_be_empty
266
303
  assigns(:comment).is_deleted?.must_equal true
267
- assigns(:comment).deleter.must_equal user2
304
+ assigns(:comment).editor.must_equal user2
268
305
  end
269
306
 
270
307
  it 'wont undelete unless authorized and deleted' do
271
- @comment.delete(@user).must_equal true
308
+ @comment.delete_by(@user).must_equal true
272
309
  put :undelete, :id => @comment.id, :use_route => :commontator
273
310
  assert_response 403
274
311
  assigns(:comment).is_deleted?.must_equal true
@@ -280,12 +317,12 @@ module Commontator
280
317
  assigns(:comment).is_deleted?.must_equal true
281
318
 
282
319
  @user.can_read = true
283
- @comment.undelete.must_equal true
320
+ @comment.undelete_by(@user).must_equal true
284
321
  put :undelete, :id => @comment.id, :use_route => :commontator
285
322
  assert_redirected_to @thread
286
323
  assigns(:comment).errors.wont_be_empty
287
324
 
288
- @comment.delete.must_equal true
325
+ @comment.delete_by(@user).must_equal true
289
326
  put :undelete, :id => @comment.id, :use_route => :commontator
290
327
  assert_response 403
291
328
  assigns(:comment).is_deleted?.must_equal true
@@ -295,8 +332,8 @@ module Commontator
295
332
  comment2.creator = @user
296
333
  comment2.body = 'Something else'
297
334
  comment2.save!
298
- @comment.undelete.must_equal true
299
- @comment.delete(@user).must_equal true
335
+ @comment.undelete_by(@user).must_equal true
336
+ @comment.delete_by(@user).must_equal true
300
337
  put :undelete, :id => @comment.id, :use_route => :commontator
301
338
  assert_response 403
302
339
  assigns(:comment).is_deleted?.must_equal true
@@ -305,7 +342,7 @@ module Commontator
305
342
  it 'must undelete if authorized and deleted' do
306
343
  sign_in @user
307
344
 
308
- @comment.delete(@user).must_equal true
345
+ @comment.delete_by(@user).must_equal true
309
346
  @user.can_read = true
310
347
  put :undelete, :id => @comment.id, :use_route => :commontator
311
348
  assert_redirected_to @thread
@@ -320,14 +357,14 @@ module Commontator
320
357
  comment2.body = 'Something else'
321
358
  comment2.save!
322
359
 
323
- assigns(:comment).delete(@user).must_equal true
360
+ assigns(:comment).delete_by(@user).must_equal true
324
361
  user2.can_edit = true
325
362
  put :undelete, :id => @comment.id, :use_route => :commontator
326
363
  assert_redirected_to @thread
327
364
  assigns(:comment).errors.must_be_empty
328
365
  assigns(:comment).is_deleted?.must_equal false
329
366
 
330
- assigns(:comment).delete(@user).must_equal true
367
+ assigns(:comment).delete_by(@user).must_equal true
331
368
  user2.can_edit = false
332
369
  user2.is_admin = true
333
370
  put :undelete, :id => @comment.id, :use_route => :commontator