proclaim 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/app/controllers/proclaim/application_controller.rb +34 -0
- data/app/controllers/proclaim/comments_controller.rb +46 -64
- data/app/controllers/proclaim/images_controller.rb +7 -48
- data/app/views/proclaim/comments/_form.html.erb +0 -2
- data/lib/proclaim/version.rb +1 -1
- data/test/controllers/proclaim/comments_controller_test.rb +1 -1
- data/test/controllers/proclaim/images_controller_test.rb +45 -2
- data/test/controllers/proclaim/posts_controller_test.rb +70 -0
- data/test/controllers/proclaim/subscriptions_controller_test.rb +6 -0
- data/test/integration/with_javascript/comment_test.rb +38 -0
- data/test/integration/with_javascript/post_form_test.rb +2 -2
- data/test/models/proclaim/subscription_test.rb +6 -0
- data/test/policies/application_policy_test.rb +87 -0
- data/test/proclaim_test.rb +3 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5010df73f9c56158e2848567ff36f237e84416b8
|
4
|
+
data.tar.gz: eb2c9683b06d54f40af0ca609af12c8f0794fae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830649b8fad5fc8c4206b1cc96b9ea6730d839a1c4a5638e1601c9327ecd947315d647b1b85ad10275d52e2a463fa4c704e16282c6b7045720247f177218e6b8
|
7
|
+
data.tar.gz: 9f55f501b0639edda86983c4bcef68531df58edd279cf13d5922977510f4cf989bed9991e3f17a4b64acb5146deccf6145ae49eea6f66a29ae113d494a6ea9ce
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.6
|
@@ -41,4 +41,38 @@ class Proclaim::ApplicationController < ApplicationController
|
|
41
41
|
def cache_name_from_url(url)
|
42
42
|
url.match(/[^\/]*?\/[^\/]*\z/)
|
43
43
|
end
|
44
|
+
|
45
|
+
def handleJsonRequest(object, options = {})
|
46
|
+
operation = options[:operation] || true
|
47
|
+
successJson = options[:success_json] || true
|
48
|
+
failureJson = options[:failure_json] || lambda {object.errors.full_messages}
|
49
|
+
unauthorizedStatus = options[:unauthorized_status] || :unauthorized
|
50
|
+
|
51
|
+
begin
|
52
|
+
authorize object
|
53
|
+
|
54
|
+
yield if block_given?
|
55
|
+
return if performed? # Don't continue if the block rendered
|
56
|
+
|
57
|
+
respond_to do |format|
|
58
|
+
if (operation == true) or (operation.respond_to?(:call) and operation.call)
|
59
|
+
if successJson.respond_to? :call
|
60
|
+
successJson = successJson.call
|
61
|
+
end
|
62
|
+
|
63
|
+
format.json { render json: successJson }
|
64
|
+
else
|
65
|
+
if failureJson.respond_to? :call
|
66
|
+
failureJson = failureJson.call
|
67
|
+
end
|
68
|
+
|
69
|
+
format.json { render json: failureJson, status: :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue Pundit::NotAuthorizedError
|
73
|
+
respond_to do |format|
|
74
|
+
format.json { render json: true, status: unauthorizedStatus }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
44
78
|
end
|
@@ -9,84 +9,66 @@ module Proclaim
|
|
9
9
|
def create
|
10
10
|
@comment = Comment.new(comment_params)
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if params and params[:subscribe]
|
19
|
-
subscription = Subscription.new(name: @comment.author,
|
20
|
-
email: params[:email],
|
21
|
-
post: @comment.post)
|
22
|
-
end
|
23
|
-
|
24
|
-
respond_to do |format|
|
25
|
-
begin
|
26
|
-
Comment.transaction do
|
27
|
-
@comment.save!
|
28
|
-
|
29
|
-
if subscription
|
30
|
-
subscription.save!
|
31
|
-
end
|
12
|
+
subscription = nil
|
13
|
+
if subscription_params and subscription_params[:subscribe]
|
14
|
+
subscription = Subscription.new(name: @comment.author,
|
15
|
+
email: subscription_params[:email],
|
16
|
+
post: @comment.post)
|
17
|
+
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
19
|
+
errors = Array.new
|
20
|
+
options = Hash.new
|
21
|
+
options[:success_json] = lambda {comment_json(@comment)}
|
22
|
+
options[:failure_json] = lambda {errors}
|
23
|
+
options[:operation] = lambda do
|
24
|
+
respond_to do |format|
|
25
|
+
begin
|
26
|
+
# Wrap saving the comment in a transaction, so if the
|
27
|
+
# subscription fails to save, the comment doesn't save either
|
28
|
+
# (and vice-versa).
|
29
|
+
Comment.transaction do
|
30
|
+
@comment.save!
|
38
31
|
|
39
32
|
if subscription
|
40
|
-
|
33
|
+
subscription.save!
|
41
34
|
end
|
42
35
|
|
43
|
-
|
36
|
+
return true
|
44
37
|
end
|
38
|
+
rescue ActiveRecord::RecordInvalid
|
39
|
+
errors += @comment.errors.full_messages
|
40
|
+
|
41
|
+
if subscription
|
42
|
+
errors += subscription.errors.full_messages
|
43
|
+
end
|
44
|
+
|
45
|
+
return false
|
45
46
|
end
|
46
|
-
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Don't leak that the post actually exists. Turn the "unauthorized"
|
51
|
+
# into a "not found"
|
52
|
+
options[:unauthorized_status] = :not_found
|
53
|
+
|
54
|
+
handleJsonRequest(@comment, options) do
|
55
|
+
if antispam_params[:answer] != antispam_params[:solution]
|
47
56
|
respond_to do |format|
|
48
57
|
format.json { render json: ["Antispam question wasn't answered correctly"], status: :unprocessable_entity }
|
49
58
|
end
|
50
59
|
end
|
51
|
-
rescue Pundit::NotAuthorizedError
|
52
|
-
respond_to do |format|
|
53
|
-
# Don't leak that the post actually exists. Turn the
|
54
|
-
# "unauthorized" into a "not found"
|
55
|
-
format.json { render json: true, status: :not_found }
|
56
|
-
end
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
63
|
def update
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
respond_to do |format|
|
65
|
-
if @comment.update(comment_params)
|
66
|
-
format.json { render_comment_json(@comment) }
|
67
|
-
else
|
68
|
-
format.json { render json: @comment.errors.full_messages, status: :unprocessable_entity }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
rescue Pundit::NotAuthorizedError
|
72
|
-
respond_to do |format|
|
73
|
-
format.json { render json: true, status: :unauthorized }
|
74
|
-
end
|
75
|
-
end
|
64
|
+
handleJsonRequest(@comment,
|
65
|
+
operation: lambda {@comment.update(comment_params)},
|
66
|
+
success_json: lambda {comment_json(@comment)})
|
76
67
|
end
|
77
68
|
|
78
69
|
def destroy
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
respond_to do |format|
|
83
|
-
@comment.destroy
|
84
|
-
format.json { render json: true, status: :ok }
|
85
|
-
end
|
86
|
-
rescue Pundit::NotAuthorizedError
|
87
|
-
respond_to do |format|
|
88
|
-
format.json { render json: true, status: :unauthorized }
|
89
|
-
end
|
70
|
+
handleJsonRequest(@comment) do
|
71
|
+
@comment.destroy
|
90
72
|
end
|
91
73
|
end
|
92
74
|
|
@@ -96,10 +78,10 @@ module Proclaim
|
|
96
78
|
@comment = Comment.find(params[:id])
|
97
79
|
end
|
98
80
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
81
|
+
def comment_json(comment)
|
82
|
+
return {
|
83
|
+
id: comment.id,
|
84
|
+
html: comment_to_html(comment)
|
103
85
|
}
|
104
86
|
end
|
105
87
|
|
@@ -7,40 +7,18 @@ module Proclaim
|
|
7
7
|
def create
|
8
8
|
@image = Image.new(post_id: image_params[:post_id])
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
handleJsonRequest(@image,
|
11
|
+
operation: lambda {@image.save},
|
12
|
+
success_json: lambda {@image.image.url}) do
|
13
13
|
@image.image = image_params[:image]
|
14
|
-
|
15
|
-
respond_to do |format|
|
16
|
-
if @image.save
|
17
|
-
format.json { render json: @image.image.url }
|
18
|
-
else
|
19
|
-
format.json { render json: @image.errors.full_messages, status: :unprocessable_entity }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
rescue Pundit::NotAuthorizedError
|
23
|
-
respond_to do |format|
|
24
|
-
format.json { render json: true, status: :unauthorized }
|
25
|
-
end
|
26
14
|
end
|
27
15
|
end
|
28
16
|
|
29
17
|
def cache
|
30
18
|
@image = Image.new
|
31
19
|
|
32
|
-
|
33
|
-
authorize @image
|
34
|
-
|
20
|
+
handleJsonRequest(@image, success_json: lambda {@image.image.url}) do
|
35
21
|
@image.image = file_params[:file]
|
36
|
-
|
37
|
-
respond_to do |format|
|
38
|
-
format.json { render json: @image.image.url }
|
39
|
-
end
|
40
|
-
rescue Pundit::NotAuthorizedError
|
41
|
-
respond_to do |format|
|
42
|
-
format.json { render json: true, status: :unauthorized }
|
43
|
-
end
|
44
22
|
end
|
45
23
|
end
|
46
24
|
|
@@ -59,37 +37,18 @@ module Proclaim
|
|
59
37
|
@image = Image.find(image_id)
|
60
38
|
end
|
61
39
|
|
62
|
-
|
63
|
-
authorize @image
|
64
|
-
|
40
|
+
handleJsonRequest(@image, success_json: {id: image_id}) do
|
65
41
|
if @image.new_record?
|
66
42
|
@image.image.remove!
|
67
43
|
end
|
68
|
-
|
69
|
-
respond_to do |format|
|
70
|
-
format.json { render json: {id: image_id}, status: :ok }
|
71
|
-
end
|
72
|
-
rescue Pundit::NotAuthorizedError
|
73
|
-
respond_to do |format|
|
74
|
-
format.json { render json: true, status: :unauthorized }
|
75
|
-
end
|
76
44
|
end
|
77
45
|
end
|
78
46
|
|
79
47
|
def destroy
|
80
48
|
@image = Image.find(params[:id])
|
81
49
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
respond_to do |format|
|
86
|
-
@image.destroy
|
87
|
-
format.json { render json: true, status: :ok }
|
88
|
-
end
|
89
|
-
rescue Pundit::NotAuthorizedError
|
90
|
-
respond_to do |format|
|
91
|
-
format.json { render json: true, status: :unauthorized }
|
92
|
-
end
|
50
|
+
handleJsonRequest(@image) do
|
51
|
+
@image.destroy
|
93
52
|
end
|
94
53
|
end
|
95
54
|
|
@@ -27,8 +27,6 @@
|
|
27
27
|
<%= f.label :body %><br />
|
28
28
|
<%= f.text_area :body, rows: 7, cols: 50 %><br />
|
29
29
|
|
30
|
-
|
31
|
-
|
32
30
|
<% if comment.new_record? %>
|
33
31
|
<%= label namespace_space+"antispam", "answer", "Spam bots can't do math. What is #{random_number_1} + #{random_number_2}?" %><br />
|
34
32
|
<%= text_field "antispam", "answer", id: namespace_space+"antispam_answer" %><br />
|
data/lib/proclaim/version.rb
CHANGED
@@ -88,7 +88,7 @@ module Proclaim
|
|
88
88
|
assert_update_comment newComment
|
89
89
|
end
|
90
90
|
|
91
|
-
test "should not root
|
91
|
+
test "should not update root comment if not logged in" do
|
92
92
|
newComment = FactoryGirl.create(:comment)
|
93
93
|
refute_update_comment newComment
|
94
94
|
end
|
@@ -45,6 +45,36 @@ module Proclaim
|
|
45
45
|
assert_response :unauthorized
|
46
46
|
end
|
47
47
|
|
48
|
+
test "should not create image without a post" do
|
49
|
+
user = FactoryGirl.create(:user)
|
50
|
+
sign_in user
|
51
|
+
|
52
|
+
image = FactoryGirl.build(:image, post: nil, image: nil)
|
53
|
+
|
54
|
+
assert_no_difference('Image.count') do
|
55
|
+
post :create, format: :json, image: {
|
56
|
+
image: Rack::Test::UploadedFile.new(File.join(Rails.root, '../', 'support', 'images', 'test.jpg'))
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_response :unprocessable_entity
|
61
|
+
end
|
62
|
+
|
63
|
+
test "should not create image without actual image" do
|
64
|
+
user = FactoryGirl.create(:user)
|
65
|
+
sign_in user
|
66
|
+
|
67
|
+
image = FactoryGirl.build(:image, image: nil)
|
68
|
+
|
69
|
+
assert_no_difference('Image.count') do
|
70
|
+
post :create, format: :json, image: {
|
71
|
+
post_id: image.post_id
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_response :unprocessable_entity
|
76
|
+
end
|
77
|
+
|
48
78
|
test "should cache image if logged in" do
|
49
79
|
user = FactoryGirl.create(:user)
|
50
80
|
sign_in user
|
@@ -93,7 +123,7 @@ module Proclaim
|
|
93
123
|
assert_response :unauthorized
|
94
124
|
end
|
95
125
|
|
96
|
-
test "should not destroy image if logged in but return ID" do
|
126
|
+
test "discard should not destroy image if logged in but return ID" do
|
97
127
|
user = FactoryGirl.create(:user)
|
98
128
|
sign_in user
|
99
129
|
|
@@ -110,11 +140,24 @@ module Proclaim
|
|
110
140
|
assert_equal image.id.to_s, json["id"]
|
111
141
|
end
|
112
142
|
|
143
|
+
test "should destroy image if logged in" do
|
144
|
+
user = FactoryGirl.create(:user)
|
145
|
+
sign_in user
|
146
|
+
|
147
|
+
image = FactoryGirl.create(:image)
|
148
|
+
|
149
|
+
assert_difference('Image.count', -1) do
|
150
|
+
delete :destroy, format: :json, id: image.id
|
151
|
+
end
|
152
|
+
|
153
|
+
assert_response :success
|
154
|
+
end
|
155
|
+
|
113
156
|
test "should not destroy image if not logged in" do
|
114
157
|
image = FactoryGirl.create(:image)
|
115
158
|
|
116
159
|
assert_no_difference('Image.count') do
|
117
|
-
|
160
|
+
delete :destroy, format: :json, id: image.id
|
118
161
|
end
|
119
162
|
|
120
163
|
assert_response :unauthorized
|
@@ -125,6 +125,44 @@ module Proclaim
|
|
125
125
|
assert assigns(:post).published?
|
126
126
|
end
|
127
127
|
|
128
|
+
test "should not create post without title" do
|
129
|
+
user = FactoryGirl.create(:user)
|
130
|
+
sign_in user
|
131
|
+
|
132
|
+
newPost = FactoryGirl.build(:post)
|
133
|
+
|
134
|
+
assert_no_difference('Post.count') do
|
135
|
+
post :create, post: {
|
136
|
+
author_id: newPost.author_id,
|
137
|
+
body: newPost.body
|
138
|
+
# Leave off title
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
assert assigns(:post).errors.any?,
|
143
|
+
"Expected an error due to lack of post title"
|
144
|
+
assert_template :new, "Expected new view to be rendered again"
|
145
|
+
end
|
146
|
+
|
147
|
+
test "should not create post without body" do
|
148
|
+
user = FactoryGirl.create(:user)
|
149
|
+
sign_in user
|
150
|
+
|
151
|
+
newPost = FactoryGirl.build(:post)
|
152
|
+
|
153
|
+
assert_no_difference('Post.count') do
|
154
|
+
post :create, post: {
|
155
|
+
author_id: newPost.author_id,
|
156
|
+
title: newPost.title
|
157
|
+
# Leave off body
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
assert assigns(:post).errors.any?,
|
162
|
+
"Expected an error due to lack of post body"
|
163
|
+
assert_template :new, "Expected new view to be rendered again"
|
164
|
+
end
|
165
|
+
|
128
166
|
test "should upload images when creating post" do
|
129
167
|
user = FactoryGirl.create(:user)
|
130
168
|
sign_in user
|
@@ -367,6 +405,38 @@ module Proclaim
|
|
367
405
|
assert_match /not authorized/, flash[:error]
|
368
406
|
end
|
369
407
|
|
408
|
+
test "should not update post without title" do
|
409
|
+
user = FactoryGirl.create(:user)
|
410
|
+
sign_in user
|
411
|
+
|
412
|
+
newPost = FactoryGirl.create(:post)
|
413
|
+
|
414
|
+
patch :update, id: newPost, post: {
|
415
|
+
author_id: newPost.author_id,
|
416
|
+
title: "" # Remove title
|
417
|
+
}
|
418
|
+
|
419
|
+
assert assigns(:post).errors.any?,
|
420
|
+
"Expected an error due to lack of post title"
|
421
|
+
assert_template :edit, "Expected edit view to be rendered again"
|
422
|
+
end
|
423
|
+
|
424
|
+
test "should not update post without body" do
|
425
|
+
user = FactoryGirl.create(:user)
|
426
|
+
sign_in user
|
427
|
+
|
428
|
+
newPost = FactoryGirl.create(:post)
|
429
|
+
|
430
|
+
patch :update, id: newPost, post: {
|
431
|
+
author_id: newPost.author_id,
|
432
|
+
body: "" # Remove body
|
433
|
+
}
|
434
|
+
|
435
|
+
assert assigns(:post).errors.any?,
|
436
|
+
"Expected an error due to lack of post body"
|
437
|
+
assert_template :edit, "Expected edit view to be rendered again"
|
438
|
+
end
|
439
|
+
|
370
440
|
test "should destroy post if logged in" do
|
371
441
|
user = FactoryGirl.create(:user)
|
372
442
|
sign_in user
|
@@ -48,6 +48,12 @@ module Proclaim
|
|
48
48
|
assert_equal subscription, assigns(:subscription)
|
49
49
|
end
|
50
50
|
|
51
|
+
test "show should return not found is token is invalid" do
|
52
|
+
assert_raises ActiveRecord::RecordNotFound do
|
53
|
+
get :show, token: 12345
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
51
57
|
test "should get new if logged in" do
|
52
58
|
user = FactoryGirl.create(:user)
|
53
59
|
sign_in user
|
@@ -240,6 +240,44 @@ class CommentTest < ActionDispatch::IntegrationTest
|
|
240
240
|
"The old child comment body should be gone!"
|
241
241
|
end
|
242
242
|
|
243
|
+
test "edit should show error without author" do
|
244
|
+
user = FactoryGirl.create(:user)
|
245
|
+
sign_in user
|
246
|
+
|
247
|
+
comment = FactoryGirl.create(:published_comment)
|
248
|
+
|
249
|
+
visit proclaim.post_path(comment.post)
|
250
|
+
|
251
|
+
@show_page.comment_edit_link(comment).click
|
252
|
+
|
253
|
+
within("#edit_comment_#{comment.id}") do
|
254
|
+
fill_in 'Author', with: "" # An empty author should result in an error
|
255
|
+
end
|
256
|
+
|
257
|
+
@show_page.edit_comment_submit_button(comment).click
|
258
|
+
|
259
|
+
assert page.has_css?('div.error')
|
260
|
+
end
|
261
|
+
|
262
|
+
test "edit should show error without body" do
|
263
|
+
user = FactoryGirl.create(:user)
|
264
|
+
sign_in user
|
265
|
+
|
266
|
+
comment = FactoryGirl.create(:published_comment)
|
267
|
+
|
268
|
+
visit proclaim.post_path(comment.post)
|
269
|
+
|
270
|
+
@show_page.comment_edit_link(comment).click
|
271
|
+
|
272
|
+
within("#edit_comment_#{comment.id}") do
|
273
|
+
fill_in 'Body', with: "" # An empty body should result in an error
|
274
|
+
end
|
275
|
+
|
276
|
+
@show_page.edit_comment_submit_button(comment).click
|
277
|
+
|
278
|
+
assert page.has_css?('div.error')
|
279
|
+
end
|
280
|
+
|
243
281
|
test "should not have option to delete if not logged in" do
|
244
282
|
comment = FactoryGirl.create(:published_comment)
|
245
283
|
|
@@ -181,7 +181,7 @@ class PostFormTest < ActionDispatch::IntegrationTest
|
|
181
181
|
assert page.has_no_text?(""quotes""), "Show page should not be showing HTML entities in title!"
|
182
182
|
end
|
183
183
|
|
184
|
-
test "should show error without title" do
|
184
|
+
test "new should show error without title" do
|
185
185
|
user = FactoryGirl.create(:user)
|
186
186
|
sign_in user
|
187
187
|
|
@@ -203,7 +203,7 @@ class PostFormTest < ActionDispatch::IntegrationTest
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
test "should show error without body" do
|
206
|
+
test "new should show error without body" do
|
207
207
|
user = FactoryGirl.create(:user)
|
208
208
|
sign_in user
|
209
209
|
|
@@ -53,6 +53,12 @@ module Proclaim
|
|
53
53
|
assert_equal subscription2, Subscription.from_token(token2)
|
54
54
|
end
|
55
55
|
|
56
|
+
test "an invalid token should raise a NotFound" do
|
57
|
+
assert_raises ActiveRecord::RecordNotFound do
|
58
|
+
Subscription.from_token("123456")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
test "should require valid post or none at all" do
|
57
63
|
# Post 12345 doesn't exist
|
58
64
|
subscription = FactoryGirl.build(:subscription, post_id: 12345)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ApplicationPolicyTest < ActiveSupport::TestCase
|
4
|
+
test "application index" do
|
5
|
+
user = FactoryGirl.create(:user)
|
6
|
+
|
7
|
+
# Verify that a user cannot visit the index by default
|
8
|
+
policy = ApplicationPolicy.new(user, nil)
|
9
|
+
refute policy.index?, "A user should be not able to visit the index by default"
|
10
|
+
|
11
|
+
# Verify that a guest cannot visit the index by default
|
12
|
+
policy = ApplicationPolicy.new(nil, nil)
|
13
|
+
refute policy.index?, "A guest should not be able to visit the index by default"
|
14
|
+
end
|
15
|
+
|
16
|
+
test "application show" do
|
17
|
+
user = FactoryGirl.create(:user)
|
18
|
+
|
19
|
+
# Verify that a user cannot view an object by default
|
20
|
+
policy = ApplicationPolicy.new(user, nil)
|
21
|
+
refute policy.show?, "A user should be not able to view an object by default"
|
22
|
+
|
23
|
+
# Verify that a guest cannot view an object by default
|
24
|
+
policy = ApplicationPolicy.new(nil, nil)
|
25
|
+
refute policy.show?, "A guest should not be able to view an object by default"
|
26
|
+
end
|
27
|
+
|
28
|
+
test "application create" do
|
29
|
+
user = FactoryGirl.create(:user)
|
30
|
+
|
31
|
+
# Verify that a user cannot create an object by default
|
32
|
+
policy = ApplicationPolicy.new(user, nil)
|
33
|
+
refute policy.create?, "A user should be not able to create an object by default"
|
34
|
+
|
35
|
+
# Verify that a guest cannot create an object by default
|
36
|
+
policy = ApplicationPolicy.new(nil, nil)
|
37
|
+
refute policy.create?, "A guest should not be able to create an object by default"
|
38
|
+
end
|
39
|
+
|
40
|
+
test "application new" do
|
41
|
+
user = FactoryGirl.create(:user)
|
42
|
+
|
43
|
+
# Verify that a user cannot visit the new action by default
|
44
|
+
policy = ApplicationPolicy.new(user, nil)
|
45
|
+
refute policy.new?, "A user should be not able to visit the new action by default"
|
46
|
+
|
47
|
+
# Verify that a guest cannot visit the new action by default
|
48
|
+
policy = ApplicationPolicy.new(nil, nil)
|
49
|
+
refute policy.new?, "A guest should not be able to visit the new action by default"
|
50
|
+
end
|
51
|
+
|
52
|
+
test "application update" do
|
53
|
+
user = FactoryGirl.create(:user)
|
54
|
+
|
55
|
+
# Verify that a user cannot update an object by default
|
56
|
+
policy = ApplicationPolicy.new(user, nil)
|
57
|
+
refute policy.update?, "A user should be not able to update an object by default"
|
58
|
+
|
59
|
+
# Verify that a guest cannot update an object by default
|
60
|
+
policy = ApplicationPolicy.new(nil, nil)
|
61
|
+
refute policy.update?, "A guest should not be able to update an object by default"
|
62
|
+
end
|
63
|
+
|
64
|
+
test "application edit" do
|
65
|
+
user = FactoryGirl.create(:user)
|
66
|
+
|
67
|
+
# Verify that a user cannot visit the edit action by default
|
68
|
+
policy = ApplicationPolicy.new(user, nil)
|
69
|
+
refute policy.edit?, "A user should be not able to visit the edit action by default"
|
70
|
+
|
71
|
+
# Verify that a guest cannot visit the edit action by default
|
72
|
+
policy = ApplicationPolicy.new(nil, nil)
|
73
|
+
refute policy.edit?, "A guest should not be able to visit the edit action by default"
|
74
|
+
end
|
75
|
+
|
76
|
+
test "application destroy" do
|
77
|
+
user = FactoryGirl.create(:user)
|
78
|
+
|
79
|
+
# Verify that a user cannot destroy an object by default
|
80
|
+
policy = ApplicationPolicy.new(user, nil)
|
81
|
+
refute policy.destroy?, "A user should be not able to destroy an object by default"
|
82
|
+
|
83
|
+
# Verify that a guest cannot destroy an object by default
|
84
|
+
policy = ApplicationPolicy.new(nil, nil)
|
85
|
+
refute policy.destroy?, "A guest should not be able to destroy an object by default"
|
86
|
+
end
|
87
|
+
end
|
data/test/proclaim_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proclaim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Fazzari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -505,6 +505,7 @@ files:
|
|
505
505
|
- test/models/proclaim/image_test.rb
|
506
506
|
- test/models/proclaim/post_test.rb
|
507
507
|
- test/models/proclaim/subscription_test.rb
|
508
|
+
- test/policies/application_policy_test.rb
|
508
509
|
- test/policies/proclaim/comment_policy_test.rb
|
509
510
|
- test/policies/proclaim/image_policy_test.rb
|
510
511
|
- test/policies/proclaim/post_policy_test.rb
|
@@ -601,6 +602,7 @@ test_files:
|
|
601
602
|
- test/dummy/config/initializers/cookies_serializer.rb
|
602
603
|
- test/dummy/config/initializers/inflections.rb
|
603
604
|
- test/dummy/README.rdoc
|
605
|
+
- test/policies/application_policy_test.rb
|
604
606
|
- test/policies/proclaim/subscription_policy_test.rb
|
605
607
|
- test/policies/proclaim/post_policy_test.rb
|
606
608
|
- test/policies/proclaim/image_policy_test.rb
|