Skip to content

Commit

Permalink
複数キーワードでの検索のテストを追加
Browse files Browse the repository at this point in the history
refs #1510

### 概要
検索可能なリソースごとに半角・全角スペース区切りで複数キーワード検索をした際に検索結果が絞り込めているかどうかを観点としてテストを追加

### 修正内容
#### 複数キーワードでの検索のテストを追加
全ての検索可能なリソースに対して3つのケースでの検証を行っている

- 単一キーワードで検索した場合
  - 絞り込み前の比較対象
- 半角スペース区切りの複数キーワードで検索した場合
  - AND検索 になっているかどうか(想定通り絞り込まれているかどうか)
- 全角スペース区切りの複数キーワードで検索した場合
  - AND検索 になっているかどうか(想定通り絞り込まれているかどうか)

### その他の修正
- test/fixtures/pages.yml で typo があり、 expected を書く際にややこしかったため正しいスペルに修正
  - Bootcmap => Bootcamp
  • Loading branch information
sanfrecce-osaka committed Apr 11, 2020
1 parent bb0b39a commit 39df4a5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/fixtures/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ page_3:
body: "## 存在しないDocsページ遷移テスト\n[存在しないページ](http://localhost:3000/pages/5555555)"

page_4:
title: Bootcmapの作業のページ
title: Bootcampの作業のページ
body: "## テスト\nテスト"
98 changes: 98 additions & 0 deletions test/models/searcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,102 @@ class SearchableTest < ActiveSupport::TestCase
assert_equal [reports(:report_12), reports(:report_14), reports(:report_13)], result
assert_not_includes(result, Answer)
end

test "returns only reports having all keywords" do
result = Searcher.search("日報", document_type: :reports)
assert_includes(result, reports(:report_9))
assert_includes(result, reports(:report_8))

result = Searcher.search("日報 WIP", document_type: :reports)
assert_includes(result, reports(:report_9))
assert_not_includes(result, reports(:report_8))

result = Searcher.search("日報 WIP", document_type: :reports)
assert_includes(result, reports(:report_9))
assert_not_includes(result, reports(:report_8))
end

test "returns only pages having all keywords" do
result = Searcher.search("テスト", document_type: :pages)
assert_includes(result, pages(:page_4))
assert_includes(result, pages(:page_3))

result = Searcher.search("テスト Bootcamp", document_type: :pages)
assert_includes(result, pages(:page_4))
assert_not_includes(result, pages(:page_3))

result = Searcher.search("テスト Bootcamp", document_type: :pages)
assert_includes(result, pages(:page_4))
assert_not_includes(result, pages(:page_3))
end

test "returns only practices having all keywords" do
result = Searcher.search("OS", document_type: :practices)
assert_includes(result, practices(:practice_1))
assert_includes(result, practices(:practice_3))

result = Searcher.search("OS クリーンインストール", document_type: :practices)
assert_includes(result, practices(:practice_1))
assert_not_includes(result, practices(:practice_3))

result = Searcher.search("OS クリーンインストール", document_type: :practices)
assert_includes(result, practices(:practice_1))
assert_not_includes(result, practices(:practice_3))
end

test "returns only questions having all keywords" do
result = Searcher.search("使う", document_type: :questions)
assert_includes(result, questions(:question_2))
assert_includes(result, questions(:question_1))

result = Searcher.search("使う エディター", document_type: :questions)
assert_includes(result, questions(:question_1))
assert_not_includes(result, questions(:question_2))

result = Searcher.search("使う エディター", document_type: :questions)
assert_includes(result, questions(:question_1))
assert_not_includes(result, questions(:question_2))
end

test "returns only answers of questions having all keywords" do
result = Searcher.search("です", document_type: :questions)
assert_includes(result, answers(:answer_1))
assert_includes(result, answers(:answer_5))

result = Searcher.search("です atom", document_type: :questions)
assert_includes(result, answers(:answer_1))
assert_not_includes(result, answers(:answer_5))

result = Searcher.search("です atom", document_type: :questions)
assert_includes(result, answers(:answer_1))
assert_not_includes(result, answers(:answer_5))
end

test "returns only announcements having all keywords" do
result = Searcher.search("お知らせ", document_type: :announcements)
assert_includes(result, announcements(:announcement_3))
assert_includes(result, announcements(:announcement_notification_active_user))

result = Searcher.search("お知らせ 通知", document_type: :announcements)
assert_includes(result, announcements(:announcement_notification_active_user))
assert_not_includes(result, announcements(:announcement_3))

result = Searcher.search("お知らせ 通知", document_type: :announcements)
assert_includes(result, announcements(:announcement_notification_active_user))
assert_not_includes(result, announcements(:announcement_3))
end

test "returns only comments having all keywords" do
result = Searcher.search("report_id", document_type: :reports)
assert_includes(result, comments(:comment_6))
assert_includes(result, comments(:comment_5))

result = Searcher.search("report_id typo", document_type: :reports)
assert_includes(result, comments(:comment_6))
assert_not_includes(result, comments(:comment_5))

result = Searcher.search("report_id typo", document_type: :reports)
assert_includes(result, comments(:comment_6))
assert_not_includes(result, comments(:comment_5))
end
end

0 comments on commit 39df4a5

Please sign in to comment.