roles_generic 0.2.7 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +25 -13
- data/Rakefile +7 -5
- data/VERSION +1 -1
- data/lib/generators/{roles_model → roles_generic}/roles/roles_generator.rb +8 -15
- data/lib/roles_generic/base.rb +40 -2
- data/lib/roles_generic/generic/role.rb +2 -16
- data/lib/roles_generic/generic/role_util.rb +30 -0
- data/lib/roles_generic/generic/user/implementation.rb +108 -6
- data/lib/roles_generic/generic/user/multi_impl.rb +27 -0
- data/lib/roles_generic/generic/user/single_impl.rb +24 -0
- data/lib/roles_generic/generic.rb +1 -1
- data/lib/roles_generic/role.rb +1 -0
- data/lib/roles_generic/rspec/api/completeness.rb +22 -0
- data/lib/roles_generic/rspec/api/full.rb +5 -0
- data/lib/roles_generic/rspec/api/read_api.rb +119 -0
- data/lib/roles_generic/rspec/api/simple_check.rb +11 -0
- data/lib/roles_generic/rspec/api/user_class_api.rb +31 -0
- data/lib/roles_generic/rspec/api/write_api.rb +50 -0
- data/lib/roles_generic/rspec/test_it.rb +2 -0
- data/lib/roles_generic/rspec/user_setup.rb +6 -0
- data/lib/roles_generic/strategy/multi/many_roles.rb +12 -19
- data/lib/roles_generic/strategy/multi/role_strings.rb +15 -12
- data/lib/roles_generic/strategy/multi/roles_mask.rb +20 -16
- data/lib/roles_generic/strategy/multi/roles_string.rb +14 -11
- data/lib/roles_generic/strategy/single/admin_flag.rb +24 -13
- data/lib/roles_generic/strategy/single/one_role.rb +19 -18
- data/lib/roles_generic/strategy/single/role_string.rb +16 -11
- data/lib/roles_generic.rb +1 -0
- data/roles_generic.gemspec +60 -46
- data/spec/generator_spec_helper.rb +1 -1
- data/spec/{generators → roles_generic/generators}/admin_flag_generator_spec.rb +2 -3
- data/spec/{generators → roles_generic/generators}/many_roles_generator_spec.rb +3 -2
- data/spec/{generators → roles_generic/generators}/one_role_generator_spec.rb +3 -2
- data/spec/{generators → roles_generic/generators}/role_string_generator_spec.rb +2 -2
- data/spec/{generators → roles_generic/generators}/role_strings_generator_spec.rb +2 -2
- data/spec/{generators → roles_generic/generators}/roles_mask_generator_spec.rb +2 -2
- data/spec/{generators → roles_generic/generators}/roles_string_generator_spec.rb +2 -2
- data/spec/roles_generic/strategy/multi/many_roles_spec.rb +26 -0
- data/spec/roles_generic/strategy/multi/role_strings_spec.rb +21 -0
- data/spec/roles_generic/strategy/multi/roles_mask_spec.rb +20 -0
- data/spec/roles_generic/strategy/multi/roles_string_spec.rb +21 -0
- data/spec/roles_generic/strategy/single/admin_flag_spec.rb +20 -0
- data/spec/roles_generic/strategy/single/one_role_spec.rb +27 -0
- data/spec/roles_generic/strategy/single/role_string_spec.rb +21 -0
- metadata +72 -50
- data/spec/roles_generic/admin_flag_spec.rb +0 -66
- data/spec/roles_generic/many_roles_spec.rb +0 -64
- data/spec/roles_generic/one_role_spec.rb +0 -71
- data/spec/roles_generic/role_string_spec.rb +0 -65
- data/spec/roles_generic/role_strings_spec.rb +0 -58
- data/spec/roles_generic/roles_mask_spec.rb +0 -57
- data/spec/roles_generic/roles_string_spec.rb +0 -58
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :many_roles
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
strategy :many_roles, :default
|
7
|
+
|
8
|
+
role_class :role
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
valid_roles_are :admin, :user, :guest
|
12
|
+
|
13
|
+
def initialize name, *new_roles
|
14
|
+
self.name = name
|
15
|
+
self.roles = new_roles
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Roles Generic: :many_roles strategy" do
|
20
|
+
require "roles_generic/rspec/test_it"
|
21
|
+
|
22
|
+
it "should return all registered roles" do
|
23
|
+
Role.all.should include(Role.roles.to_a[0])
|
24
|
+
Role.names.should include( :admin, :user )
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :role_strings
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
strategy :role_strings, :default
|
10
|
+
valid_roles_are :admin, :user, :guest
|
11
|
+
|
12
|
+
def initialize name, *new_roles
|
13
|
+
self.name = name
|
14
|
+
self.roles = new_roles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
describe "Roles Generic: :role_strings strategy" do
|
20
|
+
require "roles_generic/rspec/test_it"
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :roles_mask
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
strategy :roles_mask, :default
|
10
|
+
valid_roles_are :admin, :user, :guest
|
11
|
+
|
12
|
+
def initialize name, *new_roles
|
13
|
+
self.name = name
|
14
|
+
self.roles = new_roles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Roles Generic: :roles_mask strategy" do
|
19
|
+
require "roles_generic/rspec/test_it"
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :roles_string
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
strategy :roles_string, :default
|
10
|
+
valid_roles_are :admin, :user, :guest
|
11
|
+
|
12
|
+
def initialize name, *new_roles
|
13
|
+
self.name = name
|
14
|
+
self.roles = new_roles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
describe "Roles Generic: :roles_string strategy" do
|
20
|
+
require "roles_generic/rspec/test_it"
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :admin_flag
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
strategy :admin_flag, :default
|
10
|
+
valid_roles_are :admin, :user, :guest
|
11
|
+
|
12
|
+
def initialize name, *new_roles
|
13
|
+
self.name = name
|
14
|
+
self.roles = new_roles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Roles Generic: :admin_flag strategy" do
|
19
|
+
require "roles_generic/rspec/test_it"
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :one_role
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
strategy :one_role, :default
|
7
|
+
|
8
|
+
role_class :role
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
valid_roles_are :admin, :user, :guest
|
12
|
+
|
13
|
+
def initialize name, *new_roles
|
14
|
+
self.name = name
|
15
|
+
self.roles = new_roles
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe "Roles Generic: :one_role strategy" do
|
21
|
+
require "roles_generic/rspec/test_it"
|
22
|
+
|
23
|
+
it "should return all registered roles" do
|
24
|
+
Role.all.should include(Role.roles.to_a[0])
|
25
|
+
Role.names.should include( :admin, :user )
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :role_string
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Roles::Generic
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
strategy :role_string, :default
|
10
|
+
valid_roles_are :admin, :user, :guest
|
11
|
+
|
12
|
+
def initialize name, *new_roles
|
13
|
+
self.name = name
|
14
|
+
self.roles = new_roles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
describe "Roles Generic: :role_string strategy" do
|
20
|
+
require "roles_generic/rspec/test_it"
|
21
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-20 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,15 +23,13 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
30
30
|
- 0
|
31
31
|
- 0
|
32
|
-
|
33
|
-
- 22
|
34
|
-
version: 2.0.0.beta.22
|
32
|
+
version: 2.0.0
|
35
33
|
type: :development
|
36
34
|
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
@@ -40,13 +38,12 @@ dependencies:
|
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
|
-
- -
|
41
|
+
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
43
|
segments:
|
46
44
|
- 0
|
47
|
-
-
|
48
|
-
|
49
|
-
version: 0.6.5
|
45
|
+
- 7
|
46
|
+
version: "0.7"
|
50
47
|
type: :development
|
51
48
|
version_requirements: *id002
|
52
49
|
- !ruby/object:Gem::Dependency
|
@@ -70,13 +67,12 @@ dependencies:
|
|
70
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
68
|
none: false
|
72
69
|
requirements:
|
73
|
-
- -
|
70
|
+
- - ">="
|
74
71
|
- !ruby/object:Gem::Version
|
75
72
|
segments:
|
76
73
|
- 3
|
77
74
|
- 0
|
78
|
-
|
79
|
-
version: 3.0.0
|
75
|
+
version: "3.0"
|
80
76
|
type: :runtime
|
81
77
|
version_requirements: *id004
|
82
78
|
- !ruby/object:Gem::Dependency
|
@@ -89,9 +85,9 @@ dependencies:
|
|
89
85
|
- !ruby/object:Gem::Version
|
90
86
|
segments:
|
91
87
|
- 0
|
92
|
-
-
|
93
|
-
-
|
94
|
-
version: 0.
|
88
|
+
- 3
|
89
|
+
- 0
|
90
|
+
version: 0.3.0
|
95
91
|
type: :runtime
|
96
92
|
version_requirements: *id005
|
97
93
|
- !ruby/object:Gem::Dependency
|
@@ -104,11 +100,26 @@ dependencies:
|
|
104
100
|
- !ruby/object:Gem::Version
|
105
101
|
segments:
|
106
102
|
- 0
|
107
|
-
-
|
108
|
-
-
|
109
|
-
version: 0.
|
103
|
+
- 3
|
104
|
+
- 1
|
105
|
+
version: 0.3.1
|
110
106
|
type: :runtime
|
111
107
|
version_requirements: *id006
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: logging_assist
|
110
|
+
prerelease: false
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
- 1
|
119
|
+
- 6
|
120
|
+
version: 0.1.6
|
121
|
+
type: :runtime
|
122
|
+
version_requirements: *id007
|
112
123
|
description: Generic role strategies sharing the same API. Easy to insert in any model
|
113
124
|
email: kmandrup@gmail.com
|
114
125
|
executables: []
|
@@ -126,18 +137,29 @@ files:
|
|
126
137
|
- README.markdown
|
127
138
|
- Rakefile
|
128
139
|
- VERSION
|
129
|
-
- lib/generators/
|
140
|
+
- lib/generators/roles_generic/roles/roles_generator.rb
|
130
141
|
- lib/roles_generic.rb
|
131
142
|
- lib/roles_generic/admin.rb
|
132
143
|
- lib/roles_generic/base.rb
|
133
144
|
- lib/roles_generic/generic.rb
|
134
145
|
- lib/roles_generic/generic/role.rb
|
146
|
+
- lib/roles_generic/generic/role_util.rb
|
135
147
|
- lib/roles_generic/generic/user.rb
|
136
148
|
- lib/roles_generic/generic/user/class_methods.rb
|
137
149
|
- lib/roles_generic/generic/user/configuration.rb
|
138
150
|
- lib/roles_generic/generic/user/implementation.rb
|
151
|
+
- lib/roles_generic/generic/user/multi_impl.rb
|
152
|
+
- lib/roles_generic/generic/user/single_impl.rb
|
139
153
|
- lib/roles_generic/namespaces.rb
|
140
154
|
- lib/roles_generic/role.rb
|
155
|
+
- lib/roles_generic/rspec/api/completeness.rb
|
156
|
+
- lib/roles_generic/rspec/api/full.rb
|
157
|
+
- lib/roles_generic/rspec/api/read_api.rb
|
158
|
+
- lib/roles_generic/rspec/api/simple_check.rb
|
159
|
+
- lib/roles_generic/rspec/api/user_class_api.rb
|
160
|
+
- lib/roles_generic/rspec/api/write_api.rb
|
161
|
+
- lib/roles_generic/rspec/test_it.rb
|
162
|
+
- lib/roles_generic/rspec/user_setup.rb
|
141
163
|
- lib/roles_generic/strategy.rb
|
142
164
|
- lib/roles_generic/strategy/multi/many_roles.rb
|
143
165
|
- lib/roles_generic/strategy/multi/role_strings.rb
|
@@ -148,20 +170,20 @@ files:
|
|
148
170
|
- lib/roles_generic/strategy/single/role_string.rb
|
149
171
|
- roles_generic.gemspec
|
150
172
|
- spec/generator_spec_helper.rb
|
151
|
-
- spec/generators/admin_flag_generator_spec.rb
|
152
|
-
- spec/generators/many_roles_generator_spec.rb
|
153
|
-
- spec/generators/one_role_generator_spec.rb
|
154
|
-
- spec/generators/role_string_generator_spec.rb
|
155
|
-
- spec/generators/role_strings_generator_spec.rb
|
156
|
-
- spec/generators/roles_mask_generator_spec.rb
|
157
|
-
- spec/generators/roles_string_generator_spec.rb
|
158
|
-
- spec/roles_generic/
|
159
|
-
- spec/roles_generic/
|
160
|
-
- spec/roles_generic/
|
161
|
-
- spec/roles_generic/
|
162
|
-
- spec/roles_generic/
|
163
|
-
- spec/roles_generic/
|
164
|
-
- spec/roles_generic/
|
173
|
+
- spec/roles_generic/generators/admin_flag_generator_spec.rb
|
174
|
+
- spec/roles_generic/generators/many_roles_generator_spec.rb
|
175
|
+
- spec/roles_generic/generators/one_role_generator_spec.rb
|
176
|
+
- spec/roles_generic/generators/role_string_generator_spec.rb
|
177
|
+
- spec/roles_generic/generators/role_strings_generator_spec.rb
|
178
|
+
- spec/roles_generic/generators/roles_mask_generator_spec.rb
|
179
|
+
- spec/roles_generic/generators/roles_string_generator_spec.rb
|
180
|
+
- spec/roles_generic/strategy/multi/many_roles_spec.rb
|
181
|
+
- spec/roles_generic/strategy/multi/role_strings_spec.rb
|
182
|
+
- spec/roles_generic/strategy/multi/roles_mask_spec.rb
|
183
|
+
- spec/roles_generic/strategy/multi/roles_string_spec.rb
|
184
|
+
- spec/roles_generic/strategy/single/admin_flag_spec.rb
|
185
|
+
- spec/roles_generic/strategy/single/one_role_spec.rb
|
186
|
+
- spec/roles_generic/strategy/single/role_string_spec.rb
|
165
187
|
- spec/spec_helper.rb
|
166
188
|
- wiki/strategies/admin_flag.textile
|
167
189
|
- wiki/strategies/many_roles.textile
|
@@ -204,18 +226,18 @@ specification_version: 3
|
|
204
226
|
summary: Generic role strategies sharing the same API
|
205
227
|
test_files:
|
206
228
|
- spec/generator_spec_helper.rb
|
207
|
-
- spec/generators/admin_flag_generator_spec.rb
|
208
|
-
- spec/generators/many_roles_generator_spec.rb
|
209
|
-
- spec/generators/one_role_generator_spec.rb
|
210
|
-
- spec/generators/role_string_generator_spec.rb
|
211
|
-
- spec/generators/role_strings_generator_spec.rb
|
212
|
-
- spec/generators/roles_mask_generator_spec.rb
|
213
|
-
- spec/generators/roles_string_generator_spec.rb
|
214
|
-
- spec/roles_generic/
|
215
|
-
- spec/roles_generic/
|
216
|
-
- spec/roles_generic/
|
217
|
-
- spec/roles_generic/
|
218
|
-
- spec/roles_generic/
|
219
|
-
- spec/roles_generic/
|
220
|
-
- spec/roles_generic/
|
229
|
+
- spec/roles_generic/generators/admin_flag_generator_spec.rb
|
230
|
+
- spec/roles_generic/generators/many_roles_generator_spec.rb
|
231
|
+
- spec/roles_generic/generators/one_role_generator_spec.rb
|
232
|
+
- spec/roles_generic/generators/role_string_generator_spec.rb
|
233
|
+
- spec/roles_generic/generators/role_strings_generator_spec.rb
|
234
|
+
- spec/roles_generic/generators/roles_mask_generator_spec.rb
|
235
|
+
- spec/roles_generic/generators/roles_string_generator_spec.rb
|
236
|
+
- spec/roles_generic/strategy/multi/many_roles_spec.rb
|
237
|
+
- spec/roles_generic/strategy/multi/role_strings_spec.rb
|
238
|
+
- spec/roles_generic/strategy/multi/roles_mask_spec.rb
|
239
|
+
- spec/roles_generic/strategy/multi/roles_string_spec.rb
|
240
|
+
- spec/roles_generic/strategy/single/admin_flag_spec.rb
|
241
|
+
- spec/roles_generic/strategy/single/one_role_spec.rb
|
242
|
+
- spec/roles_generic/strategy/single/role_string_spec.rb
|
221
243
|
- spec/spec_helper.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
use_roles_strategy :admin_flag
|
3
|
-
|
4
|
-
class User
|
5
|
-
include Roles::Generic
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
strategy :admin_flag, :default
|
10
|
-
|
11
|
-
valid_roles_are :admin, :user
|
12
|
-
|
13
|
-
def initialize name, *new_roles
|
14
|
-
self.name = name
|
15
|
-
self.roles = new_roles
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "Generic AdminFlag role strategy" do
|
20
|
-
context "default setup" do
|
21
|
-
|
22
|
-
before :each do
|
23
|
-
@admin_user = User.new 'Admin user', :admin
|
24
|
-
@user = User.new 'User', :user
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should have admin user role to :admin" do
|
28
|
-
@admin_user.role.should == :admin
|
29
|
-
@admin_user.roles.should == [:admin]
|
30
|
-
@admin_user.admin?.should be_true
|
31
|
-
|
32
|
-
@admin_user.class.valid_roles.should == [:admin, :user]
|
33
|
-
|
34
|
-
@admin_user.has_role?(:user).should be_false
|
35
|
-
|
36
|
-
@admin_user.has_role?(:admin).should be_true
|
37
|
-
@admin_user.is?(:admin).should be_true
|
38
|
-
@admin_user.has_roles?(:admin).should be_true
|
39
|
-
@admin_user.has?(:admin).should be_true
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should have user role to :user" do
|
43
|
-
@user.roles.should == [:user]
|
44
|
-
@user.admin?.should be_false
|
45
|
-
|
46
|
-
@user.has_role?(:user).should be_true
|
47
|
-
@user.has_role?(:admin).should be_false
|
48
|
-
@user.is?(:admin).should be_false
|
49
|
-
|
50
|
-
@user.has_roles?(:user).should be_true
|
51
|
-
@user.has?(:admin).should be_false
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should set user role to :admin using =" do
|
55
|
-
@user.roles = :admin
|
56
|
-
@user.role.should == :admin
|
57
|
-
@user.has_role?(:admin).should be_true
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should set user role to :admin using <<" do
|
61
|
-
@user.role = :admin
|
62
|
-
@user.role.should == :admin
|
63
|
-
@user.has_role?(:admin).should be_true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
use_roles_strategy :many_roles
|
3
|
-
|
4
|
-
class User
|
5
|
-
include Roles::Generic
|
6
|
-
strategy :many_roles, :default
|
7
|
-
|
8
|
-
role_class :role
|
9
|
-
|
10
|
-
attr_accessor :name
|
11
|
-
|
12
|
-
valid_roles_are :admin, :user
|
13
|
-
|
14
|
-
def initialize name, *new_roles
|
15
|
-
self.name = name
|
16
|
-
self.roles = new_roles
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
describe "Generic ManyRoles role strategy" do
|
22
|
-
context "default setup" do
|
23
|
-
|
24
|
-
before :each do
|
25
|
-
@admin_user = User.new 'Admin user', :admin
|
26
|
-
@user = User.new 'User', :user
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should return all registered roles" do
|
30
|
-
Role.all.should include(Role.roles.to_a[0])
|
31
|
-
Role.names.should include( :admin, :user )
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have admin user role to :admin" do
|
35
|
-
@admin_user.roles_list.first.should == :admin
|
36
|
-
@admin_user.admin?.should be_true
|
37
|
-
|
38
|
-
@admin_user.has_role?(:user).should be_false
|
39
|
-
|
40
|
-
@admin_user.has_role?(:admin).should be_true
|
41
|
-
@admin_user.is?(:admin).should be_true
|
42
|
-
@admin_user.has_roles?(:admin).should be_true
|
43
|
-
@admin_user.has?(:admin).should be_true
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should have user role to :user" do
|
47
|
-
@user.roles_list.first.should == :user
|
48
|
-
@user.admin?.should be_false
|
49
|
-
|
50
|
-
@user.has_role?(:user).should be_true
|
51
|
-
@user.has_role?(:admin).should be_false
|
52
|
-
@user.is?(:admin).should be_false
|
53
|
-
|
54
|
-
@user.has_roles?(:admin).should be_false
|
55
|
-
@user.has?(:admin).should be_false
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should set user role to :admin using roles=" do
|
59
|
-
@user.roles = :admin
|
60
|
-
@user.roles_list.first.should == :admin
|
61
|
-
@user.has_role?(:admin).should be_true
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
use_roles_strategy :one_role
|
3
|
-
|
4
|
-
class User
|
5
|
-
include Roles::Generic
|
6
|
-
strategy :one_role, :default
|
7
|
-
|
8
|
-
role_class :role
|
9
|
-
|
10
|
-
attr_accessor :name
|
11
|
-
|
12
|
-
valid_roles_are :admin, :user
|
13
|
-
|
14
|
-
def initialize name, *new_roles
|
15
|
-
self.name = name
|
16
|
-
self.roles = new_roles
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
describe "Generic OneRole role strategy" do
|
22
|
-
context "default setup" do
|
23
|
-
|
24
|
-
before :each do
|
25
|
-
@admin_user = User.new 'Admin user', :admin
|
26
|
-
@user = User.new 'User', :user
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should return all registered roles" do
|
30
|
-
Role.all.should include(Role.roles.to_a[0])
|
31
|
-
Role.names.should include( :admin, :user )
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have admin user role to :admin" do
|
35
|
-
@admin_user.role.should == :admin
|
36
|
-
@admin_user.roles.should == [:admin]
|
37
|
-
@admin_user.admin?.should be_true
|
38
|
-
|
39
|
-
@admin_user.has_role?(:user).should be_false
|
40
|
-
|
41
|
-
@admin_user.has_role?(:admin).should be_true
|
42
|
-
@admin_user.is?(:admin).should be_true
|
43
|
-
@admin_user.has_roles?(:admin).should be_true
|
44
|
-
@admin_user.has?(:admin).should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should have user role to :user" do
|
48
|
-
@user.roles.should == [:user]
|
49
|
-
@user.admin?.should be_false
|
50
|
-
|
51
|
-
@user.has_role?(:user).should be_true
|
52
|
-
@user.has_role?(:admin).should be_false
|
53
|
-
@user.is?(:admin).should be_false
|
54
|
-
|
55
|
-
@user.has_roles?(:admin).should be_false
|
56
|
-
@user.has?(:admin).should be_false
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should set user role to :admin using roles=" do
|
60
|
-
@user.roles = :admin
|
61
|
-
@user.role.should == :admin
|
62
|
-
@user.has_role?(:admin).should be_true
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should set user role to :admin using role=" do
|
66
|
-
@user.roles = :admin
|
67
|
-
@user.role.should == :admin
|
68
|
-
@user.has_role?(:admin).should be_true
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
use_roles_strategy :role_string
|
3
|
-
|
4
|
-
class User
|
5
|
-
include Roles::Generic
|
6
|
-
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
strategy :role_string, :default
|
10
|
-
|
11
|
-
roles :admin, :user
|
12
|
-
|
13
|
-
def initialize name, *new_roles
|
14
|
-
self.name = name
|
15
|
-
self.roles = new_roles
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
describe "Generic RoleString role strategy" do
|
21
|
-
context "default setup" do
|
22
|
-
|
23
|
-
before :each do
|
24
|
-
@admin_user = User.new 'Admin user', :admin
|
25
|
-
@user = User.new 'User', :user
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have admin user role to :admin" do
|
29
|
-
@admin_user.role.should == :admin
|
30
|
-
@admin_user.roles.should == [:admin]
|
31
|
-
@admin_user.admin?.should be_true
|
32
|
-
|
33
|
-
@admin_user.has_role?(:user).should be_false
|
34
|
-
|
35
|
-
@admin_user.has_role?(:admin).should be_true
|
36
|
-
@admin_user.is?(:admin).should be_true
|
37
|
-
@admin_user.has_roles?(:admin).should be_true
|
38
|
-
@admin_user.has?(:admin).should be_true
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have user role to :user" do
|
42
|
-
@user.roles.should == [:user]
|
43
|
-
@user.admin?.should be_false
|
44
|
-
|
45
|
-
@user.has_role?(:user).should be_true
|
46
|
-
@user.has_role?(:admin).should be_false
|
47
|
-
@user.is?(:admin).should be_false
|
48
|
-
|
49
|
-
@user.has_roles?(:admin).should be_false
|
50
|
-
@user.has?(:admin).should be_false
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should set user role to :admin using roles=" do
|
54
|
-
@user.roles = :admin
|
55
|
-
@user.role.should == :admin
|
56
|
-
@user.has_role?(:admin).should be_true
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should set user role to :admin using role=" do
|
60
|
-
@user.role = :admin
|
61
|
-
@user.role.should == :admin
|
62
|
-
@user.has_role?(:admin).should be_true
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|