Permalink
Browse files

More cleanup of test output

  • Loading branch information...
1 parent d70d96e commit 9f5ecd4bdb6104eb75244d93f0dd89d6a0888d96 @nathanl committed Dec 8, 2012
Showing with 36 additions and 16 deletions.
  1. +1 −0 lib/authority/controller.rb
  2. +35 −16 spec/authority/controller_spec.rb
@@ -65,6 +65,7 @@ def authority_action_map
# @param [Hash] options, arbitrary options hash to forward up the chain to the authorizer
# @raise [MissingAction] if controller action isn't a key in `config.controller_action_map`
def authorize_action_for(authority_resource, *options)
+ # `action_name` comes from ActionController
authority_action = self.class.authority_action_map[action_name.to_sym]
if authority_action.nil?
raise MissingAction.new("No authority action defined for #{action_name}")
@@ -143,27 +143,46 @@ def self.before_filter(*args) ; end
let(:user) { User.new }
- it "checks authorization on the model specified" do
- controller_instance.should_receive(:authorize_action_for).with(ExampleModel)
- controller_instance.send(:run_authorization_check)
- end
+ describe "run_authorization_check (used as a before_filter)" do
+
+ it "checks authorization on the model specified" do
+ controller_instance.should_receive(:authorize_action_for).with(ExampleModel)
+ controller_instance.send(:run_authorization_check)
+ end
+
+ it "raises a MissingAction if there is no corresponding action for the controller" do
+ controller_instance.stub(:action_name).and_return('sculpt')
+ expect { controller_instance.send(:run_authorization_check) }.to raise_error(
+ Authority::Controller::MissingAction
+ )
+ end
- it "passes the options provided to `authorize_action_for` downstream" do
- controller_instance.stub(:action_name).and_return(:destroy)
- Authority.should_receive(:enforce).with('delete', ExampleModel, user, :for => 'context')
- controller_instance.send(:authorize_action_for, ExampleModel, :for => 'context')
end
- it "raises a MissingAction if there is no corresponding action for the controller" do
- controller_instance.stub(:action_name).and_return('sculpt')
- expect { controller_instance.send(:run_authorization_check) }.to raise_error(
- Authority::Controller::MissingAction
- )
+ describe "authorize_action_for" do
+
+ before(:each) { controller_instance.stub(:action_name).and_return(:destroy) }
+
+ it "calls Authority.enforce to authorize the action" do
+ Authority.should_receive(:enforce)
+ controller_instance.send(:authorize_action_for, ExampleModel)
+ end
+
+ it "passes along any options it was given" do
+ options = {:for => 'insolence'}
+ Authority.should_receive(:enforce).with('delete', ExampleModel, user, options)
+ controller_instance.send(:authorize_action_for, ExampleModel, options)
+ end
+
end
- it "returns the authority_user for the current request by using the configured user_method" do
- controller_instance.should_receive(Authority.configuration.user_method)
- controller_instance.send(:authority_user)
+ describe "authority_user" do
+
+ it "gets the user for the current request from the configured user_method" do
+ controller_instance.should_receive(Authority.configuration.user_method)
+ controller_instance.send(:authority_user)
+ end
+
end
describe "authority_forbidden action" do

0 comments on commit 9f5ecd4

Please sign in to comment.