spec/api/query/highlighting_spec.rb in benjaminkrause-sunspot-0.9.7 vs spec/api/query/highlighting_spec.rb in benjaminkrause-sunspot-0.9.8

- old
+ new

@@ -13,20 +13,68 @@ keywords 'test', :highlight => true end connection.should have_last_search_with(:hl => 'on') end + it 'should enable highlighting on multiple fields when highlighting requested as array of fields via keywords argument' do + session.search(Post) do + keywords 'test', :highlight => [:title, :body] + end + + connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts)) + end + + it 'should raise UnrecognizedFieldError if try to highlight unexisting field via keywords argument' do + lambda { + session.search(Post) do + keywords 'test', :highlight => [:unknown_field] + end + }.should raise_error(Sunspot::UnrecognizedFieldError) + end + + it 'should enable highlighting on multiple fields when highlighting requested as list of fields via block call' do + session.search(Post) do + keywords 'test' do + highlight :title, :body + end + end + + connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts)) + end + + it 'should raise UnrecognizedFieldError if try to highlight unexisting field via block call' do + lambda { + session.search(Post) do + keywords 'test' do + highlight :unknown_field + end + end + }.should raise_error(Sunspot::UnrecognizedFieldError) + end + it 'should set internal formatting' do session.search(Post) do keywords 'test', :highlight => true end connection.should have_last_search_with( :"hl.simple.pre" => '@@@hl@@@', :"hl.simple.post" => '@@@endhl@@@' ) end + it 'should set options and hihglight fields' do + session.search(Post) do + keywords 'test' do + highlight :title, :max_snippets => 3 + end + end + connection.should have_last_search_with( + :"hl.fl" => %w(title_text), + :"hl.snippets" => 3 + ) + end + it 'should set maximum highlights per field' do session.search(Post) do keywords 'test' do highlight :max_snippets => 3 end @@ -77,6 +125,7 @@ end connection.should have_last_search_with( :"hl.requireFieldMatch" => 'true' ) end + end