forked from ajh/acts_as_soft_deletable
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test helper and use them internally. Update Readme again.
git-svn-id: http://llama/svn/trunk/ruby/acts_as_soft_deletable@238 bb26965d-a405-0410-8ce8-d62df5cd24e9
- Loading branch information
(no author)
committed
Mar 13, 2008
1 parent
0bbb6e8
commit a3a974e
Showing
7 changed files
with
85 additions
and
35 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require File.join(File.dirname(__FILE__), 'lib', 'acts_as_soft_deletable') | ||
require File.join(File.dirname(__FILE__), 'lib', 'unit_test_helper.rb') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Test | ||
module Unit | ||
module ActsAsDeleted | ||
# Takes a saved model and runs assertions testing whether soft deleting is working | ||
def assert_model_soft_deletes(model) | ||
klass = model.class | ||
deleted_klass = model.class.deleted_class | ||
|
||
assert_raises(ActiveRecord::RecordNotFound) { deleted_klass.find model.id } | ||
model.destroy | ||
|
||
assert(deleted = deleted_klass.find(model.id)) | ||
assert_raises(ActiveRecord::RecordNotFound) { klass.find model.id } | ||
|
||
deleted.undestroy! | ||
|
||
assert_soft_delete_models_are_equal deleted, klass.find(model.id) | ||
assert_raises(ActiveRecord::RecordNotFound) { deleted_klass.find model.id } | ||
end | ||
|
||
# Asserts whether a two soft deleting models are equal. Intended to be passed | ||
# an instance of a model and an instance of the deleted class's model. Checks that | ||
# all attributes were saved off correctly. | ||
def assert_soft_delete_models_are_equal(a, b, message = "models weren't equal") | ||
reject_attrs = %q(deleted_at, updated_at) | ||
assert_equal \ | ||
a.attributes.reject{|k,v| reject_attrs.include? k}, | ||
b.attributes.reject{|k,v| reject_attrs.include? k}, | ||
message | ||
end | ||
end | ||
end | ||
end | ||
|
||
Test::Unit::TestCase.send(:include, Test::Unit::ActsAsDeleted) |
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
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
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
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