Created
November 14, 2011 08:47
-
-
Save holysugar/1363549 to your computer and use it in GitHub Desktop.
spec example for model which includes acts_as_paranoid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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