Permalink
Browse files

Rename AbilityModel to ExampleModel

  • Loading branch information...
1 parent 1066d03 commit 7c4f3e48ab37743c24131a37ed1498a94879eebf @nathanl committed Aug 13, 2012
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/user'
describe Authority::Abilities do
@@ -11,31 +11,31 @@
describe "authorizer" do
it "should have a class attribute getter for authorizer_name" do
- AbilityModel.should respond_to(:authorizer_name)
+ ExampleModel.should respond_to(:authorizer_name)
end
it "should have a class attribute setter for authorizer_name" do
- AbilityModel.should respond_to(:authorizer_name=)
+ ExampleModel.should respond_to(:authorizer_name=)
end
it "should have a default authorizer_name of 'ApplicationAuthorizer'" do
- AbilityModel.authorizer_name.should eq("ApplicationAuthorizer")
+ ExampleModel.authorizer_name.should eq("ApplicationAuthorizer")
end
it "should constantize the authorizer name as the authorizer" do
- AbilityModel.instance_variable_set(:@authorizer, nil)
- AbilityModel.authorizer_name.should_receive(:constantize)
- AbilityModel.authorizer
+ ExampleModel.instance_variable_set(:@authorizer, nil)
+ ExampleModel.authorizer_name.should_receive(:constantize)
+ ExampleModel.authorizer
end
it "should memoize the authorizer to avoid reconstantizing" do
- AbilityModel.authorizer
- AbilityModel.authorizer_name.should_not_receive(:constantize)
- AbilityModel.authorizer
+ ExampleModel.authorizer
+ ExampleModel.authorizer_name.should_not_receive(:constantize)
+ ExampleModel.authorizer
end
it "should raise a friendly error if the authorizer doesn't exist" do
- class NoAuthorizerModel < AbilityModel; end ;
+ class NoAuthorizerModel < ExampleModel; end ;
NoAuthorizerModel.instance_variable_set(:@authorizer, nil)
NoAuthorizerModel.authorizer_name = 'NonExistentAuthorizer'
expect { NoAuthorizerModel.authorizer }.to raise_error(Authority::NoAuthorizerError)
@@ -49,23 +49,23 @@ class NoAuthorizerModel < AbilityModel; end ;
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
- AbilityModel.should respond_to(method_name)
+ ExampleModel.should respond_to(method_name)
end
describe "if given an options hash" do
it "should delegate `#{method_name}` to its authorizer class, passing the options" do
- AbilityModel.authorizer.should_receive(method_name).with(@user, :lacking => 'nothing')
- AbilityModel.send(method_name, @user, :lacking => 'nothing')
+ ExampleModel.authorizer.should_receive(method_name).with(@user, :lacking => 'nothing')
+ ExampleModel.send(method_name, @user, :lacking => 'nothing')
end
end
describe "if not given an options hash" do
it "should delegate `#{method_name}` to its authorizer class, passing no options" do
- AbilityModel.authorizer.should_receive(method_name).with(@user)
- AbilityModel.send(method_name, @user)
+ ExampleModel.authorizer.should_receive(method_name).with(@user)
+ ExampleModel.send(method_name, @user)
end
end
@@ -77,49 +77,49 @@ class NoAuthorizerModel < AbilityModel; end ;
describe "instance methods" do
before :each do
- @ability_model = AbilityModel.new
- @authorizer = AbilityModel.authorizer.new(@ability_model)
+ @example_model = ExampleModel.new
+ @authorizer = ExampleModel.authorizer.new(@example_model)
end
Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
it "should respond to `#{method_name}`" do
- @ability_model.should respond_to(method_name)
+ @example_model.should respond_to(method_name)
end
describe "if given an options hash" do
it "should delegate `#{method_name}` to a new authorizer instance, passing the options" do
- AbilityModel.authorizer.stub(:new).and_return(@authorizer)
+ ExampleModel.authorizer.stub(:new).and_return(@authorizer)
@authorizer.should_receive(method_name).with(@user, :with => 'mayo')
- @ability_model.send(method_name, @user, :with => 'mayo')
+ @example_model.send(method_name, @user, :with => 'mayo')
end
end
describe "if not given an options hash" do
it "should delegate `#{method_name}` to a new authorizer instance, passing no options" do
- AbilityModel.authorizer.stub(:new).and_return(@authorizer)
+ ExampleModel.authorizer.stub(:new).and_return(@authorizer)
@authorizer.should_receive(method_name).with(@user)
- @ability_model.send(method_name, @user)
+ @example_model.send(method_name, @user)
end
end
end
it "should provide an accessor for its authorizer" do
- @ability_model.should respond_to(:authorizer)
+ @example_model.should respond_to(:authorizer)
end
# When checking instance methods, we want to ensure that every check uses a new
# instance of the authorizer. Otherwise, you might check, make a change to the
# model instance, check again, and get an outdated answer.
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 }
+ @example_model.class.authorizer.should_receive(:new).with(@example_model).twice
+ 2.times { @example_model.authorizer }
end
end
@@ -1,17 +1,17 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/user'
describe Authority::Authorizer do
before :each do
- @ability_model = AbilityModel.new
- @authorizer = @ability_model.authorizer
+ @example_model = ExampleModel.new
+ @authorizer = @example_model.authorizer
@user = User.new
end
it "should take a resource instance in its initializer" do
- @authorizer.resource.should eq(@ability_model)
+ @authorizer.resource.should eq(@example_model)
end
describe "instance methods" do
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/example_controllers'
require 'support/mock_rails'
require 'support/user'
@@ -61,18 +61,18 @@
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
@@ -91,7 +91,7 @@
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
@@ -1,11 +1,11 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/user'
describe Authority::UserAbilities do
before :each do
- @ability_model = AbilityModel.new
+ @example_model = ExampleModel.new
@user = User.new
end
@@ -19,17 +19,17 @@
describe "if given options" do
it "should delegate the authorization check to the resource, passing the options" do
- @ability_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user, :size => 'wee')
- @user.send(method_name, @ability_model, :size => 'wee')
+ @example_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user, :size => 'wee')
+ @user.send(method_name, @example_model, :size => 'wee')
end
end
describe "if not given options" do
it "should delegate the authorization check to the resource, passing no options" do
- @ability_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user)
- @user.send(method_name, @ability_model)
+ @example_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user)
+ @user.send(method_name, @example_model)
end
end
View
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'support/ability_model'
+require 'support/example_model'
require 'support/user'
describe Authority do
@@ -45,11 +45,11 @@
end
it "should raise a SecurityViolation if the action is unauthorized" do
- expect { Authority.enforce(:update, AbilityModel, @user) }.to raise_error(Authority::SecurityViolation)
+ expect { Authority.enforce(:update, ExampleModel, @user) }.to raise_error(Authority::SecurityViolation)
end
it "should not raise a SecurityViolation if the action is authorized" do
- expect { Authority.enforce(:read, AbilityModel, @user) }.not_to raise_error(Authority::SecurityViolation)
+ expect { Authority.enforce(:read, ExampleModel, @user) }.not_to raise_error(Authority::SecurityViolation)
end
end
@@ -1,4 +1,4 @@
-class AbilityModel
+class ExampleModel
include Authority::Abilities
end

0 comments on commit 7c4f3e4

Please sign in to comment.