Commit 4ae658a8 by Ryan Bigg

Merge pull request #5 from DatekWireless/master

Added query to ask a class or instance if it is paranoid
parents 9879f78f d6163b5d
require 'bundler'
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
def self.included(klazz)
klazz.extend Query
end
module Query
def paranoid? ; true ; end
end
def destroy
_run_destroy_callbacks
self[:deleted_at] ||= Time.now
......@@ -17,4 +25,7 @@ class ActiveRecord::Base
self.send(:include, Paranoia)
default_scope :conditions => { :deleted_at => nil }
end
def self.paranoid? ; false ; end
def paranoid? ; self.class.paranoid? ; 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