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
c1146887
Commit
c1146887
authored
Aug 3, 2023
by
Taico Aerts
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for post validations
parent
06740227
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!51
Upgrade to latest qpixel
,
!50
Update to latest codidact changes
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/system/post_test.rb
+74
-2
74 additions, 2 deletions
test/system/post_test.rb
with
74 additions
and
2 deletions
test/system/post_test.rb
+
74
−
2
View file @
c1146887
...
...
@@ -12,7 +12,7 @@ class PostTest < ApplicationSystemTestCase
assert_current_path
new_user_session_url
end
test
'Signed in user can create a
post
'
do
test
'Signed in user can create a
question
'
do
category
=
categories
(
:meta
)
log_in
:standard_user
visit
category_path
(
category
)
...
...
@@ -29,7 +29,79 @@ class PostTest < ApplicationSystemTestCase
end
end
# TODO: Post validations
test
'Creating a question is blocked when body is too short'
do
category
=
categories
(
:meta
)
log_in
:standard_user
visit
category_path
(
category
)
click_on
'Create Post'
fill_in
'Summarize your post with a title:'
,
with:
'Initial title is of sufficient length'
post_form_select_tag
tags
(
:faq
).
name
fill_in
'Body'
,
with:
'Short'
# Check that the button is disabled
find_button
"Save Post in
#{
category
.
name
}
"
,
disabled:
true
# After filling out body correctly, verify that the button becomes enabled
fill_in
'Body'
,
with:
'This body should pass the minimum length requirements for questions in the meta category.'
find_button
"Save Post in
#{
category
.
name
}
"
,
disabled:
false
end
test
'Creating a question is blocked when title is too short'
do
category
=
categories
(
:meta
)
log_in
:standard_user
visit
category_path
(
category
)
click_on
'Create Post'
fill_in
'Body'
,
with:
'This body should pass the minimum length requirements for questions in the meta category.'
post_form_select_tag
tags
(
:faq
).
name
fill_in
'Summarize your post with a title:'
,
with:
'Too short'
# Check that the button is disabled
find_button
"Save Post in
#{
category
.
name
}
"
,
disabled:
true
# After filling out the title, verify that the button becomes enabled
fill_in
'Summarize your post with a title:'
,
with:
'Updated title is of sufficient length'
find_button
"Save Post in
#{
category
.
name
}
"
,
disabled:
false
end
test
'Signed in user gets to pick post type for post creation in categories with multiple types'
do
category
=
categories
(
:main
)
log_in
:standard_user
visit
category_path
(
category
)
click_on
'Create Post'
# All the top level post types set should be present
category
.
post_types
.
where
(
is_top_level:
true
).
each
do
|
pt
|
assert_link
pt
.
name
.
underscore
.
humanize
end
# Pick a non-question post type
post_type
=
category
.
post_types
.
where
(
is_top_level:
true
).
where
.
not
(
name:
'Question'
).
first
# After clicking on a post type, we should be on the creation page of the correct category and post type.
click_on
post_type
.
name
.
underscore
.
humanize
assert_current_path
new_category_post_url
(
post_type
.
id
,
category
.
id
)
end
test
'Signed in user can answer question'
do
log_in
:standard_user
post
=
posts
(
:question_two
)
visit
post_path
(
post
)
# Answer the question
answer_text
=
'You can do this by running the rails system tests, rails test:system.'
fill_in
'Body'
,
with:
answer_text
assert_difference
'Post.count'
do
click_on
"Save Post in
#{
post
.
category
.
name
}
"
end
# We should now be looking at our answer, look for the text on the page
assert_text
answer_text
# The original post should also still be on the page
assert_text
post
.
body
end
# -------------------------------------------------------
# Show
...
...
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