Skip to content

Instantly share code, notes, and snippets.

@stratigos
Created April 19, 2018 16:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stratigos/94f6616c8ca3b624c98a65931560969f to your computer and use it in GitHub Desktop.
Save stratigos/94f6616c8ca3b624c98a65931560969f to your computer and use it in GitHub Desktop.
RSpec Matcher for ActsAsParanoid / Paranoia Active Record Model Specs
# Shared specs for models with the `acts_as_paranoid` features.
RSpec.shared_examples :soft_delete_model do
it { is_expected.to have_db_column(:deleted_at) }
it 'has a scope to select soft-deleted records' do
expect(described_class).to respond_to(:only_deleted)
end
it 'has a scope to select both not-deleted and soft-deleted records' do
expect(described_class).to respond_to(:with_deleted)
end
context 'deleting an instance' do
it 'only soft-deletes the model when deleted' do
subject.destroy
expect(subject.deleted_at).not_to be_nil
end
end
end
@stratigos
Copy link
Author

This is for simply expressing soft delete as a requirement for data models, when using gems like acts_as_paranoid or paranoia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment