Skip to content

Commit

Permalink
Fix for defining decl_auth before_filter multiple times (Fixes #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
stffn committed Sep 29, 2010
1 parent cefb636 commit c1a2f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/declarative_authorization/in_controller.rb
Expand Up @@ -274,6 +274,8 @@ def filter_access_to (*args, &filter_block)
context = options[:context]
actions = args.flatten

# prevent setting filter_access_filter multiple times
skip_before_filter :filter_access_filter
before_filter :filter_access_filter

filter_access_permissions.each do |perm|
Expand Down
15 changes: 15 additions & 0 deletions test/controller_test.rb
Expand Up @@ -198,6 +198,7 @@ def test_filter_access_all

##################
class LoadMockObjectsController < MocksController
before_filter { @@load_method_call_count = 0 }
filter_access_to :show, :attribute_check => true, :model => LoadMockObject
filter_access_to :edit, :attribute_check => true
filter_access_to :update, :delete, :attribute_check => true,
Expand All @@ -207,9 +208,18 @@ class LoadMockObjectsController < MocksController
end
filter_access_to :view, :attribute_check => true, :load_method => :load_method
def load_method
self.class.load_method_called
MockDataObject.new(:test => 2)
end
define_action_methods :show, :edit, :update, :delete, :create, :view

def self.load_method_called
@@load_method_call_count ||= 0
@@load_method_call_count += 1
end
def self.load_method_call_count
@@load_method_call_count || 0
end
end
class LoadObjectControllerTest < ActionController::TestCase
tests LoadMockObjectsController
Expand Down Expand Up @@ -287,7 +297,12 @@ def test_filter_access_with_object_load_custom

request!(MockUser.new(:test_role), "view", reader)
assert @controller.authorized?
assert_equal 1, @controller.class.load_method_call_count

request!(MockUser.new(:test_role_2), "view", reader)
assert !@controller.authorized?
assert_equal 1, @controller.class.load_method_call_count

request!(MockUser.new(:test_role), "update", reader)
assert @controller.authorized?
end
Expand Down

0 comments on commit c1a2f93

Please sign in to comment.