spec/authority/authorizer_spec.rb in authority-1.0.0 vs spec/authority/authorizer_spec.rb in authority-1.1.0

- old
+ new

@@ -5,51 +5,61 @@ describe Authority::Authorizer do before :each do @ability_model = AbilityModel.new @authorizer = @ability_model.authorizer - @user = User.new + @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 + describe "instance methods" do Authority.adjectives.each do |adjective| method_name = "#{adjective}_by?" it "should respond to `#{method_name}`" do - Authority::Authorizer.should respond_to(method_name) + @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) + 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 - describe "instance methods" do + describe "class methods" do Authority.adjectives.each do |adjective| method_name = "#{adjective}_by?" it "should respond to `#{method_name}`" do - @authorizer.should respond_to(method_name) + Authority::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) + + it "should delegate `#{method_name}` to the authorizer's `default` method by default" do + able = method_name.sub('_by?', '').to_sym + Authority::Authorizer.should_receive(:default).with(able, @user) + Authority::Authorizer.send(method_name, @user) end end end -end + describe "the default method" do + it "should call the configured `default_strategy` proc by default" do + Authority.configuration.default_strategy.should_receive(:call).with( + :implodable, Authority::Authorizer, @user + ) + Authority::Authorizer.default(:implodable, @user) + end + + end + +end