roles_mongo_mapper 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -2
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/lib/roles_mongo_mapper/base.rb +21 -4
- data/lib/roles_mongo_mapper/embedded_role.rb +35 -0
- data/lib/roles_mongo_mapper/role.rb +7 -5
- data/lib/roles_mongo_mapper/strategy/multi.rb +59 -0
- data/lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb +71 -0
- data/lib/roles_mongo_mapper/strategy/multi/many_roles.rb +69 -23
- data/lib/roles_mongo_mapper/strategy/multi/role_strings.rb +44 -24
- data/lib/roles_mongo_mapper/strategy/multi/roles_mask.rb +67 -19
- data/lib/roles_mongo_mapper/strategy/shared.rb +29 -0
- data/lib/roles_mongo_mapper/strategy/single.rb +34 -0
- data/lib/roles_mongo_mapper/strategy/single/admin_flag.rb +50 -15
- data/lib/roles_mongo_mapper/strategy/single/embed_one_role.rb +79 -0
- data/lib/roles_mongo_mapper/strategy/single/one_role.rb +38 -30
- data/lib/roles_mongo_mapper/strategy/single/role_string.rb +20 -18
- data/roles_mongo_mapper.gemspec +51 -32
- data/sandbox/test.rb +13 -3
- data/spec/roles_mongo_mapper/strategy/api_examples.rb +199 -0
- data/spec/roles_mongo_mapper/strategy/hooks.rb +7 -0
- data/spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb +19 -0
- data/spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb +19 -0
- data/spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb +19 -0
- data/spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb +18 -0
- data/spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb +18 -0
- data/spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb +19 -0
- data/spec/roles_mongo_mapper/strategy/single/one_role_spec.rb +20 -0
- data/spec/roles_mongo_mapper/strategy/single/role_string_spec.rb +19 -0
- data/spec/roles_mongo_mapper/strategy/user_setup.rb +13 -0
- data/spec/spec_helper.rb +11 -6
- metadata +60 -32
- data/spec/roles_mongo_mapper/strategy/admin_flag_spec.rb +0 -76
- data/spec/roles_mongo_mapper/strategy/many_roles_spec.rb +0 -69
- data/spec/roles_mongo_mapper/strategy/one_role_spec.rb +0 -66
- data/spec/roles_mongo_mapper/strategy/role_string_spec.rb +0 -68
- data/spec/roles_mongo_mapper/strategy/role_strings_spec.rb +0 -69
- data/spec/roles_mongo_mapper/strategy/roles_mask_spec.rb +0 -69
data/roles_mongo_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roles_mongo_mapper}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-24}
|
13
13
|
s.description = %q{Makes it easy to set a role strategy on your User model in MongoMapper}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,25 +27,36 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/generators/mongo_mapper/roles/roles_generator.rb",
|
28
28
|
"lib/roles_mongo_mapper.rb",
|
29
29
|
"lib/roles_mongo_mapper/base.rb",
|
30
|
+
"lib/roles_mongo_mapper/embedded_role.rb",
|
30
31
|
"lib/roles_mongo_mapper/namespaces.rb",
|
31
32
|
"lib/roles_mongo_mapper/role.rb",
|
32
33
|
"lib/roles_mongo_mapper/strategy.rb",
|
34
|
+
"lib/roles_mongo_mapper/strategy/multi.rb",
|
35
|
+
"lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb",
|
33
36
|
"lib/roles_mongo_mapper/strategy/multi/many_roles.rb",
|
34
37
|
"lib/roles_mongo_mapper/strategy/multi/role_strings.rb",
|
35
38
|
"lib/roles_mongo_mapper/strategy/multi/roles_mask.rb",
|
39
|
+
"lib/roles_mongo_mapper/strategy/shared.rb",
|
40
|
+
"lib/roles_mongo_mapper/strategy/single.rb",
|
36
41
|
"lib/roles_mongo_mapper/strategy/single/admin_flag.rb",
|
42
|
+
"lib/roles_mongo_mapper/strategy/single/embed_one_role.rb",
|
37
43
|
"lib/roles_mongo_mapper/strategy/single/one_role.rb",
|
38
44
|
"lib/roles_mongo_mapper/strategy/single/role_string.rb",
|
39
45
|
"roles_mongo_mapper.gemspec",
|
40
46
|
"sandbox/test.rb",
|
41
47
|
"spec/generator_spec_helper.rb",
|
42
48
|
"spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
|
43
|
-
"spec/roles_mongo_mapper/strategy/
|
44
|
-
"spec/roles_mongo_mapper/strategy/
|
45
|
-
"spec/roles_mongo_mapper/strategy/
|
46
|
-
"spec/roles_mongo_mapper/strategy/
|
47
|
-
"spec/roles_mongo_mapper/strategy/role_strings_spec.rb",
|
48
|
-
"spec/roles_mongo_mapper/strategy/roles_mask_spec.rb",
|
49
|
+
"spec/roles_mongo_mapper/strategy/api_examples.rb",
|
50
|
+
"spec/roles_mongo_mapper/strategy/hooks.rb",
|
51
|
+
"spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
|
52
|
+
"spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
|
53
|
+
"spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
|
54
|
+
"spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
|
55
|
+
"spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
|
56
|
+
"spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
|
57
|
+
"spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
|
58
|
+
"spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
|
59
|
+
"spec/roles_mongo_mapper/strategy/user_setup.rb",
|
49
60
|
"spec/spec_helper.rb"
|
50
61
|
]
|
51
62
|
s.homepage = %q{http://github.com/kristianmandrup/roles_mongo_mapper}
|
@@ -56,12 +67,17 @@ Gem::Specification.new do |s|
|
|
56
67
|
s.test_files = [
|
57
68
|
"spec/generator_spec_helper.rb",
|
58
69
|
"spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
|
59
|
-
"spec/roles_mongo_mapper/strategy/
|
60
|
-
"spec/roles_mongo_mapper/strategy/
|
61
|
-
"spec/roles_mongo_mapper/strategy/
|
62
|
-
"spec/roles_mongo_mapper/strategy/
|
63
|
-
"spec/roles_mongo_mapper/strategy/role_strings_spec.rb",
|
64
|
-
"spec/roles_mongo_mapper/strategy/roles_mask_spec.rb",
|
70
|
+
"spec/roles_mongo_mapper/strategy/api_examples.rb",
|
71
|
+
"spec/roles_mongo_mapper/strategy/hooks.rb",
|
72
|
+
"spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
|
73
|
+
"spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
|
74
|
+
"spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
|
75
|
+
"spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
|
76
|
+
"spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
|
77
|
+
"spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
|
78
|
+
"spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
|
79
|
+
"spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
|
80
|
+
"spec/roles_mongo_mapper/strategy/user_setup.rb",
|
65
81
|
"spec/spec_helper.rb"
|
66
82
|
]
|
67
83
|
|
@@ -70,33 +86,36 @@ Gem::Specification.new do |s|
|
|
70
86
|
s.specification_version = 3
|
71
87
|
|
72
88
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
73
|
-
s.add_development_dependency(%q<rspec>, [">= 2.
|
89
|
+
s.add_development_dependency(%q<rspec>, [">= 2.1"])
|
74
90
|
s.add_development_dependency(%q<generator-spec>, ["~> 0.6.5"])
|
75
|
-
s.add_runtime_dependency(%q<mongo_mapper>, ["
|
76
|
-
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0
|
91
|
+
s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.8.4"])
|
92
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
|
77
93
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
78
|
-
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.
|
79
|
-
s.add_runtime_dependency(%q<roles_generic>, ["~> 0.
|
80
|
-
s.add_runtime_dependency(%q<
|
94
|
+
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
95
|
+
s.add_runtime_dependency(%q<roles_generic>, ["~> 0.3.3"])
|
96
|
+
s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
|
97
|
+
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.5"])
|
81
98
|
else
|
82
|
-
s.add_dependency(%q<rspec>, [">= 2.
|
99
|
+
s.add_dependency(%q<rspec>, [">= 2.1"])
|
83
100
|
s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
|
84
|
-
s.add_dependency(%q<mongo_mapper>, ["
|
85
|
-
s.add_dependency(%q<activesupport>, ["~> 3.0
|
101
|
+
s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
|
102
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
86
103
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
87
|
-
s.add_dependency(%q<sugar-high>, ["~> 0.
|
88
|
-
s.add_dependency(%q<roles_generic>, ["~> 0.
|
89
|
-
s.add_dependency(%q<
|
104
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
105
|
+
s.add_dependency(%q<roles_generic>, ["~> 0.3.3"])
|
106
|
+
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
|
107
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
|
90
108
|
end
|
91
109
|
else
|
92
|
-
s.add_dependency(%q<rspec>, [">= 2.
|
110
|
+
s.add_dependency(%q<rspec>, [">= 2.1"])
|
93
111
|
s.add_dependency(%q<generator-spec>, ["~> 0.6.5"])
|
94
|
-
s.add_dependency(%q<mongo_mapper>, ["
|
95
|
-
s.add_dependency(%q<activesupport>, ["~> 3.0
|
112
|
+
s.add_dependency(%q<mongo_mapper>, [">= 0.8.4"])
|
113
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
96
114
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
97
|
-
s.add_dependency(%q<sugar-high>, ["~> 0.
|
98
|
-
s.add_dependency(%q<roles_generic>, ["~> 0.
|
99
|
-
s.add_dependency(%q<
|
115
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
116
|
+
s.add_dependency(%q<roles_generic>, ["~> 0.3.3"])
|
117
|
+
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.0"])
|
118
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
|
100
119
|
end
|
101
120
|
end
|
102
121
|
|
data/sandbox/test.rb
CHANGED
@@ -2,17 +2,27 @@ require 'mongo_mapper'
|
|
2
2
|
|
3
3
|
MongoMapper.database = 'roles_for_mm'
|
4
4
|
|
5
|
+
class Role
|
6
|
+
include MongoMapper::Document
|
7
|
+
key :name, String
|
8
|
+
end
|
9
|
+
|
5
10
|
class User
|
6
11
|
include MongoMapper::Document
|
7
12
|
|
8
13
|
key :name, String
|
14
|
+
key :one_role, ::Role
|
9
15
|
end
|
10
16
|
|
11
|
-
|
17
|
+
role = Role.create(:name => 'admin')
|
18
|
+
user = User.create(:name => 'Kristian')
|
19
|
+
user.one_role = role
|
20
|
+
user.save
|
12
21
|
|
13
|
-
puts User.first.id
|
22
|
+
puts User.first.id
|
23
|
+
puts Role.first.id
|
14
24
|
|
15
|
-
u = User.where(
|
25
|
+
u = User.where("role._id" => Role.first.id).first
|
16
26
|
puts u.inspect
|
17
27
|
|
18
28
|
|
@@ -0,0 +1,199 @@
|
|
1
|
+
describe "Roles for MonoMapper: #{api_name}" do
|
2
|
+
require "roles_mongo_mapper/strategy/user_setup.rb"
|
3
|
+
|
4
|
+
before do
|
5
|
+
default_user_setup
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#in_role' do
|
9
|
+
it "should return first user matching role" do
|
10
|
+
if User.respond_to? :in_role
|
11
|
+
User.in_role(:guest).first.name.should == 'Guest user'
|
12
|
+
User.in_role(:admin).first.name.should == 'Admin user'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#in_any_role' do
|
18
|
+
it "should return first user matching role" do
|
19
|
+
if User.respond_to? :in_roles
|
20
|
+
User.in_any_role(:guest, :user).first.name.should == 'Guest user'
|
21
|
+
User.in_any_role(:admin, :guest).should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
|
27
|
+
# mutation API
|
28
|
+
[:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
|
29
|
+
@admin_user.respond_to?(api_method).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
# inspection API
|
33
|
+
[:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
|
34
|
+
@admin_user.respond_to?(api_method).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
# class method API
|
38
|
+
[:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
|
39
|
+
@admin_user.class.respond_to?(class_api_method).should be_true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#valid_role?' do
|
44
|
+
it "should be true that the admin user has a valid role of :guest" do
|
45
|
+
# @admin_user.valid_role?(:guest).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be true that the User class has a valid role of :guest" do
|
49
|
+
# User.valid_role?(:guest).should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#valid_roles' do
|
54
|
+
it "should be true that the admin user has a valid role of :guest" do
|
55
|
+
# @admin_user.valid_roles.should include(:guest, :admin)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be true that the User class has a valid role of :guest" do
|
59
|
+
User.valid_roles.should include(:guest, :admin)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#valid_roles?' do
|
64
|
+
it "should be true that the admin user has a valid role of :guest" do
|
65
|
+
@admin_user.valid_roles?(:guest, :admin).should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be true that the User class has a valid role of :guest" do
|
69
|
+
User.valid_roles?(:guest, :admin).should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#has_role?' do
|
74
|
+
it "should have admin user role to :admin and not to :user" do
|
75
|
+
@admin_user.has_role?(:user).should be_false
|
76
|
+
@admin_user.has_role?(:admin).should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be true that guest user has role :guest and not :admin" do
|
80
|
+
@guest_user.has_role?(:guest).should be_true
|
81
|
+
@guest_user.has_role?(:admin).should be_false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#has?' do
|
86
|
+
it "should be true that the admin_user has the :admin role" do
|
87
|
+
@admin_user.has?(:admin).should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should NOT be true that the admin_user has the :admin role" do
|
91
|
+
@guest_user.has?(:admin).should be_false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#has_roles?' do
|
96
|
+
it "should be true that the admin_user has the roles :admin" do
|
97
|
+
@admin_user.has_roles?(:admin).should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should NOT be true that the user has the roles :admin" do
|
101
|
+
@guest_user.has_roles?(:admin).should be_false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#roles_list' do
|
106
|
+
it "should be true that the first role of admin_user is the :admin role" do
|
107
|
+
@admin_user.roles_list.should include(:admin)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be true that the first role of admin_user is the :user role" do
|
111
|
+
case @normal_user.class.role_strategy.multiplicity
|
112
|
+
when :single
|
113
|
+
@normal_user.roles_list.should include(:guest)
|
114
|
+
when :multi
|
115
|
+
@normal_user.roles_list.should include(:user, :guest)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#roles' do
|
121
|
+
it "should be true that the roles of admin_user is an array with the role :admin" do
|
122
|
+
roles = @admin_user.roles
|
123
|
+
if defined?(Role) && roles.kind_of?(Role)
|
124
|
+
roles.name.to_sym.should == :admin
|
125
|
+
elsif roles.kind_of? Array
|
126
|
+
if @normal_user.class.role_strategy.type == :complex
|
127
|
+
roles.first.name.to_sym.should == :admin
|
128
|
+
end
|
129
|
+
if @normal_user.class.role_strategy.name == :admin_flag
|
130
|
+
roles.first.should == true
|
131
|
+
end
|
132
|
+
else
|
133
|
+
roles.to_sym.should == :admin
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#admin?' do
|
139
|
+
it "should be true that admin_user is in the :admin role" do
|
140
|
+
@admin_user.admin?.should be_true
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should NOT be true that the user is in the :admin role" do
|
144
|
+
@guest_user.admin?.should be_false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#is?' do
|
149
|
+
it "should be true that admin_user is in the :admin role" do
|
150
|
+
@admin_user.is?(:admin).should be_true
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should NOT be true that the user is in the :admin role" do
|
154
|
+
@guest_user.is?(:admin).should be_false
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#roles=' do
|
159
|
+
it "should set user role to :admin" do
|
160
|
+
@guest_user.roles = :admin
|
161
|
+
@guest_user.has_role?(:admin).should be_true
|
162
|
+
@guest_user.roles = :guest
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#exchange_roles' do
|
167
|
+
it "should exchange user role :user with role :admin" do
|
168
|
+
@guest_user.exchange_role :guest, :with => :admin
|
169
|
+
@guest_user.has?(:guest).should be_false
|
170
|
+
@guest_user.has?(:admin).should be_true
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should exchange user role :admin with roles :user and :guest" do
|
174
|
+
case @admin_user.class.role_strategy.multiplicity
|
175
|
+
when :single
|
176
|
+
lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
|
177
|
+
when :multi
|
178
|
+
@admin_user.exchange_role :admin, :with => [:user, :guest]
|
179
|
+
@admin_user.has_role?(:user).should be_true
|
180
|
+
@admin_user.has_role?(:guest).should be_true
|
181
|
+
@admin_user.has?(:admin).should be_false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#remove_roles' do
|
187
|
+
it "should remove user role :admin using #remove_roles" do
|
188
|
+
@admin_user.remove_roles :admin
|
189
|
+
@admin_user.has_role?(:admin).should_not be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should remove user role :admin using #remove_role" do
|
193
|
+
@guest_user.add_role :admin
|
194
|
+
@guest_user.has_role?(:admin).should be_true
|
195
|
+
@guest_user.remove_role :admin
|
196
|
+
@guest_user.has_role?(:admin).should_not be_true
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :embed_many_roles
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :embed_many_roles, :role_class => :role, :config => :default
|
9
|
+
role_class :role
|
10
|
+
valid_roles_are :admin, :guest, :user
|
11
|
+
|
12
|
+
key :name, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_name
|
16
|
+
:embed_many_roles
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :many_roles
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :many_roles, :default
|
9
|
+
role_class :role
|
10
|
+
valid_roles_are :admin, :guest, :user
|
11
|
+
|
12
|
+
key :name, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_name
|
16
|
+
:many_roles
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :role_strings
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :role_strings, :default
|
9
|
+
valid_roles_are :admin, :guest, :user
|
10
|
+
|
11
|
+
key :name, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_name
|
15
|
+
:role_strings
|
16
|
+
end
|
17
|
+
|
18
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
19
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :roles_mask
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :roles_mask, :default
|
9
|
+
valid_roles_are :admin, :guest, :user
|
10
|
+
|
11
|
+
key :name, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_name
|
15
|
+
:roles_mask
|
16
|
+
end
|
17
|
+
|
18
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|