permissive 0.2.0.alpha → 0.2.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/permissive/permission_definition.rb +13 -9
- data/spec/has_permissions_spec.rb +15 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1.alpha
|
@@ -40,12 +40,14 @@ module Permissive
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def can(
|
44
|
-
if value
|
45
|
-
|
43
|
+
def can(*args)
|
44
|
+
# if value
|
45
|
+
# to(name, value)
|
46
|
+
# end
|
47
|
+
args.each do |name|
|
48
|
+
name = name.to_s.downcase.to_sym
|
49
|
+
roles[@role].push(name) unless roles[@role].include?(name)
|
46
50
|
end
|
47
|
-
name = name.to_s.downcase.to_sym
|
48
|
-
roles[@role].push(name) unless roles[@role].include?(name)
|
49
51
|
end
|
50
52
|
|
51
53
|
def initialize(model, options = {})
|
@@ -74,10 +76,12 @@ module Permissive
|
|
74
76
|
@permissions ||= {}
|
75
77
|
end
|
76
78
|
|
77
|
-
def role(
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
def role(*names, &block)
|
80
|
+
names.each do |name|
|
81
|
+
@role = name.to_s.to_sym
|
82
|
+
roles[@role] ||= []
|
83
|
+
instance_eval(&block)
|
84
|
+
end
|
81
85
|
unless model.instance_methods.include?('role=')
|
82
86
|
model.class_eval do
|
83
87
|
def role=(role_name)
|
@@ -312,6 +312,21 @@ describe Permissive::Permission do
|
|
312
312
|
Permissive::User.permissions[:global].roles[:rides].should == [:control_rides]
|
313
313
|
end
|
314
314
|
|
315
|
+
it "should accept multiple roles" do
|
316
|
+
Permissive::User.has_permissions do
|
317
|
+
to :fight, 0
|
318
|
+
to :flee, 1
|
319
|
+
to :urinate, 2
|
320
|
+
|
321
|
+
role(:normie, :hero) { can :fight }
|
322
|
+
role(:coward, :normie) { can :flee, :urinate }
|
323
|
+
end
|
324
|
+
|
325
|
+
Permissive::User.permissions[:global].roles[:normie].should == [:fight, :flee, :urinate]
|
326
|
+
Permissive::User.permissions[:global].roles[:hero].should == [:fight]
|
327
|
+
Permissive::User.permissions[:global].roles[:coward].should == [:flee, :urinate]
|
328
|
+
end
|
329
|
+
|
315
330
|
it "should allow me to assign a role" do
|
316
331
|
@james = Permissive::User.create!
|
317
332
|
@james.should respond_to(:role=)
|