forked from rubysherpas/paranoia
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added query to ask a class or instance if it is paranoid
* Added test setup
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
task :test do | ||
Dir['test/*_test.rb'].each do |testfile| | ||
load testfile | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test/unit' | ||
require 'active_record' | ||
require 'lib/paranoia' | ||
|
||
DB_FILE = 'tmp/test_db' | ||
|
||
FileUtils.mkdir_p File.dirname(DB_FILE) | ||
FileUtils.rm_f DB_FILE | ||
|
||
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => DB_FILE | ||
ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY)' | ||
ActiveRecord::Base.connection.execute 'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY)' | ||
|
||
class ParanoiaTest < Test::Unit::TestCase | ||
def test_plain_model_class_is_not_paranoid | ||
assert_equal false, PlainModel.paranoid? | ||
end | ||
|
||
def test_paranoid_model_class_is_paranoid | ||
assert_equal true, ParanoidModel.paranoid? | ||
end | ||
|
||
def test_plain_models_are_not_paranoid | ||
assert_equal false, PlainModel.new.paranoid? | ||
end | ||
|
||
def test_paranoid_models_are_paranoid | ||
assert_equal true, ParanoidModel.new.paranoid? | ||
end | ||
|
||
end | ||
|
||
# Helper classes | ||
|
||
class ParanoidModel < ActiveRecord::Base | ||
acts_as_paranoid | ||
end | ||
|
||
class PlainModel < ActiveRecord::Base | ||
end |