spec/authority/authorizer_spec.rb in authority-0.0.1 vs spec/authority/authorizer_spec.rb in authority-0.2.0
- old
+ new
@@ -1,38 +1,51 @@
require 'spec_helper'
require 'support/ability_model'
+require 'support/user'
describe Authority::Authorizer do
before :each do
@ability_model = AbilityModel.new
- @authorizer = Authority::Authorizer.new(@ability_model)
+ @authorizer = @ability_model.authorizer
+ @user = User.new
end
it "should take a resource instance in its initializer" do
@authorizer.resource.should eq(@ability_model)
end
describe "class methods" do
- Authority::ADJECTIVES.each do |adjective|
+ Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
Authority::Authorizer.should respond_to(method_name)
end
+ it "should run the default authorization strategy block" do
+ able = method_name.sub('_by?', '').to_sym
+ Authority.configuration.default_strategy.should_receive(:call).with(able, Authority::Authorizer, @user)
+ Authority::Authorizer.send(method_name, @user)
+ end
+
end
end
describe "instance methods" do
- Authority::ADJECTIVES.each do |adjective|
+ Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
@authorizer.should respond_to(method_name)
+ end
+
+ it "should delegate `#{method_name}` to the corresponding class method by default" do
+ @authorizer.class.should_receive(method_name).with(@user)
+ @authorizer.send(method_name, @user)
end
end
end