Created
May 27, 2009 12:09
-
-
Save andrew/118614 to your computer and use it in GitHub Desktop.
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
# is_paranoid shoulda macro | |
def self.should_be_paranoid | |
klass = model_class | |
should_have_db_column :deleted_at | |
context "A #{klass.name}" do | |
should "be paranoid (it will not be deleted from the database)" do | |
assert klass.is_paranoid | |
assert klass.included_modules.include?(IsParanoid::InstanceMethods) | |
end | |
should "not have a value for deleted_at" do | |
assert object = klass.find(:first) | |
assert_nil object.deleted_at | |
end | |
context "when destroyed" do | |
setup do | |
assert object = klass.find(:first), "This context requires there to be an existing #{klass}" | |
@deleted_id = object.id | |
object.destroy | |
end | |
should "not be found" do | |
assert_raise(ActiveRecord::RecordNotFound) { klass.find(@deleted_id) } | |
end | |
should "still exist in the database" do | |
deleted_object = klass.find_with_destroyed(@deleted_id) | |
assert_not_nil deleted_object.deleted_at | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment