rddd 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -31,13 +31,13 @@ module Rddd
|
|
31
31
|
# Create new rule applied to specified action and perform the given
|
32
32
|
# block.
|
33
33
|
#
|
34
|
-
# @param {Symbol} Action the rule applies to.
|
34
|
+
# @param {Symbol | Array} Action the rule applies to.
|
35
35
|
# @param {Block} Block to be executed to evaluate authorization.
|
36
36
|
#
|
37
37
|
def can(action, &block)
|
38
|
+
actions = action.kind_of?(Array) ? action : [action]
|
38
39
|
@rules ||= []
|
39
|
-
|
40
|
-
@rules << Rule.new(action, &block)
|
40
|
+
@rules.concat actions.map { |action| Rule.new(action, &block) }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/rddd/version.rb
CHANGED
@@ -17,13 +17,25 @@ describe Rddd::Authorization::RulesBuilder do
|
|
17
17
|
|
18
18
|
let(:block) { lambda{|user, params| } }
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
context 'one rule' do
|
21
|
+
before do
|
22
|
+
Rddd::Authorization::Rule.expects(:new).returns(rule)
|
22
23
|
|
23
|
-
|
24
|
+
builder.can(:foo, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
its(:first) { should be rule }
|
24
28
|
end
|
25
29
|
|
26
|
-
|
30
|
+
context 'double rule' do
|
31
|
+
before do
|
32
|
+
Rddd::Authorization::Rule.expects(:new).twice.returns(rule)
|
33
|
+
|
34
|
+
builder.can([:foo, :bar], &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
its(:size) { should eql 2 }
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
end
|