Skip to content

Commit

Permalink
fix a bug where errors caused by missing actions did not name the mis…
Browse files Browse the repository at this point in the history
…sing action correctly
  • Loading branch information
triskweline committed Nov 6, 2010
1 parent e9fc8aa commit 24b2a59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/aegis/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ def guess_action(resource_name, action_name, map = {})
compile
action = nil
action_name = action_name.to_s
guess_action_paths(resource_name, action_name, map).detect do |path|
possible_paths = guess_action_paths(resource_name, action_name, map)
possible_paths.detect do |path|
action = find_action_by_path(path, false)
end
handle_missing_action(action)
handle_missing_action(action, possible_paths.first)
end

def find_action_by_path(path, handle_missing = true)
compile
action = @actions_by_path[path.to_s]
action = handle_missing_action(action) if handle_missing
action = handle_missing_action(action, path) if handle_missing
action
end

Expand Down Expand Up @@ -117,12 +118,12 @@ def handle_missing_user(possibly_missing_user)
end
end

def handle_missing_action(possibly_missing_action)
def handle_missing_action(possibly_missing_action, path)
possibly_missing_action ||= case @missing_action_strategy
when :default_permission then Aegis::Action.undefined
when :allow then Aegis::Action.allow_to_all
when :deny then Aegis::Action.deny_to_all
when :error then raise Aegis::MissingAction, "Undefined Aegis action: #{action}"
when :error then raise Aegis::MissingAction, "Missing action: #{path}"
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/aegis/permissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,12 @@
@permissions.may?(@admin, 'missing_action').should be_false
end

it "should raise an error if the strategy is :error" do
it "should raise an error naming the missing action if the strategy is :error" do
@permissions.class_eval do
missing_action_means :error
end
lambda { @permissions.may?(@user, 'missing_action') }.should raise_error(Aegis::MissingAction)
lambda { @permissions.may?(@admin, 'missing_action') }.should raise_error(Aegis::MissingAction)
lambda { @permissions.may?(@user, 'missing_action') }.should raise_error(Aegis::MissingAction, 'Missing action: missing_action')
lambda { @permissions.may?(@admin, 'missing_action') }.should raise_error(Aegis::MissingAction, 'Missing action: missing_action')
end

end
Expand Down

0 comments on commit 24b2a59

Please sign in to comment.