roles_data_mapper 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -6
- data/VERSION +1 -1
- data/lib/roles_data_mapper/base.rb +3 -3
- data/lib/roles_data_mapper/strategy/multi/many_roles.rb +51 -25
- data/lib/roles_data_mapper/strategy/multi/roles_mask.rb +70 -23
- data/lib/roles_data_mapper/strategy/multi.rb +54 -0
- data/lib/roles_data_mapper/strategy/shared.rb +26 -0
- data/lib/roles_data_mapper/strategy/single/admin_flag.rb +55 -22
- data/lib/roles_data_mapper/strategy/single/one_role.rb +34 -23
- data/lib/roles_data_mapper/strategy/single/role_string.rb +19 -18
- data/lib/roles_data_mapper/strategy/single.rb +34 -0
- data/roles_data_mapper.gemspec +35 -30
- data/spec/roles_data_mapper/strategy/api_examples.rb +212 -0
- data/spec/roles_data_mapper/strategy/multi/many_roles_spec.rb +32 -0
- data/spec/roles_data_mapper/strategy/{roles_mask_spec.rb → multi/roles_mask_spec.rb} +13 -7
- data/spec/roles_data_mapper/strategy/{admin_flag_spec.rb → single/admin_flag_spec.rb} +11 -7
- data/spec/roles_data_mapper/strategy/single/one_role_spec.rb +27 -0
- data/spec/roles_data_mapper/strategy/single/role_string_spec.rb +49 -0
- data/spec/roles_data_mapper/strategy/user_setup.rb +4 -4
- metadata +35 -31
- data/spec/roles_data_mapper/strategy/many_roles_spec.rb +0 -23
- data/spec/roles_data_mapper/strategy/one_role_spec.rb +0 -23
- data/spec/roles_data_mapper/strategy/role_string_spec.rb +0 -22
data/roles_data_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{roles_data_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-27}
|
13
13
|
s.description = %q{Makes it easy to set a role strategy on your User model in DataMapper}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,19 +30,23 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/roles_data_mapper/namespaces.rb",
|
31
31
|
"lib/roles_data_mapper/role.rb",
|
32
32
|
"lib/roles_data_mapper/strategy.rb",
|
33
|
+
"lib/roles_data_mapper/strategy/multi.rb",
|
33
34
|
"lib/roles_data_mapper/strategy/multi/many_roles.rb",
|
34
35
|
"lib/roles_data_mapper/strategy/multi/roles_mask.rb",
|
36
|
+
"lib/roles_data_mapper/strategy/shared.rb",
|
37
|
+
"lib/roles_data_mapper/strategy/single.rb",
|
35
38
|
"lib/roles_data_mapper/strategy/single/admin_flag.rb",
|
36
39
|
"lib/roles_data_mapper/strategy/single/one_role.rb",
|
37
40
|
"lib/roles_data_mapper/strategy/single/role_string.rb",
|
38
41
|
"roles_data_mapper.gemspec",
|
39
42
|
"spec/generator_spec_helper.rb",
|
40
43
|
"spec/roles_data_mapper/generators/roles_generator_spec.rb",
|
41
|
-
"spec/roles_data_mapper/strategy/
|
42
|
-
"spec/roles_data_mapper/strategy/many_roles_spec.rb",
|
43
|
-
"spec/roles_data_mapper/strategy/
|
44
|
-
"spec/roles_data_mapper/strategy/
|
45
|
-
"spec/roles_data_mapper/strategy/
|
44
|
+
"spec/roles_data_mapper/strategy/api_examples.rb",
|
45
|
+
"spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
|
46
|
+
"spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
|
47
|
+
"spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
|
48
|
+
"spec/roles_data_mapper/strategy/single/one_role_spec.rb",
|
49
|
+
"spec/roles_data_mapper/strategy/single/role_string_spec.rb",
|
46
50
|
"spec/roles_data_mapper/strategy/user_setup.rb",
|
47
51
|
"spec/spec_helper.rb",
|
48
52
|
"tmp/rails/config/routes.rb"
|
@@ -55,11 +59,12 @@ Gem::Specification.new do |s|
|
|
55
59
|
s.test_files = [
|
56
60
|
"spec/generator_spec_helper.rb",
|
57
61
|
"spec/roles_data_mapper/generators/roles_generator_spec.rb",
|
58
|
-
"spec/roles_data_mapper/strategy/
|
59
|
-
"spec/roles_data_mapper/strategy/many_roles_spec.rb",
|
60
|
-
"spec/roles_data_mapper/strategy/
|
61
|
-
"spec/roles_data_mapper/strategy/
|
62
|
-
"spec/roles_data_mapper/strategy/
|
62
|
+
"spec/roles_data_mapper/strategy/api_examples.rb",
|
63
|
+
"spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
|
64
|
+
"spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
|
65
|
+
"spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
|
66
|
+
"spec/roles_data_mapper/strategy/single/one_role_spec.rb",
|
67
|
+
"spec/roles_data_mapper/strategy/single/role_string_spec.rb",
|
63
68
|
"spec/roles_data_mapper/strategy/user_setup.rb",
|
64
69
|
"spec/spec_helper.rb"
|
65
70
|
]
|
@@ -69,39 +74,39 @@ Gem::Specification.new do |s|
|
|
69
74
|
s.specification_version = 3
|
70
75
|
|
71
76
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
72
|
-
s.add_development_dependency(%q<rspec>, [">= 2.0.
|
77
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
73
78
|
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0"])
|
74
79
|
s.add_runtime_dependency(%q<dm-types>, ["~> 1.0"])
|
75
80
|
s.add_runtime_dependency(%q<dm-migrations>, ["~> 1.0"])
|
76
|
-
s.add_runtime_dependency(%q<activesupport>, ["
|
81
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
77
82
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
78
|
-
s.add_runtime_dependency(%q<sugar-high>, ["
|
79
|
-
s.add_runtime_dependency(%q<roles_generic>, ["
|
80
|
-
s.add_runtime_dependency(%q<rails3_artifactor>, [">= 0.
|
81
|
-
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.
|
83
|
+
s.add_runtime_dependency(%q<sugar-high>, [">= 0.3.0"])
|
84
|
+
s.add_runtime_dependency(%q<roles_generic>, [">= 0.3.1"])
|
85
|
+
s.add_runtime_dependency(%q<rails3_artifactor>, [">= 0.3.1"])
|
86
|
+
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
|
82
87
|
else
|
83
|
-
s.add_dependency(%q<rspec>, [">= 2.0.
|
88
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
84
89
|
s.add_dependency(%q<dm-core>, ["~> 1.0"])
|
85
90
|
s.add_dependency(%q<dm-types>, ["~> 1.0"])
|
86
91
|
s.add_dependency(%q<dm-migrations>, ["~> 1.0"])
|
87
|
-
s.add_dependency(%q<activesupport>, ["
|
92
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
88
93
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
89
|
-
s.add_dependency(%q<sugar-high>, ["
|
90
|
-
s.add_dependency(%q<roles_generic>, ["
|
91
|
-
s.add_dependency(%q<rails3_artifactor>, [">= 0.
|
92
|
-
s.add_dependency(%q<logging_assist>, [">= 0.1.
|
94
|
+
s.add_dependency(%q<sugar-high>, [">= 0.3.0"])
|
95
|
+
s.add_dependency(%q<roles_generic>, [">= 0.3.1"])
|
96
|
+
s.add_dependency(%q<rails3_artifactor>, [">= 0.3.1"])
|
97
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
|
93
98
|
end
|
94
99
|
else
|
95
|
-
s.add_dependency(%q<rspec>, [">= 2.0.
|
100
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
96
101
|
s.add_dependency(%q<dm-core>, ["~> 1.0"])
|
97
102
|
s.add_dependency(%q<dm-types>, ["~> 1.0"])
|
98
103
|
s.add_dependency(%q<dm-migrations>, ["~> 1.0"])
|
99
|
-
s.add_dependency(%q<activesupport>, ["
|
104
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
100
105
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
101
|
-
s.add_dependency(%q<sugar-high>, ["
|
102
|
-
s.add_dependency(%q<roles_generic>, ["
|
103
|
-
s.add_dependency(%q<rails3_artifactor>, [">= 0.
|
104
|
-
s.add_dependency(%q<logging_assist>, [">= 0.1.
|
106
|
+
s.add_dependency(%q<sugar-high>, [">= 0.3.0"])
|
107
|
+
s.add_dependency(%q<roles_generic>, [">= 0.3.1"])
|
108
|
+
s.add_dependency(%q<rails3_artifactor>, [">= 0.3.1"])
|
109
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
@@ -0,0 +1,212 @@
|
|
1
|
+
describe "Roles for Active Record: #{api_name}" do
|
2
|
+
# before do
|
3
|
+
# api_migrate
|
4
|
+
# end
|
5
|
+
#
|
6
|
+
# before :each do
|
7
|
+
# api_fixture
|
8
|
+
# end
|
9
|
+
|
10
|
+
require "roles_data_mapper/strategy/user_setup.rb"
|
11
|
+
|
12
|
+
before do
|
13
|
+
default_user_setup
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#in_role' do
|
17
|
+
it "should return first user matching role" do
|
18
|
+
if User.respond_to? :in_role
|
19
|
+
User.in_role(:guest).map(&:name).should include('Guest user')
|
20
|
+
User.in_role(:admin).map(&:name).should include('Admin user')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#in_any_role' do
|
26
|
+
it "should return first user matching role" do
|
27
|
+
if User.respond_to? :in_any_role
|
28
|
+
User.in_any_role(:guest, :user).map(&:name).should include('Guest user')
|
29
|
+
User.in_any_role(:editor).should be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
|
35
|
+
# mutation API
|
36
|
+
[:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
|
37
|
+
@admin_user.respond_to?(api_method).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
# inspection API
|
41
|
+
[:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
|
42
|
+
@admin_user.respond_to?(api_method).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
# class method API
|
46
|
+
[:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
|
47
|
+
@admin_user.class.respond_to?(class_api_method).should be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#valid_role?' do
|
52
|
+
it "should be true that the admin user has a valid role of :guest" do
|
53
|
+
# @admin_user.valid_role?(:guest).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be true that the User class has a valid role of :guest" do
|
57
|
+
# User.valid_role?(:guest).should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#valid_roles' do
|
62
|
+
it "should be true that the admin user has a valid role of :guest" do
|
63
|
+
# @admin_user.valid_roles.should include(:guest, :admin)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be true that the User class has a valid role of :guest" do
|
67
|
+
User.valid_roles.should include(:guest, :admin)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#valid_roles?' do
|
72
|
+
it "should be true that the admin user has a valid role of :guest" do
|
73
|
+
@admin_user.valid_roles?(:guest, :admin).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be true that the User class has a valid role of :guest" do
|
77
|
+
User.valid_roles?(:guest, :admin).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#has_role?' do
|
82
|
+
it "should have admin user role to :admin and not to :user" do
|
83
|
+
@admin_user.has_role?(:user).should be_false
|
84
|
+
@admin_user.has_role?(:admin).should be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be true that guest user has role :guest and not :admin" do
|
88
|
+
puts "Guest user: #{@guest_user.roles_list}"
|
89
|
+
@guest_user.has_role?(:guest).should be_true
|
90
|
+
@guest_user.has_role?(:admin).should be_false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#has?' do
|
95
|
+
it "should be true that the admin_user has the :admin role" do
|
96
|
+
@admin_user.has?(:admin).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should NOT be true that the admin_user has the :admin role" do
|
100
|
+
@guest_user.has?(:admin).should be_false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#has_roles?' do
|
105
|
+
it "should be true that the admin_user has the roles :admin" do
|
106
|
+
# @admin_user.has_roles?(:admin).should be_true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should NOT be true that the user has the roles :admin" do
|
110
|
+
@guest_user.has_roles?(:admin).should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#roles_list' do
|
115
|
+
it "should be true that the first role of admin_user is the :admin role" do
|
116
|
+
@admin_user.roles_list.should include(:admin)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be true that the first role of admin_user is the :user role" do
|
120
|
+
case @normal_user.class.role_strategy.multiplicity
|
121
|
+
when :single
|
122
|
+
#if @normal_user.class.role_strategy.name == :admin_flag
|
123
|
+
@normal_user.roles_list.should include(:guest)
|
124
|
+
# else
|
125
|
+
# @normal_user.roles_list.should include(:user)
|
126
|
+
#end
|
127
|
+
when :multi
|
128
|
+
@normal_user.roles_list.should include(:user, :guest)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#roles' do
|
134
|
+
it "should be true that the roles of admin_user is an array with the role :admin" do
|
135
|
+
roles = @admin_user.roles
|
136
|
+
if defined?(Role) && roles.kind_of?(Role)
|
137
|
+
roles.name.to_sym.should == :admin
|
138
|
+
elsif roles.kind_of? Array
|
139
|
+
if @normal_user.class.role_strategy.type == :complex
|
140
|
+
roles.first.name.to_sym.should == :admin
|
141
|
+
end
|
142
|
+
if @normal_user.class.role_strategy.name == :admin_flag
|
143
|
+
roles.first.admin?.should be_true
|
144
|
+
end
|
145
|
+
else
|
146
|
+
roles.to_sym.should == :admin
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#admin?' do
|
152
|
+
it "should be true that admin_user is in the :admin role" do
|
153
|
+
@admin_user.admin?.should be_true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should NOT be true that the user is in the :admin role" do
|
157
|
+
@guest_user.admin?.should be_false
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '#is?' do
|
162
|
+
it "should be true that admin_user is in the :admin role" do
|
163
|
+
@admin_user.is?(:admin).should be_true
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should NOT be true that the user is in the :admin role" do
|
167
|
+
@guest_user.is?(:admin).should be_false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '#roles=' do
|
172
|
+
it "should set user role to :admin" do
|
173
|
+
@guest_user.roles = :admin
|
174
|
+
@guest_user.has_role?(:admin).should be_true
|
175
|
+
@guest_user.roles = :guest
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#exchange_roles' do
|
180
|
+
it "should exchange user role :user with role :admin" do
|
181
|
+
@guest_user.exchange_role :guest, :with => :admin
|
182
|
+
@guest_user.has?(:guest).should be_false
|
183
|
+
@guest_user.has?(:admin).should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should exchange user role :admin with roles :user and :guest" do
|
187
|
+
case @admin_user.class.role_strategy.multiplicity
|
188
|
+
when :single
|
189
|
+
lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
|
190
|
+
when :multi
|
191
|
+
@admin_user.exchange_role :admin, :with => [:user, :guest]
|
192
|
+
@admin_user.has_role?(:user).should be_true
|
193
|
+
@admin_user.has_role?(:guest).should be_true
|
194
|
+
@admin_user.has?(:admin).should be_false
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe '#remove_roles' do
|
200
|
+
it "should remove user role :admin using #remove_roles" do
|
201
|
+
@admin_user.remove_roles :admin
|
202
|
+
@admin_user.has_role?(:admin).should_not be_true
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should remove user role :admin using #remove_role" do
|
206
|
+
@guest_user.add_role :admin
|
207
|
+
@guest_user.has_role?(:admin).should be_true
|
208
|
+
@guest_user.remove_role :admin
|
209
|
+
@guest_user.has_role?(:admin).should_not be_true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :many_roles
|
3
|
+
|
4
|
+
class User
|
5
|
+
include DataMapper::Resource
|
6
|
+
include Roles::DataMapper
|
7
|
+
|
8
|
+
strategy :many_roles, :default
|
9
|
+
role_class :role
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
property :name, String
|
13
|
+
end
|
14
|
+
|
15
|
+
DataMapper.finalize
|
16
|
+
DataMapper.auto_migrate!
|
17
|
+
|
18
|
+
User.valid_roles_are :admin, :guest, :user
|
19
|
+
|
20
|
+
# def api_migrate
|
21
|
+
# migrate('many_roles')
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def api_fixture
|
25
|
+
# load 'fixtures/many_roles_setup.rb'
|
26
|
+
# end
|
27
|
+
|
28
|
+
def api_name
|
29
|
+
:many_roles
|
30
|
+
end
|
31
|
+
|
32
|
+
load 'roles_data_mapper/strategy/api_examples.rb'
|
@@ -1,22 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
use_roles_strategy :roles_mask
|
3
3
|
|
4
|
-
class User
|
4
|
+
class User
|
5
5
|
include DataMapper::Resource
|
6
6
|
include Roles::DataMapper
|
7
7
|
|
8
8
|
strategy :roles_mask, :default
|
9
|
-
|
10
9
|
property :id, Serial
|
11
|
-
property :name, String
|
10
|
+
property :name, String
|
12
11
|
end
|
13
12
|
|
14
13
|
DataMapper.finalize
|
15
14
|
DataMapper.auto_migrate!
|
16
15
|
|
17
|
-
User.valid_roles_are :admin, :guest
|
16
|
+
User.valid_roles_are :admin, :guest, :user
|
17
|
+
|
18
|
+
# def api_migrate
|
19
|
+
# migrate('roles_mask')
|
20
|
+
# end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
require "roles_generic/rspec/api"
|
22
|
+
def api_name
|
23
|
+
:roles_mask
|
22
24
|
end
|
25
|
+
|
26
|
+
load 'roles_data_mapper/strategy/api_examples.rb'
|
27
|
+
|
28
|
+
|
@@ -1,22 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
use_roles_strategy :admin_flag
|
3
3
|
|
4
|
-
class User
|
4
|
+
class User
|
5
5
|
include DataMapper::Resource
|
6
6
|
include Roles::DataMapper
|
7
7
|
|
8
8
|
strategy :admin_flag, :default
|
9
|
-
|
10
9
|
property :id, Serial
|
11
|
-
property :name, String
|
10
|
+
property :name, String
|
12
11
|
end
|
13
12
|
|
14
13
|
DataMapper.finalize
|
15
14
|
DataMapper.auto_migrate!
|
16
15
|
|
17
|
-
User.valid_roles_are :admin, :guest
|
16
|
+
User.valid_roles_are :admin, :guest, :user
|
17
|
+
|
18
|
+
# def api_migrate
|
19
|
+
# migrate('roles_mask')
|
20
|
+
# end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
require "roles_generic/rspec/api"
|
22
|
+
def api_name
|
23
|
+
:admin_flag
|
22
24
|
end
|
25
|
+
|
26
|
+
load 'roles_data_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :one_role
|
3
|
+
|
4
|
+
class User
|
5
|
+
include DataMapper::Resource
|
6
|
+
include Roles::DataMapper
|
7
|
+
|
8
|
+
strategy :one_role, :default
|
9
|
+
role_class :role
|
10
|
+
property :id, Serial
|
11
|
+
property :name, String
|
12
|
+
end
|
13
|
+
|
14
|
+
DataMapper.finalize
|
15
|
+
DataMapper.auto_migrate!
|
16
|
+
|
17
|
+
User.valid_roles_are :admin, :guest, :user
|
18
|
+
|
19
|
+
# def api_migrate
|
20
|
+
# migrate('roles_mask')
|
21
|
+
# end
|
22
|
+
|
23
|
+
def api_name
|
24
|
+
:one_role
|
25
|
+
end
|
26
|
+
|
27
|
+
load 'roles_data_mapper/strategy/api_examples.rb'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
use_roles_strategy :role_string
|
3
|
+
|
4
|
+
class User
|
5
|
+
include DataMapper::Resource
|
6
|
+
include Roles::DataMapper
|
7
|
+
|
8
|
+
strategy :role_string, :default
|
9
|
+
property :id, Serial
|
10
|
+
property :name, String
|
11
|
+
end
|
12
|
+
|
13
|
+
DataMapper.finalize
|
14
|
+
DataMapper.auto_migrate!
|
15
|
+
|
16
|
+
User.valid_roles_are :admin, :guest, :user
|
17
|
+
|
18
|
+
# def api_migrate
|
19
|
+
# migrate('roles_mask')
|
20
|
+
# end
|
21
|
+
|
22
|
+
def api_name
|
23
|
+
:role_string
|
24
|
+
end
|
25
|
+
|
26
|
+
load 'roles_data_mapper/strategy/api_examples.rb'
|
27
|
+
|
28
|
+
# require 'spec_helper'
|
29
|
+
# use_roles_strategy :role_string
|
30
|
+
#
|
31
|
+
# class User
|
32
|
+
# include DataMapper::Resource
|
33
|
+
# include Roles::DataMapper
|
34
|
+
#
|
35
|
+
# strategy :role_string, :default
|
36
|
+
#
|
37
|
+
# property :id, Serial
|
38
|
+
# property :name, String
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# DataMapper.finalize
|
42
|
+
# DataMapper.auto_migrate!
|
43
|
+
#
|
44
|
+
# User.valid_roles_are :admin, :guest
|
45
|
+
#
|
46
|
+
# describe "Roles for DataMapper: :role_string strategy" do
|
47
|
+
# require "roles_data_mapper/user_setup"
|
48
|
+
# require "roles_generic/rspec/api"
|
49
|
+
# end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
def default_user_setup
|
2
|
-
@guest_user = User.create(:name => 'Guest
|
2
|
+
@guest_user = User.create(:name => 'Guest user')
|
3
3
|
@guest_user.add_roles :guest
|
4
4
|
@guest_user.save
|
5
5
|
|
6
|
-
@normal_user = User.create(:name => 'Normal
|
7
|
-
@normal_user.roles = :guest, :user
|
6
|
+
@normal_user = User.create(:name => 'Normal user')
|
7
|
+
@normal_user.roles = :guest, :user
|
8
8
|
@normal_user.save
|
9
9
|
|
10
10
|
@admin_user = User.create(:name => 'Admin user')
|
11
11
|
@admin_user.roles = :admin
|
12
|
-
@admin_user.save
|
12
|
+
@admin_user.save
|
13
13
|
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
|
+
- 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-27 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,9 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 2
|
30
30
|
- 0
|
31
|
-
-
|
32
|
-
|
33
|
-
version: 2.0.0.rc
|
31
|
+
- 1
|
32
|
+
version: 2.0.1
|
34
33
|
type: :development
|
35
34
|
version_requirements: *id001
|
36
35
|
- !ruby/object:Gem::Dependency
|
@@ -81,7 +80,7 @@ dependencies:
|
|
81
80
|
requirement: &id005 !ruby/object:Gem::Requirement
|
82
81
|
none: false
|
83
82
|
requirements:
|
84
|
-
- -
|
83
|
+
- - ">="
|
85
84
|
- !ruby/object:Gem::Version
|
86
85
|
segments:
|
87
86
|
- 3
|
@@ -111,13 +110,13 @@ dependencies:
|
|
111
110
|
requirement: &id007 !ruby/object:Gem::Requirement
|
112
111
|
none: false
|
113
112
|
requirements:
|
114
|
-
- -
|
113
|
+
- - ">="
|
115
114
|
- !ruby/object:Gem::Version
|
116
115
|
segments:
|
117
116
|
- 0
|
118
|
-
-
|
119
|
-
-
|
120
|
-
version: 0.
|
117
|
+
- 3
|
118
|
+
- 0
|
119
|
+
version: 0.3.0
|
121
120
|
type: :runtime
|
122
121
|
version_requirements: *id007
|
123
122
|
- !ruby/object:Gem::Dependency
|
@@ -126,13 +125,13 @@ dependencies:
|
|
126
125
|
requirement: &id008 !ruby/object:Gem::Requirement
|
127
126
|
none: false
|
128
127
|
requirements:
|
129
|
-
- -
|
128
|
+
- - ">="
|
130
129
|
- !ruby/object:Gem::Version
|
131
130
|
segments:
|
132
131
|
- 0
|
133
|
-
-
|
134
|
-
-
|
135
|
-
version: 0.
|
132
|
+
- 3
|
133
|
+
- 1
|
134
|
+
version: 0.3.1
|
136
135
|
type: :runtime
|
137
136
|
version_requirements: *id008
|
138
137
|
- !ruby/object:Gem::Dependency
|
@@ -145,9 +144,9 @@ dependencies:
|
|
145
144
|
- !ruby/object:Gem::Version
|
146
145
|
segments:
|
147
146
|
- 0
|
148
|
-
-
|
149
|
-
-
|
150
|
-
version: 0.
|
147
|
+
- 3
|
148
|
+
- 1
|
149
|
+
version: 0.3.1
|
151
150
|
type: :runtime
|
152
151
|
version_requirements: *id009
|
153
152
|
- !ruby/object:Gem::Dependency
|
@@ -161,8 +160,8 @@ dependencies:
|
|
161
160
|
segments:
|
162
161
|
- 0
|
163
162
|
- 1
|
164
|
-
-
|
165
|
-
version: 0.1.
|
163
|
+
- 6
|
164
|
+
version: 0.1.6
|
166
165
|
type: :runtime
|
167
166
|
version_requirements: *id010
|
168
167
|
description: Makes it easy to set a role strategy on your User model in DataMapper
|
@@ -188,19 +187,23 @@ files:
|
|
188
187
|
- lib/roles_data_mapper/namespaces.rb
|
189
188
|
- lib/roles_data_mapper/role.rb
|
190
189
|
- lib/roles_data_mapper/strategy.rb
|
190
|
+
- lib/roles_data_mapper/strategy/multi.rb
|
191
191
|
- lib/roles_data_mapper/strategy/multi/many_roles.rb
|
192
192
|
- lib/roles_data_mapper/strategy/multi/roles_mask.rb
|
193
|
+
- lib/roles_data_mapper/strategy/shared.rb
|
194
|
+
- lib/roles_data_mapper/strategy/single.rb
|
193
195
|
- lib/roles_data_mapper/strategy/single/admin_flag.rb
|
194
196
|
- lib/roles_data_mapper/strategy/single/one_role.rb
|
195
197
|
- lib/roles_data_mapper/strategy/single/role_string.rb
|
196
198
|
- roles_data_mapper.gemspec
|
197
199
|
- spec/generator_spec_helper.rb
|
198
200
|
- spec/roles_data_mapper/generators/roles_generator_spec.rb
|
199
|
-
- spec/roles_data_mapper/strategy/
|
200
|
-
- spec/roles_data_mapper/strategy/many_roles_spec.rb
|
201
|
-
- spec/roles_data_mapper/strategy/
|
202
|
-
- spec/roles_data_mapper/strategy/
|
203
|
-
- spec/roles_data_mapper/strategy/
|
201
|
+
- spec/roles_data_mapper/strategy/api_examples.rb
|
202
|
+
- spec/roles_data_mapper/strategy/multi/many_roles_spec.rb
|
203
|
+
- spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb
|
204
|
+
- spec/roles_data_mapper/strategy/single/admin_flag_spec.rb
|
205
|
+
- spec/roles_data_mapper/strategy/single/one_role_spec.rb
|
206
|
+
- spec/roles_data_mapper/strategy/single/role_string_spec.rb
|
204
207
|
- spec/roles_data_mapper/strategy/user_setup.rb
|
205
208
|
- spec/spec_helper.rb
|
206
209
|
- tmp/rails/config/routes.rb
|
@@ -239,10 +242,11 @@ summary: Implementation of Roles generic API for DataMapper
|
|
239
242
|
test_files:
|
240
243
|
- spec/generator_spec_helper.rb
|
241
244
|
- spec/roles_data_mapper/generators/roles_generator_spec.rb
|
242
|
-
- spec/roles_data_mapper/strategy/
|
243
|
-
- spec/roles_data_mapper/strategy/many_roles_spec.rb
|
244
|
-
- spec/roles_data_mapper/strategy/
|
245
|
-
- spec/roles_data_mapper/strategy/
|
246
|
-
- spec/roles_data_mapper/strategy/
|
245
|
+
- spec/roles_data_mapper/strategy/api_examples.rb
|
246
|
+
- spec/roles_data_mapper/strategy/multi/many_roles_spec.rb
|
247
|
+
- spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb
|
248
|
+
- spec/roles_data_mapper/strategy/single/admin_flag_spec.rb
|
249
|
+
- spec/roles_data_mapper/strategy/single/one_role_spec.rb
|
250
|
+
- spec/roles_data_mapper/strategy/single/role_string_spec.rb
|
247
251
|
- spec/roles_data_mapper/strategy/user_setup.rb
|
248
252
|
- spec/spec_helper.rb
|