commontator 4.0.2 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/app/assets/stylesheets/commontator/comments.css +16 -5
- data/app/assets/stylesheets/commontator/comments.css~ +98 -0
- data/app/controllers/commontator/application_controller.rb +6 -3
- data/app/controllers/commontator/application_controller.rb~ +30 -0
- data/app/controllers/commontator/threads_controller.rb +2 -0
- data/app/controllers/commontator/threads_controller.rb~ +44 -0
- data/app/helpers/commontator/threads_helper.rb +1 -8
- data/app/helpers/commontator/threads_helper.rb~ +11 -0
- data/app/mailers/commontator/subscriptions_mailer.rb +2 -4
- data/app/mailers/commontator/subscriptions_mailer.rb~ +50 -0
- data/app/models/commontator/comment.rb +23 -19
- data/app/models/commontator/comment.rb~ +106 -0
- data/app/models/commontator/thread.rb +10 -10
- data/app/models/commontator/thread.rb~ +124 -0
- data/app/views/commontator/comments/_show.html.erb +36 -34
- data/app/views/commontator/comments/_show.html.erb~ +47 -0
- data/app/views/commontator/comments/_votes.html.erb +6 -2
- data/app/views/commontator/comments/_votes.html.erb~ +61 -0
- data/app/views/commontator/comments/delete.js.erb +2 -2
- data/app/views/commontator/comments/delete.js.erb~ +17 -0
- data/app/views/commontator/comments/update.js.erb +2 -2
- data/app/views/commontator/comments/update.js.erb~ +7 -0
- data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +2 -2
- data/app/views/commontator/subscriptions_mailer/comment_created.html.erb~ +6 -0
- data/app/views/commontator/threads/_show.html.erb +3 -7
- data/app/views/commontator/threads/_show.html.erb~ +58 -0
- data/config/initializers/commontator.rb +52 -47
- data/config/initializers/commontator.rb~ +176 -0
- data/lib/commontator.rb +6 -7
- data/lib/commontator.rb~ +61 -0
- data/lib/commontator/controller_includes.rb +1 -3
- data/lib/commontator/controller_includes.rb~ +22 -0
- data/lib/commontator/shared_helper.rb +3 -8
- data/lib/commontator/shared_helper.rb~ +37 -0
- data/lib/commontator/version.rb +1 -1
- data/lib/commontator/version.rb~ +3 -0
- data/spec/app/controllers/commontator/comments_controller_spec.rb +64 -45
- data/spec/app/controllers/commontator/comments_controller_spec.rb~ +580 -0
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +3 -3
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb~ +99 -0
- data/spec/app/controllers/commontator/threads_controller_spec.rb +15 -9
- data/spec/app/controllers/commontator/threads_controller_spec.rb~ +126 -0
- data/spec/app/helpers/commontator/application_helper_spec.rb +1 -1
- data/spec/app/helpers/commontator/application_helper_spec.rb~ +9 -0
- data/spec/app/helpers/commontator/threads_helper_spec.rb +1 -5
- data/spec/app/helpers/commontator/threads_helper_spec.rb~ +13 -0
- data/spec/app/models/commontator/comment_spec.rb +4 -3
- data/spec/app/models/commontator/comment_spec.rb~ +62 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/application.rb~ +27 -0
- data/spec/dummy/config/initializers/commontator.rb +67 -55
- data/spec/dummy/config/initializers/commontator.rb~ +176 -0
- data/spec/dummy/config/initializers/commontator2.rb~ +169 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +84489 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/02d4b791eb831cf2057bf4703a1218d1 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/0f196a1a50363b0a076ec6e1ee5417f6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/e1f674c11941d62aac1764ef3a7134e4 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/e85565206c3e5fdf9dfeb367c85557b1 +0 -0
- data/spec/lib/commontator/commontable_config_spec.rb +1 -1
- data/spec/lib/commontator/commontable_config_spec.rb~ +26 -0
- data/spec/lib/commontator/commontator_config_spec.rb +5 -5
- data/spec/lib/commontator/commontator_config_spec.rb~ +26 -0
- data/spec/lib/commontator_spec.rb +6 -4
- data/spec/lib/commontator_spec.rb~ +28 -0
- data/spec/test_helper.rb +4 -4
- data/spec/test_helper.rb~ +37 -0
- metadata +46 -2
@@ -0,0 +1,580 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'acts_as_votable'
|
3
|
+
|
4
|
+
module Commontator
|
5
|
+
describe CommentsController do
|
6
|
+
before do
|
7
|
+
setup_controller_spec
|
8
|
+
@comment = Comment.new
|
9
|
+
@comment.thread = @thread
|
10
|
+
@comment.creator = @user
|
11
|
+
@comment.body = 'Something'
|
12
|
+
@comment.save!
|
13
|
+
@comment.is_votable?.must_equal true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "won't get new unless authorized" do
|
17
|
+
get :new, :thread_id => @thread.id, :use_route => :commontator
|
18
|
+
assert_response 403
|
19
|
+
|
20
|
+
sign_in @user
|
21
|
+
get :new, :thread_id => @thread.id, :use_route => :commontator
|
22
|
+
assert_response 403
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'must get new if authorized' do
|
26
|
+
sign_in @user
|
27
|
+
|
28
|
+
@user.can_read = true
|
29
|
+
get :new, :thread_id => @thread.id, :use_route => :commontator
|
30
|
+
assert_redirected_to @thread
|
31
|
+
assigns(:comment).errors.must_be_empty
|
32
|
+
|
33
|
+
@user.can_read = false
|
34
|
+
@user.can_edit = true
|
35
|
+
get :new, :thread_id => @thread.id, :use_route => :commontator
|
36
|
+
assert_redirected_to @thread
|
37
|
+
assigns(:comment).errors.must_be_empty
|
38
|
+
|
39
|
+
@user.can_edit = false
|
40
|
+
@user.is_admin = true
|
41
|
+
get :new, :thread_id => @thread.id, :use_route => :commontator
|
42
|
+
assert_redirected_to @thread
|
43
|
+
assigns(:comment).errors.must_be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "won't create unless authorized" do
|
47
|
+
attributes = Hash.new
|
48
|
+
attributes[:body] = 'Something else'
|
49
|
+
|
50
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
51
|
+
assert_response 403
|
52
|
+
|
53
|
+
sign_in @user
|
54
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
55
|
+
assert_response 403
|
56
|
+
|
57
|
+
@user.can_read = true
|
58
|
+
@user.can_edit = true
|
59
|
+
@user.is_admin = true
|
60
|
+
@thread.close.must_equal true
|
61
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
62
|
+
assert_response 403
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'must create if authorized' do
|
66
|
+
sign_in @user
|
67
|
+
attributes = Hash.new
|
68
|
+
|
69
|
+
attributes[:body] = 'Something else'
|
70
|
+
@user.can_read = true
|
71
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
72
|
+
assert_redirected_to @thread
|
73
|
+
assigns(:comment).errors.must_be_empty
|
74
|
+
assigns(:comment).body.must_equal 'Something else'
|
75
|
+
assigns(:comment).creator.must_equal @user
|
76
|
+
assigns(:comment).editor.must_be_nil
|
77
|
+
assigns(:comment).thread.must_equal @thread
|
78
|
+
|
79
|
+
attributes[:body] = 'Another thing'
|
80
|
+
@user.can_read = false
|
81
|
+
@user.can_edit = true
|
82
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
83
|
+
assert_redirected_to @thread
|
84
|
+
assigns(:comment).errors.must_be_empty
|
85
|
+
assigns(:comment).body.must_equal 'Another thing'
|
86
|
+
assigns(:comment).creator.must_equal @user
|
87
|
+
assigns(:comment).editor.must_be_nil
|
88
|
+
assigns(:comment).thread.must_equal @thread
|
89
|
+
|
90
|
+
attributes[:body] = 'And this too'
|
91
|
+
@user.can_edit = false
|
92
|
+
@user.is_admin = true
|
93
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
94
|
+
assert_redirected_to @thread
|
95
|
+
assigns(:comment).errors.must_be_empty
|
96
|
+
assigns(:comment).body.must_equal 'And this too'
|
97
|
+
assigns(:comment).creator.must_equal @user
|
98
|
+
assigns(:comment).editor.must_be_nil
|
99
|
+
assigns(:comment).thread.must_equal @thread
|
100
|
+
end
|
101
|
+
|
102
|
+
it "won't 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
|
+
|
127
|
+
it "won't edit unless authorized" do
|
128
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
129
|
+
assert_response 403
|
130
|
+
|
131
|
+
sign_in @user
|
132
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
133
|
+
assert_response 403
|
134
|
+
|
135
|
+
user2 = DummyUser.create
|
136
|
+
user2.can_read = true
|
137
|
+
user2.can_edit = true
|
138
|
+
user2.is_admin = true
|
139
|
+
sign_in user2
|
140
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
141
|
+
assert_response 403
|
142
|
+
|
143
|
+
@user.can_read = true
|
144
|
+
@user.can_edit = true
|
145
|
+
@user.is_admin = true
|
146
|
+
sign_in @user
|
147
|
+
comment2 = Comment.new
|
148
|
+
comment2.thread = @thread
|
149
|
+
comment2.creator = @user
|
150
|
+
comment2.body = 'Something else'
|
151
|
+
comment2.save!
|
152
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
153
|
+
assert_response 403
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'must edit if authorized' do
|
157
|
+
sign_in @user
|
158
|
+
|
159
|
+
@user.can_read = true
|
160
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
161
|
+
assert_redirected_to @thread
|
162
|
+
assigns(:comment).errors.must_be_empty
|
163
|
+
|
164
|
+
@user.can_read = false
|
165
|
+
@user.can_edit = true
|
166
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
167
|
+
assert_redirected_to @thread
|
168
|
+
assigns(:comment).errors.must_be_empty
|
169
|
+
|
170
|
+
@user.can_edit = false
|
171
|
+
@user.is_admin = true
|
172
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
173
|
+
assert_redirected_to @thread
|
174
|
+
assigns(:comment).errors.must_be_empty
|
175
|
+
end
|
176
|
+
|
177
|
+
it "won't update unless authorized" do
|
178
|
+
attributes = Hash.new
|
179
|
+
attributes[:body] = 'Something else'
|
180
|
+
|
181
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
182
|
+
assert_response 403
|
183
|
+
@comment.reload
|
184
|
+
@comment.body.must_equal 'Something'
|
185
|
+
@comment.editor.must_be_nil
|
186
|
+
|
187
|
+
sign_in @user
|
188
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
189
|
+
assert_response 403
|
190
|
+
@comment.reload
|
191
|
+
@comment.body.must_equal 'Something'
|
192
|
+
@comment.editor.must_be_nil
|
193
|
+
|
194
|
+
user2 = DummyUser.create
|
195
|
+
user2.can_read = true
|
196
|
+
user2.can_edit = true
|
197
|
+
user2.is_admin = true
|
198
|
+
sign_in user2
|
199
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
200
|
+
assert_response 403
|
201
|
+
@comment.reload
|
202
|
+
@comment.body.must_equal 'Something'
|
203
|
+
@comment.editor.must_be_nil
|
204
|
+
|
205
|
+
@user.can_read = true
|
206
|
+
@user.can_edit = true
|
207
|
+
@user.is_admin = true
|
208
|
+
sign_in @user
|
209
|
+
comment2 = Comment.new
|
210
|
+
comment2.thread = @thread
|
211
|
+
comment2.creator = @user
|
212
|
+
comment2.body = 'Something else'
|
213
|
+
comment2.save!
|
214
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
215
|
+
@comment.reload
|
216
|
+
@comment.body.must_equal 'Something'
|
217
|
+
@comment.editor.must_be_nil
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'must update if authorized' do
|
221
|
+
sign_in @user
|
222
|
+
attributes = Hash.new
|
223
|
+
attributes[:body] = 'Something else'
|
224
|
+
|
225
|
+
@user.can_read = true
|
226
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
227
|
+
assert_redirected_to @thread
|
228
|
+
assigns(:comment).errors.must_be_empty
|
229
|
+
assigns(:comment).editor.must_equal @user
|
230
|
+
|
231
|
+
@user.can_read = false
|
232
|
+
@user.can_edit = true
|
233
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
234
|
+
assert_redirected_to @thread
|
235
|
+
assigns(:comment).errors.must_be_empty
|
236
|
+
assigns(:comment).editor.must_equal @user
|
237
|
+
|
238
|
+
@user.can_edit = false
|
239
|
+
@user.is_admin = true
|
240
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
241
|
+
assert_redirected_to @thread
|
242
|
+
assigns(:comment).errors.must_be_empty
|
243
|
+
assigns(:comment).editor.must_equal @user
|
244
|
+
end
|
245
|
+
|
246
|
+
it "won't delete unless authorized and not deleted" do
|
247
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
248
|
+
assert_response 403
|
249
|
+
@comment.reload
|
250
|
+
@comment.is_deleted?.must_equal false
|
251
|
+
|
252
|
+
sign_in @user
|
253
|
+
|
254
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
255
|
+
assert_response 403
|
256
|
+
@comment.reload
|
257
|
+
@comment.is_deleted?.must_equal false
|
258
|
+
|
259
|
+
@user.can_read = true
|
260
|
+
@comment.delete_by(@user).must_equal true
|
261
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
262
|
+
assert_redirected_to @thread
|
263
|
+
assigns(:comment).errors.wont_be_empty
|
264
|
+
|
265
|
+
comment2 = Comment.new
|
266
|
+
comment2.thread = @thread
|
267
|
+
comment2.creator = @user
|
268
|
+
comment2.body = 'Something else'
|
269
|
+
comment2.save!
|
270
|
+
@comment.undelete_by(@user).must_equal true
|
271
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
272
|
+
assert_response 403
|
273
|
+
@comment.reload
|
274
|
+
@comment.is_deleted?.must_equal false
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'must delete if authorized and not deleted' do
|
278
|
+
sign_in @user
|
279
|
+
|
280
|
+
@user.can_read = true
|
281
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
282
|
+
assert_redirected_to @thread
|
283
|
+
assigns(:comment).errors.must_be_empty
|
284
|
+
assigns(:comment).is_deleted?.must_equal true
|
285
|
+
assigns(:comment).editor.must_equal @user
|
286
|
+
|
287
|
+
user2 = DummyUser.create
|
288
|
+
sign_in user2
|
289
|
+
comment2 = Comment.new
|
290
|
+
comment2.thread = @thread
|
291
|
+
comment2.creator = @user
|
292
|
+
comment2.body = 'Something else'
|
293
|
+
comment2.save!
|
294
|
+
|
295
|
+
assigns(:comment).undelete_by(@user).must_equal true
|
296
|
+
user2.can_edit = true
|
297
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
298
|
+
assert_redirected_to @thread
|
299
|
+
assigns(:comment).errors.must_be_empty
|
300
|
+
assigns(:comment).is_deleted?.must_equal true
|
301
|
+
assigns(:comment).editor.must_equal user2
|
302
|
+
|
303
|
+
assigns(:comment).undelete_by(@user).must_equal true
|
304
|
+
user2.can_edit = false
|
305
|
+
user2.is_admin = true
|
306
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
307
|
+
assert_redirected_to @thread
|
308
|
+
assigns(:comment).errors.must_be_empty
|
309
|
+
assigns(:comment).is_deleted?.must_equal true
|
310
|
+
assigns(:comment).editor.must_equal user2
|
311
|
+
end
|
312
|
+
|
313
|
+
it "won't undelete unless authorized and deleted" do
|
314
|
+
@comment.delete_by(@user).must_equal true
|
315
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
316
|
+
assert_response 403
|
317
|
+
@comment.reload
|
318
|
+
@comment.is_deleted?.must_equal true
|
319
|
+
|
320
|
+
sign_in @user
|
321
|
+
|
322
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
323
|
+
assert_response 403
|
324
|
+
@comment.reload
|
325
|
+
@comment.is_deleted?.must_equal true
|
326
|
+
|
327
|
+
@user.can_read = true
|
328
|
+
@comment.undelete_by(@user).must_equal true
|
329
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
330
|
+
assert_redirected_to @thread
|
331
|
+
assigns(:comment).errors.wont_be_empty
|
332
|
+
|
333
|
+
user2 = DummyUser.create
|
334
|
+
user2.can_read = true
|
335
|
+
user2.can_edit = true
|
336
|
+
user2.is_admin = true
|
337
|
+
@comment.delete_by(user2).must_equal true
|
338
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
339
|
+
assert_response 403
|
340
|
+
@comment.reload
|
341
|
+
@comment.is_deleted?.must_equal true
|
342
|
+
|
343
|
+
comment2 = Comment.new
|
344
|
+
comment2.thread = @thread
|
345
|
+
comment2.creator = @user
|
346
|
+
comment2.body = 'Something else'
|
347
|
+
comment2.save!
|
348
|
+
@comment.undelete_by(@user).must_equal true
|
349
|
+
@comment.delete_by(@user).must_equal true
|
350
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
351
|
+
assert_response 403
|
352
|
+
@comment.reload
|
353
|
+
@comment.is_deleted?.must_equal true
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'must undelete if authorized and deleted' do
|
357
|
+
sign_in @user
|
358
|
+
|
359
|
+
@comment.delete_by(@user).must_equal true
|
360
|
+
@user.can_read = true
|
361
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
362
|
+
assert_redirected_to @thread
|
363
|
+
assigns(:comment).errors.must_be_empty
|
364
|
+
assigns(:comment).is_deleted?.must_equal false
|
365
|
+
|
366
|
+
user2 = DummyUser.create
|
367
|
+
sign_in user2
|
368
|
+
comment2 = Comment.new
|
369
|
+
comment2.thread = @thread
|
370
|
+
comment2.creator = @user
|
371
|
+
comment2.body = 'Something else'
|
372
|
+
comment2.save!
|
373
|
+
|
374
|
+
assigns(:comment).delete_by(@user).must_equal true
|
375
|
+
user2.can_edit = true
|
376
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
377
|
+
assert_redirected_to @thread
|
378
|
+
assigns(:comment).errors.must_be_empty
|
379
|
+
assigns(:comment).is_deleted?.must_equal false
|
380
|
+
|
381
|
+
assigns(:comment).delete_by(@user).must_equal true
|
382
|
+
user2.can_edit = false
|
383
|
+
user2.is_admin = true
|
384
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
385
|
+
assert_redirected_to @thread
|
386
|
+
assigns(:comment).errors.must_be_empty
|
387
|
+
assigns(:comment).is_deleted?.must_equal false
|
388
|
+
end
|
389
|
+
|
390
|
+
it "won't upvote unless authorized" do
|
391
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
392
|
+
assert_response 403
|
393
|
+
@comment.reload
|
394
|
+
@comment.upvotes.must_be_empty
|
395
|
+
@comment.downvotes.must_be_empty
|
396
|
+
|
397
|
+
sign_in @user
|
398
|
+
@user.can_read = true
|
399
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
400
|
+
assert_response 403
|
401
|
+
@comment.reload
|
402
|
+
@comment.upvotes.must_be_empty
|
403
|
+
@comment.downvotes.must_be_empty
|
404
|
+
|
405
|
+
user2 = DummyUser.create
|
406
|
+
sign_in user2
|
407
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
408
|
+
assert_response 403
|
409
|
+
@comment.reload
|
410
|
+
@comment.upvotes.must_be_empty
|
411
|
+
@comment.downvotes.must_be_empty
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'must upvote if authorized' do
|
415
|
+
user2 = DummyUser.create
|
416
|
+
user2.can_read = true
|
417
|
+
sign_in user2
|
418
|
+
|
419
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
420
|
+
assert_redirected_to @thread
|
421
|
+
assigns(:comment).upvotes.count.must_equal 1
|
422
|
+
assigns(:comment).downvotes.must_be_empty
|
423
|
+
|
424
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
425
|
+
assert_redirected_to @thread
|
426
|
+
assigns(:comment).upvotes.count.must_equal 1
|
427
|
+
assigns(:comment).downvotes.must_be_empty
|
428
|
+
|
429
|
+
@comment.downvote_from(user2).must_equal true
|
430
|
+
|
431
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
432
|
+
assert_redirected_to @thread
|
433
|
+
assigns(:comment).upvotes.count.must_equal 1
|
434
|
+
assigns(:comment).downvotes.must_be_empty
|
435
|
+
end
|
436
|
+
|
437
|
+
it "won't downvote unless authorized" do
|
438
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
439
|
+
assert_response 403
|
440
|
+
@comment.reload
|
441
|
+
@comment.upvotes.must_be_empty
|
442
|
+
@comment.downvotes.must_be_empty
|
443
|
+
|
444
|
+
sign_in @user
|
445
|
+
@user.can_read = true
|
446
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
447
|
+
assert_response 403
|
448
|
+
@comment.reload
|
449
|
+
@comment.upvotes.must_be_empty
|
450
|
+
@comment.downvotes.must_be_empty
|
451
|
+
|
452
|
+
user2 = DummyUser.create
|
453
|
+
sign_in user2
|
454
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
455
|
+
assert_response 403
|
456
|
+
@comment.reload
|
457
|
+
@comment.upvotes.must_be_empty
|
458
|
+
@comment.downvotes.must_be_empty
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'must downvote if authorized' do
|
462
|
+
user2 = DummyUser.create
|
463
|
+
user2.can_read = true
|
464
|
+
sign_in user2
|
465
|
+
|
466
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
467
|
+
assert_redirected_to @thread
|
468
|
+
assigns(:comment).upvotes.must_be_empty
|
469
|
+
assigns(:comment).downvotes.count.must_equal 1
|
470
|
+
|
471
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
472
|
+
assert_redirected_to @thread
|
473
|
+
assigns(:comment).upvotes.must_be_empty
|
474
|
+
assigns(:comment).downvotes.count.must_equal 1
|
475
|
+
|
476
|
+
@comment.upvote_from(user2).must_equal true
|
477
|
+
|
478
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
479
|
+
assert_redirected_to @thread
|
480
|
+
assigns(:comment).upvotes.must_be_empty
|
481
|
+
assigns(:comment).downvotes.count.must_equal 1
|
482
|
+
end
|
483
|
+
|
484
|
+
it "won't unvote unless authorized" do
|
485
|
+
@comment.upvote_from(@user).must_equal true
|
486
|
+
|
487
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
488
|
+
assert_response 403
|
489
|
+
assigns(:comment).upvotes.count.must_equal 1
|
490
|
+
assigns(:comment).downvotes.must_be_empty
|
491
|
+
|
492
|
+
sign_in @user
|
493
|
+
@user.can_read = true
|
494
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
495
|
+
assert_response 403
|
496
|
+
assigns(:comment).upvotes.count.must_equal 1
|
497
|
+
assigns(:comment).downvotes.must_be_empty
|
498
|
+
|
499
|
+
user2 = DummyUser.create
|
500
|
+
sign_in user2
|
501
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
502
|
+
assert_response 403
|
503
|
+
@comment.reload
|
504
|
+
@comment.upvotes.count.must_equal 1
|
505
|
+
@comment.downvotes.must_be_empty
|
506
|
+
end
|
507
|
+
|
508
|
+
it 'must unvote if authorized' do
|
509
|
+
user2 = DummyUser.create
|
510
|
+
user2.can_read = true
|
511
|
+
sign_in user2
|
512
|
+
|
513
|
+
@comment.upvote_from(user2).must_equal true
|
514
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
515
|
+
assert_redirected_to @thread
|
516
|
+
assigns(:comment).upvotes.must_be_empty
|
517
|
+
assigns(:comment).downvotes.must_be_empty
|
518
|
+
|
519
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
520
|
+
assert_redirected_to @thread
|
521
|
+
assigns(:comment).upvotes.must_be_empty
|
522
|
+
assigns(:comment).downvotes.must_be_empty
|
523
|
+
|
524
|
+
@comment.downvote_from(user2).must_equal true
|
525
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
526
|
+
assert_redirected_to @thread
|
527
|
+
assigns(:comment).upvotes.must_be_empty
|
528
|
+
assigns(:comment).downvotes.must_be_empty
|
529
|
+
end
|
530
|
+
|
531
|
+
it "won't send mail if recipients empty" do
|
532
|
+
if defined?(CommentsController::SubscriptionsMailer)
|
533
|
+
CommentsController::SubscriptionsMailer.__send__(:initialize)
|
534
|
+
else
|
535
|
+
CommentsController::SubscriptionsMailer = MiniTest::Mock.new
|
536
|
+
end
|
537
|
+
|
538
|
+
user2 = DummyUser.create
|
539
|
+
user2.can_read = true
|
540
|
+
|
541
|
+
email = MiniTest::Mock.new.expect(:deliver, nil)
|
542
|
+
CommentsController::SubscriptionsMailer.expect(:comment_created, email, [Comment, [user2]])
|
543
|
+
|
544
|
+
@user.can_read = true
|
545
|
+
sign_in @user
|
546
|
+
|
547
|
+
attributes = {:body => 'Something else'}
|
548
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
549
|
+
assigns(:comment).errors.must_be_empty
|
550
|
+
|
551
|
+
proc { CommentsController::SubscriptionsMailer.verify }.must_raise(MockExpectationError)
|
552
|
+
proc { email.verify }.must_raise(MockExpectationError)
|
553
|
+
end
|
554
|
+
|
555
|
+
it 'must send mail if recipients not empty' do
|
556
|
+
if defined?(CommentsController::SubscriptionsMailer)
|
557
|
+
CommentsController::SubscriptionsMailer.__send__(:initialize)
|
558
|
+
else
|
559
|
+
CommentsController::SubscriptionsMailer = MiniTest::Mock.new
|
560
|
+
end
|
561
|
+
|
562
|
+
user2 = DummyUser.create
|
563
|
+
user2.can_read = true
|
564
|
+
@thread.subscribe(user2)
|
565
|
+
|
566
|
+
email = MiniTest::Mock.new.expect(:deliver, nil)
|
567
|
+
CommentsController::SubscriptionsMailer.expect(:comment_created, email, [Comment, [user2]])
|
568
|
+
|
569
|
+
@user.can_read = true
|
570
|
+
sign_in @user
|
571
|
+
|
572
|
+
attributes = {:body => 'Something else'}
|
573
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
574
|
+
assigns(:comment).errors.must_be_empty
|
575
|
+
|
576
|
+
CommentsController::SubscriptionsMailer.verify
|
577
|
+
email.verify
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|