Skip to content
Merged
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
160 changes: 96 additions & 64 deletions spec/models/blacklight/solr/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
require 'rspec-benchmark'

RSpec.describe Blacklight::Solr::Response, :api do
let(:raw_response) { eval(mock_query_response) }

let(:config) { Blacklight::Configuration.new }

let(:r) do
subject(:r) do
described_class.new(raw_response,
raw_response['params'],
request_params,
blacklight_config: config)
end

let(:raw_response) { eval(mock_query_response) }

let(:config) { Blacklight::Configuration.new }
let(:request_params) { raw_response['params'] }

it 'creates a valid response' do
expect(r).to respond_to(:header)
end
Expand Down Expand Up @@ -134,113 +135,144 @@
expect(facet.name).to eq 'cat'
end

it 'provides the responseHeader params' do
raw_response = eval(mock_query_response)
raw_response['responseHeader']['params']['test'] = :test
r = described_class.new(raw_response, raw_response['params'])
expect(r.params['test']).to eq :test
context 'with responseHeader params' do
let(:raw_response) do
eval(mock_query_response).tap do |resp|
resp['responseHeader']['params']['test'] = :test
end
end

it 'provides the responseHeader params' do
expect(r.params['test']).to eq :test
end
end

it 'extracts json params' do
raw_response = eval(mock_query_response)
raw_response['responseHeader']['params']['test'] = 'from query'
raw_response['responseHeader']['params'].delete('rows')
raw_response['responseHeader']['params']['json'] = { limit: 5, params: { test: 'from json params' } }.to_json
r = described_class.new(raw_response, raw_response['params'])
expect(r.params['test']).to eq 'from query'
expect(r.rows).to eq 5
context 'with json params' do
let(:raw_response) do
eval(mock_response_with_spellcheck).tap do |resp|
resp['responseHeader']['params']['test'] = 'from query'
resp['responseHeader']['params'].delete('rows')
resp['responseHeader']['params']['json'] = { limit: 5, params: { test: 'from json params' } }.to_json
end
end

it 'extracts json params' do
expect(r.params['test']).to eq 'from query'
expect(r.rows).to eq 5
end
end

it 'provides the solr-returned params and "rows" should be 11' do
raw_response = eval(mock_query_response)
r = described_class.new(raw_response, {})
expect(r.params[:rows].to_s).to eq '11'
expect(r.params[:sort]).to eq 'title_si asc, pub_date_si desc'
end

it 'provides the ruby request params if responseHeader["params"] does not exist' do
raw_response = eval(mock_query_response)
raw_response.delete 'responseHeader'
r = described_class.new(raw_response, rows: 999, sort: 'score desc, pub_date_si desc, title_si asc')
expect(r.params[:rows].to_s).to eq '999'
expect(r.params[:sort]).to eq 'score desc, pub_date_si desc, title_si asc'
context 'when responseHeader["params"] does not exist' do
before do
raw_response.delete 'responseHeader'
end

let(:request_params) { { rows: 999, sort: 'score desc, pub_date_si desc, title_si asc' } }

it 'provides the ruby request params' do
expect(r.params[:rows].to_s).to eq '999'
expect(r.params[:sort]).to eq 'score desc, pub_date_si desc, title_si asc'
end
end

it 'provides spelling suggestions for regular spellcheck results' do
raw_response = eval(mock_response_with_spellcheck)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
context 'with regular spellcheck results' do
let(:raw_response) { eval(mock_response_with_spellcheck) }
let(:request_params) { {} }

it 'provides spelling suggestions' do
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end
end

it 'provides spelling suggestions for extended spellcheck results' do
raw_response = eval(mock_response_with_spellcheck_extended)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
context 'with extended spellcheck results' do
let(:raw_response) { eval(mock_response_with_spellcheck_extended) }
let(:request_params) { {} }

it 'provides spelling suggestions' do
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end
end

it 'provides no spelling suggestions when extended results and suggestion frequency is the same as original query frequency' do
raw_response = eval(mock_response_with_spellcheck_same_frequency)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to eq []
context 'when extended results and suggestion frequency is the same as original query frequency' do
let(:raw_response) { eval(mock_response_with_spellcheck_same_frequency) }
let(:request_params) { {} }

it 'provides no spelling suggestions' do
expect(r.spelling.words).to eq []
end
end

context "pre solr 5 spellcheck collation syntax" do
context "with pre solr 5 spellcheck collation syntax" do
let(:raw_response) { eval(mock_response_with_spellcheck_collation) }
let(:request_params) { {} }

it 'provides spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end

it 'provides spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = described_class.new(raw_response, {})
expect(r.spelling.collation).to eq 'dell ultrasharp'
end
end

context "solr 5 spellcheck collation syntax" do
context "with solr 5 spellcheck collation syntax" do
let(:raw_response) { eval(mock_response_with_spellcheck_collation_solr5) }
let(:request_params) { {} }

it 'provides spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation_solr5)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end

it 'provides spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation_solr5)
r = described_class.new(raw_response, {})
expect(r.spelling.collation).to eq 'dell ultrasharp'
end
end

context 'solr 6.5 spellcheck collation syntax' do
context 'with solr 6.5 spellcheck collation syntax' do
let(:raw_response) { eval(mock_response_with_spellcheck_collation_solr65) }
let(:request_params) { {} }

it 'provides spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation_solr65)
r = described_class.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end
end

it "provides MoreLikeThis suggestions" do
raw_response = eval(mock_response_with_more_like_this)
r = described_class.new(raw_response, {})
expect(r.more_like(double(id: '79930185'))).to have(2).items
context 'with moreLikeThis suggstions' do
let(:raw_response) { eval(mock_response_with_more_like_this) }
let(:request_params) { {} }

it "provides MoreLikeThis suggestions" do
expect(r.more_like(double(id: '79930185'))).to have(2).items
end
end

it "is empty when the response has no results" do
r = described_class.new({}, {})
allow(r).to receive_messages(total: 0)
expect(r).to be_empty
context 'with no results' do
let(:raw_response) { {} }
let(:request_params) { {} }

it "is empty when the response has no results" do
expect(r).to be_empty
end
end

describe "#export_formats" do
it "collects the unique export formats for the current response" do
r = described_class.new({}, {})
before do
# rubocop:disable RSpec/SubjectStub
allow(r).to receive_messages(documents: [double(export_formats: { a: 1, b: 2 }), double(export_formats: { b: 1, c: 2 })])
# rubocop:enable RSpec/SubjectStub
end

it "collects the unique export formats for the current response" do
expect(r.export_formats).to include :a, :b
end
end
Expand Down