roles_mongoid 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{README.markdown → README.textile} +49 -32
- data/VERSION +1 -1
- data/lib/roles_mongoid/base.rb +51 -12
- data/lib/roles_mongoid/base_role.rb +13 -0
- data/lib/roles_mongoid/embedded_role.rb +0 -2
- data/lib/roles_mongoid/role.rb +1 -13
- data/lib/roles_mongoid/strategy/shared.rb +0 -1
- data/roles_mongoid.gemspec +5 -4
- data/spec/roles_mongoid/strategy/api_examples.rb +173 -173
- data/spec/roles_mongoid/strategy/multi/embed_many_roles_spec.rb +1 -4
- data/spec/roles_mongoid/strategy/multi/many_roles_spec.rb +1 -5
- data/spec/roles_mongoid/strategy/multi/role_strings_spec.rb +1 -4
- data/spec/roles_mongoid/strategy/multi/roles_mask_spec.rb +1 -2
- data/spec/roles_mongoid/strategy/single/admin_flag_spec.rb +1 -1
- data/spec/roles_mongoid/strategy/single/embed_one_role_spec.rb +1 -3
- data/spec/roles_mongoid/strategy/single/one_role_spec.rb +1 -5
- data/spec/roles_mongoid/strategy/single/role_string_spec.rb +1 -2
- metadata +7 -6
@@ -1,55 +1,72 @@
|
|
1
|
-
|
1
|
+
h1. Roles for Mongoid
|
2
2
|
|
3
|
-
A Mongoid implementation of [
|
3
|
+
A Mongoid implementation of [Roles Generic](http://github.com/kristianmandrup/roles_generic).
|
4
|
+
See the Roles [wiki](http://github.com/kristianmandrup/roles_generic/wiki) for an overview of the API and how to use it.
|
4
5
|
|
5
|
-
|
6
|
+
h2. Role strategies
|
6
7
|
|
7
|
-
|
8
|
+
Role strategies implemented:
|
8
9
|
|
9
|
-
|
10
|
-
* embed_many_roles
|
11
|
-
|
12
|
-
## Intro
|
13
|
-
|
14
|
-
Implements the [roles generic](http://github.com/kristianmandrup/roles_generic) Roles API
|
15
|
-
|
16
|
-
Generic Role strategies implemented:
|
10
|
+
Inline attribute on User
|
17
11
|
|
18
12
|
* admin_flag
|
13
|
+
* roles_mask
|
14
|
+
* role_string
|
15
|
+
* role_strings
|
16
|
+
|
17
|
+
Reference Role
|
19
18
|
|
20
|
-
* many_roles
|
19
|
+
* many_roles
|
21
20
|
* one_role
|
22
21
|
|
22
|
+
Embedded Role
|
23
|
+
|
23
24
|
* embed_many_roles
|
24
25
|
* embed_one_role
|
25
26
|
|
26
|
-
|
27
|
-
* role_string
|
28
|
-
* role_strings
|
29
|
-
|
30
|
-
# Install
|
27
|
+
h2. Install
|
31
28
|
|
32
29
|
<code>gem install roles_mongoid</code>
|
33
30
|
|
34
|
-
|
31
|
+
h3. Install in Rails app
|
35
32
|
|
36
|
-
|
33
|
+
Insert in Gemfile:
|
37
34
|
|
38
|
-
|
35
|
+
<code>gem 'roles_mongoid'</code>
|
39
36
|
|
40
|
-
|
37
|
+
Run <code>$ bundle install</code> from terminal
|
41
38
|
|
42
|
-
|
43
|
-
* one_role)
|
39
|
+
Alternatively install using [Cream](http://github.com/kristianmandrup/cream)
|
44
40
|
|
45
|
-
|
46
|
-
* embed_one_role
|
41
|
+
h2. Strategy and roles configuration
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
Example: _role_string_ strategy
|
44
|
+
|
45
|
+
<pre>class User
|
46
|
+
include Mongoid::Document
|
47
|
+
include Roles::Mongoid
|
51
48
|
|
52
|
-
|
49
|
+
strategy :one_role
|
50
|
+
valid_roles_are :admin, :guest, :user
|
51
|
+
end
|
52
|
+
</pre>
|
53
|
+
|
54
|
+
Example: _one_role_ strategy
|
55
|
+
|
56
|
+
<pre>class User
|
57
|
+
include Mongoid::Document
|
58
|
+
include Roles::Mongoid
|
59
|
+
|
60
|
+
strategy :one_role
|
61
|
+
valid_roles_are :admin, :guest, :user
|
62
|
+
end
|
63
|
+
</pre>
|
64
|
+
|
65
|
+
h2. Rails generators
|
66
|
+
|
67
|
+
The library comes with a Rails 3 generator that lets you populate a user model with a role strategy of your choice.
|
68
|
+
|
69
|
+
The following role strategies are included by default. Add your own by adding extra files inside the strategy folder, one file for each role strategy is recommended.
|
53
70
|
|
54
71
|
Apply :admin_flag Role strategy to User model using default roles :admin and :guest (default)
|
55
72
|
|
@@ -63,7 +80,7 @@ Apply :one_role Role strategy to User model without default roles, only with rol
|
|
63
80
|
|
64
81
|
<code>$ rails g mongoid:roles_migration User --strategy one_role --roles user special editor --no-default-roles</code>
|
65
82
|
|
66
|
-
|
83
|
+
h2. Note on Patches/Pull Requests
|
67
84
|
|
68
85
|
* Fork the project.
|
69
86
|
* Make your feature addition or bug fix.
|
@@ -73,6 +90,6 @@ Apply :one_role Role strategy to User model without default roles, only with rol
|
|
73
90
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
74
91
|
* Send me a pull request. Bonus points for topic branches.
|
75
92
|
|
76
|
-
|
93
|
+
h2. Copyright
|
77
94
|
|
78
95
|
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/roles_mongoid/base.rb
CHANGED
@@ -28,26 +28,65 @@ module Roles
|
|
28
28
|
:role_strings => "field :role_strings, :type => Array",
|
29
29
|
:roles_string => "field :roles_string, :type => String"
|
30
30
|
}
|
31
|
-
|
31
|
+
|
32
32
|
def strategy name, options = {}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
strategy_name = name.to_sym
|
34
|
+
raise ArgumentError, "Unknown role strategy #{strategy_name}" if !MAP.keys.include? strategy_name
|
35
|
+
use_roles_strategy strategy_name
|
36
|
+
|
37
|
+
if strategies_with_role_class.include? strategy_name
|
38
|
+
if !options.kind_of? Symbol
|
39
|
+
@role_class_name = get_role_class(strategy_name, options)
|
40
|
+
else
|
41
|
+
@role_class_name = default_role_class(strategy_name)
|
42
|
+
end
|
38
43
|
end
|
44
|
+
|
45
|
+
if default_options?(options) && MAP[strategy_name]
|
46
|
+
instance_eval statement(MAP[strategy_name])
|
47
|
+
end
|
39
48
|
|
40
49
|
case name
|
41
50
|
when :embed_one_role
|
42
|
-
raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if
|
43
|
-
|
51
|
+
raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name
|
52
|
+
@role_class_name.embedded_in :user, :inverse_of => :one_role
|
44
53
|
when :embed_many_roles
|
45
|
-
raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if
|
46
|
-
|
54
|
+
raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name
|
55
|
+
@role_class_name.embedded_in :user, :inverse_of => :many_roles
|
47
56
|
end
|
48
|
-
|
49
|
-
set_role_strategy
|
57
|
+
|
58
|
+
set_role_strategy strategy_name, options
|
50
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def default_options? options = {}
|
64
|
+
return true if options == :default
|
65
|
+
if options.kind_of? Hash
|
66
|
+
return true # if options[:config] == :default || options == {}
|
67
|
+
end
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
def statement code_str
|
72
|
+
code_str.gsub /Role/, @role_class_name.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_role_class strategy_name
|
76
|
+
if defined? ::Role
|
77
|
+
require "roles_mongoid/role"
|
78
|
+
return ::Role
|
79
|
+
end
|
80
|
+
raise "Default Role class not defined"
|
81
|
+
end
|
82
|
+
|
83
|
+
def strategies_with_role_class
|
84
|
+
[:one_role, :embed_one_role, :many_roles,:embed_many_roles]
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_role_class strategy_name, options
|
88
|
+
options[:role_class] ? options[:role_class].to_s.camelize.constantize : default_role_class(strategy_name)
|
89
|
+
end
|
51
90
|
end
|
52
91
|
end
|
53
92
|
end
|
data/lib/roles_mongoid/role.rb
CHANGED
@@ -1,16 +1,4 @@
|
|
1
|
-
|
2
|
-
def valid_roles_are(*role_list)
|
3
|
-
strategy_class.valid_roles = role_list.to_symbols
|
4
|
-
if role_class_name
|
5
|
-
role_list.each do |name|
|
6
|
-
begin
|
7
|
-
role_class_name.create(:name => name.to_s)
|
8
|
-
rescue
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require 'roles_mongoid/base_role'
|
14
2
|
|
15
3
|
class Role
|
16
4
|
include Mongoid::Document
|
@@ -3,7 +3,6 @@ module Roles::Mongoid
|
|
3
3
|
module Shared
|
4
4
|
def set_role role
|
5
5
|
raise ArgumentError, "#set_role only takes a single role as argument, not #{role}" if role.kind_of?(Array)
|
6
|
-
puts "role: #{role.inspect}, attrib: #{role_attribute.inspect}"
|
7
6
|
self.send("#{role_attribute}=", role)
|
8
7
|
end
|
9
8
|
|
data/roles_mongoid.gemspec
CHANGED
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roles_mongoid}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.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-
|
12
|
+
s.date = %q{2010-12-26}
|
13
13
|
s.description = %q{Makes it easy to set a role strategy on your User model in Mongoid}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.textile"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".bundle/config",
|
@@ -22,12 +22,13 @@ Gem::Specification.new do |s|
|
|
22
22
|
".rspec",
|
23
23
|
"Gemfile",
|
24
24
|
"LICENSE",
|
25
|
-
"README.
|
25
|
+
"README.textile",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"lib/generators/mongoid/roles/roles_generator.rb",
|
29
29
|
"lib/roles_mongoid.rb",
|
30
30
|
"lib/roles_mongoid/base.rb",
|
31
|
+
"lib/roles_mongoid/base_role.rb",
|
31
32
|
"lib/roles_mongoid/embedded_role.rb",
|
32
33
|
"lib/roles_mongoid/namespaces.rb",
|
33
34
|
"lib/roles_mongoid/role.rb",
|
@@ -23,178 +23,178 @@ describe "Roles for Mongoid: #{api_name}" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
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
|
42
31
|
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
+
# # @normal_user.roles_list.should include(:user)
|
115
|
+
# when :multi
|
116
|
+
# @normal_user.roles_list.should include(:user, :guest)
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# describe '#roles' do
|
122
|
+
# it "should be true that the roles of admin_user is an array with the role :admin" do
|
123
|
+
# roles = @admin_user.roles
|
124
|
+
# if defined?(Role) && roles.kind_of?(Role)
|
125
|
+
# roles.name.to_sym.should == :admin
|
126
|
+
# elsif roles.kind_of? Array
|
127
|
+
# if @normal_user.class.role_strategy.type == :complex
|
128
|
+
# roles.first.name.to_sym.should == :admin
|
129
|
+
# end
|
130
|
+
# if @normal_user.class.role_strategy.name == :admin_flag
|
131
|
+
# roles.first.should == true
|
132
|
+
# end
|
133
|
+
# else
|
134
|
+
# roles.to_sym.should == :admin
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
#
|
139
|
+
# describe '#admin?' do
|
140
|
+
# it "should be true that admin_user is in the :admin role" do
|
141
|
+
# @admin_user.admin?.should be_true
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# it "should NOT be true that the user is in the :admin role" do
|
145
|
+
# @guest_user.admin?.should be_false
|
146
|
+
# end
|
147
|
+
# end
|
148
|
+
#
|
149
|
+
# describe '#is?' do
|
150
|
+
# it "should be true that admin_user is in the :admin role" do
|
151
|
+
# @admin_user.is?(:admin).should be_true
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# it "should NOT be true that the user is in the :admin role" do
|
155
|
+
# @guest_user.is?(:admin).should be_false
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# describe '#roles=' do
|
160
|
+
# it "should set user role to :admin" do
|
161
|
+
# @guest_user.roles = :admin
|
162
|
+
# @guest_user.has_role?(:admin).should be_true
|
163
|
+
# @guest_user.roles = :guest
|
164
|
+
# end
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# describe '#exchange_roles' do
|
168
|
+
# it "should exchange user role :user with role :admin" do
|
169
|
+
# @guest_user.exchange_role :guest, :with => :admin
|
170
|
+
# @guest_user.has?(:guest).should be_false
|
171
|
+
# @guest_user.has?(:admin).should be_true
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# it "should exchange user role :admin with roles :user and :guest" do
|
175
|
+
# case @admin_user.class.role_strategy.multiplicity
|
176
|
+
# when :single
|
177
|
+
# lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
|
178
|
+
# when :multi
|
179
|
+
# @admin_user.exchange_role :admin, :with => [:user, :guest]
|
180
|
+
# @admin_user.has_role?(:user).should be_true
|
181
|
+
# @admin_user.has_role?(:guest).should be_true
|
182
|
+
# @admin_user.has?(:admin).should be_false
|
183
|
+
# end
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# describe '#remove_roles' do
|
188
|
+
# it "should remove user role :admin using #remove_roles" do
|
189
|
+
# @admin_user.remove_roles :admin
|
190
|
+
# @admin_user.has_role?(:admin).should_not be_true
|
191
|
+
# end
|
192
|
+
#
|
193
|
+
# it "should remove user role :admin using #remove_role" do
|
194
|
+
# @guest_user.add_role :admin
|
195
|
+
# @guest_user.has_role?(:admin).should be_true
|
196
|
+
# @guest_user.remove_role :admin
|
197
|
+
# @guest_user.has_role?(:admin).should_not be_true
|
198
|
+
# end
|
199
|
+
# end
|
200
200
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
use_roles_strategy :embed_many_roles
|
4
|
-
|
5
3
|
class User
|
6
4
|
include Mongoid::Document
|
7
5
|
include Roles::Mongoid
|
8
6
|
|
9
|
-
strategy :embed_many_roles, :role_class => :role
|
10
|
-
|
7
|
+
strategy :embed_many_roles, :role_class => :role #, :config => :default
|
11
8
|
valid_roles_are :admin, :guest, :user
|
12
9
|
end
|
13
10
|
|
@@ -1,14 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
use_roles_strategy :many_roles
|
4
|
-
|
5
3
|
class User
|
6
4
|
include Mongoid::Document
|
7
5
|
include Roles::Mongoid
|
8
6
|
|
9
|
-
strategy :many_roles
|
10
|
-
role_class :role
|
11
|
-
|
7
|
+
strategy :many_roles
|
12
8
|
valid_roles_are :admin, :guest, :user
|
13
9
|
end
|
14
10
|
|
@@ -6,9 +6,7 @@ class User
|
|
6
6
|
include Mongoid::Document
|
7
7
|
include Roles::Mongoid
|
8
8
|
|
9
|
-
strategy :embed_one_role, :role_class => :role
|
10
|
-
role_class :role
|
11
|
-
|
9
|
+
strategy :embed_one_role, :role_class => :role #, :config => :default
|
12
10
|
valid_roles_are :admin, :guest, :user
|
13
11
|
end
|
14
12
|
|
@@ -1,14 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
use_roles_strategy :one_role
|
4
|
-
|
5
3
|
class User
|
6
4
|
include Mongoid::Document
|
7
5
|
include Roles::Mongoid
|
8
6
|
|
9
|
-
strategy :one_role
|
10
|
-
role_class :role
|
11
|
-
|
7
|
+
strategy :one_role
|
12
8
|
valid_roles_are :admin, :guest, :user
|
13
9
|
end
|
14
10
|
|
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
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
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-12-
|
17
|
+
date: 2010-12-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -239,19 +239,20 @@ extensions: []
|
|
239
239
|
|
240
240
|
extra_rdoc_files:
|
241
241
|
- LICENSE
|
242
|
-
- README.
|
242
|
+
- README.textile
|
243
243
|
files:
|
244
244
|
- .bundle/config
|
245
245
|
- .document
|
246
246
|
- .rspec
|
247
247
|
- Gemfile
|
248
248
|
- LICENSE
|
249
|
-
- README.
|
249
|
+
- README.textile
|
250
250
|
- Rakefile
|
251
251
|
- VERSION
|
252
252
|
- lib/generators/mongoid/roles/roles_generator.rb
|
253
253
|
- lib/roles_mongoid.rb
|
254
254
|
- lib/roles_mongoid/base.rb
|
255
|
+
- lib/roles_mongoid/base_role.rb
|
255
256
|
- lib/roles_mongoid/embedded_role.rb
|
256
257
|
- lib/roles_mongoid/namespaces.rb
|
257
258
|
- lib/roles_mongoid/role.rb
|