Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Combine the support files

  • Loading branch information...
commit 4c460544ee5ef08f5923334be18756d48d622077 1 parent 864390e
@nathanl authored
View
3  spec/authority/abilities_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe Authority::Abilities do
View
3  spec/authority/authorizer_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe Authority::Authorizer do
View
3  spec/authority/controller_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
-require 'support/example_model'
+require 'support/example_classes'
require 'support/mock_rails'
-require 'support/user'
require 'active_support/core_ext/proc'
describe Authority::Controller do
View
3  spec/authority/integration_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe "integration from user through model to authorizer" do
View
3  spec/authority/user_abilities_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe Authority::UserAbilities do
View
39 spec/authority_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe Authority do
@@ -15,7 +14,7 @@
end
it "has a convenience accessor for the ability verbs" do
- expect(Authority.verbs.map(&:to_s).sort).to eq(['create', 'delete', 'read', 'update'])
+ expect(Authority.verbs.sort).to eq([:create, :delete, :read, :update])
end
it "has a convenience accessor for the ability adjectives" do
@@ -40,16 +39,14 @@
describe "enforcement" do
- before :each do
- @user = User.new
- end
+ let(:user) { User.new }
describe "if given options" do
it "checks the user's authorization, passing along the options" do
options = { :for => 'context' }
- @user.should_receive(:can_delete?).with(ExampleModel, options).and_return(true)
- Authority.enforce(:delete, ExampleModel, @user, options)
+ user.should_receive(:can_delete?).with(ExampleModel, options).and_return(true)
+ Authority.enforce(:delete, ExampleModel, user, options)
end
end
@@ -57,45 +54,43 @@
describe "if not given options" do
it "checks the user's authorization, passing no options" do
- @user.should_receive(:can_delete?).with(ExampleModel).and_return(true)
- Authority.enforce(:delete, ExampleModel, @user)
+ user.should_receive(:can_delete?).with(ExampleModel).and_return(true)
+ Authority.enforce(:delete, ExampleModel, user)
end
end
it "raises a SecurityViolation if the action is unauthorized" do
- expect { Authority.enforce(:update, ExampleModel, @user) }.to raise_error(Authority::SecurityViolation)
+ expect { Authority.enforce(:update, ExampleModel, user) }.to raise_error(Authority::SecurityViolation)
end
it "doesn't raise a SecurityViolation if the action is authorized" do
- expect { Authority.enforce(:read, ExampleModel, @user) }.not_to raise_error(Authority::SecurityViolation)
+ expect { Authority.enforce(:read, ExampleModel, user) }.not_to raise_error(Authority::SecurityViolation)
end
end
describe Authority::SecurityViolation do
- before :each do
- @user = "I am a user"
- @action = :keelhaul
- @resource = "I am a resource"
- @security_violation = Authority::SecurityViolation.new(@user, @action, @resource)
- end
+ let(:user) { :"Cap'n Ned" }
+ let(:action) { :keelhaul }
+ let(:resource) { :houseplant }
+ let(:security_violation) { Authority::SecurityViolation.new(user, action, resource) }
it "has a reader for the user" do
- expect(@security_violation.user).to eq(@user)
+ expect(security_violation.user).to eq(user)
end
it "has a reader for the action" do
- expect(@security_violation.action).to eq(@action)
+ expect(security_violation.action).to eq(action)
end
it "has a reader for the resource" do
- expect(@security_violation.resource).to eq(@resource)
+ expect(security_violation.resource).to eq(resource)
end
it "uses them all in its message" do
- expect(@security_violation.message).to eq("#{@user} is not authorized to #{@action} this resource: #{@resource}")
+ expect(security_violation.message).to eq("#{user} is not authorized to #{action} this resource: #{resource}")
end
end
View
4 spec/support/example_model.rb → spec/support/example_classes.rb
@@ -1,3 +1,7 @@
+class User
+ include Authority::UserAbilities
+end
+
class ExampleModel
include Authority::Abilities
end
View
3  spec/support/user.rb
@@ -1,3 +0,0 @@
-class User
- include Authority::UserAbilities
-end
Please sign in to comment.
Something went wrong with that request. Please try again.