Skip to content

Instantly share code, notes, and snippets.

@holysugar
Created November 14, 2011 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holysugar/1363549 to your computer and use it in GitHub Desktop.
Save holysugar/1363549 to your computer and use it in GitHub Desktop.
spec example for model which includes acts_as_paranoid
# for model which includes 'acts_as_paranoid'
# example (for User class):
# describe "acts_as_taggable" do
# let (:scope) { Question }
# it_behaves_like 'soft delete'
# it_behaves_like 'with_deleted scopes'
# end
shared_examples_for "soft delete" do
subject { create scope.to_s.downcase.to_sym }
it { expect { subject.destroy }.to_not change { scope.count } }
it "records when deleted at" do
subject.deleted_at.should_not be
subject.destroy
subject.deleted_at.should be
end
end
shared_examples_for "with_deleted scopes" do
before do
3.times{ create scope.to_s.downcase.to_sym }
scope.first.destroy
end
context "default scope" do
subject { scope }
it { should have(2).items }
end
context "with_deleted scope" do
subject { scope.with_deleted }
it { should have(3).items }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment