spec/mongoid/persistable/destroyable_spec.rb in mongoid-8.0.8 vs spec/mongoid/persistable/destroyable_spec.rb in mongoid-8.1.0
- old
+ new
@@ -10,17 +10,37 @@
Person.create!
end
context "when destroying a readonly document" do
- let(:from_db) do
- Person.only(:_id).first
+ context "when legacy_attributes is true" do
+ config_override :legacy_readonly, true
+
+ let(:from_db) do
+ Person.only(:_id).first
+ end
+
+ it "raises an error" do
+ expect(from_db.readonly?).to be true
+ expect {
+ from_db.destroy
+ }.to raise_error(Mongoid::Errors::ReadonlyDocument)
+ end
end
- it "raises an error" do
- expect {
- from_db.destroy
- }.to raise_error(Mongoid::Errors::ReadonlyDocument)
+ context "when legacy_attributes is false" do
+ config_override :legacy_readonly, false
+
+ let(:from_db) do
+ Person.first.tap(&:readonly!)
+ end
+
+ it "raises an error" do
+ expect(from_db.readonly?).to be true
+ expect {
+ from_db.destroy
+ }.to raise_error(Mongoid::Errors::ReadonlyDocument)
+ end
end
end
context 'when destroying a document that was not saved' do
let(:unsaved_person) { Person.new(id: person.id) }