spec/authority/abilities_spec.rb in authority-0.0.1 vs spec/authority/abilities_spec.rb in authority-0.2.0

- old
+ new

@@ -1,13 +1,13 @@ require 'spec_helper' require 'support/ability_model' -require 'support/actor' +require 'support/user' describe Authority::Abilities do before :each do - @actor = Actor.new + @user = User.new end describe "authorizer" do it "should have a class attribute getter for authorizer_name" do @@ -36,20 +36,20 @@ 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 AbilityModel.should respond_to(method_name) end it "should delegate `#{method_name}` to its authorizer class" do - AbilityModel.authorizer.should_receive(method_name).with(@actor) - AbilityModel.send(method_name, @actor) + AbilityModel.authorizer.should_receive(method_name).with(@user) + AbilityModel.send(method_name, @user) end end end @@ -59,29 +59,33 @@ before :each do @ability_model = AbilityModel.new @authorizer = AbilityModel.authorizer.new(@ability_model) end - Authority::ADJECTIVES.each do |adjective| + Authority.adjectives.each do |adjective| method_name = "#{adjective}_by?" it "should respond to `#{method_name}`" do @ability_model.should respond_to(method_name) end it "should delegate `#{method_name}` to a new authorizer instance" do AbilityModel.authorizer.stub(:new).and_return(@authorizer) - @authorizer.should_receive(method_name).with(@actor) - @ability_model.send(method_name, @actor) + @authorizer.should_receive(method_name).with(@user) + @ability_model.send(method_name, @user) end - it "should always create a new authorizer instance when checking `#{method_name}`" do - 2.times do - @ability_model.class.authorizer.should_receive(:new).with(@ability_model).and_return(@authorizer) - @ability_model.send(method_name, @actor) - end - end + end + it "should provide an accessor for its authorizer" do + @ability_model.should respond_to(:authorizer) + end + + # TODO: Nathan will comment more clearly in the future + # aka "don't memoize" (to prevent dirty models from contaminating authorization) + it "should always create a new authorizer instance when accessing the authorizer" do + @ability_model.class.authorizer.should_receive(:new).with(@ability_model).twice + 2.times { @ability_model.authorizer } end end end