load to mitigate `first` missing db connection

When calling `first` in Rails 5.2 the connection is not found
however by forcing the records to load with `to_a` which happens to
function correctly the call is then sent to `Array.first`
This commit is contained in:
Jeffrey Martin 2020-08-03 10:29:01 -05:00
parent c43df01e9e
commit dee523f9e7
No known key found for this signature in database
GPG Key ID: 0CD9BBC2AF15F171
1 changed files with 5 additions and 1 deletions

View File

@ -41,7 +41,11 @@ module LoginDataProxy
core_opts[:host_ranges] = [ opts.fetch(:address) ] if opts[:address]
core_opts[:svcs] = [ opts.fetch(:service_name) ] if opts[:service_name]
core = creds(core_opts).first
# searching for cores and loading the array is a mitigation for
# an issue seen with Rails 5 when calling first using a local database
cores = creds(core_opts)
cores = cores.to_a unless cores.kind_of?(Array)
core = cores.first
if core
core.logins.each do |login|
login_opts = opts.slice(:access_level, :status, :last_attempted_at)