Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Qpixel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Answers
Qpixel
Commits
38ed1d85
Commit
38ed1d85
authored
Dec 14, 2020
by
ArtOfCode-
Browse files
Options
Downloads
Patches
Plain Diff
Full close tests
parent
82c39205
Loading
Loading
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/controllers/posts_controller_test.rb
+62
-0
62 additions, 0 deletions
test/controllers/posts_controller_test.rb
with
62 additions
and
0 deletions
test/controllers/posts_controller_test.rb
+
62
−
0
View file @
38ed1d85
...
...
@@ -316,4 +316,66 @@ class PostsControllerTest < ActionController::TestCase
end
assert_equal
'success'
,
JSON
.
parse
(
response
.
body
)[
'status'
]
end
test
'close requires authentication'
do
post
:close
,
params:
{
id:
posts
(
:question_one
).
id
,
reason_id:
close_reasons
(
:not_good
).
id
}
assert_response
302
assert_redirected_to
new_user_session_path
end
test
'unprivileged user cannot close'
do
sign_in
users
(
:standard_user
)
before_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
post
:close
,
params:
{
id:
posts
(
:question_one
).
id
,
reason_id:
close_reasons
(
:not_good
).
id
}
after_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
assert_response
403
assert_not_nil
assigns
(
:post
)
assert_equal
before_history
,
after_history
,
'PostHistory event incorrectly created on closure'
assert_nothing_raised
do
JSON
.
parse
(
response
.
body
)
end
assert_equal
'failed'
,
JSON
.
parse
(
response
.
body
)[
'status'
]
end
test
'cannot close a closed post'
do
sign_in
users
(
:closer
)
before_history
=
PostHistory
.
where
(
post:
posts
(
:closed
)).
count
post
:close
,
params:
{
id:
posts
(
:closed
).
id
,
reason_id:
close_reasons
(
:not_good
).
id
}
after_history
=
PostHistory
.
where
(
post:
posts
(
:closed
)).
count
assert_response
400
assert_not_nil
assigns
(
:post
)
assert_equal
before_history
,
after_history
,
'PostHistory event incorrectly created on closure'
assert_nothing_raised
do
JSON
.
parse
(
response
.
body
)
end
assert_equal
'failed'
,
JSON
.
parse
(
response
.
body
)[
'status'
]
end
test
'close rejects nonexistent close reason'
do
sign_in
users
(
:closer
)
before_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
post
:close
,
params:
{
id:
posts
(
:question_one
).
id
,
reason_id:
-
999
}
after_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
assert_response
404
assert_not_nil
assigns
(
:post
)
assert_equal
before_history
,
after_history
,
'PostHistory event incorrectly created on closure'
assert_nothing_raised
do
JSON
.
parse
(
response
.
body
)
end
assert_equal
'failed'
,
JSON
.
parse
(
response
.
body
)[
'status'
]
end
test
'close ensures other post exists if reason requires it'
do
sign_in
users
(
:closer
)
before_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
post
:close
,
params:
{
id:
posts
(
:question_one
).
id
,
reason_id:
close_reasons
(
:duplicate
)
}
after_history
=
PostHistory
.
where
(
post:
posts
(
:question_one
)).
count
assert_response
400
assert_not_nil
assigns
(
:post
)
assert_equal
before_history
,
after_history
,
'PostHistory event incorrectly created on closure'
assert_nothing_raised
do
JSON
.
parse
(
response
.
body
)
end
assert_equal
'failed'
,
JSON
.
parse
(
response
.
body
)[
'status'
]
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment