id_please 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,8 @@ class ActiveSupport::TestCase
6
6
  setup do
7
7
  Role.delete_all
8
8
  [subject_class, Foo, Bar, Uuid].each { |c| c.delete_all }
9
- @subject1 = subject_class.create!
10
- @subject2 = subject_class.create!
9
+ @subject1 = subject_class.create!(:name => "#{subject_class.to_s}1")
10
+ @subject2 = subject_class.create!(:name => "#{subject_class.to_s}2")
11
11
  @foo = Foo.create!
12
12
  @bar = Bar.create!
13
13
  @uuid = Uuid.create!(:uuid => "C41642EE-2780-0001-189F-17F3101B26E0")
@@ -216,14 +216,14 @@ class RolesTest < ActiveSupport::TestCase
216
216
 
217
217
  context "group testing: " do
218
218
  setup do
219
- @user1 = User.create!
220
- @user2 = User.create!
221
- @user3 = User.create!
222
- @group1 = Group.create!
223
- @group2 = Group.create!
224
- @group3 = Group.create!
225
- @group4 = Group.create!
226
- @group5 = Group.create!
219
+ @user1 = User.create!(:name => "User1")
220
+ @user2 = User.create!(:name => "User2")
221
+ @user3 = User.create!(:name => "User3")
222
+ @group1 = Group.create!(:name => "Group1")
223
+ @group2 = Group.create!(:name => "Group2")
224
+ @group3 = Group.create!(:name => "Group3")
225
+ @group4 = Group.create!(:name => "Group4")
226
+ @group5 = Group.create!(:name => "Group5")
227
227
 
228
228
 
229
229
  @foo = Foo.create!
@@ -249,9 +249,13 @@ class RolesTest < ActiveSupport::TestCase
249
249
  @user1.in_group!(@group1)
250
250
  @group1.in_group!(@group2)
251
251
  @group2.in_group!(@group4)
252
+ @user1.in_group!(@group4)
252
253
 
253
254
  @user1.in_group!(@group3)
254
255
  @user2.in_group!(@group2)
256
+
257
+ @user3.has_role!(:owner, @group4)
258
+
255
259
  end
256
260
 
257
261
  should "avoid circularity" do
@@ -272,7 +276,7 @@ class RolesTest < ActiveSupport::TestCase
272
276
  end
273
277
 
274
278
  should "handle nested groups" do
275
- assert_same_elements @user1.groups(:nested => false), [@group1, @group3]
279
+ assert_same_elements @user1.groups(:nested => false), [@group1, @group3, @group4]
276
280
  assert_same_elements @user1.groups, [@group1, @group2, @group3, @group4]
277
281
  assert_same_elements @user2.groups, [@group2, @group4]
278
282
 
@@ -281,30 +285,39 @@ class RolesTest < ActiveSupport::TestCase
281
285
 
282
286
  assert @group4.accepts_role?(:member, @user1)
283
287
  assert @group2.accepts_role?(:member, @user1)
284
-
288
+
289
+ assert @group4.accepts_role?(:member, @user1, :check_groups => false)
290
+ @user1.not_in_group!(@group4)
285
291
  assert_false @group4.accepts_role?(:member, @user1, :check_groups => false)
286
292
  end
287
293
 
288
294
  should "be able to filter children based on roles" do
289
- assert_same_elements @group4.children(:roles => :any), [@group2, @group1, @user1, @user2]
290
- assert_same_elements @group4.children(:roles => [:member]), [@group2, @group1, @user1, @user2]
291
- assert_same_elements @group4.children(:roles => [:owner]), []
292
-
293
-
294
- @user3.has_role!(:owner, @group4)
295
-
296
295
  assert_same_elements @group4.children(), [@group2, @group1, @user1, @user2]
297
296
  assert_same_elements @group4.children(:roles => :any), [@group2, @group1, @user1, @user2, @user3]
298
297
  assert_same_elements @group4.children(:roles => [:member]), [@group2, @group1, @user1, @user2]
299
298
  assert_same_elements @group4.children(:roles => [:owner]), [@user3]
300
-
301
299
  end
302
300
 
303
301
  should "be able to display hashes of subject permissions" do
304
- @user3.has_role!(:owner, @group4)
305
302
  assert_equal @group4.children(:roles => :any, :view => :subject_hash), {@group2 => [:member], @group1 => [:member], @user1 => [:member], @user2 => [:member], @user3 => [:owner]}
306
303
  end
307
304
 
305
+ should "display a list of roles, or a hash of roles to users" do
306
+ assert_same_elements @group4.children(:roles => :any, :view => :roles), [:member, :owner]
307
+
308
+ role_hash = @group4.children(:roles => :any, :view => :role_hash)
309
+ assert_same_elements role_hash[:member], [@group1, @group2, @user1, @user2]
310
+ assert_same_elements role_hash[:owner], [@user3]
311
+ end
312
+
313
+ should "display a hash of roles to users with the relevant groups attached" do
314
+ role_with_assignments = @group4.children(:roles => :any, :view => :role_with_assignments)
315
+ assert_equal role_with_assignments[:owner], {@user3 => [@group4]}
316
+ assert_same_elements role_with_assignments[:member].keys, [@user1, @user2, @group1, @group2]
317
+ assert_equal role_with_assignments[:member], {@group2 => [@group4], @group1 => [@group2], @user1 => [@group1, @group4], @user2 => [@group2]}
318
+
319
+ end
320
+
308
321
  should "check roles based on groups" do
309
322
 
310
323
  assert @user2.has_role?(:member, @group2)
@@ -9,14 +9,26 @@ end
9
9
 
10
10
  class User < ActiveRecord::Base
11
11
  acts_as_authorization_subject
12
+
13
+ def to_s
14
+ name
15
+ end
12
16
  end
13
17
 
14
18
  class UserNoGroup < ActiveRecord::Base
15
19
  acts_as_authorization_subject :groups_enabled => false, :nested_groups => false
20
+
21
+ def to_s
22
+ name
23
+ end
16
24
  end
17
25
 
18
26
  class Group < ActiveRecord::Base
19
27
  acts_as_authorization_group
28
+
29
+ def to_s
30
+ name
31
+ end
20
32
  end
21
33
 
22
34
  class Foo < ActiveRecord::Base
@@ -6,9 +6,13 @@ ActiveRecord::Schema.define(:version => 0) do
6
6
  t.timestamps
7
7
  end
8
8
 
9
- create_table "users", :force => true do |t| end
9
+ create_table "users", :force => true do |t|
10
+ t.string "name"
11
+ end
10
12
 
11
- create_table "user_no_groups", :force => true do |t| end
13
+ create_table "user_no_groups", :force => true do |t|
14
+ t.string "name"
15
+ end
12
16
 
13
17
  create_table "roles", :force => true do |t|
14
18
  t.string "name", :limit => 50, :null => false
@@ -17,7 +21,9 @@ ActiveRecord::Schema.define(:version => 0) do
17
21
  t.timestamps
18
22
  end
19
23
 
20
- create_table "groups", :force => true do |t| end
24
+ create_table "groups", :force => true do |t|
25
+ t.string "name"
26
+ end
21
27
 
22
28
  create_table "foos", :force => true do |t|
23
29
  t.timestamps
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id_please
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stuart
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-17 00:00:00 -05:00
12
+ date: 2010-02-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency