spec/authority/controller_spec.rb in authority-2.1.0 vs spec/authority/controller_spec.rb in authority-2.2.0
- old
+ new
@@ -1,7 +1,7 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/example_controllers'
require 'support/mock_rails'
require 'support/user'
require 'active_support/core_ext/proc'
@@ -59,22 +59,22 @@
end
describe "DSL (class) methods" do
it "should allow specifying the model to protect" do
- ExampleController.authorize_actions_for AbilityModel
- ExampleController.authority_resource.should eq(AbilityModel)
+ ExampleController.authorize_actions_for ExampleModel
+ ExampleController.authority_resource.should eq(ExampleModel)
end
it "should pass the options provided to the before filter that is set up" do
@options = {:only => [:show, :edit, :update]}
ExampleController.should_receive(:before_filter).with(:run_authorization_check, @options)
- ExampleController.authorize_actions_for AbilityModel, @options
+ ExampleController.authorize_actions_for ExampleModel, @options
end
it "should allow specifying the authority action map in the `authorize_actions_for` declaration" do
- ExampleController.authorize_actions_for AbilityModel, :actions => {:eat => 'delete'}
+ ExampleController.authorize_actions_for ExampleModel, :actions => {:eat => 'delete'}
ExampleController.authority_action_map[:eat].should eq('delete')
end
it "should have a write into the authority actions map usuable in a DSL format" do
ExampleController.authority_action :smite => 'delete'
@@ -89,11 +89,17 @@
@controller.stub!(:action_name).and_return(:edit)
@controller.stub!(Authority.configuration.user_method).and_return(@user)
end
it "should check authorization on the model specified" do
- @controller.should_receive(:authorize_action_for).with(AbilityModel)
+ @controller.should_receive(:authorize_action_for).with(ExampleModel)
@controller.send(:run_authorization_check)
+ end
+
+ it "should pass the options provided to `authorize_action_for` downstream" do
+ @controller.stub!(:action_name).and_return(:destroy)
+ Authority.should_receive(:enforce).with('delete', ExampleModel, @user, :for => 'context')
+ @controller.send(:authorize_action_for, ExampleModel, :for => 'context')
end
it "should raise a SecurityViolation if authorization fails" do
expect { @controller.send(:run_authorization_check) }.to raise_error(Authority::SecurityViolation)
end