diff --git a/apps/dashboard/config/configuration_singleton.rb b/apps/dashboard/config/configuration_singleton.rb index 2eb5179a83..39e11ff40d 100644 --- a/apps/dashboard/config/configuration_singleton.rb +++ b/apps/dashboard/config/configuration_singleton.rb @@ -387,7 +387,7 @@ def can_access_core_app?(name) def read_config files = Pathname.glob(config_directory.join("*.{yml,yaml,yml.erb,yaml.erb}")) - files.each_with_object({}) do |f, conf| + files.sort.each_with_object({}) do |f, conf| begin content = ERB.new(f.read, trim_mode: "-").result(binding) yml = YAML.safe_load(content, aliases: true) || {} diff --git a/apps/dashboard/test/config/configuration_singleton_test.rb b/apps/dashboard/test/config/configuration_singleton_test.rb index cc80b8c651..c4328dfb83 100644 --- a/apps/dashboard/test/config/configuration_singleton_test.rb +++ b/apps/dashboard/test/config/configuration_singleton_test.rb @@ -460,4 +460,40 @@ def no_config_env end end end + + test 'config files are sorted by name' do + Dir.mktmpdir do |dir| + with_modified_env({ OOD_CONFIG_D_DIRECTORY: dir.to_s }) do + a_config = { 'nav_categories' => ['AAA', 'BBB'] } + z_config = { 'nav_categories' => ['YYY', 'ZZZ'] } + + File.open("#{dir}/a_config.yml", 'w+') { |f| f.write(a_config.to_yaml) } + File.open("#{dir}/z_config.yml", 'w+') { |f| f.write(z_config.to_yaml) } + + config = ConfigurationSingleton.new.config + nav = config.fetch(:nav_categories) + + # z_config has overwritten a_config + assert_equal(['YYY', 'ZZZ'], nav) + end + end + end + + test 'config files are sorted by name with numbers' do + Dir.mktmpdir do |dir| + with_modified_env({ OOD_CONFIG_D_DIRECTORY: dir.to_s }) do + zero_config = { 'nav_categories' => ['AAA', 'BBB'] } + one_config = { 'nav_categories' => ['YYY', 'ZZZ'] } + + File.open("#{dir}/00_config.yml", 'w+') { |f| f.write(zero_config.to_yaml) } + File.open("#{dir}/01_config.yml", 'w+') { |f| f.write(one_config.to_yaml) } + + config = ConfigurationSingleton.new.config + nav = config.fetch(:nav_categories) + + # z_config has overwritten a_config + assert_equal(['YYY', 'ZZZ'], nav) + end + end + end end