Permalink
Browse files

remove stray objects on associations in rails 3

  • Loading branch information...
1 parent e9e1aff commit fac29b7db513197dfc34c453320bfae900a21d6f @jhawthorn jhawthorn committed with Steffen Bartsch Aug 12, 2012
Showing with 2 additions and 1 deletion.
  1. +1 −1 lib/declarative_authorization/authorization.rb
  2. +1 −0 test/model_test.rb
@@ -164,7 +164,7 @@ def permit! (privilege, options = {})
# Example: permit!( :edit, :object => user.posts )
#
if Authorization.is_a_association_proxy?(options[:object]) && options[:object].respond_to?(:new)
- options[:object] = options[:object].new
+ options[:object] = (Rails.version < "3.0" ? options[:object] : options[:object].scoped).new
end
options[:context] ||= options[:object] && (
View
@@ -1801,6 +1801,7 @@ def test_authorization_permit_association_proxy
test_model = TestModel.create(:content => "content")
assert engine.permit?(:read, :object => test_model.test_attrs,
:user => MockUser.new(:test_role))
+ assert test_model.test_attrs.empty?
assert !engine.permit?(:read, :object => TestAttr.new,
:user => MockUser.new(:test_role))
TestModel.delete_all

0 comments on commit fac29b7

Please sign in to comment.