public

spec example for model which includes acts_as_paranoid

  • Download Gist
rails3_acts_as_paranoid_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.