permissive 0.2.1.alpha → 0.2.2.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/permissive/has_permissions.rb +3 -2
- data/lib/permissive/permission_definition.rb +4 -3
- data/spec/has_permissions_spec.rb +7 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2.alpha
|
@@ -85,10 +85,11 @@ module Permissive
|
|
85
85
|
permission_setter = options[:on].nil? || options[:on] == :global ? 'permissions=' : "#{options[:on].to_s.singularize}_permissions="
|
86
86
|
class_eval <<-eoc
|
87
87
|
def #{permission_setter}(values)
|
88
|
+
values ||= []
|
88
89
|
if values.all? {|value| value.is_a?(String) || value.is_a?(Symbol)}
|
89
90
|
can!(values, :reset => true, :on => #{options[:on].inspect})
|
90
91
|
else
|
91
|
-
super
|
92
|
+
super(values)
|
92
93
|
end
|
93
94
|
end
|
94
95
|
eoc
|
@@ -125,7 +126,7 @@ module Permissive
|
|
125
126
|
revoke(#{[permissions, args].flatten.join(', ').inspect}, :on => scope)
|
126
127
|
end
|
127
128
|
end_eval
|
128
|
-
return
|
129
|
+
return revoke(*[permissions, options].flatten)
|
129
130
|
elsif setter
|
130
131
|
class_eval <<-end_eval
|
131
132
|
def #{method}(scope = nil)
|
@@ -29,14 +29,15 @@ module Permissive
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def normalize_scope(model, scope)
|
32
|
-
case scope
|
32
|
+
scope = case scope
|
33
33
|
when Class
|
34
34
|
scope.name.tableize
|
35
35
|
when String, Symbol
|
36
36
|
interpolate_scope(model, scope).to_s.tableize
|
37
37
|
else
|
38
38
|
:global
|
39
|
-
end
|
39
|
+
end
|
40
|
+
scope.to_s.gsub('/', '_').to_sym
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -80,7 +81,7 @@ module Permissive
|
|
80
81
|
names.each do |name|
|
81
82
|
@role = name.to_s.to_sym
|
82
83
|
roles[@role] ||= []
|
83
|
-
instance_eval(&block)
|
84
|
+
instance_eval(&block) if block_given?
|
84
85
|
end
|
85
86
|
unless model.instance_methods.include?('role=')
|
86
87
|
model.class_eval do
|
@@ -287,6 +287,13 @@ describe Permissive::Permission do
|
|
287
287
|
@user.can_manage_games_in?(@organization).should be_true
|
288
288
|
end
|
289
289
|
end
|
290
|
+
|
291
|
+
it "should support revoking, too" do
|
292
|
+
@user.can_manage_games!
|
293
|
+
@user.can_manage_games?.should be_true
|
294
|
+
@user.cannot_manage_games!
|
295
|
+
@user.can_manage_games?.should be_false
|
296
|
+
end
|
290
297
|
end
|
291
298
|
|
292
299
|
describe "roles" do
|