Skip to content

Commit

Permalink
Fetch the adapter from the config
Browse files Browse the repository at this point in the history
`nil` is not a valid option for `:adapter`
  • Loading branch information
jcoyne committed Jan 19, 2016
1 parent b38f916 commit 1e462ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def self.repository_class
when /::/
connection_config[:adapter].constantize
else
Blacklight.const_get("#{connection_config[:adapter]}/Repository".classify)
raise "The value for :adapter was not found in the blacklight.yml config" unless connection_config.key? :adapter
Blacklight.const_get("#{connection_config.fetch(:adapter)}/Repository".classify)
end
end

Expand Down
13 changes: 10 additions & 3 deletions spec/lib/blacklight_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
require 'spec_helper'

describe Blacklight do

context 'root' do

let(:blroot) { File.expand_path(File.join(__FILE__, '..', '..', '..' )) }

it 'should return the full path to the BL plugin' do
expect(Blacklight.root).to eq blroot
end

end

describe '.default_index' do
Expand All @@ -25,6 +22,16 @@
end

describe '.repository_class' do
context 'when the adapter key is missing' do
before do
allow(Blacklight).to receive(:connection_config).and_return({})
end

it 'raises an error' do
expect { Blacklight.repository_class }.to raise_error RuntimeError, 'The value for :adapter was not found in the blacklight.yml config'
end
end

context 'for a solr index' do
before do
allow(Blacklight).to receive(:connection_config).and_return(adapter: 'solr')
Expand Down

0 comments on commit 1e462ff

Please sign in to comment.