Commit c14aa4b6 by Daniel Lehmann

Extended Tests.

parent 512654f3
......@@ -15,8 +15,11 @@ Gem::Specification.new do |s|
s.rubyforge_project = "paranoia"
s.add_dependency "activerecord", ">= 3.0.0"
#s.add_dependency "activerecord", ">= 3.1.0.rc1"
s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "sqlite3"
s.add_development_dependency "rake", "0.8.7"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
......
require 'test/unit'
require 'active_record'
require 'lib/paranoia'
require 'paranoia'
DB_FILE = 'tmp/test_db'
......@@ -8,8 +8,9 @@ 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)'
ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
ActiveRecord::Base.connection.execute 'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32))'
ActiveRecord::Base.connection.execute 'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
class ParanoiaTest < Test::Unit::TestCase
def test_plain_model_class_is_not_paranoid
......@@ -28,6 +29,50 @@ class ParanoiaTest < Test::Unit::TestCase
assert_equal true, ParanoidModel.new.paranoid?
end
def test_delete_behavior_for_plain_models
model = PlainModel.new
assert_equal 0, model.class.count
model.save!
assert_equal 1, model.class.count
model.delete
assert_equal true, model.deleted_at.nil?
assert_equal 0, model.class.count
assert_equal 0, model.class.unscoped.count
end
def test_delete_behavior_for_paranoid_models
model = ParanoidModel.new
assert_equal 0, model.class.count
model.save!
assert_equal 1, model.class.count
model.delete
assert_equal false, model.deleted_at.nil?
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
end
def test_delete_behavior_for_featureful_paranoid_models
model = get_featureful_model
assert_equal 0, model.class.count
model.save!
assert_equal 1, model.class.count
model.delete
assert_equal false, model.deleted_at.nil?
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
end
private
def get_featureful_model
FeaturefulModel.new(:name => "not empty")
end
end
# Helper classes
......@@ -36,5 +81,10 @@ class ParanoidModel < ActiveRecord::Base
acts_as_paranoid
end
class FeaturefulModel < ActiveRecord::Base
acts_as_paranoid
validates :name, :presence => true, :uniqueness => true
end
class PlainModel < ActiveRecord::Base
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment