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
@@ -1,74 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
|
3
|
-
describe CanHasPermission::HasPermission do
|
4
|
-
it "should be valid with a permission_id, type and model_id" do
|
5
|
-
has_permission = CanHasPermission::HasPermission.new(:permission_id => 1, :model => 'Bingo', :model_id => 1)
|
6
|
-
has_permission.should be_valid
|
7
|
-
end
|
8
|
-
it "should not be valid without a permission_id" do
|
9
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :model_id => 1)
|
10
|
-
has_permission.should_not be_valid
|
11
|
-
end
|
12
|
-
it "should not be valid without a type" do
|
13
|
-
has_permission = CanHasPermission::HasPermission.new(:permission_id => 1, :model_id => 1)
|
14
|
-
has_permission.should_not be_valid
|
15
|
-
end
|
16
|
-
it "should not be valid without a model_id" do
|
17
|
-
has_permission = CanHasPermission::HasPermission.new(:permission_id => 1, :model => 'Type')
|
18
|
-
has_permission.should_not be_valid
|
19
|
-
end
|
20
|
-
it "should not be valid when it has a permission_id, model_id and type that already exist" do
|
21
|
-
name = 'the same'
|
22
|
-
has_permission1 = CanHasPermission::HasPermission.create!(:permission_id => 1, :model => 'Bingo', :model_id => 1)
|
23
|
-
has_permission2 = CanHasPermission::HasPermission.new(:permission_id => 1, :model => 'Bingo', :model_id => 1)
|
24
|
-
has_permission1.should be_valid
|
25
|
-
has_permission1.id.should_not be_nil
|
26
|
-
has_permission2.should_not be_valid
|
27
|
-
end
|
28
|
-
describe "when a permission exists" do
|
29
|
-
before(:each) do
|
30
|
-
CanHasPermission::Permission.create!(:name => 'this_exists')
|
31
|
-
@permission_count = CanHasPermission::Permission.count
|
32
|
-
end
|
33
|
-
it "should be valid without a permission_id but with the permission name" do
|
34
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :permission => 'this_exists', :model_id => 1)
|
35
|
-
has_permission.should be_valid
|
36
|
-
end
|
37
|
-
it "should be valid without a permission_id but with the permission name as a symbol" do
|
38
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :permission => :this_exists, :model_id => 1)
|
39
|
-
has_permission.should be_valid
|
40
|
-
end
|
41
|
-
it "should not create another permission" do
|
42
|
-
CanHasPermission::HasPermission.create!(:model => 'Bingo', :permission => 'this_exists', :model_id => 1)
|
43
|
-
CanHasPermission::Permission.count.should == @permission_count
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "when a permission does not exist" do
|
48
|
-
before(:each) do
|
49
|
-
CanHasPermission::Permission.count.should ==0
|
50
|
-
end
|
51
|
-
it "should be valid without a permission_id but with the permission name" do
|
52
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :permission => 'this_exists', :model_id => 1)
|
53
|
-
has_permission.should be_valid
|
54
|
-
end
|
55
|
-
it "should be valid without a permission_id but with the permission name as a symbol" do
|
56
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :permission => :this_exists, :model_id => 1)
|
57
|
-
has_permission.should be_valid
|
58
|
-
end
|
59
|
-
it "should create the permission" do
|
60
|
-
has_permission = CanHasPermission::HasPermission.create!(:model => 'Bingo2', :permission => 'this_exists', :model_id => 1)
|
61
|
-
CanHasPermission::Permission.count.should == 1
|
62
|
-
CanHasPermission::Permission.find_by_name('this_exists').should_not be_nil
|
63
|
-
end
|
64
|
-
it "should create the permission with symbol" do
|
65
|
-
has_permission = CanHasPermission::HasPermission.create!(:model => 'Bingo2', :permission => :this_exists, :model_id => 1)
|
66
|
-
CanHasPermission::Permission.count.should == 1
|
67
|
-
CanHasPermission::Permission.find_by_name('this_exists').should_not be_nil
|
68
|
-
end
|
69
|
-
it "should be invalid with a blank permission" do
|
70
|
-
has_permission = CanHasPermission::HasPermission.new(:model => 'Bingo', :permission => '', :model_id => 1)
|
71
|
-
has_permission.should be_invalid
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/spec/tests/has_role_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
|
3
|
-
describe CanHasPermission::HasRole do
|
4
|
-
it "should be valid with a role_id, type and model_id" do
|
5
|
-
has_role = CanHasPermission::HasRole.new(:role_id => 1, :model => 'Bingo', :model_id => 1)
|
6
|
-
has_role.should be_valid
|
7
|
-
end
|
8
|
-
it "should not be valid without a role_id" do
|
9
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :model_id => 1)
|
10
|
-
has_role.should_not be_valid
|
11
|
-
end
|
12
|
-
it "should not be valid without a type" do
|
13
|
-
has_role = CanHasPermission::HasRole.new(:role_id => 1, :model_id => 1)
|
14
|
-
has_role.should_not be_valid
|
15
|
-
end
|
16
|
-
it "should not be valid without a model_id" do
|
17
|
-
has_role = CanHasPermission::HasRole.new(:role_id => 1, :model => 'Type')
|
18
|
-
has_role.should_not be_valid
|
19
|
-
end
|
20
|
-
it "should not be valid when it has a role_id, model_id and type that already exist" do
|
21
|
-
name = 'the same'
|
22
|
-
has_role1 = CanHasPermission::HasRole.create!(:role_id => 1, :model => 'Bingo', :model_id => 1)
|
23
|
-
has_role2 = CanHasPermission::HasRole.new(:role_id => 1, :model => 'Bingo', :model_id => 1)
|
24
|
-
has_role1.should be_valid
|
25
|
-
has_role1.id.should_not be_nil
|
26
|
-
has_role2.should_not be_valid
|
27
|
-
end
|
28
|
-
describe "when a role exists" do
|
29
|
-
before(:each) do
|
30
|
-
CanHasPermission::Role.create!(:name => 'this_exists')
|
31
|
-
@role_count = CanHasPermission::Role.count
|
32
|
-
end
|
33
|
-
it "should be valid without a role_id but with the role name" do
|
34
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :role => 'this_exists', :model_id => 1)
|
35
|
-
has_role.should be_valid
|
36
|
-
end
|
37
|
-
it "should be valid without a role_id but with the role name as a symbol" do
|
38
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :role => :this_exists, :model_id => 1)
|
39
|
-
has_role.should be_valid
|
40
|
-
end
|
41
|
-
it "should not create another role" do
|
42
|
-
CanHasPermission::HasRole.create!(:model => 'Bingo', :role => 'this_exists', :model_id => 1)
|
43
|
-
CanHasPermission::Role.count.should == @role_count
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "when a role does not exist" do
|
48
|
-
before(:each) do
|
49
|
-
CanHasPermission::Role.count.should ==0
|
50
|
-
end
|
51
|
-
it "should be valid without a role_id but with the role name" do
|
52
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :role => 'this_exists', :model_id => 1)
|
53
|
-
has_role.should be_valid
|
54
|
-
end
|
55
|
-
it "should be valid without a role_id but with the role name as a symbol" do
|
56
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :role => :this_exists, :model_id => 1)
|
57
|
-
has_role.should be_valid
|
58
|
-
end
|
59
|
-
it "should create the role" do
|
60
|
-
has_role = CanHasPermission::HasRole.create!(:model => 'Bingo2', :role => 'this_exists', :model_id => 1)
|
61
|
-
CanHasPermission::Role.count.should == 1
|
62
|
-
CanHasPermission::Role.find_by_name('this_exists').should_not be_nil
|
63
|
-
end
|
64
|
-
it "should create the role with symbol" do
|
65
|
-
has_role = CanHasPermission::HasRole.create!(:model => 'Bingo2', :role => :this_exists, :model_id => 1)
|
66
|
-
CanHasPermission::Role.count.should == 1
|
67
|
-
CanHasPermission::Role.find_by_name('this_exists').should_not be_nil
|
68
|
-
end
|
69
|
-
it "should be invalid with a blank role" do
|
70
|
-
has_role = CanHasPermission::HasRole.new(:model => 'Bingo', :role => '', :model_id => 1)
|
71
|
-
has_role.should be_invalid
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|