make serializable_hash always return a hash with indifferent access

flag=none

Previously, the method would only return a hash with indifferent access
when include_root was false. When include_root was true, it would return
a plain-old hash. This change makes the return value type consistent, so
that it always returns a hash with indifferent access.

Test Plan:
- specs pass

Change-Id: I8fbc23523f1476a45a592cd02884d84d7c5a85e3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/334369
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
This commit is contained in:
Spencer Olson 2023-12-04 10:39:36 -06:00
parent 5b32cc92c9
commit cd41464f8a
2 changed files with 15 additions and 1 deletions

View File

@ -2119,7 +2119,7 @@ module UserContentSerialization
end
end
if options && options[:include_root]
result = { self.class.base_class.model_name.element => result }
result = { self.class.base_class.model_name.element => result }.with_indifferent_access
end
result
end

View File

@ -19,6 +19,20 @@
module ActiveRecord
describe Base do
describe ".serializable_hash" do
let(:account) { Account.create! }
it "returns a hash with indifferent access when the root is included" do
hash = account.serializable_hash(include_root: true)
expect(hash).to be_a ActiveSupport::HashWithIndifferentAccess
end
it "returns a hash with indifferent access when the root is excluded" do
hash = account.serializable_hash(include_root: false)
expect(hash).to be_a ActiveSupport::HashWithIndifferentAccess
end
end
describe ".wildcard" do
it "produces a useful wildcard sql string" do
sql = Base.wildcard("users.name", "users.short_name", "Sinatra, Frank", delimiter: ",")