-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ERB parsing capability for xapian_db.yml
- Loading branch information
1 parent
ff1f1a1
commit 82e82cf
Showing
4 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
require File.expand_path(File.dirname(__FILE__) + '/../../lib/xapian_db/railtie.rb') | ||
|
||
RSpec.describe 'test' do | ||
let(:yaml_content_with_erb) do | ||
<<-YAML | ||
development: | ||
adapter: <%= ENV.fetch('XAPIAN_DB_ADAPTER', 'fallback_adapter') %> | ||
test: | ||
adapter: xapian | ||
YAML | ||
end | ||
|
||
around do |example| | ||
Tempfile.open('xapian_db.yml') do |file| | ||
file.write(yaml_content_with_erb) | ||
file.rewind | ||
@config_file_path = file.path | ||
|
||
example.run | ||
end | ||
end | ||
|
||
context 'when loading adapter from a temporary YAML file with ERB' do | ||
it 'loads the generic adapter based on environment variable' do | ||
ENV['XAPIAN_DB_ADAPTER'] = 'generic' | ||
|
||
db_config = if YAML.respond_to?(:unsafe_load_file) | ||
YAML.unsafe_load(ERB.new(File.read(@config_file_path)).result) | ||
else | ||
YAML.safe_load(ERB.new(File.read(@config_file_path)).result, aliases: true) | ||
end | ||
|
||
XapianDb::Railtie.configure_from(db_config['development']) | ||
|
||
expect(XapianDb::Railtie.instance_variable_get(:@adapter)).to eq('generic') | ||
end | ||
|
||
it 'loads the xapian adapter based on direct value' do | ||
db_config = if YAML.respond_to?(:unsafe_load_file) | ||
YAML.unsafe_load(ERB.new(IO.read(@config_file_path)).result) | ||
else | ||
YAML.safe_load(ERB.new(IO.read(@config_file_path)).result, aliases: true) | ||
end | ||
|
||
XapianDb::Railtie.configure_from(db_config['test']) | ||
|
||
expect(XapianDb::Railtie.instance_variable_get(:@adapter)).to eq('xapian') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters