effective_roles 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +9 -19
- data/app/models/concerns/acts_as_role_restricted.rb +18 -10
- data/lib/effective_roles.rb +10 -3
- data/lib/effective_roles/version.rb +1 -1
- data/spec/dummy/log/test.log +114 -0
- data/spec/effective_roles_spec.rb +10 -10
- data/spec/models/acts_as_role_restricted_spec.rb +192 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa6baafe8b9e81b1baa9862c885beb88c8483735
|
4
|
+
data.tar.gz: b4beee32f21b88b94046c6a467b681f0c1142ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebb6efc26b4c837b5c8ed50dbb3c277c146092c439f374ad42740cfbb3a8803650479e19dcd9e5a0b09eed19c5e2e2f7327383f69a1bf24e726c7b93e35b8355
|
7
|
+
data.tar.gz: bf6748ec5daa3e3560a8c3352bde647a12ebc4d3565ac6bd17c4071641ce22ed17855588ccc70566574be6fcbde93edfe3b37be5fd73c38104df48ca053d19f7
|
data/README.md
CHANGED
@@ -103,39 +103,29 @@ post.roles
|
|
103
103
|
Compare against another acts_as_role_restricted object:
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
user = User.new()
|
107
|
-
user.roles = []
|
108
|
-
|
109
106
|
post = Post.new()
|
110
107
|
post.roles = [:admin]
|
111
108
|
|
112
|
-
user.
|
113
|
-
|
109
|
+
user = User.new()
|
110
|
+
user.roles = []
|
114
111
|
|
115
|
-
post.
|
116
|
-
=>
|
112
|
+
post.roles_permit?(user)
|
113
|
+
=> false # Post requires the :admin role, but User has no admin role
|
117
114
|
```
|
118
115
|
|
119
116
|
```ruby
|
120
|
-
user.roles = [:admin]
|
121
117
|
post.roles = [:superadmin]
|
118
|
+
user.roles = [:admin]
|
122
119
|
|
123
|
-
|
120
|
+
post.roles_permit?(user)
|
124
121
|
=> false # User does not have the superadmin role
|
125
122
|
|
126
|
-
post.roles_match_with?(user)
|
127
|
-
=> false # Post does not have the admin role
|
128
|
-
```
|
129
|
-
|
130
123
|
```ruby
|
131
|
-
user.roles = [:superadmin, :admin]
|
132
124
|
post.roles = [:admin]
|
125
|
+
user.roles = [:superadmin, :admin]
|
133
126
|
|
134
|
-
|
135
|
-
=> true # User has :admin
|
136
|
-
|
137
|
-
post.roles_match_with?(user)
|
138
|
-
=> true # Post has :admin and so does User
|
127
|
+
post.roles_permit?(user)
|
128
|
+
=> true # User has required :admin role
|
139
129
|
```
|
140
130
|
|
141
131
|
### Finder Methods
|
@@ -74,19 +74,27 @@ module ActsAsRoleRestricted
|
|
74
74
|
roles.include?(role.try(:to_sym))
|
75
75
|
end
|
76
76
|
|
77
|
-
#
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
# Are both objects unrestricted, or do any roles overlap?
|
78
|
+
def roles_overlap?(obj)
|
79
|
+
obj_roles = EffectiveRoles.roles_for(obj)
|
80
|
+
(roles.blank? && obj_roles.blank?) || (roles & obj_roles).any?
|
81
|
+
end
|
82
|
+
|
83
|
+
# Are both objects unrestricted, or are both roles identical?
|
84
|
+
def roles_match?(obj)
|
85
|
+
obj_roles = EffectiveRoles.roles_for(obj)
|
86
|
+
matching_roles = (roles & obj_roles)
|
87
|
+
matching_roles.length == roles.length && matching_roles.length == obj_roles.length
|
88
|
+
end
|
89
|
+
|
90
|
+
# Any I unrestricted, or do any roles overlap?
|
91
|
+
def roles_permit?(obj)
|
92
|
+
roles.blank? || roles_overlap?(obj)
|
86
93
|
end
|
87
94
|
|
88
95
|
def is_role_restricted?
|
89
|
-
|
96
|
+
roles.present?
|
90
97
|
end
|
98
|
+
|
91
99
|
end
|
92
100
|
|
data/lib/effective_roles.rb
CHANGED
@@ -12,9 +12,16 @@ module EffectiveRoles
|
|
12
12
|
yield self
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
16
|
-
|
17
|
-
|
15
|
+
def self.roles_for(obj)
|
16
|
+
if obj.respond_to?(:is_role_restricted?)
|
17
|
+
obj.roles
|
18
|
+
elsif obj.kind_of?(Integer)
|
19
|
+
roles.reject { |r| (obj & 2**roles.index(r)).zero? }
|
20
|
+
elsif obj.nil?
|
21
|
+
[]
|
22
|
+
else
|
23
|
+
raise 'unsupported object passed to EffectiveRoles.roles_for method. Expecting an acts_as_role_restricted object or a roles_mask integer'
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
def self.roles_collection(obj = nil, user = nil)
|
data/spec/dummy/log/test.log
CHANGED
@@ -90,3 +90,117 @@
|
|
90
90
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
91
91
|
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
92
92
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
93
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
94
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
95
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
96
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
97
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
98
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
99
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
100
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
101
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
102
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
103
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
104
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.8ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
105
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
106
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
107
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
108
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
109
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
110
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
111
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
112
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
113
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
114
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
115
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
116
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
117
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
118
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
119
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
120
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
121
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
122
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
123
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
124
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
125
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
126
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
127
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
128
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
129
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
130
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
131
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
132
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
133
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
134
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
135
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
136
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
137
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
138
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
139
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
140
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
141
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
142
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
143
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
144
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
145
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
146
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
147
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
148
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
149
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
150
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
151
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
152
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
153
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
154
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
155
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
156
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
157
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
158
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
159
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
160
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
161
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
162
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
163
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
164
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
165
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
166
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
167
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
168
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
169
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
170
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
171
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
172
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
173
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
174
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
175
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
176
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
177
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
178
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
179
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
180
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
181
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
182
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
183
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
184
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
185
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
186
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
187
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
188
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
189
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
190
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
191
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
192
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
193
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
194
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
195
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
196
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
197
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
198
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
199
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
200
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
201
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
202
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
203
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
204
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
205
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
206
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
@@ -16,16 +16,16 @@ describe EffectiveRoles do
|
|
16
16
|
|
17
17
|
describe '#roles_for_roles_mask' do
|
18
18
|
it 'computes the appropriate roles for the given mask' do
|
19
|
-
EffectiveRoles.
|
20
|
-
EffectiveRoles.
|
21
|
-
EffectiveRoles.
|
22
|
-
EffectiveRoles.
|
23
|
-
EffectiveRoles.
|
24
|
-
EffectiveRoles.
|
25
|
-
EffectiveRoles.
|
26
|
-
EffectiveRoles.
|
27
|
-
EffectiveRoles.
|
28
|
-
EffectiveRoles.
|
19
|
+
EffectiveRoles.roles_for(nil).should eq []
|
20
|
+
EffectiveRoles.roles_for(0).should eq []
|
21
|
+
EffectiveRoles.roles_for(1).should eq [:superadmin]
|
22
|
+
EffectiveRoles.roles_for(2).should eq [:admin]
|
23
|
+
EffectiveRoles.roles_for(3).should eq [:superadmin, :admin]
|
24
|
+
EffectiveRoles.roles_for(4).should eq [:member]
|
25
|
+
EffectiveRoles.roles_for(5).should eq [:superadmin, :member]
|
26
|
+
EffectiveRoles.roles_for(6).should eq [:admin, :member]
|
27
|
+
EffectiveRoles.roles_for(7).should eq [:superadmin, :admin, :member]
|
28
|
+
EffectiveRoles.roles_for(8).should eq []
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,192 @@
|
|
1
|
+
describe 'Acts As Role Restricted' do
|
2
|
+
let(:roles) { [:superadmin, :admin, :member] }
|
3
|
+
|
4
|
+
let(:user) { User.new.tap { |user| user.roles = [] } }
|
5
|
+
let(:member) { User.new.tap { |user| user.roles = [:member] } }
|
6
|
+
let(:admin) { User.new.tap { |user| user.roles = [:admin] } }
|
7
|
+
let(:superadmin) { User.new.tap { |user| user.roles = [:superadmin] } }
|
8
|
+
let(:member_and_admin) { User.new.tap { |user| user.roles = [:member, :admin] } }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
EffectiveRoles.setup { |config| config.roles = roles }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#roles_permit?(obj)' do
|
15
|
+
describe 'when subject has no roles' do
|
16
|
+
let(:post) { Post.new }
|
17
|
+
|
18
|
+
it 'should be true when passed nil' do
|
19
|
+
post.roles_permit?(nil).should eq true
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should be true for any user' do
|
23
|
+
post.roles_permit?(user).should eq true
|
24
|
+
post.roles_permit?(member).should eq true
|
25
|
+
post.roles_permit?(admin).should eq true
|
26
|
+
post.roles_permit?(superadmin).should eq true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when subject has one role' do
|
31
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
32
|
+
|
33
|
+
it 'should be false when passed nil' do
|
34
|
+
post.roles_permit?(nil).should eq false
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should be false when passed object doesnt share roles' do
|
38
|
+
post.roles_permit?(user).should eq false
|
39
|
+
post.roles_permit?(admin).should eq false
|
40
|
+
post.roles_permit?(superadmin).should eq false
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be true for a user with all the same roles' do
|
44
|
+
post.roles_permit?(member).should eq true
|
45
|
+
post.roles_permit?(member_and_admin).should eq true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'when subject has multiple roles' do
|
50
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
51
|
+
|
52
|
+
it 'should be false when passed nil' do
|
53
|
+
post.roles_permit?(nil).should eq false
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should be false when passed object doesnt share all roles' do
|
57
|
+
post.roles_permit?(user).should eq false
|
58
|
+
post.roles_permit?(superadmin).should eq false
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should be true for a user with overlapping roles' do
|
62
|
+
post.roles_permit?(member).should eq true
|
63
|
+
post.roles_permit?(admin).should eq true
|
64
|
+
post.roles_permit?(member_and_admin).should eq true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#roles_overlap?(obj)' do
|
70
|
+
describe 'when subject has no roles' do
|
71
|
+
let(:post) { Post.new }
|
72
|
+
|
73
|
+
it 'should be true when passed nil' do
|
74
|
+
post.roles_overlap?(nil).should eq true
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should be true when user has no roles either' do
|
78
|
+
post.roles_overlap?(user).should eq true
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should be false for any user with roles' do
|
82
|
+
post.roles_overlap?(member).should eq false
|
83
|
+
post.roles_overlap?(admin).should eq false
|
84
|
+
post.roles_overlap?(superadmin).should eq false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'when subject has one role' do
|
89
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
90
|
+
|
91
|
+
it 'should be false when passed nil' do
|
92
|
+
post.roles_overlap?(nil).should eq false
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be false when passed object doesnt share roles' do
|
96
|
+
post.roles_overlap?(user).should eq false
|
97
|
+
post.roles_overlap?(admin).should eq false
|
98
|
+
post.roles_overlap?(superadmin).should eq false
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should be true for a user with all the same roles' do
|
102
|
+
post.roles_overlap?(member).should eq true
|
103
|
+
post.roles_overlap?(member_and_admin).should eq true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'when subject has multiple roles' do
|
108
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
109
|
+
|
110
|
+
it 'should be false when passed nil' do
|
111
|
+
post.roles_overlap?(nil).should eq false
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should be false when passed object doesnt share all roles' do
|
115
|
+
post.roles_overlap?(user).should eq false
|
116
|
+
post.roles_overlap?(superadmin).should eq false
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should be true for a user with overlapping roles' do
|
120
|
+
post.roles_overlap?(member).should eq true
|
121
|
+
post.roles_overlap?(admin).should eq true
|
122
|
+
post.roles_overlap?(member_and_admin).should eq true
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
describe '#roles_match?(obj)' do
|
129
|
+
describe 'when subject has no roles' do
|
130
|
+
let(:post) { Post.new }
|
131
|
+
|
132
|
+
it 'should be true when passed nil' do
|
133
|
+
post.roles_match?(nil).should eq true
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should be true when user has no roles either' do
|
137
|
+
post.roles_match?(user).should eq true
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should be false for any user with roles' do
|
141
|
+
post.roles_match?(member).should eq false
|
142
|
+
post.roles_match?(admin).should eq false
|
143
|
+
post.roles_match?(superadmin).should eq false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'when subject has one role' do
|
148
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
149
|
+
|
150
|
+
it 'should be false when passed nil' do
|
151
|
+
post.roles_match?(nil).should eq false
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should be false when passed object doesnt share roles' do
|
155
|
+
post.roles_match?(user).should eq false
|
156
|
+
post.roles_match?(admin).should eq false
|
157
|
+
post.roles_match?(superadmin).should eq false
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should be true for a user with all the same roles' do
|
161
|
+
post.roles_match?(member).should eq true
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should be false when the user has more roles' do
|
165
|
+
post.roles_match?(member_and_admin).should eq false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'when subject has multiple roles' do
|
170
|
+
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
171
|
+
|
172
|
+
it 'should be false when passed nil' do
|
173
|
+
post.roles_match?(nil).should eq false
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should be false when passed object doesnt share all roles' do
|
177
|
+
post.roles_match?(user).should eq false
|
178
|
+
post.roles_match?(superadmin).should eq false
|
179
|
+
post.roles_match?(member).should eq false
|
180
|
+
post.roles_match?(admin).should eq false
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should be true for a user with same roles' do
|
184
|
+
post.roles_match?(member_and_admin).should eq true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- spec/dummy/db/test.sqlite3
|
201
201
|
- spec/dummy/log/test.log
|
202
202
|
- spec/effective_roles_spec.rb
|
203
|
+
- spec/models/acts_as_role_restricted_spec.rb
|
203
204
|
- spec/spec_helper.rb
|
204
205
|
- spec/support/factories.rb
|
205
206
|
homepage: https://github.com/code-and-effect/effective_roles
|
@@ -257,5 +258,6 @@ test_files:
|
|
257
258
|
- spec/dummy/Rakefile
|
258
259
|
- spec/dummy/README.rdoc
|
259
260
|
- spec/effective_roles_spec.rb
|
261
|
+
- spec/models/acts_as_role_restricted_spec.rb
|
260
262
|
- spec/spec_helper.rb
|
261
263
|
- spec/support/factories.rb
|