Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

add option for never deleting records from db #109

Open
wants to merge 1 commit into
base: rails3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/acts_as_paranoid/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def destroy
self
end
end
else
elsif !paranoid_configuration[:never_delete]
destroy!
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,10 @@ def test_string_type_with_no_nil_value_after_destroyed_twice
2.times { ps.destroy }
assert_equal 0, ParanoidString.with_deleted.where(:id => ps).count
end

def test_string_type_destroyed_twice_but_never_deleted
ps = ParanoidStringNeverDeleted.create!(:deleted => 'not dead')
2.times { ps.destroy }
assert_equal 1, ParanoidStringNeverDeleted.with_deleted.where(:id => ps).count
end
end
9 changes: 9 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def setup_db
t.string :deleted
end

create_table :paranoid_string_never_deleteds do |t|
t.string :name
t.string :deleted
end

create_table :not_paranoids do |t|
t.string :name
t.integer :paranoid_time_id
Expand Down Expand Up @@ -202,6 +207,10 @@ class ParanoidString < ActiveRecord::Base
acts_as_paranoid :column_type => "string", :column => "deleted", :deleted_value => "dead"
end

class ParanoidStringNeverDeleted < ActiveRecord::Base
acts_as_paranoid :column_type => "string", :column => "deleted", :deleted_value => "dead", :never_delete => true
end

class NotParanoid < ActiveRecord::Base
end

Expand Down