From 3d49bf32c810da4c951aacc895b9ee6cb669704e Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 18 Oct 2018 14:22:02 +0200 Subject: [PATCH] Fixed bug: Application is in undefined state while using spring because of usage of 'require' instead of 'require_dependency' to track dependencies. --- app/controllers/search_controller.rb | 2 +- app/models/application_model/can_assets.rb | 2 +- app/models/channel.rb | 2 +- app/models/external_credential.rb | 2 +- config/routes.rb | 2 +- lib/email_helper/probe.rb | 4 ++-- lib/email_helper/verify.rb | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index aac7a750f..dddb9c284 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -66,7 +66,7 @@ class SearchController < ApplicationController if objects_with_direct_search_index.present? items = SearchIndexBackend.search(query, limit, objects_with_direct_search_index) items.each do |item| - require item[:type].to_filename + require_dependency item[:type].to_filename local_class = Kernel.const_get(item[:type]) record = local_class.lookup(id: item[:id]) next if !record diff --git a/app/models/application_model/can_assets.rb b/app/models/application_model/can_assets.rb index fe1307257..7036377b6 100644 --- a/app/models/application_model/can_assets.rb +++ b/app/models/application_model/can_assets.rb @@ -144,7 +144,7 @@ get assets of object list def assets_of_object_list(list, assets = {}) list.each do |item| - require item['object'].to_filename + require_dependency item['object'].to_filename record = Kernel.const_get(item['object']).find(item['o_id']) assets = record.assets(assets) if item['created_by_id'].present? diff --git a/app/models/channel.rb b/app/models/channel.rb index ef0c43e9a..6442d585c 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -318,7 +318,7 @@ load channel driver and return class # 'warning: toplevel constant Twitter referenced by Channel::Driver::Twitter' error e.g. # so we have to convert the channel name to the filename via Rails String.underscore # http://stem.ps/rails/2015/01/25/ruby-gotcha-toplevel-constant-referenced-by.html - require "channel/driver/#{adapter.to_filename}" + require_dependency "channel/driver/#{adapter.to_filename}" Object.const_get("::Channel::Driver::#{adapter.to_classname}") end diff --git a/app/models/external_credential.rb b/app/models/external_credential.rb index 560d078fa..829679373 100644 --- a/app/models/external_credential.rb +++ b/app/models/external_credential.rb @@ -29,7 +29,7 @@ class ExternalCredential < ApplicationModel def self.load_backend(provider) adapter = "ExternalCredential::#{provider.camelcase}" - require adapter.to_filename.to_s + require_dependency adapter.to_filename.to_s load_adapter(adapter) end diff --git a/config/routes.rb b/config/routes.rb index 3baffc146..cb6722b7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ Rails.application.routes.draw do files = Dir.glob( "#{dir}/routes/*.rb" ) files.each do |file| if Rails.configuration.cache_classes - require file + require_dependency file else load file end diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 00d04372d..75ccbc18a 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -221,7 +221,7 @@ returns on fail # connection test result_inbound = {} begin - require "channel/driver/#{adapter.to_filename}" + require_dependency "channel/driver/#{adapter.to_filename}" driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}") driver_instance = driver_class.new @@ -319,7 +319,7 @@ returns on fail # test connection begin - require "channel/driver/#{adapter.to_filename}" + require_dependency "channel/driver/#{adapter.to_filename}" driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}") driver_instance = driver_class.new diff --git a/lib/email_helper/verify.rb b/lib/email_helper/verify.rb index 25c42c958..3dcb91d49 100644 --- a/lib/email_helper/verify.rb +++ b/lib/email_helper/verify.rb @@ -80,7 +80,7 @@ or fetch_result = nil begin - require "channel/driver/#{adapter.to_filename}" + require_dependency "channel/driver/#{adapter.to_filename}" driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}") driver_instance = driver_class.new