Skip to content

Commit

Permalink
define AR callback as method for Rails 4.1 compatibility
Browse files Browse the repository at this point in the history
rails/rails#12981

This was causing me issues when trying to destroy an instance of a model with a protect block defined.
  • Loading branch information
kamui committed Dec 30, 2013
1 parent 9a6bbb5 commit ae156cc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/protector/adapters/active_record/base.rb
Expand Up @@ -9,6 +9,8 @@ module Base
include Protector::DSL::Base
include Protector::DSL::Entry

before_save :before_save_callback

# We need this to make sure no ActiveRecord classes managed
# to cache db scheme and create corresponding methods since
# we want to modify the way they get created
Expand All @@ -25,11 +27,6 @@ module Base
end
end

before_destroy do
return true unless protector_subject?
destroyable?
end

# Drops {Protector::DSL::Meta::Box} cache when subject changes
def restrict!(*args)
@protector_meta = nil
Expand Down Expand Up @@ -133,6 +130,12 @@ def destroyable?
def can?(action, field=false)
protector_meta.can?(action, field)
end

private
def before_save_callback
return true unless protector_subject?
destroyable?
end
end
end
end
Expand Down

0 comments on commit ae156cc

Please sign in to comment.