forked from Dinda-com-br/braspag-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ERB blocks inside the configuration file
This is useful for applications that are using environment variables and [dotenv][1] to load different configuration values without touching the YAML file. This patch also expands the documentation of how to configure the gem in a Rails app and removes the `Singleton` usage from the `Configuration` class to simplify how the class is tested and to avoid leaking state between the multiple test examples that assert operations inside a config object. [1] https://github.com/bkeepers/dotenv
- Loading branch information
1 parent
39f6725
commit 00f048f
Showing
7 changed files
with
107 additions
and
42 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
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,51 @@ | ||
require 'spec_helper' | ||
|
||
describe BraspagRest::Configuration do | ||
context 'when there is custom configuration file and environment name' do | ||
subject(:configuration) { BraspagRest::Configuration.new } | ||
|
||
it 'configures the gem using values from configuration file' do | ||
configuration.config_file_path = 'spec/fixtures/configuration.yml' | ||
configuration.environment = 'test' | ||
|
||
expect(configuration.config_file_path).to eq('spec/fixtures/configuration.yml') | ||
expect(configuration.environment).to eq('test') | ||
expect(configuration.url).to eq('https://apisandbox.braspag.com.br') | ||
expect(configuration.query_url).to eq('https://apiquerysandbox.braspag.com.br') | ||
expect(configuration.merchant_id).to eq('12345678-1234-1234-1234-123456789012') | ||
expect(configuration.merchant_key).to eq('1234567890123456789012345678901234567890') | ||
end | ||
end | ||
|
||
context 'default configuration' do | ||
subject(:configuration) { BraspagRest::Configuration.new } | ||
|
||
it 'returns a instance of braspag configuration with default config file path' do | ||
expect(configuration.config_file_path).to eq('config/braspag-rest.yml') | ||
end | ||
|
||
it 'sets RACK_ENV variable value as environment if is filled' do | ||
ENV['RACK_ENV'] = 'production' | ||
ENV['RAILS_ENV'] = nil | ||
expect(configuration.environment).to eq('production') | ||
end | ||
|
||
it 'sets RAILS_ENV variable value as environment if is filled' do | ||
ENV['RAILS_ENV'] = 'qa' | ||
ENV['RACK_ENV'] = nil | ||
expect(configuration.environment).to eq('qa') | ||
end | ||
end | ||
|
||
context 'when the config file has ERB blocks' do | ||
subject(:configuration) { BraspagRest::Configuration.new } | ||
|
||
it 'processes the ERB code before parsing the configuration' do | ||
configuration.config_file_path = 'spec/fixtures/configuration.yml' | ||
configuration.environment = 'production' | ||
|
||
ENV['BRASPAG_MERCHANT_KEY'] = 'MERCHANT_KEY_SET_THROUGH_ENV' | ||
expect(configuration.merchant_key).to eq('MERCHANT_KEY_SET_THROUGH_ENV') | ||
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