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 CHANGED
@@ -1 +1 @@
1
- 0.2.0.alpha
1
+ 0.2.1.alpha
@@ -40,12 +40,14 @@ module Permissive
40
40
  end
41
41
  end
42
42
 
43
- def can(name, value = nil)
44
- if value
45
- to(name, value)
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(name, &block)
78
- @role = name.to_s.to_sym
79
- roles[@role] ||= []
80
- instance_eval(&block)
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=)
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
8
+ - 1
9
9
  - alpha
10
- version: 0.2.0.alpha
10
+ version: 0.2.1.alpha
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser