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.
Files changed (38) hide show
  1. data/README.markdown +11 -2
  2. data/Rakefile +7 -6
  3. data/VERSION +1 -1
  4. data/lib/roles_mongo_mapper/base.rb +21 -4
  5. data/lib/roles_mongo_mapper/embedded_role.rb +35 -0
  6. data/lib/roles_mongo_mapper/role.rb +7 -5
  7. data/lib/roles_mongo_mapper/strategy/multi.rb +59 -0
  8. data/lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb +71 -0
  9. data/lib/roles_mongo_mapper/strategy/multi/many_roles.rb +69 -23
  10. data/lib/roles_mongo_mapper/strategy/multi/role_strings.rb +44 -24
  11. data/lib/roles_mongo_mapper/strategy/multi/roles_mask.rb +67 -19
  12. data/lib/roles_mongo_mapper/strategy/shared.rb +29 -0
  13. data/lib/roles_mongo_mapper/strategy/single.rb +34 -0
  14. data/lib/roles_mongo_mapper/strategy/single/admin_flag.rb +50 -15
  15. data/lib/roles_mongo_mapper/strategy/single/embed_one_role.rb +79 -0
  16. data/lib/roles_mongo_mapper/strategy/single/one_role.rb +38 -30
  17. data/lib/roles_mongo_mapper/strategy/single/role_string.rb +20 -18
  18. data/roles_mongo_mapper.gemspec +51 -32
  19. data/sandbox/test.rb +13 -3
  20. data/spec/roles_mongo_mapper/strategy/api_examples.rb +199 -0
  21. data/spec/roles_mongo_mapper/strategy/hooks.rb +7 -0
  22. data/spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb +19 -0
  23. data/spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb +19 -0
  24. data/spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb +19 -0
  25. data/spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb +18 -0
  26. data/spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb +18 -0
  27. data/spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb +19 -0
  28. data/spec/roles_mongo_mapper/strategy/single/one_role_spec.rb +20 -0
  29. data/spec/roles_mongo_mapper/strategy/single/role_string_spec.rb +19 -0
  30. data/spec/roles_mongo_mapper/strategy/user_setup.rb +13 -0
  31. data/spec/spec_helper.rb +11 -6
  32. metadata +60 -32
  33. data/spec/roles_mongo_mapper/strategy/admin_flag_spec.rb +0 -76
  34. data/spec/roles_mongo_mapper/strategy/many_roles_spec.rb +0 -69
  35. data/spec/roles_mongo_mapper/strategy/one_role_spec.rb +0 -66
  36. data/spec/roles_mongo_mapper/strategy/role_string_spec.rb +0 -68
  37. data/spec/roles_mongo_mapper/strategy/role_strings_spec.rb +0 -69
  38. data/spec/roles_mongo_mapper/strategy/roles_mask_spec.rb +0 -69
@@ -1,66 +0,0 @@
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
-
11
- key :name, String
12
- end
13
-
14
- describe "Roles for MongoMapper" do
15
- before :each do
16
- User.valid_roles_are :admin, :guest
17
-
18
- @user = User.create(:name => 'Kristian')
19
- @user.roles = :guest
20
- @user.save
21
-
22
- @admin_user = User.create(:name => 'Admin user')
23
- @admin_user.roles = :admin
24
- @admin_user.save
25
- end
26
-
27
- describe '#in_role' do
28
- it "should return first user matching role" do
29
- User.in_role(:guest).first.name.should == 'Kristian'
30
- User.in_role(:admin).first.name.should == 'Admin user'
31
- end
32
- end
33
-
34
- describe "Role API" do
35
- it "should have admin user role to :admin" do
36
- @admin_user.roles_list.first.should == :admin
37
- @admin_user.admin?.should be_true
38
-
39
- @admin_user.has_role?(:guest).should be_false
40
-
41
- @admin_user.has_role?(:admin).should be_true
42
- @admin_user.is?(:admin).should be_true
43
- @admin_user.has_roles?(:admin).should be_true
44
- @admin_user.has?(:admin).should be_true
45
- end
46
-
47
- it "should have user role to :guest" do
48
- @user.roles_list.first.should == :guest
49
- @user.admin?.should be_false
50
-
51
- @user.has_role?(:guest).should be_true
52
- @user.has_role?(:admin).should be_false
53
- @user.is?(:admin).should be_false
54
-
55
- @user.has_roles?(:admin).should be_false
56
- @user.has?(:admin).should be_false
57
- end
58
-
59
- it "should set user role to :admin using roles=" do
60
- @user.roles = :admin
61
- @user.roles_list.first.should == :admin
62
- @user.has_role?(:admin).should be_true
63
- end
64
- end
65
- end
66
-
@@ -1,68 +0,0 @@
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
-
10
- valid_roles_are :admin, :guest
11
-
12
- key :name, String
13
- end
14
-
15
- describe "Roles for MongoMapper" do
16
- context "default setup" do
17
-
18
- before do
19
- @user = User.create(:name => 'Kristian')
20
- @user.role = :guest
21
- @user.save
22
-
23
- @admin_user = User.create(:name => 'Admin user')
24
- @admin_user.roles = :admin
25
- @admin_user.save
26
- end
27
-
28
- describe '#in_role' do
29
- it "should return first user matching role" do
30
- User.in_role(:guest).first.name.should == 'Kristian'
31
- User.in_role(:admin).first.name.should == 'Admin user'
32
- end
33
- end
34
-
35
- describe "Role API" do
36
- it "should have admin user role to :admin" do
37
- @admin_user.roles_list.first.should == :admin
38
- @admin_user.admin?.should be_true
39
-
40
- @admin_user.has_role?(:guest).should be_false
41
-
42
- @admin_user.has_role?(:admin).should be_true
43
- @admin_user.is?(:admin).should be_true
44
- @admin_user.has_roles?(:admin).should be_true
45
- @admin_user.has?(:admin).should be_true
46
- end
47
-
48
- it "should have user role to :guest" do
49
- @user.roles_list.first.should == :guest
50
- @user.admin?.should be_false
51
-
52
- @user.has_role?(:guest).should be_true
53
- @user.has_role?(:admin).should be_false
54
- @user.is?(:admin).should be_false
55
-
56
- @user.has_roles?(:admin).should be_false
57
- @user.has?(:admin).should be_false
58
- end
59
-
60
- it "should set user role to :admin using roles=" do
61
- @user.roles = :admin
62
- @user.roles_list.first.should == :admin
63
- @user.has_role?(:admin).should be_true
64
- end
65
- end
66
- end
67
- end
68
-
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :role_strings
3
-
4
- class User
5
- include MongoMapper::Document
6
- include Roles::MongoMapper
7
-
8
- strategy :role_strings, :default
9
-
10
- valid_roles_are :admin, :guest
11
-
12
- key :name, String
13
- end
14
-
15
- describe "Roles for MongoMapper" do
16
-
17
- context "default setup" do
18
-
19
- before do
20
- @user = User.create(:name => 'Kristian')
21
- @user.role = :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
-
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :roles_mask
3
-
4
- class User
5
- include MongoMapper::Document
6
- include Roles::MongoMapper
7
-
8
- strategy :roles_mask, :default
9
-
10
- valid_roles_are :admin, :guest
11
-
12
- key :name, String
13
- end
14
-
15
- describe "Roles for MongoMapper" do
16
-
17
- context "default setup" do
18
-
19
- before do
20
- @user = User.create(:name => 'Kristian')
21
- @user.role = :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
-