forked from sunspot/sunspot
/
highlighting_spec.rb
32 lines (27 loc) · 1.4 KB
/
highlighting_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require File.join(File.dirname(__FILE__), 'spec_helper')
require 'pp'
describe 'attachment keyword highlighting' do
before :all do
test_docs = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'test_docs'))
@posts = []
@posts << RichTextPost.new(:rich_attachment => File.join(test_docs, 'TestPDF.pdf'))
@posts << RichTextPost.new(:rich_attachment => File.join(test_docs, 'JustAnotherTest.pdf'), :title => "This is the title")
Sunspot.index!(*@posts)
@search_result = Sunspot.search(RichTextPost) { keywords 'lorem', :highlight => true }
end
it 'should include highlights in the results' do
@search_result.hits.first.highlights.length.should == 1
end
it 'should return formatted highlight fragments' do
@search_result.hits.first.highlights(:rich_attachment).should_not be_empty
@search_result.hits.first.highlights(:rich_attachment).first.format.should == "This is a test \nPDF file. <em>Lorem</em> ipsum dolor sit amet, consectetur adipiscing elit"
end
it 'should be empty for non-keyword searches' do
search_result = Sunspot.search(RichTextPost){ with :title, "This is the title" }
search_result.hits.first.highlights.should be_empty
end
it 'should return multple hits for multiple occurances' do
pp @search_result.hits.first.highlights(:rich_attachment)
@search_result.hits.first.highlights(:rich_attachment).length.should > 1
end
end