diff --git a/lib/browse_everything.rb b/lib/browse_everything.rb index 6470ac37..24168488 100644 --- a/lib/browse_everything.rb +++ b/lib/browse_everything.rb @@ -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 diff --git a/spec/lib/browse_everything_spec.rb b/spec/lib/browse_everything_spec.rb index 4c5ce8c8..0be005c0 100644 --- a/spec/lib/browse_everything_spec.rb +++ b/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