This happens because Rails marks the internal attributes hash with freeze
after calling destroy on a model. This frozen hash prohibits the object from further change: A later destroy(force: true)
wants to remove the id
, a reload
wants to override some attributes with fresh value from the database - both will fail.
The only way to avoid this problem is to reload the object manually:
describe "after .destroy(force: true)" do
before do
slide.save
slide.destroy(force: false)
@slide = Slide.with_deleted.find(slide.id) # manual reload
end
it "is invisible" do
expect{@slide.destroy(force: true)}.to_not change(Slide, :count)
end
it "visible if .only_deleted" do
expect{@slide.destroy(force: true)}.to change(Slide.only_deleted, :count).by(-1)
end
it "visible if .with_deleted" do
expect{@slide.destroy(force: true)}.to change(Slide.with_deleted, :count).by(-1)
end
end