role_model 0.8.0 → 0.8.1
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/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/role_model/implementation.rb +6 -1
- data/role_model.gemspec +1 -1
- data/spec/role_model_spec.rb +24 -18
- metadata +3 -3
data/README.rdoc
CHANGED
|
@@ -52,7 +52,7 @@ It works like this:
|
|
|
52
52
|
=> [:admin, :manager, :author]
|
|
53
53
|
|
|
54
54
|
# ... retrieve all assigned roles
|
|
55
|
-
>> u.roles #
|
|
55
|
+
>> u.roles # also: u.role_symbols for DeclarativeAuthorization compatibility
|
|
56
56
|
=> [:admin, :manager]
|
|
57
57
|
|
|
58
58
|
# ... check for individual roles
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.8.
|
|
1
|
+
0.8.1
|
|
@@ -10,7 +10,12 @@ module RoleModel
|
|
|
10
10
|
def roles
|
|
11
11
|
Roles.new(self, self.class.valid_roles.reject { |r| ((self.send(self.class.roles_attribute_name) || 0) & 2**self.class.valid_roles.index(r)).zero? })
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
# query assigned roles returning an Array for the
|
|
15
|
+
# declarative_authorization gem
|
|
16
|
+
def role_symbols
|
|
17
|
+
roles.to_a
|
|
18
|
+
end
|
|
14
19
|
|
|
15
20
|
# :call-seq:
|
|
16
21
|
# has_all_roles?(:role)
|
data/role_model.gemspec
CHANGED
data/spec/role_model_spec.rb
CHANGED
|
@@ -53,16 +53,22 @@ describe RoleModel do
|
|
|
53
53
|
|
|
54
54
|
[:roles, :role_symbols].each do |role_query_method|
|
|
55
55
|
describe "##{role_query_method}" do
|
|
56
|
-
|
|
56
|
+
let(:model) { model_class.new }
|
|
57
|
+
subject { model.send(role_query_method) }
|
|
57
58
|
|
|
58
59
|
it "should return the assigned roles as symbols" do
|
|
59
|
-
|
|
60
|
-
subject.
|
|
61
|
-
subject.
|
|
60
|
+
model.roles = [:foo, :bar]
|
|
61
|
+
subject.should include(:foo, :bar)
|
|
62
|
+
subject.should have(2).elements
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should be empty when no roles have been assigned" do
|
|
66
|
+
subject.should be_empty
|
|
62
67
|
end
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
if role_query_method == :role_symbols
|
|
70
|
+
# DeclarativeAuthorization specifically wants an Array
|
|
71
|
+
it { should be_an(Array) }
|
|
66
72
|
end
|
|
67
73
|
end
|
|
68
74
|
end
|
|
@@ -296,10 +302,10 @@ describe RoleModel do
|
|
|
296
302
|
end
|
|
297
303
|
end
|
|
298
304
|
end
|
|
299
|
-
|
|
305
|
+
|
|
300
306
|
describe "dynamically query for an individual role" do
|
|
301
307
|
subject { model_class.new }
|
|
302
|
-
|
|
308
|
+
|
|
303
309
|
it "should return true when the given role was assigned" do
|
|
304
310
|
subject.roles = :foo
|
|
305
311
|
subject.is_foo?.should be_true
|
|
@@ -321,7 +327,7 @@ describe RoleModel do
|
|
|
321
327
|
lambda { subject.baz? }.should raise_error(NoMethodError)
|
|
322
328
|
lambda { subject.is_baz? }.should raise_error(NoMethodError)
|
|
323
329
|
end
|
|
324
|
-
|
|
330
|
+
|
|
325
331
|
it "should not define dynamic finders when opting out" do
|
|
326
332
|
non_dynamic_klass = Class.new do
|
|
327
333
|
attr_accessor :roles_mask
|
|
@@ -329,41 +335,41 @@ describe RoleModel do
|
|
|
329
335
|
include RoleModel
|
|
330
336
|
roles :foo, :bar, :third, :dynamic => false
|
|
331
337
|
end
|
|
332
|
-
|
|
338
|
+
|
|
333
339
|
model = non_dynamic_klass.new
|
|
334
340
|
lambda { model.is_foo? }.should raise_error(NoMethodError)
|
|
335
341
|
lambda { model.bar? }.should raise_error(NoMethodError)
|
|
336
342
|
end
|
|
337
|
-
|
|
343
|
+
|
|
338
344
|
it "should be able to override the default dynamic query methods and call super" do
|
|
339
345
|
klass = Class.new do
|
|
340
346
|
def bar?
|
|
341
347
|
return false
|
|
342
348
|
end
|
|
343
|
-
|
|
349
|
+
|
|
344
350
|
attr_accessor :roles_mask
|
|
345
351
|
attr_accessor :custom_roles_mask
|
|
346
352
|
include RoleModel
|
|
347
353
|
roles :foo, :bar, :baz
|
|
348
|
-
|
|
354
|
+
|
|
349
355
|
def is_baz?
|
|
350
356
|
return false
|
|
351
357
|
end
|
|
352
|
-
|
|
358
|
+
|
|
353
359
|
def foo?
|
|
354
360
|
ret = super
|
|
355
361
|
!ret
|
|
356
362
|
end
|
|
357
363
|
end
|
|
358
|
-
|
|
364
|
+
|
|
359
365
|
model = klass.new
|
|
360
366
|
model.roles = [:foo, :bar, :baz]
|
|
361
|
-
|
|
367
|
+
|
|
362
368
|
model.foo?.should be_false
|
|
363
|
-
|
|
369
|
+
|
|
364
370
|
model.bar?.should be_false
|
|
365
371
|
model.is_bar?.should be_true
|
|
366
|
-
|
|
372
|
+
|
|
367
373
|
model.is_baz?.should be_false
|
|
368
374
|
model.baz?.should be_true
|
|
369
375
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: role_model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 61
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 8
|
|
9
|
-
-
|
|
10
|
-
version: 0.8.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.8.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Martin Rehfeld
|