Skip to content

Commit 06aa1d4

Browse files
committed
Test application.rb
1 parent b2a6b43 commit 06aa1d4

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

config/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ def self.load_config_file(logger)
153153
Panorama::Application.set_and_log_attrib_from_env(:PANORAMA_VAR_HOME, default: def_panorama_var_home)
154154
config.panorama_var_home_user_defined = config.panorama_var_home != def_panorama_var_home
155155

156-
unless File.exist?(config.panorama_var_home) # Ensure that directory exists
156+
unless File.directory?(config.panorama_var_home) # Ensure that directory exists
157157
begin
158158
Dir.mkdir config.panorama_var_home
159159
raise "Directory #{config.panorama_var_home} does not exist and could not be created" unless File.exist?(config.panorama_var_home)
160160
rescue Exception => e
161-
logger.error('Panorama::Application') { "Error #{e.class}:#{e.message} while creating #{config.panorama_var_home}" }
161+
logger.error('Panorama::Application') { "Error #{e.class}:#{e.message} while creating the missing directory PANORAMA_VAR_HOME = #{config.panorama_var_home}" }
162162
exit! 1 # Ensure application terminates if initialization fails
163163
end
164164
end

lib/tasks/panorama_tasks.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Rake::TaskManager.class_eval do
77

88
if Rails.env.test?
99
Rake.application.delete_task("db:test:load")
10-
Rake.application.delete_task("db:test:purge")
10+
# raises Don't know how to build task 'db:test:purge' (See the list of available tasks with `bin/rails --tasks`)
11+
# Rake.application.delete_task("db:test:purge")
1112
Rake.application.delete_task("db:abort_if_pending_migrations")
1213

1314
msg = "Test-Environment at #{Time.now}:

lib/tasks/precompile.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Rake::TaskManager.class_eval do
88
@tasks.delete(task_name.to_s)
99
end
1010
Rake.application.delete_task("db:test:load")
11-
Rake.application.delete_task("db:test:purge")
11+
# raises: Don't know how to build task 'db:test:purge' (See the list of available tasks with `bin/rails --tasks`)
12+
# Rake.application.delete_task("db:test:purge")
1213
Rake.application.delete_task("db:abort_if_pending_migrations")
1314
end
1415

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'test_helper'
2+
3+
class ApplicationTest < ActionView::TestCase
4+
setup do
5+
end
6+
7+
test "load application successful" do
8+
assert_nothing_raised do
9+
config_file_name = "#{Dir.tmpdir}/test_panorama_config.yml"
10+
File.open(config_file_name, 'w') do |file|
11+
file.puts "SECRET_KEY_BASE: 5484235198p2531589230952815723187562731532621756"
12+
end
13+
14+
[
15+
{
16+
PANORAMA_CONFIG_FILE_NAME: nil,
17+
PANORAMA_VAR_HOME: nil,
18+
},
19+
{
20+
PANORAMA_CONFIG_FILE_NAME: config_file_name,
21+
PANORAMA_VAR_HOME: "#{Dir.tmpdir}/test_panorama_var_home",
22+
},
23+
{
24+
PANORAMA_CONFIG_FILE_NAME: config_file_name,
25+
PANORAMA_VAR_HOME: nil,
26+
}
27+
].each do |new_env|
28+
# Set the env according to new_env
29+
new_env.each do |key, value|
30+
ENV[key.to_s] = value
31+
ENV.delete(key.to_s) if value.nil?
32+
end
33+
34+
# Load the class/module again although it is already loaded
35+
load 'config/application.rb'
36+
end
37+
end
38+
end
39+
40+
41+
42+
end

0 commit comments

Comments
 (0)