Skip to content

Commit f563bc0

Browse files
p-mongop
andauthored
MONGOID-5363 add test that #upsert replaces existing document (#5289)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 981e372 commit f563bc0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spec/mongoid/persistable/upsertable_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@
5353
it "flags the document as persisted" do
5454
expect(existing).to be_persisted
5555
end
56+
57+
context 'when existing document contains other fields' do
58+
let!(:existing) do
59+
Band.create!(name: "Photek", views: 42)
60+
end
61+
62+
it 'removes the existing fields' do
63+
Band.count.should == 1
64+
65+
existing.reload
66+
existing.views.should be nil
67+
existing.name.should == 'Tool'
68+
end
69+
end
5670
end
5771

5872
context "when no matching document exists in the db" do

0 commit comments

Comments
 (0)