rolify 3.0.0 → 3.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/CHANGELOG.rdoc +13 -1
- data/{README.rdoc → README.md} +69 -41
- data/lib/generators/rolify/role/role_generator.rb +2 -2
- data/lib/generators/rolify/role/templates/initializer.rb +3 -3
- data/lib/generators/rolify/role/templates/role-mongoid.rb +9 -0
- data/lib/rolify.rb +10 -7
- data/lib/rolify/adapters/active_record/resource_adapter.rb +17 -0
- data/lib/rolify/adapters/{active_record.rb → active_record/role_adapter.rb} +12 -21
- data/lib/rolify/adapters/base.rb +24 -22
- data/lib/rolify/adapters/mongoid/resource_adapter.rb +23 -0
- data/lib/rolify/adapters/{mongoid.rb → mongoid/role_adapter.rb} +11 -31
- data/lib/rolify/configure.rb +5 -4
- data/lib/rolify/dynamic.rb +1 -1
- data/lib/rolify/role.rb +11 -7
- data/lib/rolify/utils.rb +10 -0
- data/lib/rolify/version.rb +1 -1
- data/rolify.gemspec +1 -1
- data/spec/generators/rolify/role/role_generator_spec.rb +41 -19
- data/spec/rolify/config_spec.rb +13 -11
- data/spec/rolify/resource_spec.rb +28 -29
- data/spec/rolify/shared_contexts.rb +17 -17
- data/spec/rolify/shared_examples/{shared_examples_for_has_role_setter.rb → shared_examples_for_add_role.rb} +16 -16
- data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +6 -6
- data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +6 -6
- data/spec/rolify/shared_examples/{shared_examples_for_has_role_getter.rb → shared_examples_for_has_role.rb} +0 -0
- data/spec/rolify/shared_examples/{shared_examples_for_has_no_role.rb → shared_examples_for_remove_role.rb} +37 -13
- data/spec/rolify/shared_examples/shared_examples_for_roles.rb +18 -20
- data/spec/spec_helper.rb +0 -4
- data/spec/support/adapters/active_record.rb +2 -0
- data/spec/support/adapters/mongoid.rb +2 -0
- metadata +33 -31
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rolify/adapters/base'
|
2
|
+
|
3
|
+
module Rolify
|
4
|
+
module Adapter
|
5
|
+
class ResourceAdapter < ResourceAdapterBase
|
6
|
+
def resources_find(roles_table, relation, role_name)
|
7
|
+
roles = roles_table.classify.constantize.where(:name => role_name, :resource_type => relation.to_s)
|
8
|
+
resources = []
|
9
|
+
roles.each do |role|
|
10
|
+
return relation.all if role.resource_id.nil?
|
11
|
+
resources << role.resource
|
12
|
+
end
|
13
|
+
resources
|
14
|
+
end
|
15
|
+
|
16
|
+
def in(resources, roles)
|
17
|
+
return [] if resources.empty? || roles.empty?
|
18
|
+
resources.delete_if { |resource| (resource.applied_roles & roles).empty? }
|
19
|
+
resources
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'rolify/adapters/base'
|
2
2
|
|
3
3
|
module Rolify
|
4
|
-
module Adapter
|
5
|
-
class
|
6
|
-
def
|
7
|
-
query = build_query(role_name, resource)
|
8
|
-
query.each do |condition|
|
9
|
-
criteria = relation.where(condition)
|
10
|
-
return criteria.all if !criteria.empty?
|
11
|
-
end
|
12
|
-
[]
|
13
|
-
end
|
14
|
-
|
15
|
-
def where(relation, args)
|
4
|
+
module Adapter
|
5
|
+
class RoleAdapter < RoleAdapterBase
|
6
|
+
def where(relation, *args)
|
16
7
|
conditions = build_conditions(relation, args)
|
17
8
|
relation.any_of(*conditions)
|
18
9
|
end
|
@@ -28,26 +19,15 @@ module Rolify
|
|
28
19
|
end
|
29
20
|
|
30
21
|
def remove(relation, role_name, resource = nil)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
relation.where(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
resources = []
|
40
|
-
roles.each do |role|
|
41
|
-
return relation.all if role.resource_id.nil?
|
42
|
-
resources << role.resource
|
22
|
+
roles = { :name => role_name }
|
23
|
+
roles.merge!({:resource_type => (resource.is_a?(Class) ? resource.to_s : resource.class.name)}) if resource
|
24
|
+
roles.merge!({ :resource_id => resource.id }) if resource && !resource.is_a?(Class)
|
25
|
+
roles_to_remove = relation.roles.where(roles)
|
26
|
+
roles_to_remove.each do |role|
|
27
|
+
relation.roles.delete(role)
|
28
|
+
role.reload
|
29
|
+
role.destroy if role.send(user_class.to_s.tableize.to_sym).empty?
|
43
30
|
end
|
44
|
-
resources
|
45
|
-
end
|
46
|
-
|
47
|
-
def in(resources, roles)
|
48
|
-
return [] if resources.empty? || roles.empty?
|
49
|
-
resources.delete_if { |resource| (resource.applied_roles && roles).empty? }
|
50
|
-
resources
|
51
31
|
end
|
52
32
|
|
53
33
|
def exists?(relation, column)
|
data/lib/rolify/configure.rb
CHANGED
@@ -8,7 +8,7 @@ module Rolify
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def dynamic_shortcuts
|
11
|
-
@@dynamic_shortcuts
|
11
|
+
@@dynamic_shortcuts
|
12
12
|
end
|
13
13
|
|
14
14
|
def dynamic_shortcuts=(is_dynamic)
|
@@ -32,9 +32,10 @@ module Rolify
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def use_defaults
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
configure do |config|
|
36
|
+
config.dynamic_shortcuts = false
|
37
|
+
config.orm = "active_record"
|
38
|
+
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/rolify/dynamic.rb
CHANGED
@@ -14,7 +14,7 @@ module Rolify
|
|
14
14
|
|
15
15
|
define_method("is_#{role_name}_of?".to_sym) do |arg|
|
16
16
|
has_role?("#{role_name}", arg)
|
17
|
-
end if !method_defined?("is_#{role_name}_of?".to_sym) &&
|
17
|
+
end if !method_defined?("is_#{role_name}_of?".to_sym) && resource
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/rolify/role.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Rolify
|
2
2
|
module Role
|
3
|
-
|
3
|
+
extend Utils
|
4
|
+
|
5
|
+
def add_role(role_name, resource = nil)
|
4
6
|
role = self.class.adapter.find_or_create_by(role_name,
|
5
7
|
(resource.is_a?(Class) ? resource.to_s : resource.class.name if resource),
|
6
8
|
(resource.id if resource && !resource.is_a?(Class)))
|
@@ -11,10 +13,11 @@ module Rolify
|
|
11
13
|
end
|
12
14
|
role
|
13
15
|
end
|
14
|
-
alias_method :grant, :
|
16
|
+
alias_method :grant, :add_role
|
17
|
+
deprecate :has_role, :add_role
|
15
18
|
|
16
19
|
def has_role?(role_name, resource = nil)
|
17
|
-
self.class.adapter.
|
20
|
+
self.class.adapter.where(self.roles, :name => role_name, :resource => resource).size > 0
|
18
21
|
end
|
19
22
|
|
20
23
|
def has_all_roles?(*args)
|
@@ -31,13 +34,14 @@ module Rolify
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def has_any_role?(*args)
|
34
|
-
self.class.adapter.where(self.roles, args).size > 0
|
37
|
+
self.class.adapter.where(self.roles, *args).size > 0
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
self.class.adapter.remove(self
|
40
|
+
def remove_role(role_name, resource = nil)
|
41
|
+
self.class.adapter.remove(self, role_name, resource)
|
39
42
|
end
|
40
|
-
alias_method :revoke, :
|
43
|
+
alias_method :revoke, :remove_role
|
44
|
+
deprecate :has_no_role, :remove_role
|
41
45
|
|
42
46
|
def roles_name
|
43
47
|
self.roles.select(:name).map { |r| r.name }
|
data/lib/rolify/utils.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Rolify
|
2
|
+
module Utils
|
3
|
+
def deprecate(old_method, new_method)
|
4
|
+
define_method(old_method) do |*args|
|
5
|
+
warn "[DEPRECATION] #{caller.first}: `#{old_method}` is deprecated. Please use `#{new_method}` instead."
|
6
|
+
send(new_method, *args)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/rolify/version.rb
CHANGED
data/rolify.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["f.monbillard@gmail.com"]
|
11
11
|
s.homepage = "https://github.com/EppO/rolify"
|
12
12
|
s.summary = %q{Roles library with resource scoping}
|
13
|
-
s.description = %q{Very simple Roles library without any authorization enforcement
|
13
|
+
s.description = %q{Very simple Roles library without any authorization enforcement supporting scope on resource objects (instance or class)}
|
14
14
|
|
15
15
|
s.rubyforge_project = s.name
|
16
16
|
|
@@ -31,7 +31,9 @@ describe Rolify::Generators::RoleGenerator do
|
|
31
31
|
describe 'config/initializers/rolify.rb' do
|
32
32
|
subject { file('config/initializers/rolify.rb') }
|
33
33
|
it { should exist }
|
34
|
-
it { should contain "
|
34
|
+
it { should contain "Rolify.configure do |config|"}
|
35
|
+
it { should contain "# config.use_dynamic_shortcuts" }
|
36
|
+
it { should contain "# config.use_mongoid" }
|
35
37
|
end
|
36
38
|
|
37
39
|
describe 'app/models/role.rb' do
|
@@ -48,20 +50,21 @@ describe Rolify::Generators::RoleGenerator do
|
|
48
50
|
end
|
49
51
|
|
50
52
|
describe 'migration file' do
|
51
|
-
subject {
|
53
|
+
subject { migration_file('db/migrate/rolify_create_roles.rb') }
|
52
54
|
|
53
|
-
# should be_a_migration - verifies the file exists with a migration timestamp as part of the filename
|
54
55
|
it { should be_a_migration }
|
56
|
+
it { should contain "create_table(:roles) do" }
|
57
|
+
it { should contain "create_table(:users_roles, :id => false) do" }
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
describe 'specifying user and role names' do
|
59
|
-
before(:all) { arguments %w(
|
62
|
+
before(:all) { arguments %w(AdminRole AdminUser) }
|
60
63
|
|
61
64
|
before {
|
62
65
|
capture(:stdout) {
|
63
|
-
generator.create_file "app/models/
|
64
|
-
"class
|
66
|
+
generator.create_file "app/models/admin_user.rb" do
|
67
|
+
"class AdminUser < ActiveRecord::Base\nend"
|
65
68
|
end
|
66
69
|
}
|
67
70
|
run_generator
|
@@ -69,29 +72,34 @@ describe Rolify::Generators::RoleGenerator do
|
|
69
72
|
|
70
73
|
describe 'config/initializers/rolify.rb' do
|
71
74
|
subject { file('config/initializers/rolify.rb') }
|
75
|
+
|
72
76
|
it { should exist }
|
73
|
-
it { should contain "
|
77
|
+
it { should contain "Rolify.configure do |config|"}
|
78
|
+
it { should contain "# config.use_dynamic_shortcuts" }
|
79
|
+
it { should contain "# config.use_mongoid" }
|
74
80
|
end
|
75
81
|
|
76
82
|
describe 'app/models/rank.rb' do
|
77
|
-
subject { file('app/models/
|
83
|
+
subject { file('app/models/admin_role.rb') }
|
84
|
+
|
78
85
|
it { should exist }
|
79
|
-
it { should contain "class
|
80
|
-
it { should contain "has_and_belongs_to_many :
|
86
|
+
it { should contain "class AdminRole < ActiveRecord::Base" }
|
87
|
+
it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
|
81
88
|
it { should contain "belongs_to :resource, :polymorphic => true" }
|
82
89
|
end
|
83
90
|
|
84
91
|
describe 'app/models/client.rb' do
|
85
|
-
subject { file('app/models/
|
92
|
+
subject { file('app/models/admin_user.rb') }
|
93
|
+
|
86
94
|
it { should contain "rolify" }
|
87
95
|
end
|
88
96
|
|
89
97
|
describe 'migration file' do
|
90
|
-
subject {
|
98
|
+
subject { migration_file('db/migrate/rolify_create_admin_roles.rb') }
|
91
99
|
|
92
|
-
# should be_a_migration - verifies the file exists with a migration timestamp as part of the filename
|
93
100
|
it { should be_a_migration }
|
94
|
-
|
101
|
+
it { should contain "create_table(:admin_roles)" }
|
102
|
+
it { should contain "create_table(:admin_users_admin_roles, :id => false) do" }
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
@@ -110,7 +118,9 @@ describe Rolify::Generators::RoleGenerator do
|
|
110
118
|
describe 'config/initializers/rolify.rb' do
|
111
119
|
subject { file('config/initializers/rolify.rb') }
|
112
120
|
it { should exist }
|
113
|
-
it {
|
121
|
+
it { should contain "Rolify.configure do |config|"}
|
122
|
+
it { should_not contain "# config.use_dynamic_shortcuts" }
|
123
|
+
it { should contain "# config.use_mongoid" }
|
114
124
|
end
|
115
125
|
|
116
126
|
describe 'app/models/role.rb' do
|
@@ -127,10 +137,11 @@ describe Rolify::Generators::RoleGenerator do
|
|
127
137
|
end
|
128
138
|
|
129
139
|
describe 'migration file' do
|
130
|
-
subject {
|
140
|
+
subject { migration_file('db/migrate/rolify_create_roles.rb') }
|
131
141
|
|
132
|
-
# should be_a_migration - verifies the file exists with a migration timestamp as part of the filename
|
133
142
|
it { should be_a_migration }
|
143
|
+
it { should contain "create_table(:roles) do" }
|
144
|
+
it { should contain "create_table(:users_roles, :id => false) do" }
|
134
145
|
end
|
135
146
|
end
|
136
147
|
|
@@ -155,8 +166,9 @@ describe Rolify::Generators::RoleGenerator do
|
|
155
166
|
describe 'config/initializers/rolify.rb' do
|
156
167
|
subject { file('config/initializers/rolify.rb') }
|
157
168
|
it { should exist }
|
158
|
-
it {
|
159
|
-
it {
|
169
|
+
it { should contain "Rolify.configure do |config|"}
|
170
|
+
it { should_not contain "# config.use_mongoid" }
|
171
|
+
it { should contain "# config.use_dynamic_shortcuts" }
|
160
172
|
end
|
161
173
|
|
162
174
|
describe 'app/models/role.rb' do
|
@@ -165,6 +177,16 @@ describe Rolify::Generators::RoleGenerator do
|
|
165
177
|
it { should contain "class Role\n" }
|
166
178
|
it { should contain "has_and_belongs_to_many :users\n" }
|
167
179
|
it { should contain "belongs_to :resource, :polymorphic => true" }
|
180
|
+
it { should contain "field :name, :type => String" }
|
181
|
+
it { should contain "index :name, unique: true" }
|
182
|
+
it { should contain " index(\n"
|
183
|
+
" [\n"
|
184
|
+
" [:name, Mongo::ASCENDING],\n"
|
185
|
+
" [:resource_type, Mongo::ASCENDING],\n"
|
186
|
+
" [:resource_id, Mongo::ASCENDING]\n"
|
187
|
+
" ],\n"
|
188
|
+
" unique: true\n"
|
189
|
+
" )\n" }
|
168
190
|
end
|
169
191
|
|
170
192
|
describe 'app/models/user.rb' do
|
data/spec/rolify/config_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "active_record"
|
3
|
+
require "mongoid"
|
2
4
|
|
3
5
|
class ARUser < ActiveRecord::Base
|
4
6
|
extend Rolify
|
@@ -45,7 +47,7 @@ describe Rolify do
|
|
45
47
|
|
46
48
|
subject { ARUser }
|
47
49
|
|
48
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
50
|
+
its("adapter.class") { should be(Rolify::Adapter::RoleAdapter) }
|
49
51
|
end
|
50
52
|
|
51
53
|
context "on the Forum class" do
|
@@ -55,7 +57,7 @@ describe Rolify do
|
|
55
57
|
|
56
58
|
subject { Forum }
|
57
59
|
|
58
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
60
|
+
its("adapter.class") { should be(Rolify::Adapter::ResourceAdapter) }
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
@@ -76,7 +78,7 @@ describe Rolify do
|
|
76
78
|
|
77
79
|
subject { MUser }
|
78
80
|
|
79
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
81
|
+
its("adapter.class") { should be(Rolify::Adapter::RoleAdapter) }
|
80
82
|
end
|
81
83
|
|
82
84
|
context "on the Forum class" do
|
@@ -86,7 +88,7 @@ describe Rolify do
|
|
86
88
|
|
87
89
|
subject { Forum }
|
88
90
|
|
89
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
91
|
+
its("adapter.class") { should be(Rolify::Adapter::ResourceAdapter) }
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
@@ -106,7 +108,7 @@ describe Rolify do
|
|
106
108
|
|
107
109
|
subject { MUser }
|
108
110
|
|
109
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
111
|
+
its("adapter.class") { should be(Rolify::Adapter::RoleAdapter) }
|
110
112
|
end
|
111
113
|
|
112
114
|
context "on the Forum class" do
|
@@ -116,7 +118,7 @@ describe Rolify do
|
|
116
118
|
|
117
119
|
subject { Forum }
|
118
120
|
|
119
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
121
|
+
its("adapter.class") { should be(Rolify::Adapter::ResourceAdapter) }
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -154,9 +156,9 @@ describe Rolify do
|
|
154
156
|
|
155
157
|
describe :configure do
|
156
158
|
before do
|
157
|
-
Rolify.configure do |
|
158
|
-
|
159
|
-
|
159
|
+
Rolify.configure do |config|
|
160
|
+
config.dynamic_shortcuts = true
|
161
|
+
config.orm = "mongoid"
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
@@ -172,7 +174,7 @@ describe Rolify do
|
|
172
174
|
|
173
175
|
it { should satisfy { |u| u.include? Rolify::Role }}
|
174
176
|
it { should satisfy { |u| u.singleton_class.include? Rolify::Dynamic } }
|
175
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
177
|
+
its("adapter.class") { should be(Rolify::Adapter::RoleAdapter) }
|
176
178
|
end
|
177
179
|
|
178
180
|
context "on the Forum class" do
|
@@ -183,7 +185,7 @@ describe Rolify do
|
|
183
185
|
subject { Forum }
|
184
186
|
|
185
187
|
it { should satisfy { |u| u.include? Rolify::Resource }}
|
186
|
-
its("adapter.class") { should be(Rolify::Adapter::
|
188
|
+
its("adapter.class") { should be(Rolify::Adapter::ResourceAdapter) }
|
187
189
|
end
|
188
190
|
end
|
189
191
|
end
|
@@ -3,7 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe Rolify::Resource do
|
4
4
|
before(:all) do
|
5
5
|
reset_defaults
|
6
|
-
#Role.destroy_all
|
7
6
|
User.rolify :role_cname => "Role"
|
8
7
|
Forum.resourcify :role_cname => "Role"
|
9
8
|
Group.resourcify :role_cname => "Role"
|
@@ -14,11 +13,11 @@ describe Rolify::Resource do
|
|
14
13
|
let(:tourist) { User.last }
|
15
14
|
|
16
15
|
# roles
|
17
|
-
let!(:forum_role) { admin.
|
18
|
-
let!(:godfather_role) { admin.
|
19
|
-
let!(:group_role) { admin.
|
20
|
-
let!(:tourist_role) { tourist.
|
21
|
-
let!(:sneaky_role) { tourist.
|
16
|
+
let!(:forum_role) { admin.add_role(:forum, Forum.first) }
|
17
|
+
let!(:godfather_role) { admin.add_role(:godfather, Forum) }
|
18
|
+
let!(:group_role) { admin.add_role(:group, Group.last) }
|
19
|
+
let!(:tourist_role) { tourist.add_role(:forum, Forum.last) }
|
20
|
+
let!(:sneaky_role) { tourist.add_role(:group, Forum.first) }
|
22
21
|
|
23
22
|
describe ".with_roles" do
|
24
23
|
subject { Group }
|
@@ -31,10 +30,10 @@ describe Rolify::Resource do
|
|
31
30
|
subject { Forum }
|
32
31
|
|
33
32
|
it "should include Forum instances with forum role" do
|
34
|
-
subject.with_role(
|
33
|
+
subject.with_role(:forum).should include(Forum.first, Forum.last)
|
35
34
|
end
|
36
35
|
it "should include Forum instances with godfather role" do
|
37
|
-
subject.with_role(
|
36
|
+
subject.with_role(:godfather).should eq(Forum.all)
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
@@ -42,7 +41,7 @@ describe Rolify::Resource do
|
|
42
41
|
subject { Group }
|
43
42
|
|
44
43
|
it "should include Group instances with group role" do
|
45
|
-
subject.with_role(
|
44
|
+
subject.with_role(:group).should include(Group.last)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
@@ -53,27 +52,27 @@ describe Rolify::Resource do
|
|
53
52
|
subject { Forum }
|
54
53
|
|
55
54
|
it "should get all Forum instances binded to the forum role and the admin user" do
|
56
|
-
subject.with_role(
|
55
|
+
subject.with_role(:forum, admin).should include(Forum.first)
|
57
56
|
end
|
58
57
|
|
59
58
|
it "should get all Forum instances binded to the forum role and the tourist user" do
|
60
|
-
subject.with_role(
|
59
|
+
subject.with_role(:forum, tourist).should include(Forum.last)
|
61
60
|
end
|
62
61
|
|
63
62
|
it "should get all Forum instances binded to the godfather role and the admin user" do
|
64
|
-
subject.with_role(
|
63
|
+
subject.with_role(:godfather, admin).should == Forum.all
|
65
64
|
end
|
66
65
|
|
67
66
|
it "should get all Forum instances binded to the godfather role and the tourist user" do
|
68
|
-
subject.with_role(
|
67
|
+
subject.with_role(:godfather, tourist).should be_empty
|
69
68
|
end
|
70
69
|
|
71
70
|
it "should get Forum instances binded to the group role and the tourist user" do
|
72
|
-
subject.with_role(
|
71
|
+
subject.with_role(:group, tourist).should include(Forum.first)
|
73
72
|
end
|
74
73
|
|
75
74
|
it "should not get Forum instances not binded to the group role and the tourist user" do
|
76
|
-
subject.with_role(
|
75
|
+
subject.with_role(:group, tourist).should_not include(Forum.last)
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
@@ -81,11 +80,11 @@ describe Rolify::Resource do
|
|
81
80
|
subject { Group }
|
82
81
|
|
83
82
|
it "should get all resources binded to the group role and the admin user" do
|
84
|
-
subject.with_role(
|
83
|
+
subject.with_role(:group, admin).should include(Group.last)
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should not get resources not binded to the group role and the admin user" do
|
88
|
-
subject.with_role(
|
87
|
+
subject.with_role(:group, admin).should_not include(Group.first)
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|
@@ -146,31 +145,31 @@ describe Rolify::Resource do
|
|
146
145
|
|
147
146
|
context "without using a user parameter" do
|
148
147
|
it "should get all roles binded to a Forum class or instance and forum role name" do
|
149
|
-
subject.find_roles(
|
148
|
+
subject.find_roles(:forum).should include(forum_role, tourist_role)
|
150
149
|
end
|
151
150
|
|
152
151
|
it "should not get roles not binded to a Forum class or instance and forum role name" do
|
153
|
-
subject.find_roles(
|
152
|
+
subject.find_roles(:forum).should_not include(godfather_role, sneaky_role, group_role)
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
157
156
|
context "using a user parameter" do
|
158
157
|
it "should get all roles binded to any resource" do
|
159
|
-
subject.find_roles(
|
158
|
+
subject.find_roles(:forum, admin).should include(forum_role)
|
160
159
|
end
|
161
160
|
|
162
161
|
it "should not get roles not binded to the admin user and forum role name" do
|
163
|
-
subject.find_roles(
|
162
|
+
subject.find_roles(:forum, admin).should_not include(godfather_role, tourist_role, sneaky_role, group_role)
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
167
166
|
context "using :any parameter" do
|
168
167
|
it "should get all roles binded to any resource with forum role name" do
|
169
|
-
subject.find_roles(
|
168
|
+
subject.find_roles(:forum, :any).should include(forum_role, tourist_role)
|
170
169
|
end
|
171
170
|
|
172
171
|
it "should not get roles not binded to a resource with forum role name" do
|
173
|
-
subject.find_roles(
|
172
|
+
subject.find_roles(:forum, :any).should_not include(godfather_role, sneaky_role, group_role)
|
174
173
|
end
|
175
174
|
end
|
176
175
|
end
|
@@ -180,31 +179,31 @@ describe Rolify::Resource do
|
|
180
179
|
|
181
180
|
context "without using a user parameter" do
|
182
181
|
it "should get all roles binded to a Group class or instance and group role name" do
|
183
|
-
subject.find_roles(
|
182
|
+
subject.find_roles(:group).should include(group_role)
|
184
183
|
end
|
185
184
|
|
186
185
|
it "should not get roles not binded to a Forum class or instance and forum role name" do
|
187
|
-
subject.find_roles(
|
186
|
+
subject.find_roles(:group).should_not include(tourist_role, godfather_role, sneaky_role, forum_role)
|
188
187
|
end
|
189
188
|
end
|
190
189
|
|
191
190
|
context "using a user parameter" do
|
192
191
|
it "should get all roles binded to any resource" do
|
193
|
-
subject.find_roles(
|
192
|
+
subject.find_roles(:group, admin).should include(group_role)
|
194
193
|
end
|
195
194
|
|
196
195
|
it "should not get roles not binded to the admin user and forum role name" do
|
197
|
-
subject.find_roles(
|
196
|
+
subject.find_roles(:group, admin).should_not include(godfather_role, tourist_role, sneaky_role, forum_role)
|
198
197
|
end
|
199
198
|
end
|
200
199
|
|
201
200
|
context "using :any parameter" do
|
202
201
|
it "should get all roles binded to any resource with forum role name" do
|
203
|
-
subject.find_roles(
|
202
|
+
subject.find_roles(:group, :any).should include(group_role)
|
204
203
|
end
|
205
204
|
|
206
205
|
it "should not get roles not binded to a resource with forum role name" do
|
207
|
-
subject.find_roles(
|
206
|
+
subject.find_roles(:group, :any).should_not include(godfather_role, sneaky_role, forum_role, tourist_role)
|
208
207
|
end
|
209
208
|
end
|
210
209
|
end
|