commontator 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/commontator/version.rb +1 -1
- data/lib/commontator/version.rb~ +1 -1
- data/spec/app/controllers/comments_controller_spec.rb~ +7 -0
- data/spec/app/controllers/commontator/application_controller_spec.rb~ +30 -0
- data/spec/app/controllers/commontator/comments_controller_spec.rb +473 -0
- data/spec/app/controllers/commontator/comments_controller_spec.rb~ +473 -0
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +99 -0
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb~ +99 -0
- data/spec/app/controllers/commontator/threads_controller_spec.rb +121 -0
- data/spec/app/controllers/commontator/threads_controller_spec.rb~ +121 -0
- data/spec/app/controllers/threads_controller_spec.rb~ +12 -0
- data/spec/app/helpers/commontator/application_helper_spec.rb +7 -0
- data/spec/app/helpers/commontator/application_helper_spec.rb~ +7 -0
- data/spec/app/helpers/commontator/threads_helper_spec.rb +17 -0
- data/spec/app/helpers/commontator/threads_helper_spec.rb~ +17 -0
- data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb +38 -0
- data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb~ +37 -0
- data/spec/app/models/commontator/comment_spec.rb +60 -0
- data/spec/app/models/commontator/comment_spec.rb~ +60 -0
- data/spec/app/models/commontator/subscription_spec.rb +28 -0
- data/spec/app/models/commontator/subscription_spec.rb~ +28 -0
- data/spec/app/models/commontator/thread_spec.rb +130 -0
- data/spec/app/models/commontator/thread_spec.rb~ +130 -0
- data/spec/dummy/Gemfile~ +3 -0
- data/spec/dummy/README.md +3 -0
- data/spec/dummy/README.md~ +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/application_controller.rb~ +7 -0
- data/spec/dummy/app/controllers/dummies_controller.rb~ +17 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb +29 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb~ +29 -0
- data/spec/dummy/app/helpers/application_helper.rb +15 -0
- data/spec/dummy/app/helpers/application_helper.rb~ +15 -0
- data/spec/dummy/app/models/dummy.rb~ +3 -0
- data/spec/dummy/app/models/dummy_model.rb +3 -0
- data/spec/dummy/app/models/dummy_user.rb +9 -0
- data/spec/dummy/app/models/dummy_user.rb~ +9 -0
- data/spec/dummy/app/models/user.rb~ +5 -0
- data/spec/dummy/app/views/dummy_model/show.html.erb +1 -0
- data/spec/dummy/app/views/dummy_model/show.html.erb~ +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/application.rb~ +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/commontator.rb +158 -0
- data/spec/dummy/config/initializers/commontator.rb~ +157 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/config/routes.rb~ +7 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/0_create_dummies.rb~ +48 -0
- data/spec/dummy/db/migrate/0_create_dummy_models.rb +7 -0
- data/spec/dummy/db/migrate/0_create_dummy_models.rb~ +7 -0
- data/spec/dummy/db/migrate/1_create_dummy_users.rb +7 -0
- data/spec/dummy/db/migrate/1_create_dummy_users.rb~ +7 -0
- data/spec/dummy/db/migrate/1_create_users.rb~ +7 -0
- data/spec/dummy/db/migrate/2_install_commontator.rb +49 -0
- data/spec/dummy/db/migrate/2_install_commontator.rb~ +49 -0
- data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +20 -0
- data/spec/dummy/db/schema.rb +84 -0
- data/spec/dummy/db/schema.rb~ +71 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +14298 -0
- data/spec/dummy/log/test.log +149321 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/CCB/1D0/sprockets%2F02d4b791eb831cf2057bf4703a1218d1 +0 -0
- data/spec/dummy/tmp/cache/assets/CD1/510/sprockets%2Fc69ee3cc5796188d873574179290a6ef +0 -0
- data/spec/dummy/tmp/cache/assets/D01/8B0/sprockets%2F0f196a1a50363b0a076ec6e1ee5417f6 +0 -0
- data/spec/dummy/tmp/cache/assets/D06/2F0/sprockets%2Fe1f674c11941d62aac1764ef3a7134e4 +0 -0
- data/spec/dummy/tmp/cache/assets/D54/060/sprockets%2Fe85565206c3e5fdf9dfeb367c85557b1 +0 -0
- data/spec/dummy/tmp/cache/assets/D9B/550/sprockets%2Fa41c8be5379abec3c0d0d98e2f0d5609 +0 -0
- data/spec/dummy/tmp/cache/assets/E01/2E0/sprockets%2Fa3fb9025f90ff05a6fd4afc7ded2692c +0 -0
- data/spec/lib/commontator/acts_as_commontable_spec.rb +26 -0
- data/spec/lib/commontator/acts_as_commontable_spec.rb~ +26 -0
- data/spec/lib/commontator/acts_as_commontator_spec.rb +25 -0
- data/spec/lib/commontator/acts_as_commontator_spec.rb~ +25 -0
- data/spec/lib/commontator/commontable_config_spec.rb +26 -0
- data/spec/lib/commontator/commontable_config_spec.rb~ +26 -0
- data/spec/lib/commontator/commontator_config_spec.rb +26 -0
- data/spec/lib/commontator/commontator_config_spec.rb~ +26 -0
- data/spec/lib/commontator/controller_includes_spec.rb +15 -0
- data/spec/lib/commontator/controller_includes_spec.rb~ +15 -0
- data/spec/lib/commontator/shared_helper_spec.rb +12 -0
- data/spec/lib/commontator/shared_helper_spec.rb~ +12 -0
- data/spec/lib/commontator_spec.rb +23 -0
- data/spec/lib/commontator_spec.rb~ +23 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/spec_helper.rb~ +30 -0
- metadata +212 -2
data/lib/commontator/version.rb
CHANGED
data/lib/commontator/version.rb~
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commontator::ApplicationController do
|
4
|
+
before do
|
5
|
+
|
6
|
+
@controller = Commontator::ApplicationController.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'must get user' do
|
10
|
+
@controller.send :get_user
|
11
|
+
@user.must_be_nil
|
12
|
+
|
13
|
+
user = DummyUser.create
|
14
|
+
sign_in user
|
15
|
+
@controller.send :get_user
|
16
|
+
@user.must_equal user
|
17
|
+
@user.is_commontator.must_equal true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'must get thread' do
|
21
|
+
@controller.send :get_thread
|
22
|
+
@thread.must_be_instance_of Commontator::Thread
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'must get commontable url' do
|
26
|
+
@controller.send :get_thread
|
27
|
+
@controller.send :get_commontable_url
|
28
|
+
@commontable_url.must_equal 'a'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,473 @@
|
|
1
|
+
require 'spec_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 'wont 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 'wont create unless authorized' do
|
47
|
+
attributes = Hash.new
|
48
|
+
attributes[:body] = 'Something'
|
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
|
+
attributes[:body] = 'Something'
|
69
|
+
|
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'
|
75
|
+
assigns(:comment).creator.must_equal @user
|
76
|
+
assigns(:comment).thread.must_equal @thread
|
77
|
+
|
78
|
+
@user.can_read = false
|
79
|
+
@user.can_edit = true
|
80
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
81
|
+
assert_redirected_to @thread
|
82
|
+
assigns(:comment).errors.must_be_empty
|
83
|
+
assigns(:comment).body.must_equal 'Something'
|
84
|
+
assigns(:comment).creator.must_equal @user
|
85
|
+
assigns(:comment).thread.must_equal @thread
|
86
|
+
|
87
|
+
@user.can_edit = false
|
88
|
+
@user.is_admin = true
|
89
|
+
post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
|
90
|
+
assert_redirected_to @thread
|
91
|
+
assigns(:comment).errors.must_be_empty
|
92
|
+
assigns(:comment).body.must_equal 'Something'
|
93
|
+
assigns(:comment).creator.must_equal @user
|
94
|
+
assigns(:comment).thread.must_equal @thread
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'wont edit unless authorized' do
|
98
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
99
|
+
assert_response 403
|
100
|
+
|
101
|
+
sign_in @user
|
102
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
103
|
+
assert_response 403
|
104
|
+
|
105
|
+
user2 = DummyUser.create
|
106
|
+
user2.can_read = true
|
107
|
+
user2.can_edit = true
|
108
|
+
user2.is_admin = true
|
109
|
+
sign_in user2
|
110
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
111
|
+
assert_response 403
|
112
|
+
|
113
|
+
@user.can_read = true
|
114
|
+
@user.can_edit = true
|
115
|
+
@user.is_admin = true
|
116
|
+
sign_in @user
|
117
|
+
comment2 = Comment.new
|
118
|
+
comment2.thread = @thread
|
119
|
+
comment2.creator = @user
|
120
|
+
comment2.body = 'Something else'
|
121
|
+
comment2.save!
|
122
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
123
|
+
assert_response 403
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'must edit if authorized' do
|
127
|
+
sign_in @user
|
128
|
+
|
129
|
+
@user.can_read = true
|
130
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
131
|
+
assert_redirected_to @thread
|
132
|
+
assigns(:comment).errors.must_be_empty
|
133
|
+
|
134
|
+
@user.can_read = false
|
135
|
+
@user.can_edit = true
|
136
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
137
|
+
assert_redirected_to @thread
|
138
|
+
assigns(:comment).errors.must_be_empty
|
139
|
+
|
140
|
+
@user.can_edit = false
|
141
|
+
@user.is_admin = true
|
142
|
+
get :edit, :id => @comment.id, :use_route => :commontator
|
143
|
+
assert_redirected_to @thread
|
144
|
+
assigns(:comment).errors.must_be_empty
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'wont update unless authorized' do
|
148
|
+
attributes = Hash.new
|
149
|
+
attributes[:body] = 'Something else'
|
150
|
+
|
151
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
152
|
+
assert_response 403
|
153
|
+
assigns(:comment).body.must_equal 'Something'
|
154
|
+
|
155
|
+
sign_in @user
|
156
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
157
|
+
assert_response 403
|
158
|
+
assigns(:comment).body.must_equal 'Something'
|
159
|
+
|
160
|
+
user2 = DummyUser.create
|
161
|
+
user2.can_read = true
|
162
|
+
user2.can_edit = true
|
163
|
+
user2.is_admin = true
|
164
|
+
sign_in user2
|
165
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
166
|
+
assert_response 403
|
167
|
+
assigns(:comment).body.must_equal 'Something'
|
168
|
+
|
169
|
+
@user.can_read = true
|
170
|
+
@user.can_edit = true
|
171
|
+
@user.is_admin = true
|
172
|
+
sign_in @user
|
173
|
+
comment2 = Comment.new
|
174
|
+
comment2.thread = @thread
|
175
|
+
comment2.creator = @user
|
176
|
+
comment2.body = 'Something else'
|
177
|
+
comment2.save!
|
178
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
179
|
+
assert_response 403
|
180
|
+
assigns(:comment).body.must_equal 'Something'
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'must update if authorized' do
|
184
|
+
sign_in @user
|
185
|
+
attributes = Hash.new
|
186
|
+
attributes[:body] = 'Something else'
|
187
|
+
|
188
|
+
@user.can_read = true
|
189
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
190
|
+
assert_redirected_to @thread
|
191
|
+
assigns(:comment).errors.must_be_empty
|
192
|
+
|
193
|
+
@user.can_read = false
|
194
|
+
@user.can_edit = true
|
195
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
196
|
+
assert_redirected_to @thread
|
197
|
+
assigns(:comment).errors.must_be_empty
|
198
|
+
|
199
|
+
@user.can_edit = false
|
200
|
+
@user.is_admin = true
|
201
|
+
put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
|
202
|
+
assert_redirected_to @thread
|
203
|
+
assigns(:comment).errors.must_be_empty
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'wont delete unless authorized and not deleted' do
|
207
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
208
|
+
assert_response 403
|
209
|
+
assigns(:comment).is_deleted?.must_equal false
|
210
|
+
|
211
|
+
sign_in @user
|
212
|
+
|
213
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
214
|
+
assert_response 403
|
215
|
+
assigns(:comment).is_deleted?.must_equal false
|
216
|
+
|
217
|
+
@user.can_read = true
|
218
|
+
@comment.delete(@user).must_equal true
|
219
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
220
|
+
assert_redirected_to @thread
|
221
|
+
assigns(:comment).errors.wont_be_empty
|
222
|
+
|
223
|
+
comment2 = Comment.new
|
224
|
+
comment2.thread = @thread
|
225
|
+
comment2.creator = @user
|
226
|
+
comment2.body = 'Something else'
|
227
|
+
comment2.save!
|
228
|
+
@comment.undelete.must_equal true
|
229
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
230
|
+
assert_response 403
|
231
|
+
assigns(:comment).is_deleted?.must_equal false
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'must delete if authorized and not deleted' do
|
235
|
+
sign_in @user
|
236
|
+
|
237
|
+
@user.can_read = true
|
238
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
239
|
+
assert_redirected_to @thread
|
240
|
+
assigns(:comment).errors.must_be_empty
|
241
|
+
assigns(:comment).is_deleted?.must_equal true
|
242
|
+
assigns(:comment).deleter.must_equal @user
|
243
|
+
|
244
|
+
user2 = DummyUser.create
|
245
|
+
sign_in user2
|
246
|
+
comment2 = Comment.new
|
247
|
+
comment2.thread = @thread
|
248
|
+
comment2.creator = @user
|
249
|
+
comment2.body = 'Something else'
|
250
|
+
comment2.save!
|
251
|
+
|
252
|
+
assigns(:comment).undelete.must_equal true
|
253
|
+
user2.can_edit = true
|
254
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
255
|
+
assert_redirected_to @thread
|
256
|
+
assigns(:comment).errors.must_be_empty
|
257
|
+
assigns(:comment).is_deleted?.must_equal true
|
258
|
+
assigns(:comment).deleter.must_equal user2
|
259
|
+
|
260
|
+
assigns(:comment).undelete.must_equal true
|
261
|
+
user2.can_edit = false
|
262
|
+
user2.is_admin = true
|
263
|
+
put :delete, :id => @comment.id, :use_route => :commontator
|
264
|
+
assert_redirected_to @thread
|
265
|
+
assigns(:comment).errors.must_be_empty
|
266
|
+
assigns(:comment).is_deleted?.must_equal true
|
267
|
+
assigns(:comment).deleter.must_equal user2
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'wont undelete unless authorized and deleted' do
|
271
|
+
@comment.delete(@user).must_equal true
|
272
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
273
|
+
assert_response 403
|
274
|
+
assigns(:comment).is_deleted?.must_equal true
|
275
|
+
|
276
|
+
sign_in @user
|
277
|
+
|
278
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
279
|
+
assert_response 403
|
280
|
+
assigns(:comment).is_deleted?.must_equal true
|
281
|
+
|
282
|
+
@user.can_read = true
|
283
|
+
@comment.undelete.must_equal true
|
284
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
285
|
+
assert_redirected_to @thread
|
286
|
+
assigns(:comment).errors.wont_be_empty
|
287
|
+
|
288
|
+
@comment.delete.must_equal true
|
289
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
290
|
+
assert_response 403
|
291
|
+
assigns(:comment).is_deleted?.must_equal true
|
292
|
+
|
293
|
+
comment2 = Comment.new
|
294
|
+
comment2.thread = @thread
|
295
|
+
comment2.creator = @user
|
296
|
+
comment2.body = 'Something else'
|
297
|
+
comment2.save!
|
298
|
+
@comment.undelete.must_equal true
|
299
|
+
@comment.delete(@user).must_equal true
|
300
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
301
|
+
assert_response 403
|
302
|
+
assigns(:comment).is_deleted?.must_equal true
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'must undelete if authorized and deleted' do
|
306
|
+
sign_in @user
|
307
|
+
|
308
|
+
@comment.delete(@user).must_equal true
|
309
|
+
@user.can_read = true
|
310
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
311
|
+
assert_redirected_to @thread
|
312
|
+
assigns(:comment).errors.must_be_empty
|
313
|
+
assigns(:comment).is_deleted?.must_equal false
|
314
|
+
|
315
|
+
user2 = DummyUser.create
|
316
|
+
sign_in user2
|
317
|
+
comment2 = Comment.new
|
318
|
+
comment2.thread = @thread
|
319
|
+
comment2.creator = @user
|
320
|
+
comment2.body = 'Something else'
|
321
|
+
comment2.save!
|
322
|
+
|
323
|
+
assigns(:comment).delete(@user).must_equal true
|
324
|
+
user2.can_edit = true
|
325
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
326
|
+
assert_redirected_to @thread
|
327
|
+
assigns(:comment).errors.must_be_empty
|
328
|
+
assigns(:comment).is_deleted?.must_equal false
|
329
|
+
|
330
|
+
assigns(:comment).delete(@user).must_equal true
|
331
|
+
user2.can_edit = false
|
332
|
+
user2.is_admin = true
|
333
|
+
put :undelete, :id => @comment.id, :use_route => :commontator
|
334
|
+
assert_redirected_to @thread
|
335
|
+
assigns(:comment).errors.must_be_empty
|
336
|
+
assigns(:comment).is_deleted?.must_equal false
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'wont upvote if not authorized' do
|
340
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
341
|
+
assert_response 403
|
342
|
+
assigns(:comment).upvotes.must_be_empty
|
343
|
+
assigns(:comment).downvotes.must_be_empty
|
344
|
+
|
345
|
+
sign_in @user
|
346
|
+
@user.can_read = true
|
347
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
348
|
+
assert_response 403
|
349
|
+
assigns(:comment).upvotes.must_be_empty
|
350
|
+
assigns(:comment).downvotes.must_be_empty
|
351
|
+
|
352
|
+
user2 = DummyUser.create
|
353
|
+
sign_in user2
|
354
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
355
|
+
assert_response 403
|
356
|
+
assigns(:comment).upvotes.must_be_empty
|
357
|
+
assigns(:comment).downvotes.must_be_empty
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'must upvote if authorized' do
|
361
|
+
user2 = DummyUser.create
|
362
|
+
user2.can_read = true
|
363
|
+
sign_in user2
|
364
|
+
|
365
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
366
|
+
assert_redirected_to @thread
|
367
|
+
assigns(:comment).upvotes.count.must_equal 1
|
368
|
+
assigns(:comment).downvotes.must_be_empty
|
369
|
+
|
370
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
371
|
+
assert_redirected_to @thread
|
372
|
+
assigns(:comment).upvotes.count.must_equal 1
|
373
|
+
assigns(:comment).downvotes.must_be_empty
|
374
|
+
|
375
|
+
@comment.downvote_from(user2).must_equal true
|
376
|
+
|
377
|
+
put :upvote, :id => @comment.id, :use_route => :commontator
|
378
|
+
assert_redirected_to @thread
|
379
|
+
assigns(:comment).upvotes.count.must_equal 1
|
380
|
+
assigns(:comment).downvotes.must_be_empty
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'wont downvote if not authorized' do
|
384
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
385
|
+
assert_response 403
|
386
|
+
assigns(:comment).upvotes.must_be_empty
|
387
|
+
assigns(:comment).downvotes.must_be_empty
|
388
|
+
|
389
|
+
sign_in @user
|
390
|
+
@user.can_read = true
|
391
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
392
|
+
assert_response 403
|
393
|
+
assigns(:comment).upvotes.must_be_empty
|
394
|
+
assigns(:comment).downvotes.must_be_empty
|
395
|
+
|
396
|
+
user2 = DummyUser.create
|
397
|
+
sign_in user2
|
398
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
399
|
+
assert_response 403
|
400
|
+
assigns(:comment).upvotes.must_be_empty
|
401
|
+
assigns(:comment).downvotes.must_be_empty
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'must downvote if authorized' do
|
405
|
+
user2 = DummyUser.create
|
406
|
+
user2.can_read = true
|
407
|
+
sign_in user2
|
408
|
+
|
409
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
410
|
+
assert_redirected_to @thread
|
411
|
+
assigns(:comment).upvotes.must_be_empty
|
412
|
+
assigns(:comment).downvotes.count.must_equal 1
|
413
|
+
|
414
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
415
|
+
assert_redirected_to @thread
|
416
|
+
assigns(:comment).upvotes.must_be_empty
|
417
|
+
assigns(:comment).downvotes.count.must_equal 1
|
418
|
+
|
419
|
+
@comment.upvote_from(user2).must_equal true
|
420
|
+
|
421
|
+
put :downvote, :id => @comment.id, :use_route => :commontator
|
422
|
+
assert_redirected_to @thread
|
423
|
+
assigns(:comment).upvotes.must_be_empty
|
424
|
+
assigns(:comment).downvotes.count.must_equal 1
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'wont unvote if not authorized' do
|
428
|
+
@comment.upvote_from(@user).must_equal true
|
429
|
+
|
430
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
431
|
+
assert_response 403
|
432
|
+
assigns(:comment).upvotes.count.must_equal 1
|
433
|
+
assigns(:comment).downvotes.must_be_empty
|
434
|
+
|
435
|
+
sign_in @user
|
436
|
+
@user.can_read = true
|
437
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
438
|
+
assert_response 403
|
439
|
+
assigns(:comment).upvotes.count.must_equal 1
|
440
|
+
assigns(:comment).downvotes.must_be_empty
|
441
|
+
|
442
|
+
user2 = DummyUser.create
|
443
|
+
sign_in user2
|
444
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
445
|
+
assert_response 403
|
446
|
+
assigns(:comment).upvotes.count.must_equal 1
|
447
|
+
assigns(:comment).downvotes.must_be_empty
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'must unvote if authorized' do
|
451
|
+
user2 = DummyUser.create
|
452
|
+
user2.can_read = true
|
453
|
+
sign_in user2
|
454
|
+
|
455
|
+
@comment.upvote_from(user2).must_equal true
|
456
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
457
|
+
assert_redirected_to @thread
|
458
|
+
assigns(:comment).upvotes.must_be_empty
|
459
|
+
assigns(:comment).downvotes.must_be_empty
|
460
|
+
|
461
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
462
|
+
assert_redirected_to @thread
|
463
|
+
assigns(:comment).upvotes.must_be_empty
|
464
|
+
assigns(:comment).downvotes.must_be_empty
|
465
|
+
|
466
|
+
@comment.downvote_from(user2).must_equal true
|
467
|
+
put :unvote, :id => @comment.id, :use_route => :commontator
|
468
|
+
assert_redirected_to @thread
|
469
|
+
assigns(:comment).upvotes.must_be_empty
|
470
|
+
assigns(:comment).downvotes.must_be_empty
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|