Skip to content

Commit d5bdce1

Browse files
pimpinclaude
andcommitted
Add test coverage for nested Hash attribute quoting in update_all
Cover string values, nil values, and special character quoting in Hash-style update_all to verify the N1QL injection fix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6d3711c commit d5bdce1

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

spec/relation_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,32 @@ def self.active
357357
expect(m3.reload.children.map(&:age)).to eq([50, 20])
358358
end
359359

360+
it "should update nested hash attributes with string values" do
361+
m1 = RelationModel.create!(age: 10, children: [NestedRelationModel.new(age: 10, name: "Tom"), NestedRelationModel.new(age: 20, name: "Jerry")])
362+
m2 = RelationModel.create!(age: 20, children: [NestedRelationModel.new(age: 15, name: "Tom"), NestedRelationModel.new(age: 20, name: "Jerry")])
363+
364+
RelationModel.where(age: 20).update_all(child: {name: "Updated", _for: :children, _when: {child: {name: "Tom"}}})
365+
366+
expect(m1.reload.children.map(&:name)).to eq(["Tom", "Jerry"])
367+
expect(m2.reload.children.map(&:name)).to eq(["Updated", "Jerry"])
368+
end
369+
370+
it "should update nested hash attributes with nil values" do
371+
m1 = RelationModel.create!(age: 20, children: [NestedRelationModel.new(age: 10, name: "Tom"), NestedRelationModel.new(age: 20, name: "Jerry")])
372+
373+
RelationModel.where(age: 20).update_all(child: {name: nil, _for: :children, _when: {child: {name: "Tom"}}})
374+
375+
expect(m1.reload.children.map(&:name)).to eq([nil, "Jerry"])
376+
end
377+
378+
it "should properly quote string values containing special characters in hash updates" do
379+
m1 = RelationModel.create!(age: 20, children: [NestedRelationModel.new(age: 10, name: "Tom"), NestedRelationModel.new(age: 20, name: "Jerry")])
380+
381+
RelationModel.where(age: 20).update_all(child: {name: "it's a test", _for: :children, _when: {child: {name: "Tom"}}})
382+
383+
expect(m1.reload.children.map(&:name)).to eq(["it's a test", "Jerry"])
384+
end
385+
360386
it "should update nested attributes with a path in a for clause" do
361387
m1 = RelationModel.create!(
362388
pathelement: PathRelationModel.new(

0 commit comments

Comments
 (0)