Skip to content

Commit

Permalink
Allow browse_everything_providers.yml to contain symbols
Browse files Browse the repository at this point in the history
Co-authored-by: Brendan Quinn <brendan-quinn@northwestern.edu>
  • Loading branch information
mbklein and bmquinn committed Aug 2, 2018
1 parent 9fc3093 commit 3f075f1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/browse_everything.rb
Expand Up @@ -53,7 +53,7 @@ def configure(value)
elsif value.is_a?(String)
config_file_content = File.read(value)
config_file_template = ERB.new(config_file_content)
config_values = YAML.safe_load(config_file_template.result)
config_values = YAML.safe_load(config_file_template.result, [Symbol])
@config = ActiveSupport::HashWithIndifferentAccess.new config_values
@config.deep_symbolize_keys
else
Expand Down
96 changes: 56 additions & 40 deletions spec/lib/browse_everything_spec.rb
@@ -1,60 +1,76 @@
# frozen_string_literal: true

describe BrowseEverything do
describe '.configure' do
let(:config) do
{
dropbox: {
app_key: 'test-key',
app_secret: 'test-secret'
},
box: {
client_id: 'test-id',
client_secret: 'test-secret'
},
google_drive: {
client_id: 'test-id',
client_secret: 'test-secret'
}
}
end

before do
described_class.configure(config)
end

it 'registers the configuration for the drivers' do
expect(described_class.config).to be_a ActiveSupport::HashWithIndifferentAccess
shared_examples "a configured BrowseEverything module" do
describe 'registered configuration' do
it 'registers the configuration for the drivers' do
expect(described_class.config).to be_a ActiveSupport::HashWithIndifferentAccess

expect(described_class.config).to include 'dropbox'
expect(described_class.config['dropbox']).to include('app_key' => 'test-key')
expect(described_class.config['dropbox']).to include('app_secret' => 'test-secret')
expect(described_class.config).to include 'dropbox'
expect(described_class.config['dropbox']).to include('app_key' => 'test-key')
expect(described_class.config['dropbox']).to include('app_secret' => 'test-secret')

expect(described_class.config).to include 'box'
expect(described_class.config['box']).to include('client_id' => 'test-id')
expect(described_class.config['box']).to include('client_secret' => 'test-secret')
expect(described_class.config).to include 'box'
expect(described_class.config['box']).to include('client_id' => 'test-id')
expect(described_class.config['box']).to include('client_secret' => 'test-secret')

expect(described_class.config).to include 'google_drive'
expect(described_class.config['google_drive']).to include('client_id' => 'test-id')
expect(described_class.config['google_drive']).to include('client_secret' => 'test-secret')
expect(described_class.config).to include 'google_drive'
expect(described_class.config['google_drive']).to include('client_id' => 'test-id')
expect(described_class.config['google_drive']).to include('client_secret' => 'test-secret')
end
end
end

context 'with an entry for the drop_box provider' do
describe '.configure' do
context 'with a hash' do
let(:config) do
{
drop_box: {
dropbox: {
app_key: 'test-key',
app_secret: 'test-secret'
},
box: {
client_id: 'test-id',
client_secret: 'test-secret'
},
google_drive: {
client_id: 'test-id',
client_secret: 'test-secret'
}
}
end

it 'logs a deprecation warning and sets it to the dropbox key' do
expect(described_class.config).not_to include 'drop_box'
expect(described_class.config).to include 'dropbox'
expect(described_class.config['dropbox']).to include('app_key' => 'test-key')
expect(described_class.config['dropbox']).to include('app_secret' => 'test-secret')
before do
described_class.configure(config)
end

it_behaves_like 'a configured BrowseEverything module'

context 'with an entry for the drop_box provider' do
let(:config) do
{
drop_box: {
app_key: 'test-key',
app_secret: 'test-secret'
}
}
end

it 'logs a deprecation warning and sets it to the dropbox key' do
expect(described_class.config).not_to include 'drop_box'
expect(described_class.config).to include 'dropbox'
expect(described_class.config['dropbox']).to include('app_key' => 'test-key')
expect(described_class.config['dropbox']).to include('app_secret' => 'test-secret')
end
end
end

context 'with a YAML file' do
before do
described_class.configure(File.expand_path('../../fixtures/config/browse_everything_providers.yml', __FILE__))
end

it_behaves_like 'a configured BrowseEverything module'
end
end

Expand Down

0 comments on commit 3f075f1

Please sign in to comment.