Use unsafe_load instead of load

This commit is contained in:
Alfonso Uceda 2021-12-29 10:50:09 +01:00
parent ace1b1bccd
commit b36ba3216f
No known key found for this signature in database
GPG Key ID: 45DA29E882BA7EB6
3 changed files with 20 additions and 4 deletions

View File

@ -35,7 +35,11 @@ RSpec.describe Gadget, type: :model do
gadget.update_attribute(:updated_at, Time.current + 1)
}.to(change { gadget.versions.size }.by(1))
expect(
YAML.load(gadget.versions.last.object_changes).keys
if ::YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(gadget.versions.last.object_changes).keys
else
YAML.load(gadget.versions.last.object_changes).keys
end
).to eq(["updated_at"])
end
end

View File

@ -27,7 +27,11 @@ RSpec.describe NoObject, versioning: true do
# New feature: destroy populates object_changes
# https://github.com/paper-trail-gem/paper_trail/pull/1123
h = YAML.load a["object_changes"]
h = if ::YAML.respond_to?(:unsafe_load)
YAML.unsafe_load a["object_changes"]
else
YAML.load a["object_changes"]
end
expect(h["id"]).to eq([n.id, nil])
expect(h["letter"]).to eq([n.letter, nil])
expect(h["created_at"][0]).to be_present

View File

@ -21,7 +21,11 @@ module PaperTrail
let(:data) { described_class.new(skipper, false).data }
it "includes `object` without skipped attributes" do
object = YAML.load(data[:object])
object = if ::YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(data[:object])
else
YAML.load(data[:object])
end
expect(object["id"]).to eq(skipper.id)
expect(object).to have_key("updated_at")
expect(object).to have_key("created_at")
@ -29,7 +33,11 @@ module PaperTrail
end
it "includes `object_changes` without skipped and ignored attributes" do
changes = YAML.load(data[:object_changes])
changes = if ::YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(data[:object_changes])
else
YAML.load(data[:object_changes])
end
expect(changes["id"]).to eq([skipper.id, nil])
expect(changes["updated_at"][0]).to be_present
expect(changes["updated_at"][1]).to be_nil