Skip to content

Commit

Permalink
elastcisearch検索のテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
suusan2go committed Feb 14, 2016
1 parent f2e2c0b commit cc36fac
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/models/poem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@
it { is_expected.to eq @poem_previous }
end
end

describe '.search' do
let!(:nasu_poem) { create(:poem, title: '那須', description: 'がんばれよ!') }
let!(:suzuki_poem) { create(:poem, title: '鈴木さん', description: 'やったぜ!') }
let!(:iwaki_poem) { create(:poem, title: '岩木山', description: 'がんばれよ!那須さん') }
before { sleep 1 } # elasticsearchにindexが反映されるのを少し待つ

it 'キーワードに応じた検索結果が得られること' do
aggregate_failures do
expect(Poem.search(keywords: '那須').records.to_a).to include nasu_poem
expect(Poem.search(keywords: 'がんばれ').records.to_a).to include nasu_poem, iwaki_poem
expect(Poem.search(keywords: 'やったぜ').records.to_a).to include suzuki_poem
expect(Poem.search(keywords: 'hoge').records.to_a).to eq []
end
end
end
end

0 comments on commit cc36fac

Please sign in to comment.