Commit d6163b5d by donv

* Added query to ask a class or instance if it is paranoid

* Added test setup
parent 9879f78f
require 'bundler' require 'bundler'
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks
task :test do
Dir['test/*_test.rb'].each do |testfile|
load testfile
end
end
\ No newline at end of file
module Paranoia module Paranoia
def self.included(klazz)
klazz.extend Query
end
module Query
def paranoid? ; true ; end
end
def destroy def destroy
_run_destroy_callbacks _run_destroy_callbacks
self[:deleted_at] ||= Time.now self[:deleted_at] ||= Time.now
...@@ -17,4 +25,7 @@ class ActiveRecord::Base ...@@ -17,4 +25,7 @@ class ActiveRecord::Base
self.send(:include, Paranoia) self.send(:include, Paranoia)
default_scope :conditions => { :deleted_at => nil } default_scope :conditions => { :deleted_at => nil }
end end
def self.paranoid? ; false ; end
def paranoid? ; self.class.paranoid? ; end
end end
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
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