Commit 6881e750 by Braden Anderson

raise error for acts_as_paranoid on models without primary keys

see https://github.com/radar/paranoia/issues/169
parent ba0e7b92
......@@ -154,6 +154,7 @@ end
class ActiveRecord::Base
def self.acts_as_paranoid(options={})
raise "primary key required for "+self.name unless self.primary_key
alias :destroy! :destroy
alias :delete! :delete
def really_destroy!
......
......@@ -28,6 +28,7 @@ def connect!
ActiveRecord::Base.connection.execute 'CREATE TABLE custom_column_models (id INTEGER NOT NULL PRIMARY KEY, destroyed_at DATETIME)'
ActiveRecord::Base.connection.execute 'CREATE TABLE custom_sentinel_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME NOT NULL)'
ActiveRecord::Base.connection.execute 'CREATE TABLE non_paranoid_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER)'
ActiveRecord::Base.connection.execute 'CREATE TABLE idless_models (deleted_at DATETIME)'
end
class WithDifferentConnection < ActiveRecord::Base
......@@ -620,6 +621,12 @@ class ParanoiaTest < test_framework
assert_equal 3, parent.very_related_models.size
end
def test_model_without_primary_key
assert_raises(RuntimeError) do
IdlessModel.class_eval{ acts_as_paranoid }
end
end
private
def get_featureful_model
FeaturefulModel.new(:name => "not empty")
......@@ -758,3 +765,6 @@ class AsplodeModel < ActiveRecord::Base
raise StandardError, 'ASPLODE!'
end
end
class IdlessModel < 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