Fix a couple of bugs introduced by symbolizing to_ar
parent
e9931fa70e
commit
10cceb0e9b
|
@ -11,19 +11,19 @@ module RemoteCredentialDataService
|
||||||
path = get_path_select(opts, CREDENTIAL_API_PATH)
|
path = get_path_select(opts, CREDENTIAL_API_PATH)
|
||||||
data = self.get_data(path, nil, opts)
|
data = self.get_data(path, nil, opts)
|
||||||
rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, [])
|
rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, [])
|
||||||
parsed_body = JSON.parse(data.response.body).symbolize_keys
|
parsed_body = JSON.parse(data.response.body, symbolize_names: true)
|
||||||
data = parsed_body[:data]
|
data = parsed_body[:data]
|
||||||
data.each do |cred|
|
data.each do |cred|
|
||||||
if cred['public']
|
if cred[:public]
|
||||||
public_object = to_ar(cred['public']['type'].constantize, cred['public'])
|
public_object = to_ar(cred[:public][:type].constantize, cred[:public])
|
||||||
rv[data.index(cred)].public = public_object
|
rv[data.index(cred)].public = public_object
|
||||||
end
|
end
|
||||||
if cred['private']
|
if cred[:private]
|
||||||
private_object = to_ar(cred['private']['type'].constantize, cred['private'])
|
private_object = to_ar(cred[:private][:type].constantize, cred[:private])
|
||||||
rv[data.index(cred)].private = private_object
|
rv[data.index(cred)].private = private_object
|
||||||
end
|
end
|
||||||
if cred['origin']
|
if cred[:origin]
|
||||||
origin_object = to_ar(cred['origin']['type'].constantize, cred['origin'])
|
origin_object = to_ar(cred[:origin][:type].constantize, cred[:origin])
|
||||||
rv[data.index(cred)].origin = origin_object
|
rv[data.index(cred)].origin = origin_object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,7 +99,7 @@ module ResponseDataHelper
|
||||||
# @return [ActiveRecord::Base] A klass object, which inherits from ActiveRecord::Base.
|
# @return [ActiveRecord::Base] A klass object, which inherits from ActiveRecord::Base.
|
||||||
def to_ar(klass, val, base_object = nil)
|
def to_ar(klass, val, base_object = nil)
|
||||||
return nil unless val
|
return nil unless val
|
||||||
data = val.class == Hash ? val.dup : JSON.parse(val)
|
data = val.class == Hash ? val.dup : JSON.parse(val, symbolize_names: true)
|
||||||
obj = base_object || klass.new
|
obj = base_object || klass.new
|
||||||
|
|
||||||
obj_associations = klass.reflect_on_all_associations(:has_many).reduce({}) do |reflection, i|
|
obj_associations = klass.reflect_on_all_associations(:has_many).reduce({}) do |reflection, i|
|
||||||
|
|
Loading…
Reference in New Issue