easy_roles 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +22 -0
- data/Manifest +5 -1
- data/README.rdoc +1 -18
- data/Rakefile +2 -2
- data/easy_roles.gemspec +15 -6
- data/lib/easy_roles.rb +12 -1
- data/spec/easy_roles_spec.rb +332 -0
- data/spec/spec_helper.rb +65 -0
- metadata +67 -9
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
=== 06 September 2010 - Version 1.1.0
|
2
|
+
Fixed the issue where the is_user? method was not working through association, if the is_user? method had not been called before
|
3
|
+
Wrote tests (FINALLY!!!)
|
4
|
+
|
5
|
+
=== 05 April 2010 - Version 1.0.0
|
6
|
+
Serialize method updated for Rails 3 compatibility. (Thanks to firebelly for pointing this out)
|
7
|
+
|
8
|
+
=== 03 February 2010 - Version 0.4.2
|
9
|
+
Fixed migration names
|
10
|
+
Does not allow duplicates to be added
|
11
|
+
|
12
|
+
=== 08 December 2009 - Version 0.4.1
|
13
|
+
Added a bitmask migration generator (Read below for usage)
|
14
|
+
|
15
|
+
=== 08 December 2009 - Version 0.4.0
|
16
|
+
Added the ability to use bitmasks instead of serializing the roles in a table (Read below on how to setup and use)
|
17
|
+
|
18
|
+
=== 17 November 2009 - Version 0.3.0
|
19
|
+
Added a generator to generate the database columns "script/generate easy_roles Table Column_Name"
|
20
|
+
|
21
|
+
=== 21 October 2009 - Version 0.2.0
|
22
|
+
Added bang methods for 'add_role' and 'remove_role' which can be accessed through 'add_role!' and 'remove_role!' respectively.
|
data/Manifest
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
CHANGELOG.rdoc
|
2
2
|
README.rdoc
|
3
3
|
Rakefile
|
4
|
+
easy_roles.gemspec
|
4
5
|
generators/easy_bitmask_roles/USAGE
|
5
6
|
generators/easy_bitmask_roles/easy_bitmask_roles_generator.rb
|
6
7
|
generators/easy_bitmask_roles/templates/migration.rb
|
@@ -9,3 +10,6 @@ generators/easy_roles/easy_roles_generator.rb
|
|
9
10
|
generators/easy_roles/templates/migration.rb
|
10
11
|
init.rb
|
11
12
|
lib/easy_roles.rb
|
13
|
+
spec/easy_roles_spec.rb
|
14
|
+
spec/spec_helper.rb
|
15
|
+
Manifest
|
data/README.rdoc
CHANGED
@@ -4,24 +4,7 @@ Simple rails gem for basic role authorization with ruby on rails.
|
|
4
4
|
|
5
5
|
== Changelog
|
6
6
|
|
7
|
-
|
8
|
-
Serialize method updated for Rails 3 compatibility. (Thanks to firebelly for pointing this out)
|
9
|
-
|
10
|
-
=== 03 February 2010 - Version 0.4.2
|
11
|
-
Fixed migration names
|
12
|
-
Does not allow duplicates to be added
|
13
|
-
|
14
|
-
=== 08 December 2009 - Version 0.4.1
|
15
|
-
Added a bitmask migration generator (Read below for usage)
|
16
|
-
|
17
|
-
=== 08 December 2009 - Version 0.4.0
|
18
|
-
Added the ability to use bitmasks instead of serializing the roles in a table (Read below on how to setup and use)
|
19
|
-
|
20
|
-
=== 17 November 2009 - Version 0.3.0
|
21
|
-
Added a generator to generate the database columns "script/generate easy_roles Table Column_Name"
|
22
|
-
|
23
|
-
=== 21 October 2009 - Version 0.2.0
|
24
|
-
Added bang methods for 'add_role' and 'remove_role' which can be accessed through 'add_role!' and 'remove_role!' respectively.
|
7
|
+
Please read the CHANGELOG.rdoc file.
|
25
8
|
|
26
9
|
== Install
|
27
10
|
|
data/Rakefile
CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('easy_roles', '1.
|
5
|
+
Echoe.new('easy_roles', '1.1.0') do |p|
|
6
6
|
p.description = "Easy role authorization in rails"
|
7
7
|
p.url = "http://github.com/platform45/easy_roles"
|
8
8
|
p.author = "Platform45"
|
9
9
|
p.email = "ryan@platform45.com"
|
10
10
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
p.development_dependencies = []
|
11
|
+
p.development_dependencies = ["rspec", "active_record", "sqlite3-ruby"]
|
12
12
|
end
|
data/easy_roles.gemspec
CHANGED
@@ -2,29 +2,38 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{easy_roles}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Platform45"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-09-06}
|
10
10
|
s.description = %q{Easy role authorization in rails}
|
11
11
|
s.email = %q{ryan@platform45.com}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/easy_roles.rb"]
|
13
|
-
s.files = ["
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/easy_roles.rb"]
|
13
|
+
s.files = ["CHANGELOG.rdoc", "README.rdoc", "Rakefile", "easy_roles.gemspec", "generators/easy_bitmask_roles/USAGE", "generators/easy_bitmask_roles/easy_bitmask_roles_generator.rb", "generators/easy_bitmask_roles/templates/migration.rb", "generators/easy_roles/USAGE", "generators/easy_roles/easy_roles_generator.rb", "generators/easy_roles/templates/migration.rb", "init.rb", "lib/easy_roles.rb", "spec/easy_roles_spec.rb", "spec/spec_helper.rb", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/platform45/easy_roles}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Easy_roles", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{easy_roles}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
19
|
s.summary = %q{Easy role authorization in rails}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
|
-
if Gem::Version.new(Gem::
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
27
|
+
s.add_development_dependency(%q<active_record>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
26
29
|
else
|
30
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
31
|
+
s.add_dependency(%q<active_record>, [">= 0"])
|
32
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
27
33
|
end
|
28
34
|
else
|
35
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
36
|
+
s.add_dependency(%q<active_record>, [">= 0"])
|
37
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
29
38
|
end
|
30
39
|
end
|
data/lib/easy_roles.rb
CHANGED
@@ -2,6 +2,7 @@ module EasyRoles
|
|
2
2
|
def self.included(base)
|
3
3
|
base.extend ClassMethods
|
4
4
|
base.send :alias_method_chain, :method_missing, :roles
|
5
|
+
base.send :alias_method_chain, :respond_to?, :roles
|
5
6
|
end
|
6
7
|
|
7
8
|
module ClassMethods
|
@@ -113,8 +114,18 @@ module EasyRoles
|
|
113
114
|
method_missing_without_roles(method_id, *args, &block)
|
114
115
|
end
|
115
116
|
end
|
117
|
+
|
118
|
+
def respond_to_with_roles?(method_id, include_private = false)
|
119
|
+
match = method_id.to_s.match(/^is_(\w+)[?]$/)
|
120
|
+
if match && respond_to?('has_role?')
|
121
|
+
true
|
122
|
+
else
|
123
|
+
respond_to_without_roles?(method_id, include_private = false)
|
124
|
+
end
|
125
|
+
end
|
116
126
|
end
|
117
127
|
|
118
128
|
class ActiveRecord::Base
|
119
129
|
include EasyRoles
|
120
|
-
end
|
130
|
+
end
|
131
|
+
|
@@ -0,0 +1,332 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EasyRoles do
|
4
|
+
describe "serialize method" do
|
5
|
+
it "should allow me to set a users role" do
|
6
|
+
user = SerializeUser.new
|
7
|
+
user.add_role 'admin'
|
8
|
+
user.roles.include?("admin").should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return true for is_admin? if the admin role is added to the user" do
|
12
|
+
user = SerializeUser.new
|
13
|
+
user.add_role 'admin'
|
14
|
+
user.is_admin?.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return true for has_role? 'admin' if the admin role is added to the user" do
|
18
|
+
user = SerializeUser.new
|
19
|
+
user.add_role 'admin'
|
20
|
+
user.has_role?('admin').should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should turn false for has_role? 'manager' if manager role is not added to the user" do
|
24
|
+
user = SerializeUser.new
|
25
|
+
user.has_role?('manager').should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should turn false for is_manager? if manager role is not added to the user" do
|
29
|
+
user = SerializeUser.new
|
30
|
+
user.is_manager?.should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the users role through association" do
|
34
|
+
user = BitmaskUser.create(:name => "Bob")
|
35
|
+
user.add_role! "admin"
|
36
|
+
|
37
|
+
membership = Membership.create(:name => "Test Membership", :bitmask_user => user)
|
38
|
+
|
39
|
+
Membership.last.bitmask_user.is_admin?.should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get no method error if no easy roles on model" do
|
43
|
+
begin
|
44
|
+
b = Beggar.create(:name => "Ivor")
|
45
|
+
|
46
|
+
b.is_admin?
|
47
|
+
rescue => e
|
48
|
+
e.class.should == NoMethodError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should get no method error if no easy roles on model even through association" do
|
53
|
+
begin
|
54
|
+
b = Beggar.create(:name => "Ivor")
|
55
|
+
m = Membership.create(:name => "Beggars club", :beggar => b)
|
56
|
+
|
57
|
+
Membership.last.beggar.is_admin?
|
58
|
+
rescue => e
|
59
|
+
e.class.should == NoMethodError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "normal methods" do
|
64
|
+
it "should not save to the database if not implicitly saved" do
|
65
|
+
user = SerializeUser.create(:name => "Ryan")
|
66
|
+
user.add_role 'admin'
|
67
|
+
user.is_admin?.should be_true
|
68
|
+
user.reload
|
69
|
+
|
70
|
+
user.is_admin?.should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should save to the database if implicity saved" do
|
74
|
+
user = SerializeUser.create(:name => "Ryan")
|
75
|
+
user.add_role 'admin'
|
76
|
+
user.is_admin?.should be_true
|
77
|
+
user.save
|
78
|
+
user.reload
|
79
|
+
|
80
|
+
user.is_admin?.should be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should clear all roles and not save if not implicitly saved" do
|
84
|
+
user = SerializeUser.create(:name => "Ryan")
|
85
|
+
user.add_role 'admin'
|
86
|
+
user.is_admin?.should be_true
|
87
|
+
user.save
|
88
|
+
user.reload
|
89
|
+
user.is_admin?.should be_true
|
90
|
+
|
91
|
+
user.clear_roles
|
92
|
+
user.is_admin?.should be_false
|
93
|
+
user.reload
|
94
|
+
|
95
|
+
user.is_admin?.should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should clear all roles and save if implicitly saved" do
|
99
|
+
user = SerializeUser.create(:name => "Ryan")
|
100
|
+
user.add_role 'admin'
|
101
|
+
user.is_admin?.should be_true
|
102
|
+
user.save
|
103
|
+
user.reload
|
104
|
+
user.is_admin?.should be_true
|
105
|
+
|
106
|
+
user.clear_roles
|
107
|
+
user.is_admin?.should be_false
|
108
|
+
user.save
|
109
|
+
user.reload
|
110
|
+
|
111
|
+
user.is_admin?.should be_false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should remove a role and not save unless implicitly saved" do
|
115
|
+
user = SerializeUser.create(:name => "Ryan")
|
116
|
+
user.add_role 'admin'
|
117
|
+
user.is_admin?.should be_true
|
118
|
+
user.save
|
119
|
+
user.reload
|
120
|
+
|
121
|
+
user.is_admin?.should be_true
|
122
|
+
user.remove_role 'admin'
|
123
|
+
user.is_admin?.should be_false
|
124
|
+
user.reload
|
125
|
+
|
126
|
+
user.is_admin?.should be_true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should remove a role and save if implicitly saved" do
|
130
|
+
user = SerializeUser.create(:name => "Ryan")
|
131
|
+
user.add_role 'admin'
|
132
|
+
user.is_admin?.should be_true
|
133
|
+
user.save
|
134
|
+
user.reload
|
135
|
+
|
136
|
+
user.is_admin?.should be_true
|
137
|
+
user.remove_role 'admin'
|
138
|
+
user.is_admin?.should be_false
|
139
|
+
user.save
|
140
|
+
user.reload
|
141
|
+
|
142
|
+
user.is_admin?.should be_false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "bang method" do
|
147
|
+
it "should save to the database if the bang method is used" do
|
148
|
+
user = SerializeUser.create(:name => "Ryan")
|
149
|
+
user.add_role! 'admin'
|
150
|
+
user.is_admin?.should be_true
|
151
|
+
user.reload
|
152
|
+
|
153
|
+
user.is_admin?.should be_true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should remove a role and save" do
|
157
|
+
user = SerializeUser.create(:name => "Ryan")
|
158
|
+
user.add_role 'admin'
|
159
|
+
user.is_admin?.should be_true
|
160
|
+
user.save
|
161
|
+
user.reload
|
162
|
+
|
163
|
+
user.is_admin?.should be_true
|
164
|
+
user.remove_role! 'admin'
|
165
|
+
user.is_admin?.should be_false
|
166
|
+
user.reload
|
167
|
+
|
168
|
+
user.is_admin?.should be_false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "bitmask method" do
|
174
|
+
it "should allow me to set a users role" do
|
175
|
+
user = BitmaskUser.new
|
176
|
+
user.add_role 'admin'
|
177
|
+
user.roles.include?("admin").should be_true
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should return true for is_admin? if the admin role is added to the user" do
|
181
|
+
user = BitmaskUser.new
|
182
|
+
user.add_role 'admin'
|
183
|
+
user.is_admin?.should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should return true for has_role? 'admin' if the admin role is added to the user" do
|
187
|
+
user = BitmaskUser.new
|
188
|
+
user.add_role 'admin'
|
189
|
+
user.has_role?('admin').should be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should turn false for has_role? 'manager' if manager role is not added to the user" do
|
193
|
+
user = BitmaskUser.new
|
194
|
+
user.has_role?('manager').should be_false
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should turn false for is_manager? if manager role is not added to the user" do
|
198
|
+
user = BitmaskUser.new
|
199
|
+
user.is_manager?.should be_false
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should not allow you to add a role not in the array list of roles" do
|
203
|
+
user = BitmaskUser.new
|
204
|
+
user.add_role 'lolcat'
|
205
|
+
user.is_lolcat?.should be_false
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "normal methods" do
|
209
|
+
it "should not save to the database if not implicitly saved" do
|
210
|
+
user = BitmaskUser.create(:name => "Ryan")
|
211
|
+
user.add_role 'admin'
|
212
|
+
user.is_admin?.should be_true
|
213
|
+
user.reload
|
214
|
+
|
215
|
+
user.is_admin?.should be_false
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should save to the database if implicity saved" do
|
219
|
+
user = BitmaskUser.create(:name => "Ryan")
|
220
|
+
user.add_role 'admin'
|
221
|
+
user.is_admin?.should be_true
|
222
|
+
user.save
|
223
|
+
user.reload
|
224
|
+
|
225
|
+
user.is_admin?.should be_true
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should clear all roles and not save if not implicitly saved" do
|
229
|
+
user = BitmaskUser.create(:name => "Ryan")
|
230
|
+
user.add_role 'admin'
|
231
|
+
user.is_admin?.should be_true
|
232
|
+
user.save
|
233
|
+
user.reload
|
234
|
+
user.is_admin?.should be_true
|
235
|
+
|
236
|
+
user.clear_roles
|
237
|
+
user.is_admin?.should be_false
|
238
|
+
user.reload
|
239
|
+
|
240
|
+
user.is_admin?.should be_true
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should clear all roles and save if implicitly saved" do
|
244
|
+
user = BitmaskUser.create(:name => "Ryan")
|
245
|
+
user.add_role 'admin'
|
246
|
+
user.is_admin?.should be_true
|
247
|
+
user.save
|
248
|
+
user.reload
|
249
|
+
user.is_admin?.should be_true
|
250
|
+
|
251
|
+
user.clear_roles
|
252
|
+
user.is_admin?.should be_false
|
253
|
+
user.save
|
254
|
+
user.reload
|
255
|
+
|
256
|
+
user.is_admin?.should be_false
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should remove a role and not save unless implicitly saved" do
|
260
|
+
user = BitmaskUser.create(:name => "Ryan")
|
261
|
+
user.add_role 'admin'
|
262
|
+
user.is_admin?.should be_true
|
263
|
+
user.save
|
264
|
+
user.reload
|
265
|
+
|
266
|
+
user.is_admin?.should be_true
|
267
|
+
user.remove_role 'admin'
|
268
|
+
user.is_admin?.should be_false
|
269
|
+
user.reload
|
270
|
+
|
271
|
+
user.is_admin?.should be_true
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should remove a role and save if implicitly saved" do
|
275
|
+
user = BitmaskUser.create(:name => "Ryan")
|
276
|
+
user.add_role 'admin'
|
277
|
+
user.is_admin?.should be_true
|
278
|
+
user.save
|
279
|
+
user.reload
|
280
|
+
|
281
|
+
user.is_admin?.should be_true
|
282
|
+
user.remove_role 'admin'
|
283
|
+
user.is_admin?.should be_false
|
284
|
+
user.save
|
285
|
+
user.reload
|
286
|
+
|
287
|
+
user.is_admin?.should be_false
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "bang method" do
|
292
|
+
it "should save to the database if the bang method is used" do
|
293
|
+
user = BitmaskUser.create(:name => "Ryan")
|
294
|
+
user.add_role! 'admin'
|
295
|
+
user.is_admin?.should be_true
|
296
|
+
user.reload
|
297
|
+
|
298
|
+
user.is_admin?.should be_true
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should remove a role and save" do
|
302
|
+
user = BitmaskUser.create(:name => "Ryan")
|
303
|
+
user.add_role 'admin'
|
304
|
+
user.is_admin?.should be_true
|
305
|
+
user.save
|
306
|
+
user.reload
|
307
|
+
|
308
|
+
user.is_admin?.should be_true
|
309
|
+
user.remove_role! 'admin'
|
310
|
+
user.is_admin?.should be_false
|
311
|
+
user.reload
|
312
|
+
|
313
|
+
user.is_admin?.should be_false
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should clear all roles and save" do
|
317
|
+
user = BitmaskUser.create(:name => "Ryan")
|
318
|
+
user.add_role 'admin'
|
319
|
+
user.is_admin?.should be_true
|
320
|
+
user.save
|
321
|
+
user.reload
|
322
|
+
user.is_admin?.should be_true
|
323
|
+
|
324
|
+
user.clear_roles!
|
325
|
+
user.is_admin?.should be_false
|
326
|
+
user.reload
|
327
|
+
|
328
|
+
user.is_admin?.should be_false
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require 'easy_roles'
|
6
|
+
|
7
|
+
require 'spec'
|
8
|
+
require 'spec/autorun'
|
9
|
+
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
15
|
+
|
16
|
+
def setup_db
|
17
|
+
ActiveRecord::Schema.define(:version => 1) do
|
18
|
+
create_table :serialize_users do |t|
|
19
|
+
t.string :name
|
20
|
+
t.string :roles, :default => "--- []"
|
21
|
+
end
|
22
|
+
create_table :bitmask_users do |t|
|
23
|
+
t.string :name
|
24
|
+
t.integer :roles_mask, :default => 0
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table :memberships do |t|
|
28
|
+
t.string :name
|
29
|
+
t.integer :bitmask_user_id
|
30
|
+
t.integer :beggar_id
|
31
|
+
end
|
32
|
+
|
33
|
+
create_table :beggars do |t|
|
34
|
+
t.string :name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown_db
|
40
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
41
|
+
ActiveRecord::Base.connection.drop_table(table)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
setup_db
|
46
|
+
|
47
|
+
class SerializeUser < ActiveRecord::Base
|
48
|
+
easy_roles :roles, :method => :serialize
|
49
|
+
end
|
50
|
+
|
51
|
+
class BitmaskUser < ActiveRecord::Base
|
52
|
+
has_many :memberships
|
53
|
+
easy_roles :roles_mask, :method => :bitmask
|
54
|
+
|
55
|
+
ROLES_MASK = %w[admin manager user]
|
56
|
+
end
|
57
|
+
|
58
|
+
class Membership < ActiveRecord::Base
|
59
|
+
belongs_to :bitmask_user
|
60
|
+
belongs_to :beggar
|
61
|
+
end
|
62
|
+
|
63
|
+
class Beggar < ActiveRecord::Base
|
64
|
+
has_many :memberships
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Platform45
|
@@ -9,10 +15,51 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-09-06 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: active_record
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: sqlite3-ruby
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
16
63
|
description: Easy role authorization in rails
|
17
64
|
email: ryan@platform45.com
|
18
65
|
executables: []
|
@@ -20,12 +67,14 @@ executables: []
|
|
20
67
|
extensions: []
|
21
68
|
|
22
69
|
extra_rdoc_files:
|
70
|
+
- CHANGELOG.rdoc
|
23
71
|
- README.rdoc
|
24
72
|
- lib/easy_roles.rb
|
25
73
|
files:
|
26
|
-
-
|
74
|
+
- CHANGELOG.rdoc
|
27
75
|
- README.rdoc
|
28
76
|
- Rakefile
|
77
|
+
- easy_roles.gemspec
|
29
78
|
- generators/easy_bitmask_roles/USAGE
|
30
79
|
- generators/easy_bitmask_roles/easy_bitmask_roles_generator.rb
|
31
80
|
- generators/easy_bitmask_roles/templates/migration.rb
|
@@ -34,7 +83,9 @@ files:
|
|
34
83
|
- generators/easy_roles/templates/migration.rb
|
35
84
|
- init.rb
|
36
85
|
- lib/easy_roles.rb
|
37
|
-
-
|
86
|
+
- spec/easy_roles_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- Manifest
|
38
89
|
has_rdoc: true
|
39
90
|
homepage: http://github.com/platform45/easy_roles
|
40
91
|
licenses: []
|
@@ -50,21 +101,28 @@ rdoc_options:
|
|
50
101
|
require_paths:
|
51
102
|
- lib
|
52
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
53
105
|
requirements:
|
54
106
|
- - ">="
|
55
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
56
111
|
version: "0"
|
57
|
-
version:
|
58
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
59
114
|
requirements:
|
60
115
|
- - ">="
|
61
116
|
- !ruby/object:Gem::Version
|
117
|
+
hash: 11
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 2
|
62
121
|
version: "1.2"
|
63
|
-
version:
|
64
122
|
requirements: []
|
65
123
|
|
66
124
|
rubyforge_project: easy_roles
|
67
|
-
rubygems_version: 1.3.
|
125
|
+
rubygems_version: 1.3.7
|
68
126
|
signing_key:
|
69
127
|
specification_version: 3
|
70
128
|
summary: Easy role authorization in rails
|