Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIPの質問は未解決一覧には含めず、全ての質問一覧にだけ含める #4604

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index
elsif params[:all].present?
Question.all
else
Question.not_solved
Question.not_solved.not_wip
end
questions = params[:practice_id].present? ? questions.where(practice_id: params[:practice_id]) : questions
questions = params[:user_id].present? ? Question.where(user_id: params[:user_id]) : questions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/practices/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
if params[:solved].present?
@practice.questions.solved
elsif params[:not_solved].present?
@practice.questions.not_solved
@practice.questions.not_solved.not_wip
else
@practice.questions
end
Expand Down
11 changes: 11 additions & 0 deletions test/system/practice/questions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ class Practice::QuestionsTest < ApplicationSystemTestCase
visit_with_auth "/practices/#{practices(:practice1).id}/questions", 'hatsuno'
assert_equal 'OS X Mountain Lionをクリーンインストールする | FJORD BOOT CAMP(フィヨルドブートキャンプ)', title
end

test 'show a WIP question on the all questions list ' do
visit_with_auth "/practices/#{practices(:practice1).id}/questions", 'hatsuno'
assert_text 'wipテスト用の質問(wip中)'
end

test 'not show a WIP question on the unsolved questions list ' do
visit_with_auth "/practices/#{practices(:practice1).id}/questions?not_solved=true", 'hatsuno'
assert_no_text 'wipテスト用の質問(wip中)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何かがないことをテストする際は、そのページ特有のものがあることを一緒にアサーションしたほうがよいかなと思いました。

参考 : システムスペックやフィーチャスペックで「〜が表示されないこと」だけを検証するのはちょっと危険、という話 - Qiita

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます!こちら、「未解決」のラベルがアクティブになっていることの検証も追加してみました。

assert_selector('a.tab-nav__item-link.is-active', text: '未解決')
end
end
10 changes: 8 additions & 2 deletions test/system/questions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,21 @@ class QuestionsTest < ApplicationSystemTestCase
assert_selector '.thread-header-title__label.is-wip', text: 'WIP'
end

test 'show a WIP question on the Q&A list page' do
visit_with_auth questions_path, 'kimura'
test 'show a WIP question on the All Q&A list page' do
visit_with_auth questions_path(all: 'true'), 'kimura'
assert_text 'wipテスト用の質問(wip中)'
element = all('.thread-list-item').find { |component| component.has_text?('wipテスト用の質問(wip中)') }
within element do
assert_selector '.thread-list-item-title__icon.is-wip', text: 'WIP'
end
end

test 'not show a WIP question on the unsolved Q&A list page' do
visit_with_auth questions_path, 'kimura'
assert_no_text 'wipテスト用の質問(wip中)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何かがないことをテストする際は、そのページ特有のものがあることを一緒にアサーションしたほうがよいかなと思いました。

同じです!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちら、「未解決の質問一覧」の文言が表示されていることの検証も追加してみました。

assert_text '未解決の質問一覧'
end

test "visit user profile page when clicked on user's name on question" do
visit_with_auth questions_path, 'kimura'
assert_text '質問のタブの作り方'
Expand Down