roleup 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/roleup/has_roles.rb +8 -0
- data/lib/roleup/list.rb +14 -5
- data/lib/roleup/version.rb +1 -1
- data/test/has_roles_test.rb +18 -9
- data/test/list_test.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5788b1e970d2996a5a2ed6a9d16cabd9d99c25b3
|
4
|
+
data.tar.gz: 4b26ad508625ff3c48f39c5a82ac4b39d8b33df2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cc8c5aa7f4630c489aecc332c2d8f5be52655d19a33e625dfa8a8ad9bfd08d8f9634994e5599feca8a6a67593ac823acc96859aa758f10ea5b4e48c02d672c6
|
7
|
+
data.tar.gz: 75c9efe1849081f76c38b239d6457bab025e7e7eb24158fbe5e3fdecc84739a6a46475b7ec5a3a38e6b4278f5bcdeec475ff6144a59fd03a6dfbde9b99e99827
|
data/lib/roleup/has_roles.rb
CHANGED
data/lib/roleup/list.rb
CHANGED
@@ -7,30 +7,39 @@ module Roleup
|
|
7
7
|
def_delegators :inner_list, :each, :length, :size
|
8
8
|
|
9
9
|
def initialize(*values)
|
10
|
-
@inner_list = values
|
10
|
+
@inner_list = standardize_values(*values)
|
11
11
|
end
|
12
12
|
|
13
13
|
def include?(value)
|
14
|
-
inner_list.include?
|
14
|
+
inner_list.include? standardize_value(value)
|
15
15
|
end
|
16
16
|
|
17
17
|
def push(value)
|
18
18
|
return self if include?(value)
|
19
|
-
inner_list <<
|
19
|
+
inner_list << standardize_value(value)
|
20
20
|
end
|
21
21
|
|
22
22
|
alias_method :<<, :push
|
23
23
|
|
24
24
|
def delete(value)
|
25
|
-
inner_list.delete
|
25
|
+
inner_list.delete standardize_value(value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def &(*values)
|
29
|
+
inner_list & standardize_values(*values)
|
26
30
|
end
|
27
31
|
|
28
32
|
protected
|
29
33
|
|
30
34
|
attr_reader :inner_list
|
31
35
|
|
32
|
-
def
|
36
|
+
def standardize_value(value)
|
33
37
|
value.to_s.downcase.to_sym
|
34
38
|
end
|
39
|
+
|
40
|
+
def standardize_values(*values)
|
41
|
+
values.flatten.map { |value| standardize_value(value) }.uniq.sort
|
42
|
+
end
|
43
|
+
|
35
44
|
end
|
36
45
|
end
|
data/lib/roleup/version.rb
CHANGED
data/test/has_roles_test.rb
CHANGED
@@ -2,23 +2,32 @@ require_relative "test_helper"
|
|
2
2
|
|
3
3
|
module Roleup
|
4
4
|
class HasRolesTest < MicroTest::Test
|
5
|
+
class User
|
6
|
+
include HasRoles
|
7
|
+
end
|
5
8
|
|
6
9
|
before do
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
@obj_with_roles = class_with_roles.new
|
12
|
-
@obj_with_roles.roles = :admin, :editor
|
10
|
+
@user = User.new
|
11
|
+
@user.roles = :admin, :editor
|
13
12
|
end
|
14
13
|
|
15
14
|
test "assign roles" do
|
16
|
-
assert @
|
15
|
+
assert @user.roles.to_a == [:admin, :editor]
|
17
16
|
end
|
18
17
|
|
19
18
|
test "has_role?" do
|
20
|
-
assert @
|
21
|
-
assert @
|
19
|
+
assert @user.has_role?(:admin)
|
20
|
+
assert @user.has_role?(:editor)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "has_all_roles?" do
|
24
|
+
assert @user.has_all_roles?(:admin, :EDITOR)
|
25
|
+
assert !@user.has_all_roles?(:admin, :editor, :other)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "has_one_role?" do
|
29
|
+
assert @user.has_one_role?(:other, :editor, :VIEWER)
|
30
|
+
assert !@user.has_one_role?(:other, :viewer)
|
22
31
|
end
|
23
32
|
|
24
33
|
end
|
data/test/list_test.rb
CHANGED