Skip to content

Commit

Permalink
Blacklight.default_index should respect the Blacklight adapter config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
cbeer committed Sep 25, 2015
1 parent 6abc7e9 commit f969b63
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,31 @@ def self.add_routes(router, options = {})
Blacklight::Routes.new(router, options).draw
end

##
# The default index connection for the search index
def self.default_index
@default_index ||= Blacklight::SolrRepository.new(Blacklight::Configuration.new)
@default_index ||= repository_class.new(default_configuration)
end

##
# The configured repository class. By convention, this is
# the class Blacklight::{name of the adapter}::Repository, e.g.
# elastic_search => Blacklight::ElasticSearch::Repository
def self.repository_class
case connection_config[:adapter]
when 'solr'
Blacklight::SolrRepository
when /::/
connection_config[:adapter].constantize
else
Blacklight.const_get("#{connection_config[:adapter]}/Repository".classify)
end
end

##
# The default Blacklight configuration.
def self.default_configuration
Blacklight::Configuration.new
end

def self.connection_config
Expand Down
52 changes: 52 additions & 0 deletions spec/lib/blacklight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,57 @@
end

end

describe '.default_index' do
context 'for a solr index' do
before do
allow(Blacklight).to receive(:connection_config).and_return(adapter: 'solr')
end

it 'is an instance of Blacklight::SolrRepository' do
expect(Blacklight.default_index).to be_a Blacklight::SolrRepository
end
end
end

describe '.repository_class' do
context 'for a solr index' do
before do
allow(Blacklight).to receive(:connection_config).and_return(adapter: 'solr')
end

it 'resolves to the SolrRepository implementation' do
expect(Blacklight.repository_class).to eq Blacklight::SolrRepository
end
end

context 'for an elastic_search index' do
before do
stub_const("Blacklight::ElasticSearch::Repository", double)
allow(Blacklight).to receive(:connection_config).and_return(adapter: 'elastic_search')
end

it 'resolves to the SolrRepository implementation' do
expect(Blacklight.repository_class).to eq Blacklight::ElasticSearch::Repository
end
end

context 'for an explicitly provided class' do
before do
stub_const("CustomSearch::Repository", double)
allow(Blacklight).to receive(:connection_config).and_return(adapter: 'CustomSearch::Repository')
end

it 'resolves to the custom implementation' do
expect(Blacklight.repository_class).to eq CustomSearch::Repository
end
end
end

describe '.default_configuration' do
it 'is a Blacklight configuration' do
expect(Blacklight.default_configuration).to be_a Blacklight::Configuration
end
end

end

0 comments on commit f969b63

Please sign in to comment.