|
57 | 57 | end
|
58 | 58 | end
|
59 | 59 |
|
60 |
| - context "when removing a root document" do |
| 60 | + context "when deleting a root document" do |
61 | 61 |
|
62 | 62 | let!(:deleted) do
|
63 | 63 | person.delete
|
|
76 | 76 | it "resets the flagged for destroy flag" do
|
77 | 77 | expect(person).to_not be_flagged_for_destroy
|
78 | 78 | end
|
| 79 | + |
| 80 | + context 'when :persist option false' do |
| 81 | + |
| 82 | + let!(:deleted) do |
| 83 | + person.delete(persist: false) |
| 84 | + end |
| 85 | + |
| 86 | + it "does not delete the document from the collection" do |
| 87 | + expect(Person.find(person.id)).to eq person |
| 88 | + end |
| 89 | + |
| 90 | + it "returns true" do |
| 91 | + expect(deleted).to be true |
| 92 | + end |
| 93 | + |
| 94 | + it "does not set the flagged for destroy flag" do |
| 95 | + expect(person).to_not be_flagged_for_destroy |
| 96 | + end |
| 97 | + end |
79 | 98 | end
|
80 | 99 |
|
81 |
| - context "when removing an embedded document" do |
| 100 | + context "when deleting an embedded document" do |
82 | 101 |
|
83 | 102 | let(:address) do
|
84 | 103 | person.addresses.build(street: "Bond Street")
|
|
114 | 133 | Person.find(person.id)
|
115 | 134 | end
|
116 | 135 |
|
117 |
| - it "removes the object from the parent and database" do |
| 136 | + it "removes the object from the parent" do |
| 137 | + expect(person.addresses).to be_empty |
| 138 | + end |
| 139 | + |
| 140 | + it "removes the object from the database" do |
| 141 | + expect(from_db.addresses).to be_empty |
| 142 | + end |
| 143 | + end |
| 144 | + |
| 145 | + context 'when :persist option false' do |
| 146 | + |
| 147 | + before do |
| 148 | + address.save! |
| 149 | + address.delete(persist: false) |
| 150 | + end |
| 151 | + |
| 152 | + let(:from_db) do |
| 153 | + Person.find(person.id) |
| 154 | + end |
| 155 | + |
| 156 | + it "does not remove the object from the parent" do |
| 157 | + expect(person.addresses).to eq [address] |
| 158 | + expect(person.addresses.first).to_not be_flagged_for_destroy |
| 159 | + end |
| 160 | + |
| 161 | + it "does not remove the object from the database" do |
| 162 | + expect(from_db.addresses).to eq [address] |
| 163 | + expect(from_db.addresses.first).to_not be_flagged_for_destroy |
| 164 | + end |
| 165 | + end |
| 166 | + |
| 167 | + context 'when :suppress option true' do |
| 168 | + |
| 169 | + before do |
| 170 | + address.save! |
| 171 | + address.delete(suppress: true) |
| 172 | + end |
| 173 | + |
| 174 | + let(:from_db) do |
| 175 | + Person.find(person.id) |
| 176 | + end |
| 177 | + |
| 178 | + it "does not remove the object from the parent" do |
| 179 | + expect(person.addresses).to eq [address] |
| 180 | + expect(person.addresses.first).to_not be_flagged_for_destroy |
| 181 | + end |
| 182 | + |
| 183 | + it "removes the object from the database" do |
118 | 184 | expect(from_db.addresses).to be_empty
|
119 | 185 | end
|
120 | 186 | end
|
121 | 187 | end
|
122 | 188 |
|
123 |
| - context "when removing deeply embedded documents" do |
| 189 | + context "when deleting deeply embedded documents" do |
124 | 190 |
|
125 | 191 | context "when the document has been saved" do
|
126 | 192 |
|
|
0 commit comments