can-has-permission 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/generators/can_has_permission_generator.rb +17 -0
- data/generators/templates/can_has_permission_create_anonymous.rb +14 -0
- data/generators/templates/can_has_permission_create_permission_types.rb +14 -0
- data/generators/templates/can_has_permission_create_permissions.rb +18 -0
- data/generators/templates/can_has_permission_create_role_types.rb +14 -0
- data/generators/templates/can_has_permission_create_roles.rb +18 -0
- data/lib/can-has-permission.rb +16 -43
- data/lib/can-has-permission/anonymous.rb +7 -0
- data/lib/can-has-permission/permission.rb +26 -3
- data/lib/can-has-permission/permission_type.rb +7 -0
- data/lib/can-has-permission/role.rb +24 -4
- data/lib/can-has-permission/role_type.rb +14 -0
- data/spec/spec_helper.rb +16 -12
- data/spec/tests/anonymous_spec.rb +76 -0
- data/spec/tests/permission_spec.rb +50 -11
- data/spec/tests/permission_type_spec.rb +20 -0
- data/spec/tests/role_spec.rb +50 -11
- data/spec/tests/role_type_spec.rb +38 -0
- metadata +20 -22
- data/.gitignore +0 -1
- data/Rakefile +0 -23
- data/VERSION +0 -1
- data/can-has-permission.gemspec +0 -65
- data/lib/can-has-permission/has_permission.rb +0 -24
- data/lib/can-has-permission/has_role.rb +0 -22
- data/lib/generators/can-has-permission-generator.rb +0 -7
- data/lib/generators/migrate/create_has_permissions.rb +0 -14
- data/lib/generators/migrate/create_has_roles.rb +0 -14
- data/lib/generators/migrate/create_permissions.rb +0 -12
- data/lib/generators/migrate/create_roles.rb +0 -12
- data/spec/tests/can_has_permission_spec.rb +0 -279
- data/spec/tests/has_permission_spec.rb +0 -74
- data/spec/tests/has_role_spec.rb +0 -74
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe CanHasPermission::PermissionType do
|
4
|
+
it "should be valid with a name" do
|
5
|
+
role = CanHasPermission::PermissionType.new(:name => 'Bingo')
|
6
|
+
role.should be_valid
|
7
|
+
end
|
8
|
+
it "should not be valid without a name" do
|
9
|
+
role = CanHasPermission::PermissionType.new()
|
10
|
+
role.should_not be_valid
|
11
|
+
end
|
12
|
+
it "should not be valid when it has a name that already exists" do
|
13
|
+
name = 'the same'
|
14
|
+
role1 = CanHasPermission::PermissionType.create!(:name => 'the same')
|
15
|
+
role2 = CanHasPermission::PermissionType.new(:name => 'the same')
|
16
|
+
role1.should be_valid
|
17
|
+
role1.id.should_not be_nil
|
18
|
+
role2.should_not be_valid
|
19
|
+
end
|
20
|
+
end
|
data/spec/tests/role_spec.rb
CHANGED
@@ -1,20 +1,59 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
3
|
describe CanHasPermission::Role do
|
4
|
-
it "should be valid
|
5
|
-
role = CanHasPermission::Role.new(:name => '
|
4
|
+
it "created with all attributes should be valid" do
|
5
|
+
role = CanHasPermission::Role.new(:permissible_id => 1, :permissible_type => 'Object', :name => 'role')
|
6
6
|
role.should be_valid
|
7
7
|
end
|
8
|
-
it "should
|
9
|
-
role = CanHasPermission::Role.new()
|
10
|
-
role.
|
8
|
+
it "should be invalid without a name" do
|
9
|
+
role = CanHasPermission::Role.new(:permissible_id => 1, :permissible_type => 'Object')
|
10
|
+
role.should be_invalid
|
11
11
|
end
|
12
|
-
it "
|
13
|
-
|
14
|
-
|
15
|
-
role2 = CanHasPermission::Role.new(:name => 'the same')
|
16
|
-
role1.should be_valid
|
17
|
-
role1.id.should_not be_nil
|
12
|
+
it "two roles with the same object and role should not be valid" do
|
13
|
+
role1 = CanHasPermission::Role.create!(:permissible_id => 1, :permissible_type => 'Object', :name => 'role')
|
14
|
+
role2 = CanHasPermission::Role.new(:permissible_id => 1, :permissible_type => 'Object', :name => 'role')
|
18
15
|
role2.should_not be_valid
|
19
16
|
end
|
17
|
+
it "two roles with the same object should be valid" do
|
18
|
+
role1 = CanHasPermission::Role.create!(:permissible_id => 1, :permissible_type => 'Object', :name => 'role')
|
19
|
+
role2 = CanHasPermission::Role.new(:permissible_id => 2, :permissible_type => 'Object', :name => 'role')
|
20
|
+
role2.should be_valid
|
21
|
+
end
|
22
|
+
describe "with a role type" do
|
23
|
+
before(:each) do
|
24
|
+
@role_type = CanHasPermission::RoleType.create!(:name => 'role')
|
25
|
+
end
|
26
|
+
it "should be valid without a name" do
|
27
|
+
role = CanHasPermission::Role.new(:permissible_id => 1, :permissible_type => 'Object', :role_type => @role_type)
|
28
|
+
role.should be_valid
|
29
|
+
end
|
30
|
+
end
|
31
|
+
it "should be invalid without a permissible_id" do
|
32
|
+
role = CanHasPermission::Role.new(:permissible_type => 'Object', :name => 'role')
|
33
|
+
role.should be_invalid
|
34
|
+
end
|
35
|
+
it "should be invalid without a permissible_type" do
|
36
|
+
role = CanHasPermission::Role.new(:permissible_id => 1, :name => 'role', :name => 'role')
|
37
|
+
role.should be_invalid
|
38
|
+
end
|
39
|
+
describe "created with a name and not a type" do
|
40
|
+
before(:each) do
|
41
|
+
@role_name = 'role'
|
42
|
+
@role = CanHasPermission::Role.create!(:permissible_id => 1, :permissible_type => 'Object', :name => @role_name)
|
43
|
+
end
|
44
|
+
it "should create a role_type" do
|
45
|
+
CanHasPermission::RoleType.count(:conditions => {:name => @role_name}).should == 1
|
46
|
+
end
|
47
|
+
describe "and another role of the same type is created" do
|
48
|
+
before(:each) do
|
49
|
+
@role2 = CanHasPermission::Role.create!(:permissible_id => 2, :permissible_type => 'Object', :name => @role_name)
|
50
|
+
end
|
51
|
+
it "should not create a second role_type" do
|
52
|
+
CanHasPermission::RoleType.count(:conditions => {:name => @role_name}).should == 1
|
53
|
+
end
|
54
|
+
it "both should have the same role_type instance" do
|
55
|
+
@role2.role_type_id.should == @role.role_type_id
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
20
59
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe CanHasPermission::RoleType do
|
4
|
+
it "should be valid with a name" do
|
5
|
+
role = CanHasPermission::RoleType.new(:name => 'Bingo')
|
6
|
+
role.should be_valid
|
7
|
+
end
|
8
|
+
it "should not be valid without a name" do
|
9
|
+
role = CanHasPermission::RoleType.new()
|
10
|
+
role.should_not be_valid
|
11
|
+
end
|
12
|
+
it "should not be valid when it has a name that already exists" do
|
13
|
+
name = 'the same'
|
14
|
+
role1 = CanHasPermission::RoleType.create!(:name => 'the same')
|
15
|
+
role2 = CanHasPermission::RoleType.new(:name => 'the same')
|
16
|
+
role1.should be_valid
|
17
|
+
role1.id.should_not be_nil
|
18
|
+
role2.should_not be_valid
|
19
|
+
end
|
20
|
+
describe "creating a role_type with permissions" do
|
21
|
+
before(:each) do
|
22
|
+
@role = CanHasPermission::RoleType.create!(:name => 'joe')
|
23
|
+
@role.permissions.create!(:name => 'perm')
|
24
|
+
@role.reload
|
25
|
+
end
|
26
|
+
it "should have an attached permission" do
|
27
|
+
@role.permissions.should_not be_empty
|
28
|
+
end
|
29
|
+
describe "#can?" do
|
30
|
+
it "should return true when given the permission" do
|
31
|
+
@role.can?(:perm).should be_true
|
32
|
+
end
|
33
|
+
it "should return false when given a different permission" do
|
34
|
+
@role.can?(:perm2).should be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Rode
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-25 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,29 +28,27 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.rdoc
|
30
30
|
files:
|
31
|
-
- .
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
31
|
+
- generators/can_has_permission_generator.rb
|
32
|
+
- generators/templates/can_has_permission_create_anonymous.rb
|
33
|
+
- generators/templates/can_has_permission_create_permission_types.rb
|
34
|
+
- generators/templates/can_has_permission_create_permissions.rb
|
35
|
+
- generators/templates/can_has_permission_create_role_types.rb
|
36
|
+
- generators/templates/can_has_permission_create_roles.rb
|
36
37
|
- lib/can-has-permission.rb
|
37
|
-
- lib/can-has-permission/
|
38
|
-
- lib/can-has-permission/has_role.rb
|
38
|
+
- lib/can-has-permission/anonymous.rb
|
39
39
|
- lib/can-has-permission/permission.rb
|
40
|
+
- lib/can-has-permission/permission_type.rb
|
40
41
|
- lib/can-has-permission/role.rb
|
41
|
-
- lib/
|
42
|
-
-
|
43
|
-
- lib/generators/migrate/create_has_roles.rb
|
44
|
-
- lib/generators/migrate/create_permissions.rb
|
45
|
-
- lib/generators/migrate/create_roles.rb
|
42
|
+
- lib/can-has-permission/role_type.rb
|
43
|
+
- README.rdoc
|
46
44
|
- spec/spec_helper.rb
|
47
|
-
- spec/tests/
|
48
|
-
- spec/tests/has_permission_spec.rb
|
49
|
-
- spec/tests/has_role_spec.rb
|
45
|
+
- spec/tests/anonymous_spec.rb
|
50
46
|
- spec/tests/permission_spec.rb
|
47
|
+
- spec/tests/permission_type_spec.rb
|
51
48
|
- spec/tests/role_spec.rb
|
49
|
+
- spec/tests/role_type_spec.rb
|
52
50
|
has_rdoc: true
|
53
|
-
homepage: http://github.com/cirode/
|
51
|
+
homepage: http://github.com/cirode/can-has-permission
|
54
52
|
licenses: []
|
55
53
|
|
56
54
|
post_install_message:
|
@@ -85,8 +83,8 @@ specification_version: 3
|
|
85
83
|
summary: simple permissions based authorisation
|
86
84
|
test_files:
|
87
85
|
- spec/spec_helper.rb
|
88
|
-
- spec/tests/
|
89
|
-
- spec/tests/has_permission_spec.rb
|
90
|
-
- spec/tests/has_role_spec.rb
|
86
|
+
- spec/tests/anonymous_spec.rb
|
91
87
|
- spec/tests/permission_spec.rb
|
88
|
+
- spec/tests/permission_type_spec.rb
|
92
89
|
- spec/tests/role_spec.rb
|
90
|
+
- spec/tests/role_type_spec.rb
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pkg
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].each{|task| load task}
|
5
|
-
|
6
|
-
task :test do
|
7
|
-
system("spec spec/tests/*_spec.rb")
|
8
|
-
end
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'jeweler'
|
12
|
-
Jeweler::Tasks.new do |gemspec|
|
13
|
-
gemspec.name = "can-has-permission"
|
14
|
-
gemspec.summary = "simple permissions based authorisation"
|
15
|
-
gemspec.description = "simple permissions based authorisation with roles"
|
16
|
-
gemspec.email = "cirode@gmail.com"
|
17
|
-
gemspec.homepage = "http://github.com/cirode/can_has_permission"
|
18
|
-
gemspec.authors = ["Chris Rode"]
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
23
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|
data/can-has-permission.gemspec
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{can-has-permission}
|
8
|
-
s.version = "0.0.2"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Chris Rode"]
|
12
|
-
s.date = %q{2010-08-11}
|
13
|
-
s.description = %q{simple permissions based authorisation with roles}
|
14
|
-
s.email = %q{cirode@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"README.rdoc",
|
21
|
-
"Rakefile",
|
22
|
-
"VERSION",
|
23
|
-
"can-has-permission.gemspec",
|
24
|
-
"lib/can-has-permission.rb",
|
25
|
-
"lib/can-has-permission/has_permission.rb",
|
26
|
-
"lib/can-has-permission/has_role.rb",
|
27
|
-
"lib/can-has-permission/permission.rb",
|
28
|
-
"lib/can-has-permission/role.rb",
|
29
|
-
"lib/generators/can-has-permission-generator.rb",
|
30
|
-
"lib/generators/migrate/create_has_permissions.rb",
|
31
|
-
"lib/generators/migrate/create_has_roles.rb",
|
32
|
-
"lib/generators/migrate/create_permissions.rb",
|
33
|
-
"lib/generators/migrate/create_roles.rb",
|
34
|
-
"spec/spec_helper.rb",
|
35
|
-
"spec/tests/can_has_permission_spec.rb",
|
36
|
-
"spec/tests/has_permission_spec.rb",
|
37
|
-
"spec/tests/has_role_spec.rb",
|
38
|
-
"spec/tests/permission_spec.rb",
|
39
|
-
"spec/tests/role_spec.rb"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/cirode/can_has_permission}
|
42
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
-
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.7}
|
45
|
-
s.summary = %q{simple permissions based authorisation}
|
46
|
-
s.test_files = [
|
47
|
-
"spec/spec_helper.rb",
|
48
|
-
"spec/tests/can_has_permission_spec.rb",
|
49
|
-
"spec/tests/has_permission_spec.rb",
|
50
|
-
"spec/tests/has_role_spec.rb",
|
51
|
-
"spec/tests/permission_spec.rb",
|
52
|
-
"spec/tests/role_spec.rb"
|
53
|
-
]
|
54
|
-
|
55
|
-
if s.respond_to? :specification_version then
|
56
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
-
s.specification_version = 3
|
58
|
-
|
59
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
-
else
|
61
|
-
end
|
62
|
-
else
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class CanHasPermission::HasPermission < ActiveRecord::Base
|
2
|
-
validates_presence_of :permission_id, :if => lambda{|instance| instance.permission.blank?}
|
3
|
-
validates_presence_of :model_id
|
4
|
-
validates_presence_of :model
|
5
|
-
validates_uniqueness_of :model, :model_id, :scope => :permission_id
|
6
|
-
before_save :create_permission, :unless => lambda{|instance| instance.permission.blank?}
|
7
|
-
|
8
|
-
belongs_to :permission_class, :class_name => 'CanHasPermission::Permission', :foreign_key => 'permission_id'
|
9
|
-
|
10
|
-
def permission=(permission)
|
11
|
-
@permission = permission.to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
#test this
|
15
|
-
def permission
|
16
|
-
permission_class.try(:name).try(:to_sym) || @permission
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def create_permission
|
22
|
-
self.permission_id = CanHasPermission::Permission.find_or_create_by_name(:name => self.permission).id
|
23
|
-
end
|
24
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class CanHasPermission::HasRole < ActiveRecord::Base
|
2
|
-
validates_presence_of :role_id, :if => lambda{|instance| instance.role.blank?}
|
3
|
-
validates_presence_of :model_id
|
4
|
-
validates_presence_of :model
|
5
|
-
validates_uniqueness_of :model, :model_id, :scope => :role_id
|
6
|
-
before_save :create_role, :unless => lambda{|instance| instance.role.blank?}
|
7
|
-
|
8
|
-
belongs_to :role_class, :class_name => 'CanHasPermission::Role', :foreign_key => 'role_id'
|
9
|
-
|
10
|
-
#write and test a callback that changes the role on save if changed
|
11
|
-
def role=(role)
|
12
|
-
@role = role.to_s
|
13
|
-
end
|
14
|
-
#test this
|
15
|
-
def role
|
16
|
-
role_class.try(:name).try(:to_sym) || @role
|
17
|
-
end
|
18
|
-
protected
|
19
|
-
def create_role
|
20
|
-
self.role_id = CanHasPermission::Role.find_or_create_by_name(:name => self.role).id
|
21
|
-
end
|
22
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class CreateHasPermissions < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :has_permissions do |t|
|
4
|
-
t.string :model, :null => false
|
5
|
-
t.integer :model_id, :null => false
|
6
|
-
t.integer :permission_id, :null => false
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
drop_table :has_permissions
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class CreateHasRoles < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :has_roles do |t|
|
4
|
-
t.string :model, :null => false
|
5
|
-
t.integer :model_id, :null => false
|
6
|
-
t.integer :role_id, :null => false
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
drop_table :has_roles
|
13
|
-
end
|
14
|
-
end
|
@@ -1,279 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
|
3
|
-
|
4
|
-
class TestingClass
|
5
|
-
include CanHasPermission
|
6
|
-
attr_accessor :id
|
7
|
-
def initialize(id=nil)
|
8
|
-
@@id ||=0
|
9
|
-
self.id = id || (@@id +=1)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.find(id)
|
13
|
-
self.class.new(id)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe CanHasPermission, "after including in TestingClass object" do
|
18
|
-
before(:each) do
|
19
|
-
@testing_object = TestingClass.new
|
20
|
-
end
|
21
|
-
describe ", TestingClass object " do
|
22
|
-
it "should have #has_role?" do
|
23
|
-
@testing_object.respond_to?(:has_role?).should be_true
|
24
|
-
end
|
25
|
-
it "should have #roles" do
|
26
|
-
@testing_object.respond_to?(:roles).should be_true
|
27
|
-
end
|
28
|
-
it "should have #add_roles" do
|
29
|
-
@testing_object.respond_to?(:add_roles).should be_true
|
30
|
-
end
|
31
|
-
it "should have #remove_roles" do
|
32
|
-
@testing_object.respond_to?(:remove_roles).should be_true
|
33
|
-
end
|
34
|
-
it "should have #can?" do
|
35
|
-
@testing_object.respond_to?(:can?).should be_true
|
36
|
-
end
|
37
|
-
it "should have #can" do
|
38
|
-
@testing_object.respond_to?(:can).should be_true
|
39
|
-
end
|
40
|
-
it "should have #can=" do
|
41
|
-
@testing_object.respond_to?(:can=).should be_true
|
42
|
-
end
|
43
|
-
it "should have #can_not" do
|
44
|
-
@testing_object.respond_to?(:can_not).should be_true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "with no permissions" do
|
49
|
-
it "#can should return an empty list" do
|
50
|
-
@testing_object.can.should be_empty
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#can?" do
|
54
|
-
it "should return false with a symbol" do
|
55
|
-
@testing_object.can?(:do_something).should be_false
|
56
|
-
end
|
57
|
-
it "should return false with a string" do
|
58
|
-
@testing_object.can?('do_something').should be_false
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#can=" do
|
63
|
-
it "should accept an empty list" do
|
64
|
-
@testing_object.can=([])
|
65
|
-
@testing_object.can.should be_empty
|
66
|
-
end
|
67
|
-
it "should accept being given a list with items and treat them as strings" do
|
68
|
-
@testing_object.can=[true]
|
69
|
-
@testing_object.can.size.should == 1
|
70
|
-
@testing_object.can.first.should == true.to_s.to_sym
|
71
|
-
end
|
72
|
-
it "should treat any object as its string representation" do
|
73
|
-
@testing_object.can=true
|
74
|
-
@testing_object.can.size.should == 1
|
75
|
-
@testing_object.can.first.should == true.to_s.to_sym
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "with permissions" do
|
81
|
-
before(:each) do
|
82
|
-
@testing_object.can=(:role1)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "#can should return a filled list" do
|
86
|
-
@testing_object.can.should_not be_empty
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#can?" do
|
90
|
-
describe "when the permission isnt in the list" do
|
91
|
-
it "should return false with a symbol" do
|
92
|
-
@testing_object.can?(:do_something).should be_false
|
93
|
-
end
|
94
|
-
it "should return false with a string" do
|
95
|
-
@testing_object.can?('do_something').should be_false
|
96
|
-
end
|
97
|
-
end
|
98
|
-
describe "when the permission is in the list" do
|
99
|
-
it "should return true with a symbol" do
|
100
|
-
@testing_object.can?(:role1).should be_true
|
101
|
-
end
|
102
|
-
it "should return true with a string" do
|
103
|
-
@testing_object.can?('role1').should be_true
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#can=" do
|
109
|
-
it "should accept an empty list" do
|
110
|
-
@testing_object.can=([])
|
111
|
-
@testing_object.can.should_not be_empty
|
112
|
-
end
|
113
|
-
it "should accept being given a list with items and treat them as strings" do
|
114
|
-
@testing_object.can=[true]
|
115
|
-
@testing_object.can.size.should == 2
|
116
|
-
@testing_object.can.should include(true.to_s.to_sym)
|
117
|
-
end
|
118
|
-
it "should treat any object as its string representation" do
|
119
|
-
@testing_object.can=true
|
120
|
-
@testing_object.can.size.should == 2
|
121
|
-
@testing_object.can.should include(true.to_s.to_sym)
|
122
|
-
end
|
123
|
-
it "should accept an already added permission and change nothing" do
|
124
|
-
@testing_object.can=(:role1)
|
125
|
-
@testing_object.can.size.should == 1
|
126
|
-
@testing_object.can.should include(:role1.to_s.to_sym)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#can_not" do
|
131
|
-
it "should accept an empty list" do
|
132
|
-
@testing_object.can_not([])
|
133
|
-
@testing_object.can.should_not be_empty
|
134
|
-
end
|
135
|
-
it "should accept being given a list with items and treat them as strings" do
|
136
|
-
@testing_object.can_not([:role1])
|
137
|
-
@testing_object.can.should be_empty
|
138
|
-
@testing_object.can.should_not include(:role1)
|
139
|
-
end
|
140
|
-
it "should treat any object as its string representation" do
|
141
|
-
old_size = @testing_object.can.size
|
142
|
-
@testing_object.can=(true)
|
143
|
-
@testing_object.can_not(true)
|
144
|
-
@testing_object.can.size.should == old_size
|
145
|
-
@testing_object.can.should_not include(true.to_s.to_sym)
|
146
|
-
end
|
147
|
-
it "should accept a role not added and change nothing" do
|
148
|
-
@testing_object.can_not(true)
|
149
|
-
@testing_object.can.should_not be_empty
|
150
|
-
@testing_object.can.should include(:role1)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "with no roles" do
|
156
|
-
it "#roles should return an empty list" do
|
157
|
-
@testing_object.roles.should be_empty
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#has_role?" do
|
161
|
-
it "should return false with a symbol" do
|
162
|
-
@testing_object.has_role?(:do_something).should be_false
|
163
|
-
end
|
164
|
-
it "should return false with a string" do
|
165
|
-
@testing_object.has_role?('do_something').should be_false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "#add_roles" do
|
170
|
-
it "should accept an empty list" do
|
171
|
-
@testing_object.add_roles([])
|
172
|
-
@testing_object.roles.should be_empty
|
173
|
-
end
|
174
|
-
it "should accept being given a list with items and treat them as strings" do
|
175
|
-
@testing_object.add_roles([true])
|
176
|
-
@testing_object.roles.size.should == 1
|
177
|
-
@testing_object.roles.first.should == true.to_s.to_sym
|
178
|
-
end
|
179
|
-
it "should treat any object as its string representation" do
|
180
|
-
@testing_object.add_roles(true)
|
181
|
-
@testing_object.roles.size.should == 1
|
182
|
-
@testing_object.roles.first.should == true.to_s.to_sym
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "with roles" do
|
188
|
-
before(:each) do
|
189
|
-
@testing_object.add_roles(:role1)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "#roles should return a filled list" do
|
193
|
-
@testing_object.roles.size.should == 1
|
194
|
-
end
|
195
|
-
|
196
|
-
describe "#has_role?" do
|
197
|
-
describe "when the role isnt in the list" do
|
198
|
-
it "should return false with a symbol" do
|
199
|
-
@testing_object.has_role?(:do_something).should be_false
|
200
|
-
end
|
201
|
-
it "should return false with a string" do
|
202
|
-
@testing_object.has_role?('do_something').should be_false
|
203
|
-
end
|
204
|
-
end
|
205
|
-
describe "when the role is in the list" do
|
206
|
-
it "should return true with a symbol" do
|
207
|
-
@testing_object.has_role?(:role1).should be_true
|
208
|
-
end
|
209
|
-
it "should return true with a string" do
|
210
|
-
@testing_object.has_role?('role1').should be_true
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "#add_roles" do
|
216
|
-
it "should accept an empty list" do
|
217
|
-
@testing_object.add_roles([])
|
218
|
-
@testing_object.roles.should_not be_empty
|
219
|
-
end
|
220
|
-
it "should accept being given a list with items and treat them as strings" do
|
221
|
-
@testing_object.add_roles([true])
|
222
|
-
@testing_object.roles.size.should == 2
|
223
|
-
@testing_object.roles.should include(true.to_s.to_sym)
|
224
|
-
end
|
225
|
-
it "should treat any object as its string representation" do
|
226
|
-
@testing_object.add_roles(true)
|
227
|
-
@testing_object.roles.size.should == 2
|
228
|
-
@testing_object.roles.should include(true.to_s.to_sym)
|
229
|
-
end
|
230
|
-
it "should accept an already added role and change nothing" do
|
231
|
-
@testing_object.add_roles(:role1)
|
232
|
-
@testing_object.roles.size.should == 1
|
233
|
-
@testing_object.roles.should include(:role1.to_s.to_sym)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "#remove_roles" do
|
238
|
-
it "should accept an empty list" do
|
239
|
-
@testing_object.remove_roles([])
|
240
|
-
@testing_object.roles.should_not be_empty
|
241
|
-
end
|
242
|
-
it "should accept being given a list with items and treat them as strings" do
|
243
|
-
@testing_object.remove_roles([:role1])
|
244
|
-
@testing_object.roles.should be_empty
|
245
|
-
@testing_object.roles.should_not include(:role1)
|
246
|
-
end
|
247
|
-
it "should treat any object as its string representation" do
|
248
|
-
old_size = @testing_object.roles.size
|
249
|
-
@testing_object.add_roles(true)
|
250
|
-
@testing_object.remove_roles(true)
|
251
|
-
@testing_object.roles.size.should == old_size
|
252
|
-
@testing_object.roles.should_not include(true.to_s.to_sym)
|
253
|
-
end
|
254
|
-
it "should accept a role not added and change nothing" do
|
255
|
-
@testing_object.remove_roles(true)
|
256
|
-
@testing_object.roles.should_not be_empty
|
257
|
-
@testing_object.roles.should include(:role1)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "#can?" do
|
262
|
-
it "should return false" do
|
263
|
-
@testing_object.can?(:do_stuff).should be_false
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe "that have permissions" do
|
268
|
-
before(:each) do
|
269
|
-
role = CanHasPermission::Role.find(:first)
|
270
|
-
role.can=(:do_stuff)
|
271
|
-
end
|
272
|
-
describe "#can?" do
|
273
|
-
it "should return true when given a permission the role has" do
|
274
|
-
@testing_object.can?(:do_stuff).should be_true
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|