Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisters should error if you try to save something which is gone now, but used to be persisted. #867

Merged
merged 15 commits into from
Oct 15, 2021
Merged
6 changes: 6 additions & 0 deletions lib/valkyrie/persistence/delete_tracking_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def delete(resource:)
@deletes << resource
super
end

# A buffered memory persister can save anything, it doesn't have to hold
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it doesn't actually persist anything directly; proxies to other persisters.

# a consistent internal state.
def valid_for_save?(_)
true
end
end
end
end
10 changes: 10 additions & 0 deletions spec/valkyrie/persistence/buffered_persister_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@ class Resource < Valkyrie::Resource
end
expect(buffer.query_service.find_all.length).to eq 1
end
it "can handle saving an object which was previously saved" do
buffer = nil
resource = Resource.new
output = adapter.persister.save(resource: resource)
persister.with_buffer do |inner_persister, memory_buffer|
inner_persister.save(resource: output)
buffer = memory_buffer
end
expect(buffer.query_service.find_all.length).to eq 1
end
end
end