Skip to content

Commit fd1b2c1

Browse files
MONGOID-5833 Fix Document#touch (#6079)
* Changing how we determine if a field should have a write on touch * add test to ensure code path is not reached * add a comment for test
1 parent 4326490 commit fd1b2c1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/mongoid/touchable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def touch(field = nil)
3939
# seems to not always/ever be set here. See MONGOID-5014.
4040
_parent.touch
4141

42-
if field
42+
if field.present?
4343
# If we are told to also touch a field, perform a separate write
4444
# for that field. See MONGOID-5136.
4545
# In theory we should combine the writes, which would require

spec/mongoid/touchable_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@
149149
building.updated_at.should == update_time
150150
end
151151
end
152+
153+
context 'when not updating an additional field' do
154+
it 'does not call set_field_atomic_updates' do
155+
# Regression test for MONGOID-5833
156+
entrance
157+
update_time
158+
expect(entrance).not_to receive(:set_field_atomic_updates)
159+
entrance.touch
160+
161+
entrance.updated_at.should == update_time
162+
end
163+
end
152164
end
153165

154166
context "when the document is referenced" do

0 commit comments

Comments
 (0)