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
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :admin_flag
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :admin_flag, :default
|
9
|
+
valid_roles_are :admin, :guest
|
10
|
+
|
11
|
+
key :name, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_name
|
15
|
+
:admin_flag
|
16
|
+
end
|
17
|
+
|
18
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :embed_one_role
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :embed_one_role, :role_class => :role, :config => :default
|
9
|
+
role_class :role
|
10
|
+
valid_roles_are :admin, :guest
|
11
|
+
|
12
|
+
key :name, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_name
|
16
|
+
:embed_one_role
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :one_role
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :one_role, :default
|
9
|
+
role_class :role
|
10
|
+
valid_roles_are :admin, :guest
|
11
|
+
|
12
|
+
key :name, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_name
|
16
|
+
:one_role
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :role_string
|
3
|
+
|
4
|
+
class User
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Roles::MongoMapper
|
7
|
+
|
8
|
+
strategy :role_string, :default
|
9
|
+
valid_roles_are :admin, :guest
|
10
|
+
|
11
|
+
key :name, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_name
|
15
|
+
:role_string
|
16
|
+
end
|
17
|
+
|
18
|
+
load 'roles_mongo_mapper/strategy/api_examples.rb'
|
19
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
def default_user_setup
|
2
|
+
@guest_user = User.create(:name => 'Guest user')
|
3
|
+
@guest_user.add_roles :guest
|
4
|
+
@guest_user.save
|
5
|
+
|
6
|
+
@normal_user = User.create(:name => 'Normal user')
|
7
|
+
@normal_user.roles = :guest, :user
|
8
|
+
@normal_user.save
|
9
|
+
|
10
|
+
@admin_user = User.create(:name => 'Admin user')
|
11
|
+
@admin_user.add_roles :admin
|
12
|
+
@admin_user.save
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,11 @@ require 'roles_mongo_mapper'
|
|
3
3
|
|
4
4
|
MongoMapper.database = 'roles_mongo_mapper'
|
5
5
|
|
6
|
+
MongoMapper.database.collections.each do |coll|
|
7
|
+
coll.drop unless coll.name =~ /(.*\.)?system\..*/
|
8
|
+
end
|
9
|
+
|
10
|
+
|
6
11
|
module Database
|
7
12
|
def self.teardown
|
8
13
|
# MongoMapper.database.collections.each {|collection| collection.drop }
|
@@ -14,13 +19,13 @@ end
|
|
14
19
|
|
15
20
|
RSpec.configure do |config|
|
16
21
|
config.mock_with :mocha
|
17
|
-
config.before do
|
18
|
-
|
19
|
-
end
|
22
|
+
# config.before do
|
23
|
+
# Database.teardown
|
24
|
+
# end
|
20
25
|
|
21
|
-
config.after do
|
22
|
-
|
23
|
-
end
|
26
|
+
# config.after do
|
27
|
+
# Database.teardown
|
28
|
+
# end
|
24
29
|
|
25
30
|
end
|
26
31
|
|
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
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.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-
|
17
|
+
date: 2010-11-24 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,10 +27,8 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
30
|
-
-
|
31
|
-
|
32
|
-
- rc
|
33
|
-
version: 2.0.0.rc
|
30
|
+
- 1
|
31
|
+
version: "2.1"
|
34
32
|
type: :development
|
35
33
|
version_requirements: *id001
|
36
34
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +52,7 @@ dependencies:
|
|
54
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
53
|
none: false
|
56
54
|
requirements:
|
57
|
-
- -
|
55
|
+
- - ">="
|
58
56
|
- !ruby/object:Gem::Version
|
59
57
|
segments:
|
60
58
|
- 0
|
@@ -74,8 +72,7 @@ dependencies:
|
|
74
72
|
segments:
|
75
73
|
- 3
|
76
74
|
- 0
|
77
|
-
|
78
|
-
version: 3.0.0
|
75
|
+
version: "3.0"
|
79
76
|
type: :runtime
|
80
77
|
version_requirements: *id004
|
81
78
|
- !ruby/object:Gem::Dependency
|
@@ -103,9 +100,9 @@ dependencies:
|
|
103
100
|
- !ruby/object:Gem::Version
|
104
101
|
segments:
|
105
102
|
- 0
|
106
|
-
-
|
107
|
-
-
|
108
|
-
version: 0.
|
103
|
+
- 3
|
104
|
+
- 0
|
105
|
+
version: 0.3.0
|
109
106
|
type: :runtime
|
110
107
|
version_requirements: *id006
|
111
108
|
- !ruby/object:Gem::Dependency
|
@@ -118,13 +115,13 @@ dependencies:
|
|
118
115
|
- !ruby/object:Gem::Version
|
119
116
|
segments:
|
120
117
|
- 0
|
121
|
-
-
|
122
|
-
-
|
123
|
-
version: 0.
|
118
|
+
- 3
|
119
|
+
- 3
|
120
|
+
version: 0.3.3
|
124
121
|
type: :runtime
|
125
122
|
version_requirements: *id007
|
126
123
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
124
|
+
name: rails3_artifactor
|
128
125
|
prerelease: false
|
129
126
|
requirement: &id008 !ruby/object:Gem::Requirement
|
130
127
|
none: false
|
@@ -133,11 +130,26 @@ dependencies:
|
|
133
130
|
- !ruby/object:Gem::Version
|
134
131
|
segments:
|
135
132
|
- 0
|
136
|
-
- 1
|
137
133
|
- 3
|
138
|
-
|
134
|
+
- 0
|
135
|
+
version: 0.3.0
|
139
136
|
type: :runtime
|
140
137
|
version_requirements: *id008
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: logging_assist
|
140
|
+
prerelease: false
|
141
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
- 1
|
149
|
+
- 5
|
150
|
+
version: 0.1.5
|
151
|
+
type: :runtime
|
152
|
+
version_requirements: *id009
|
141
153
|
description: Makes it easy to set a role strategy on your User model in MongoMapper
|
142
154
|
email: kmandrup@gmail.com
|
143
155
|
executables: []
|
@@ -158,25 +170,36 @@ files:
|
|
158
170
|
- lib/generators/mongo_mapper/roles/roles_generator.rb
|
159
171
|
- lib/roles_mongo_mapper.rb
|
160
172
|
- lib/roles_mongo_mapper/base.rb
|
173
|
+
- lib/roles_mongo_mapper/embedded_role.rb
|
161
174
|
- lib/roles_mongo_mapper/namespaces.rb
|
162
175
|
- lib/roles_mongo_mapper/role.rb
|
163
176
|
- lib/roles_mongo_mapper/strategy.rb
|
177
|
+
- lib/roles_mongo_mapper/strategy/multi.rb
|
178
|
+
- lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb
|
164
179
|
- lib/roles_mongo_mapper/strategy/multi/many_roles.rb
|
165
180
|
- lib/roles_mongo_mapper/strategy/multi/role_strings.rb
|
166
181
|
- lib/roles_mongo_mapper/strategy/multi/roles_mask.rb
|
182
|
+
- lib/roles_mongo_mapper/strategy/shared.rb
|
183
|
+
- lib/roles_mongo_mapper/strategy/single.rb
|
167
184
|
- lib/roles_mongo_mapper/strategy/single/admin_flag.rb
|
185
|
+
- lib/roles_mongo_mapper/strategy/single/embed_one_role.rb
|
168
186
|
- lib/roles_mongo_mapper/strategy/single/one_role.rb
|
169
187
|
- lib/roles_mongo_mapper/strategy/single/role_string.rb
|
170
188
|
- roles_mongo_mapper.gemspec
|
171
189
|
- sandbox/test.rb
|
172
190
|
- spec/generator_spec_helper.rb
|
173
191
|
- spec/roles_mongo_mapper/generators/roles_generator_spec.rb
|
174
|
-
- spec/roles_mongo_mapper/strategy/
|
175
|
-
- spec/roles_mongo_mapper/strategy/
|
176
|
-
- spec/roles_mongo_mapper/strategy/
|
177
|
-
- spec/roles_mongo_mapper/strategy/
|
178
|
-
- spec/roles_mongo_mapper/strategy/role_strings_spec.rb
|
179
|
-
- spec/roles_mongo_mapper/strategy/roles_mask_spec.rb
|
192
|
+
- spec/roles_mongo_mapper/strategy/api_examples.rb
|
193
|
+
- spec/roles_mongo_mapper/strategy/hooks.rb
|
194
|
+
- spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb
|
195
|
+
- spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb
|
196
|
+
- spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb
|
197
|
+
- spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb
|
198
|
+
- spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb
|
199
|
+
- spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb
|
200
|
+
- spec/roles_mongo_mapper/strategy/single/one_role_spec.rb
|
201
|
+
- spec/roles_mongo_mapper/strategy/single/role_string_spec.rb
|
202
|
+
- spec/roles_mongo_mapper/strategy/user_setup.rb
|
180
203
|
- spec/spec_helper.rb
|
181
204
|
has_rdoc: true
|
182
205
|
homepage: http://github.com/kristianmandrup/roles_mongo_mapper
|
@@ -213,10 +236,15 @@ summary: Implementation of Roles generic API for MongoMapper
|
|
213
236
|
test_files:
|
214
237
|
- spec/generator_spec_helper.rb
|
215
238
|
- spec/roles_mongo_mapper/generators/roles_generator_spec.rb
|
216
|
-
- spec/roles_mongo_mapper/strategy/
|
217
|
-
- spec/roles_mongo_mapper/strategy/
|
218
|
-
- spec/roles_mongo_mapper/strategy/
|
219
|
-
- spec/roles_mongo_mapper/strategy/
|
220
|
-
- spec/roles_mongo_mapper/strategy/role_strings_spec.rb
|
221
|
-
- spec/roles_mongo_mapper/strategy/roles_mask_spec.rb
|
239
|
+
- spec/roles_mongo_mapper/strategy/api_examples.rb
|
240
|
+
- spec/roles_mongo_mapper/strategy/hooks.rb
|
241
|
+
- spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb
|
242
|
+
- spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb
|
243
|
+
- spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb
|
244
|
+
- spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb
|
245
|
+
- spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb
|
246
|
+
- spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb
|
247
|
+
- spec/roles_mongo_mapper/strategy/single/one_role_spec.rb
|
248
|
+
- spec/roles_mongo_mapper/strategy/single/role_string_spec.rb
|
249
|
+
- spec/roles_mongo_mapper/strategy/user_setup.rb
|
222
250
|
- spec/spec_helper.rb
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
use_roles_strategy :admin_flag
|
3
|
-
|
4
|
-
class User
|
5
|
-
include MongoMapper::Document
|
6
|
-
include Roles::MongoMapper
|
7
|
-
|
8
|
-
strategy :admin_flag, :default
|
9
|
-
valid_roles_are :admin, :guest
|
10
|
-
|
11
|
-
key :name, String
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "Roles for MongoMapper" do
|
15
|
-
after :each do
|
16
|
-
Database.teardown
|
17
|
-
end
|
18
|
-
|
19
|
-
before :each do
|
20
|
-
@user = User.create(:name => 'Kristian')
|
21
|
-
@user.roles = :guest
|
22
|
-
@user.save
|
23
|
-
|
24
|
-
@admin_user = User.create(:name => 'Admin user')
|
25
|
-
@admin_user.roles = :admin
|
26
|
-
@admin_user.save
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "Admin flag strategy " do
|
30
|
-
|
31
|
-
describe '#in_role' do
|
32
|
-
it "should return first user maching role" do
|
33
|
-
puts "Guest: #{User.where(:name => "Kristian").first}"
|
34
|
-
|
35
|
-
User.in_role(:guest).first.name.should == 'Kristian'
|
36
|
-
User.in_role(:admin).first.name.should == 'Admin user'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'roles API' do
|
41
|
-
it "should have admin user role to :admin" do
|
42
|
-
@admin_user.role.should == :admin
|
43
|
-
@admin_user.roles.should == [:admin]
|
44
|
-
@admin_user.admin?.should be_true
|
45
|
-
|
46
|
-
@admin_user.class.valid_roles.should == [:admin, :guest]
|
47
|
-
|
48
|
-
@admin_user.has_role?(:guest).should be_false
|
49
|
-
|
50
|
-
@admin_user.has_role?(:admin).should be_true
|
51
|
-
@admin_user.is?(:admin).should be_true
|
52
|
-
@admin_user.has_roles?(:admin).should be_true
|
53
|
-
@admin_user.has?(:admin).should be_true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should have user role to :guest" do
|
57
|
-
@user.roles.should == [:guest]
|
58
|
-
@user.admin?.should be_false
|
59
|
-
|
60
|
-
@user.has_role?(:guest).should be_true
|
61
|
-
@user.has_role?(:admin).should be_false
|
62
|
-
@user.is?(:admin).should be_false
|
63
|
-
|
64
|
-
@user.has_roles?(:guest).should be_true
|
65
|
-
@user.has?(:admin).should be_false
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should set user role to :admin using =" do
|
69
|
-
@user.roles = :admin
|
70
|
-
@user.role.should == :admin
|
71
|
-
@user.has_role?(:admin).should be_true
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
@@ -1,69 +0,0 @@
|
|
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
|
-
|
11
|
-
key :name, String
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "Roles for MongoMapper" do
|
15
|
-
context "default setup" do
|
16
|
-
|
17
|
-
before do
|
18
|
-
User.valid_roles_are :admin, :guest
|
19
|
-
|
20
|
-
@user = User.create(:name => 'Kristian')
|
21
|
-
@user.add_roles :guest
|
22
|
-
@user.save
|
23
|
-
|
24
|
-
@admin_user = User.create(:name => 'Admin user')
|
25
|
-
@admin_user.roles = :admin
|
26
|
-
@admin_user.save
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#in_role' do
|
30
|
-
it "should return first user matching role" do
|
31
|
-
User.in_role(:guest).first.name.should == 'Kristian'
|
32
|
-
User.in_role(:admin).first.name.should == 'Admin user'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "Role API" do
|
37
|
-
it "should have admin user role to :admin" do
|
38
|
-
@admin_user.roles_list.first.should == :admin
|
39
|
-
@admin_user.admin?.should be_true
|
40
|
-
|
41
|
-
@admin_user.has_role?(:guest).should be_false
|
42
|
-
|
43
|
-
@admin_user.has_role?(:admin).should be_true
|
44
|
-
@admin_user.is?(:admin).should be_true
|
45
|
-
@admin_user.has_roles?(:admin).should be_true
|
46
|
-
@admin_user.has?(:admin).should be_true
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should have user role to :guest" do
|
50
|
-
@user.roles_list.first.should == :guest
|
51
|
-
@user.admin?.should be_false
|
52
|
-
|
53
|
-
@user.has_role?(:guest).should be_true
|
54
|
-
@user.has_role?(:admin).should be_false
|
55
|
-
@user.is?(:admin).should be_false
|
56
|
-
|
57
|
-
@user.has_roles?(:admin).should be_false
|
58
|
-
@user.has?(:admin).should be_false
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should set user role to :admin using roles=" do
|
62
|
-
@user.roles = :admin
|
63
|
-
@user.roles_list.first.should == :admin
|
64
|
-
@user.has_role?(:admin).should be_true
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|