canard 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +4 -1
- data/lib/canard/user_model.rb +45 -19
- data/lib/canard/version.rb +1 -1
- data/test/dummy/app/models/plain_ruby_non_user.rb +7 -0
- data/test/dummy/app/models/plain_ruby_user.rb +9 -0
- data/test/dummy/app/models/user.rb +0 -2
- data/test/dummy/app/models/user_without_role.rb +0 -1
- data/test/dummy/app/models/user_without_role_mask.rb +0 -1
- data/test/dummy/db/schema.rb +2 -2
- data/test/test_helper.rb +1 -0
- data/test/user_model_test.rb +110 -76
- metadata +109 -68
data/TODO
CHANGED
@@ -3,4 +3,7 @@
|
|
3
3
|
* Expand the tests to produce all the standard abilities: index,show,read,new,create,edit,update,destroy.
|
4
4
|
* Add test unit generator.
|
5
5
|
* Add install generator to allow overriding of the default tests.
|
6
|
-
* Make the Ability user referece configureable.
|
6
|
+
* Make the Ability user referece configureable in Ability.
|
7
|
+
* Abstract out the ActiveRecord extensions into a model adapter.
|
8
|
+
* Make the roles_attribute_name configureable in UserModel.
|
9
|
+
* Remove ActiveSupport runtime dependency.
|
data/lib/canard/user_model.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Canard
|
2
2
|
|
3
3
|
module UserModel
|
4
|
-
|
4
|
+
|
5
5
|
# Canard applies roles to a model using the acts_as_user class method. The following User model
|
6
6
|
# will be given the :manager and :admin roles
|
7
7
|
#
|
@@ -11,10 +11,23 @@ module Canard
|
|
11
11
|
#
|
12
12
|
# end
|
13
13
|
#
|
14
|
+
# If using Canard with a non ActiveRecord class you can still assign roles but you will need to
|
15
|
+
# extend the class with Canard::UserModel and add a roles_mask attribute.
|
16
|
+
#
|
17
|
+
# class User
|
18
|
+
#
|
19
|
+
# extend Canard::UserModel
|
20
|
+
#
|
21
|
+
# attr_accessor :roles_mask
|
22
|
+
#
|
23
|
+
# acts_as_user :roles => :manager, :admin
|
24
|
+
#
|
25
|
+
# end
|
26
|
+
#
|
14
27
|
# == Scopes
|
15
28
|
#
|
16
29
|
# Beyond applying the roles to model acts_as_user also creates some useful scopes on the User
|
17
|
-
# model;
|
30
|
+
# model for ActiveRecord models;
|
18
31
|
#
|
19
32
|
# User.with_any_role(:manager, :admin)
|
20
33
|
#
|
@@ -44,23 +57,36 @@ module Canard
|
|
44
57
|
|
45
58
|
options = args.extract_options!.symbolize_keys
|
46
59
|
|
47
|
-
roles options[:roles] if options.has_key?(:roles) &&
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
roles options[:roles] if options.has_key?(:roles) && has_roles_mask_attribute? || has_roles_mask_accessors?
|
61
|
+
|
62
|
+
if respond_to?(:table_exists?) && table_exists?
|
63
|
+
valid_roles.each do |role|
|
64
|
+
define_scopes_for_role role
|
65
|
+
end
|
66
|
+
|
67
|
+
define_scope_method(:with_any_role) do |*roles|
|
68
|
+
where("#{role_mask_column} & :role_mask > 0", { :role_mask => mask_for(*roles) })
|
69
|
+
end
|
70
|
+
|
71
|
+
define_scope_method(:with_all_roles) do |*roles|
|
72
|
+
where("#{role_mask_column} & :role_mask = :role_mask", { :role_mask => mask_for(*roles) })
|
73
|
+
end
|
59
74
|
end
|
60
75
|
end
|
61
|
-
|
76
|
+
|
62
77
|
private
|
63
|
-
|
78
|
+
|
79
|
+
def has_roles_mask_accessors?
|
80
|
+
instance_method_names = instance_methods.map { |method_name| method_name.to_s }
|
81
|
+
[roles_attribute_name.to_s, "#{roles_attribute_name}="].all? do |accessor|
|
82
|
+
instance_method_names.include?(accessor)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_roles_mask_attribute?
|
87
|
+
respond_to?(:column_names) && column_names.include?(roles_attribute_name.to_s)
|
88
|
+
end
|
89
|
+
|
64
90
|
def define_scopes_for_role(role)
|
65
91
|
include_scope = role.to_s.pluralize
|
66
92
|
exclude_scope = "non_#{include_scope}"
|
@@ -73,17 +99,17 @@ module Canard
|
|
73
99
|
where("#{role_mask_column} & :role_mask = 0 or #{role_mask_column} is null", { :role_mask => mask_for(role) })
|
74
100
|
end
|
75
101
|
end
|
76
|
-
|
102
|
+
|
77
103
|
def define_scope_method(method, &block)
|
78
104
|
(class << self; self end).class_eval do
|
79
105
|
define_method(method, block)
|
80
106
|
end
|
81
107
|
end
|
82
|
-
|
108
|
+
|
83
109
|
def role_mask_column
|
84
110
|
%{"#{table_name}"."#{roles_attribute_name}"}
|
85
111
|
end
|
86
112
|
|
87
113
|
end
|
88
114
|
|
89
|
-
end
|
115
|
+
end
|
data/lib/canard/version.rb
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -21,11 +21,11 @@ ActiveRecord::Schema.define(:version => 20120430083231) do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
create_table "user_without_roles", :force => true do |t|
|
24
|
-
t.
|
24
|
+
t.integer "roles_mask"
|
25
25
|
end
|
26
26
|
|
27
27
|
create_table "users", :force => true do |t|
|
28
|
-
t.
|
28
|
+
t.integer "roles_mask"
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
data/test/test_helper.rb
CHANGED
data/test/user_model_test.rb
CHANGED
@@ -2,11 +2,11 @@ require 'test_helper'
|
|
2
2
|
require 'canard'
|
3
3
|
|
4
4
|
describe Canard::UserModel do
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
Canard.abilities_path = 'abilities'
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# Sanity test
|
11
11
|
it "must be an user" do
|
12
12
|
user = User.new
|
@@ -16,44 +16,61 @@ describe Canard::UserModel do
|
|
16
16
|
user = UserWithoutRoleMask.new
|
17
17
|
user.must_be_instance_of UserWithoutRoleMask
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe 'acts_as_user' do
|
21
|
-
|
21
|
+
|
22
22
|
it 'should add role_model to this model' do
|
23
23
|
User.included_modules.must_include RoleModel
|
24
24
|
User.must_respond_to :roles
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
describe 'on a model with a role mask' do
|
28
|
-
|
28
|
+
|
29
29
|
describe 'and :roles => [] specified' do
|
30
|
-
|
31
|
-
it '
|
30
|
+
|
31
|
+
it 'sets the valid_roles for the class' do
|
32
32
|
User.valid_roles.must_equal [:viewer, :author, :admin]
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
describe 'with no :roles => [] specified' do
|
38
|
-
|
39
|
-
it '
|
38
|
+
|
39
|
+
it 'sets no roles' do
|
40
40
|
UserWithoutRole.valid_roles.must_equal []
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
end
|
45
|
-
|
46
|
-
describe 'with no roles_mask' do
|
47
|
-
|
48
|
-
it '
|
45
|
+
|
46
|
+
describe 'on a model with no roles_mask' do
|
47
|
+
|
48
|
+
it 'sets no roles' do
|
49
49
|
UserWithoutRole.valid_roles.must_equal []
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
|
+
describe "on a non ActiveRecord User class" do
|
54
|
+
|
55
|
+
describe "with a roles_mask attribute" do
|
56
|
+
|
57
|
+
it "assigns the roles" do
|
58
|
+
PlainRubyUser.valid_roles.must_equal [:viewer, :author, :admin]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with no roles_mask" do
|
63
|
+
|
64
|
+
it "sets no roles" do
|
65
|
+
PlainRubyNonUser.valid_roles.must_equal []
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
53
70
|
end
|
54
71
|
|
55
72
|
describe "scopes" do
|
56
|
-
|
73
|
+
|
57
74
|
before do
|
58
75
|
@no_role = User.create
|
59
76
|
@admin_author_viewer = User.create(:roles => [:admin, :author, :viewer])
|
@@ -62,38 +79,38 @@ describe Canard::UserModel do
|
|
62
79
|
@admin_only = User.create(:roles => [:admin])
|
63
80
|
@author_only = User.create(:roles => [:author])
|
64
81
|
end
|
65
|
-
|
82
|
+
|
66
83
|
after do
|
67
84
|
User.delete_all
|
68
85
|
end
|
69
|
-
|
86
|
+
|
70
87
|
describe "on models with roles" do
|
71
|
-
|
88
|
+
|
72
89
|
subject { User }
|
73
|
-
|
74
|
-
it "
|
90
|
+
|
91
|
+
it "adds a scope to return instances with each role" do
|
75
92
|
subject.must_respond_to :admins
|
76
93
|
subject.must_respond_to :authors
|
77
94
|
subject.must_respond_to :viewers
|
78
95
|
end
|
79
|
-
|
80
|
-
it "
|
96
|
+
|
97
|
+
it "adds a scope to return instances without each role" do
|
81
98
|
subject.must_respond_to :non_admins
|
82
99
|
subject.must_respond_to :non_authors
|
83
100
|
subject.must_respond_to :non_viewers
|
84
101
|
end
|
85
|
-
|
102
|
+
|
86
103
|
describe "finding instances with a role" do
|
87
|
-
|
104
|
+
|
88
105
|
describe "admins scope" do
|
89
106
|
|
90
107
|
subject { User.admins.sort_by(&:id) }
|
91
108
|
|
92
|
-
it "
|
109
|
+
it "returns only admins" do
|
93
110
|
subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
|
94
111
|
end
|
95
112
|
|
96
|
-
it "
|
113
|
+
it "doesn't return non admins" do
|
97
114
|
subject.wont_include @no_role
|
98
115
|
subject.wont_include @author_viewer
|
99
116
|
subject.wont_include @author_only
|
@@ -106,11 +123,11 @@ describe Canard::UserModel do
|
|
106
123
|
|
107
124
|
subject { User.authors.sort_by(&:id) }
|
108
125
|
|
109
|
-
it "
|
126
|
+
it "returns only authors" do
|
110
127
|
subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
|
111
128
|
end
|
112
129
|
|
113
|
-
it "
|
130
|
+
it "doesn't return non authors" do
|
114
131
|
subject.wont_include @no_role
|
115
132
|
subject.wont_include @admin_only
|
116
133
|
subject.wont_include @viewer
|
@@ -122,11 +139,11 @@ describe Canard::UserModel do
|
|
122
139
|
|
123
140
|
subject { User.viewers.sort_by(&:id) }
|
124
141
|
|
125
|
-
it "
|
142
|
+
it "returns only viewers" do
|
126
143
|
subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
|
127
144
|
end
|
128
145
|
|
129
|
-
it "
|
146
|
+
it "doesn't return non authors" do
|
130
147
|
subject.wont_include @no_role
|
131
148
|
subject.wont_include @admin_only
|
132
149
|
subject.wont_include @author_only
|
@@ -135,18 +152,18 @@ describe Canard::UserModel do
|
|
135
152
|
end
|
136
153
|
|
137
154
|
end
|
138
|
-
|
155
|
+
|
139
156
|
describe "finding instances without a role" do
|
140
|
-
|
157
|
+
|
141
158
|
describe "non_admins scope" do
|
142
159
|
|
143
160
|
subject { User.non_admins.sort_by(&:id) }
|
144
161
|
|
145
|
-
it "
|
162
|
+
it "returns only non_admins" do
|
146
163
|
subject.must_equal [@no_role, @author_viewer, @viewer, @author_only].sort_by(&:id)
|
147
164
|
end
|
148
165
|
|
149
|
-
it "
|
166
|
+
it "doesn't return admins" do
|
150
167
|
subject.wont_include @admin_author_viewer
|
151
168
|
subject.wont_include @admin_only
|
152
169
|
end
|
@@ -157,11 +174,11 @@ describe Canard::UserModel do
|
|
157
174
|
|
158
175
|
subject { User.non_authors.sort_by(&:id) }
|
159
176
|
|
160
|
-
it "
|
177
|
+
it "returns only non_authors" do
|
161
178
|
subject.must_equal [@no_role, @viewer, @admin_only].sort_by(&:id)
|
162
179
|
end
|
163
180
|
|
164
|
-
it "
|
181
|
+
it "doesn't return authors" do
|
165
182
|
subject.wont_include @admin_author_viewer
|
166
183
|
subject.wont_include @author_viewer
|
167
184
|
subject.wont_include @author_only
|
@@ -173,11 +190,11 @@ describe Canard::UserModel do
|
|
173
190
|
|
174
191
|
subject { User.non_viewers.sort_by(&:id) }
|
175
192
|
|
176
|
-
it "
|
193
|
+
it "returns only non_viewers" do
|
177
194
|
subject.must_equal [@no_role, @admin_only, @author_only].sort_by(&:id)
|
178
195
|
end
|
179
196
|
|
180
|
-
it "
|
197
|
+
it "doesn't return viewers" do
|
181
198
|
subject.wont_include @admin_author_viewer
|
182
199
|
subject.wont_include @author_viewer
|
183
200
|
subject.wont_include @viewer
|
@@ -186,18 +203,18 @@ describe Canard::UserModel do
|
|
186
203
|
end
|
187
204
|
|
188
205
|
end
|
189
|
-
|
206
|
+
|
190
207
|
describe "with_any_role" do
|
191
|
-
|
208
|
+
|
192
209
|
describe "specifying admin only" do
|
193
210
|
|
194
211
|
subject { User.with_any_role(:admin).sort_by(&:id) }
|
195
212
|
|
196
|
-
it "
|
213
|
+
it "returns only admins" do
|
197
214
|
subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
|
198
215
|
end
|
199
216
|
|
200
|
-
it "
|
217
|
+
it "doesn't return non admins" do
|
201
218
|
subject.wont_include @no_role
|
202
219
|
subject.wont_include @author_viewer
|
203
220
|
subject.wont_include @author_only
|
@@ -210,11 +227,11 @@ describe Canard::UserModel do
|
|
210
227
|
|
211
228
|
subject { User.with_any_role(:author).sort_by(&:id) }
|
212
229
|
|
213
|
-
it "
|
230
|
+
it "returns only authors" do
|
214
231
|
subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
|
215
232
|
end
|
216
233
|
|
217
|
-
it "
|
234
|
+
it "doesn't return non authors" do
|
218
235
|
subject.wont_include @no_role
|
219
236
|
subject.wont_include @admin_only
|
220
237
|
subject.wont_include @viewer
|
@@ -226,11 +243,11 @@ describe Canard::UserModel do
|
|
226
243
|
|
227
244
|
subject { User.with_any_role(:viewer).sort_by(&:id) }
|
228
245
|
|
229
|
-
it "
|
246
|
+
it "returns only viewers" do
|
230
247
|
subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
|
231
248
|
end
|
232
249
|
|
233
|
-
it "
|
250
|
+
it "doesn't return non authors" do
|
234
251
|
subject.wont_include @no_role
|
235
252
|
subject.wont_include @admin_only
|
236
253
|
subject.wont_include @author_only
|
@@ -242,11 +259,11 @@ describe Canard::UserModel do
|
|
242
259
|
|
243
260
|
subject { User.with_any_role(:admin, :author).sort_by(&:id) }
|
244
261
|
|
245
|
-
it "
|
262
|
+
it "returns only admins and authors" do
|
246
263
|
subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @author_only].sort_by(&:id)
|
247
264
|
end
|
248
265
|
|
249
|
-
it "
|
266
|
+
it "doesn't return non admins or authors" do
|
250
267
|
subject.wont_include @no_role
|
251
268
|
subject.wont_include @viewer
|
252
269
|
end
|
@@ -257,11 +274,11 @@ describe Canard::UserModel do
|
|
257
274
|
|
258
275
|
subject { User.with_any_role(:admin, :viewer).sort_by(&:id) }
|
259
276
|
|
260
|
-
it "
|
277
|
+
it "returns only admins and viewers" do
|
261
278
|
subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @viewer].sort_by(&:id)
|
262
279
|
end
|
263
280
|
|
264
|
-
it "
|
281
|
+
it "doesn't return non admins or viewers" do
|
265
282
|
subject.wont_include @no_role
|
266
283
|
subject.wont_include @author_only
|
267
284
|
end
|
@@ -272,11 +289,11 @@ describe Canard::UserModel do
|
|
272
289
|
|
273
290
|
subject { User.with_any_role(:author, :viewer).sort_by(&:id) }
|
274
291
|
|
275
|
-
it "
|
292
|
+
it "returns only authors and viewers" do
|
276
293
|
subject.must_equal [@admin_author_viewer, @author_viewer, @author_only, @viewer].sort_by(&:id)
|
277
294
|
end
|
278
295
|
|
279
|
-
it "
|
296
|
+
it "doesn't return non authors or viewers" do
|
280
297
|
subject.wont_include @no_role
|
281
298
|
subject.wont_include @admin_only
|
282
299
|
end
|
@@ -287,29 +304,29 @@ describe Canard::UserModel do
|
|
287
304
|
|
288
305
|
subject { User.with_any_role(:admin, :author, :viewer).sort_by(&:id) }
|
289
306
|
|
290
|
-
it "
|
307
|
+
it "returns only admins, authors and viewers" do
|
291
308
|
subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @author_only, @viewer].sort_by(&:id)
|
292
309
|
end
|
293
310
|
|
294
|
-
it "
|
311
|
+
it "doesn't return non admins, authors or viewers" do
|
295
312
|
subject.wont_include @no_role
|
296
313
|
end
|
297
314
|
|
298
315
|
end
|
299
316
|
|
300
317
|
end
|
301
|
-
|
318
|
+
|
302
319
|
describe "with_all_roles" do
|
303
|
-
|
320
|
+
|
304
321
|
describe "specifying admin only" do
|
305
322
|
|
306
323
|
subject { User.with_all_roles(:admin).sort_by(&:id) }
|
307
324
|
|
308
|
-
it "
|
325
|
+
it "returns only admins" do
|
309
326
|
subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
|
310
327
|
end
|
311
328
|
|
312
|
-
it "
|
329
|
+
it "doesn't return non admins" do
|
313
330
|
subject.wont_include @no_role
|
314
331
|
subject.wont_include @author_viewer
|
315
332
|
subject.wont_include @author_only
|
@@ -322,11 +339,11 @@ describe Canard::UserModel do
|
|
322
339
|
|
323
340
|
subject { User.with_all_roles(:author).sort_by(&:id) }
|
324
341
|
|
325
|
-
it "
|
342
|
+
it "returns only authors" do
|
326
343
|
subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
|
327
344
|
end
|
328
345
|
|
329
|
-
it "
|
346
|
+
it "doesn't return non authors" do
|
330
347
|
subject.wont_include @no_role
|
331
348
|
subject.wont_include @admin_only
|
332
349
|
subject.wont_include @viewer
|
@@ -338,11 +355,11 @@ describe Canard::UserModel do
|
|
338
355
|
|
339
356
|
subject { User.with_all_roles(:viewer).sort_by(&:id) }
|
340
357
|
|
341
|
-
it "
|
358
|
+
it "returns only viewers" do
|
342
359
|
subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
|
343
360
|
end
|
344
361
|
|
345
|
-
it "
|
362
|
+
it "doesn't return non authors" do
|
346
363
|
subject.wont_include @no_role
|
347
364
|
subject.wont_include @admin_only
|
348
365
|
subject.wont_include @author_only
|
@@ -354,11 +371,11 @@ describe Canard::UserModel do
|
|
354
371
|
|
355
372
|
subject { User.with_all_roles(:admin, :author).sort_by(&:id) }
|
356
373
|
|
357
|
-
it "
|
374
|
+
it "returns only admins and authors" do
|
358
375
|
subject.must_equal [@admin_author_viewer].sort_by(&:id)
|
359
376
|
end
|
360
377
|
|
361
|
-
it "
|
378
|
+
it "doesn't return non admin and authors" do
|
362
379
|
subject.wont_include @no_role
|
363
380
|
subject.wont_include @author_viewer
|
364
381
|
subject.wont_include @author_only
|
@@ -372,11 +389,11 @@ describe Canard::UserModel do
|
|
372
389
|
|
373
390
|
subject { User.with_all_roles(:admin, :viewer).sort_by(&:id) }
|
374
391
|
|
375
|
-
it "
|
392
|
+
it "returns only admins and viewers" do
|
376
393
|
subject.must_equal [@admin_author_viewer].sort_by(&:id)
|
377
394
|
end
|
378
395
|
|
379
|
-
it "
|
396
|
+
it "doesn't return non admins or viewers" do
|
380
397
|
subject.wont_include @no_role
|
381
398
|
subject.wont_include @author_viewer
|
382
399
|
subject.wont_include @author_only
|
@@ -390,11 +407,11 @@ describe Canard::UserModel do
|
|
390
407
|
|
391
408
|
subject { User.with_all_roles(:author, :viewer).sort_by(&:id) }
|
392
409
|
|
393
|
-
it "
|
410
|
+
it "returns only authors and viewers" do
|
394
411
|
subject.must_equal [@admin_author_viewer, @author_viewer].sort_by(&:id)
|
395
412
|
end
|
396
413
|
|
397
|
-
it "
|
414
|
+
it "doesn't return non authors or viewers" do
|
398
415
|
subject.wont_include @no_role
|
399
416
|
subject.wont_include @admin_only
|
400
417
|
subject.wont_include @author_only
|
@@ -407,11 +424,11 @@ describe Canard::UserModel do
|
|
407
424
|
|
408
425
|
subject { User.with_all_roles(:admin, :author, :viewer).sort_by(&:id) }
|
409
426
|
|
410
|
-
it "
|
427
|
+
it "returns only admins, authors and viewers" do
|
411
428
|
subject.must_equal [@admin_author_viewer].sort_by(&:id)
|
412
429
|
end
|
413
430
|
|
414
|
-
it "
|
431
|
+
it "doesn't return non admins, authors or viewers" do
|
415
432
|
subject.wont_include @no_role
|
416
433
|
subject.wont_include @author_viewer
|
417
434
|
subject.wont_include @author_only
|
@@ -422,9 +439,26 @@ describe Canard::UserModel do
|
|
422
439
|
end
|
423
440
|
|
424
441
|
end
|
425
|
-
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
describe "on a non ActiveRecord class" do
|
446
|
+
|
447
|
+
subject { PlainRubyUser }
|
448
|
+
|
449
|
+
it "creates no scope methods" do
|
450
|
+
subject.wont_respond_to :admins
|
451
|
+
subject.wont_respond_to :authors
|
452
|
+
subject.wont_respond_to :viewers
|
453
|
+
subject.wont_respond_to :non_admins
|
454
|
+
subject.wont_respond_to :non_authors
|
455
|
+
subject.wont_respond_to :non_viewers
|
456
|
+
subject.wont_respond_to :with_any_role
|
457
|
+
subject.wont_respond_to :with_all_roles
|
458
|
+
end
|
459
|
+
|
426
460
|
end
|
427
461
|
|
428
462
|
end
|
429
|
-
|
463
|
+
|
430
464
|
end
|
metadata
CHANGED
@@ -1,90 +1,118 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: canard
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- James McCarthy
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-05-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: minitest
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
version: "2"
|
22
32
|
type: :development
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
26
35
|
name: sqlite3
|
27
|
-
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
38
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
33
46
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
37
49
|
name: rails
|
38
|
-
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
52
|
none: false
|
40
|
-
requirements:
|
53
|
+
requirements:
|
41
54
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 9
|
57
|
+
segments:
|
58
|
+
- 3
|
59
|
+
- 2
|
60
|
+
- 3
|
43
61
|
version: 3.2.3
|
44
62
|
type: :development
|
45
|
-
|
46
|
-
|
47
|
-
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
48
65
|
name: activesupport
|
49
|
-
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
68
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
55
76
|
type: :runtime
|
56
|
-
|
57
|
-
|
58
|
-
- !ruby/object:Gem::Dependency
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
59
79
|
name: cancan
|
60
|
-
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
82
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
66
90
|
type: :runtime
|
67
|
-
|
68
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
70
93
|
name: role_model
|
71
|
-
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
72
96
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
77
104
|
type: :runtime
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
easy in Rails 3.x.
|
82
|
-
email:
|
105
|
+
version_requirements: *id006
|
106
|
+
description: Wraps CanCan and RoleModel up to make role based authorisation really easy in Rails 3.x.
|
107
|
+
email:
|
83
108
|
- james2mccarthy@gmail.com
|
84
109
|
executables: []
|
110
|
+
|
85
111
|
extensions: []
|
112
|
+
|
86
113
|
extra_rdoc_files: []
|
87
|
-
|
114
|
+
|
115
|
+
files:
|
88
116
|
- .gitignore
|
89
117
|
- Gemfile
|
90
118
|
- MIT-LICENSE
|
@@ -117,6 +145,8 @@ files:
|
|
117
145
|
- test/dummy/app/controllers/application_controller.rb
|
118
146
|
- test/dummy/app/models/activity.rb
|
119
147
|
- test/dummy/app/models/member.rb
|
148
|
+
- test/dummy/app/models/plain_ruby_non_user.rb
|
149
|
+
- test/dummy/app/models/plain_ruby_user.rb
|
120
150
|
- test/dummy/app/models/post.rb
|
121
151
|
- test/dummy/app/models/user.rb
|
122
152
|
- test/dummy/app/models/user_without_role.rb
|
@@ -143,29 +173,38 @@ files:
|
|
143
173
|
- test/user_model_test.rb
|
144
174
|
homepage: https://github.com/james2m/canard
|
145
175
|
licenses: []
|
176
|
+
|
146
177
|
post_install_message:
|
147
178
|
rdoc_options: []
|
148
|
-
|
179
|
+
|
180
|
+
require_paths:
|
149
181
|
- lib
|
150
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
183
|
none: false
|
152
|
-
requirements:
|
153
|
-
- -
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
|
156
|
-
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
hash: 3
|
188
|
+
segments:
|
189
|
+
- 0
|
190
|
+
version: "0"
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
192
|
none: false
|
158
|
-
requirements:
|
159
|
-
- -
|
160
|
-
- !ruby/object:Gem::Version
|
161
|
-
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
hash: 3
|
197
|
+
segments:
|
198
|
+
- 0
|
199
|
+
version: "0"
|
162
200
|
requirements: []
|
201
|
+
|
163
202
|
rubyforge_project: canard
|
164
|
-
rubygems_version: 1.8.
|
203
|
+
rubygems_version: 1.8.21
|
165
204
|
signing_key:
|
166
205
|
specification_version: 3
|
167
206
|
summary: Adds role based authorisation to Rails by combining RoleModel and CanCan.
|
168
|
-
test_files:
|
207
|
+
test_files:
|
169
208
|
- test/abilities/admins.rb
|
170
209
|
- test/abilities_test.rb
|
171
210
|
- test/ability_test.rb
|
@@ -178,6 +217,8 @@ test_files:
|
|
178
217
|
- test/dummy/app/controllers/application_controller.rb
|
179
218
|
- test/dummy/app/models/activity.rb
|
180
219
|
- test/dummy/app/models/member.rb
|
220
|
+
- test/dummy/app/models/plain_ruby_non_user.rb
|
221
|
+
- test/dummy/app/models/plain_ruby_user.rb
|
181
222
|
- test/dummy/app/models/post.rb
|
182
223
|
- test/dummy/app/models/user.rb
|
183
224
|
- test/dummy/app/models/user_without_role.rb
|