Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vovanmozg committed Mar 7, 2024
1 parent 7f4dab4 commit 6a02452
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,42 @@
expect(Settings.size).to eq(2)
end

describe 'load_and_set_settings in the Rails context' do
if defined?(Rails)
let(:config_name) { Rails.root.join('config', 'initializers', 'config.rb') }
let(:default_settings_file_name) { Rails.root.join('config', 'settings.yml') }
let(:custom_settings_file_name) { Rails.root.join('config', 'settings_custom.yml') }

before do
File.write(default_settings_file_name, "default: default_value")
File.write(custom_settings_file_name, "custom: custom_value")
end

after do
File.delete(config_name) if File.exist?(config_name)
File.delete(default_settings_file_name) if File.exist?(default_settings_file_name)
File.delete(custom_settings_file_name) if File.exist?(custom_settings_file_name)
end

it "should read value only from default settings without config.rb" do
values = `#{Rails.root.join('bin', 'rails')} runner 'print "\#{Settings.default}|\#{Settings.custom}"'`
expect(values).to eq("default_value|")
end

it "should read value only from default settings without use of load_and_set_settings" do
File.write(config_name, "Config.setup { |config| }")
values = `#{Rails.root.join('bin', 'rails')} runner 'print "\#{Settings.default}|\#{Settings.custom}"'`
expect(values).to eq("default_value|")
end

it "should read value only from custom settings with use of load_and_set_settings" do
File.write(config_name, "Config.setup { |config| config.load_and_set_settings(['#{custom_settings_file_name}']) }")
values = `#{Rails.root.join('bin', 'rails')} runner 'print "\#{Settings.default}|\#{Settings.custom}"'`
expect(values).to eq("|custom_value")
end
end
end



context "Nested Settings" do
Expand Down

0 comments on commit 6a02452

Please sign in to comment.