forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase_configuration_spec.rb
57 lines (46 loc) · 1.81 KB
/
database_configuration_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'tempfile'
RSpec.describe "DatabaseConfiguration patch" do
let(:db_config_path) { File.expand_path "../../../config/database.yml", __dir__ }
let(:fake_db_config) { Pathname.new("does/not/exist") }
before do
allow(ManageIQ).to receive_messages(:env => ActiveSupport::StringInquirer.new("production"))
@app = Vmdb::Application.new
@app.config.paths["config/database"] = fake_db_config.to_s # ignore real database.yml
end
context "ERB in the template" do
it "doesn't execute" do
Tempfile.create do |database_config|
database_config.write("---\nvalue: <%= 1 %>\n")
database_config.flush
allow(Pathname).to receive(:new).with(db_config_path).and_return(Pathname.new(database_config.path))
expect(@app.config.database_configuration).to eq('value' => '<%= 1 %>')
end
end
end
context "when DATABASE_URL is set" do
around(:each) do |example|
old_env = ENV.delete('DATABASE_URL')
ENV['DATABASE_URL'] = 'postgres://'
example.run
ensure
# ENV['x'] = nil deletes the key because ENV accepts only string values
ENV['DATABASE_URL'] = old_env
end
it "ignores a missing file" do
expect(Pathname).to receive(:new).with(db_config_path).and_return(fake_db_config)
expect(@app.config.database_configuration).to eq({})
end
end
context "with no source of configuration" do
it "explains the problem" do
expect(Pathname).to receive(:new).with(db_config_path).and_return(fake_db_config)
begin
old = ENV.delete('DATABASE_URL')
expect { @app.config.database_configuration }.to raise_error(/Could not load database configuration/)
ensure
# ENV['x'] = nil deletes the key because ENV accepts only string values
ENV['DATABASE_URL'] = old
end
end
end
end