roles_mongoid 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/Rakefile +11 -7
  2. data/VERSION +1 -1
  3. data/lib/roles_mongoid/base.rb +6 -4
  4. data/lib/roles_mongoid/role.rb +3 -1
  5. data/lib/roles_mongoid/strategy/multi/many_roles.rb +51 -35
  6. data/lib/roles_mongoid/strategy/multi/role_strings.rb +43 -22
  7. data/lib/roles_mongoid/strategy/multi/roles_mask.rb +67 -18
  8. data/lib/roles_mongoid/strategy/multi.rb +59 -0
  9. data/lib/roles_mongoid/strategy/shared.rb +29 -0
  10. data/lib/roles_mongoid/strategy/single/admin_flag.rb +20 -18
  11. data/lib/roles_mongoid/strategy/single/one_role.rb +55 -24
  12. data/lib/roles_mongoid/strategy/single/role_string.rb +54 -22
  13. data/lib/roles_mongoid/strategy/single.rb +34 -0
  14. data/roles_mongoid.gemspec +44 -34
  15. data/sandbox/single_role.rb +25 -11
  16. data/spec/{generators → roles_mongoid/generators}/roles_generator_spec.rb +0 -0
  17. data/spec/roles_mongoid/strategy/api_examples.rb +200 -0
  18. data/spec/roles_mongoid/strategy/multi/many_roles_spec.rb +40 -0
  19. data/spec/roles_mongoid/strategy/multi/role_strings_spec.rb +19 -0
  20. data/spec/roles_mongoid/strategy/multi/roles_mask_spec.rb +39 -0
  21. data/spec/roles_mongoid/strategy/single/admin_flag_spec.rb +18 -0
  22. data/spec/roles_mongoid/strategy/single/one_role_spec.rb +19 -0
  23. data/spec/roles_mongoid/strategy/single/role_string_spec.rb +19 -0
  24. data/spec/roles_mongoid/strategy/user_setup.rb +13 -0
  25. data/spec/spec_helper.rb +0 -13
  26. metadata +62 -43
  27. data/spec/roles_mongoid/admin_flag_spec.rb +0 -74
  28. data/spec/roles_mongoid/many_roles_spec.rb +0 -74
  29. data/spec/roles_mongoid/one_role_spec.rb +0 -74
  30. data/spec/roles_mongoid/role_string_spec.rb +0 -73
  31. data/spec/roles_mongoid/role_strings_spec.rb +0 -73
  32. data/spec/roles_mongoid/roles_mask_spec.rb +0 -73
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :admin_flag
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :admin_flag, :default
9
- valid_roles_are :admin, :guest
10
-
11
- field :name, :type => String
12
- end
13
-
14
- describe "Roles for Mongoid" do
15
- after :each do
16
- Database.teardown
17
- end
18
-
19
- before :each do
20
- @user = User.create(:name => 'Kristian')
21
- @user.roles = :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 "Admin flag strategy " do
30
-
31
- describe '#in_role' do
32
- it "should return first user maching role" do
33
- User.in_role(:guest).first.name.should == 'Kristian'
34
- User.in_role(:admin).first.name.should == 'Admin user'
35
- end
36
- end
37
-
38
- describe 'roles API' do
39
- it "should have admin user role to :admin" do
40
- @admin_user.role.should == :admin
41
- @admin_user.roles.should == [:admin]
42
- @admin_user.admin?.should be_true
43
-
44
- @admin_user.class.valid_roles.should == [:admin, :guest]
45
-
46
- @admin_user.has_role?(:guest).should be_false
47
-
48
- @admin_user.has_role?(:admin).should be_true
49
- @admin_user.is?(:admin).should be_true
50
- @admin_user.has_roles?(:admin).should be_true
51
- @admin_user.has?(:admin).should be_true
52
- end
53
-
54
- it "should have user role to :guest" do
55
- @user.roles.should == [:guest]
56
- @user.admin?.should be_false
57
-
58
- @user.has_role?(:guest).should be_true
59
- @user.has_role?(:admin).should be_false
60
- @user.is?(:admin).should be_false
61
-
62
- @user.has_roles?(:guest).should be_true
63
- @user.has?(:admin).should be_false
64
- end
65
-
66
- it "should set user role to :admin using =" do
67
- @user.roles = :admin
68
- @user.role.should == :admin
69
- @user.has_role?(:admin).should be_true
70
- end
71
- end
72
- end
73
- end
74
-
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :many_roles
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :many_roles, :default
9
- role_class :role
10
-
11
- valid_roles_are :admin, :guest
12
-
13
- field :name, :type => String
14
- end
15
-
16
- describe "Roles for Mongoid" do
17
-
18
- after :each do
19
- Database.teardown
20
- end
21
-
22
- context "default setup" do
23
-
24
- before do
25
- @user = User.create(:name => 'Kristian')
26
- @user.add_roles :guest
27
- @user.save
28
-
29
- @admin_user = User.create(:name => 'Admin user')
30
- @admin_user.roles = :admin
31
- @admin_user.save
32
- end
33
-
34
- describe '#in_role' do
35
- it "should return first user matching role" do
36
- User.in_role(:guest).first.name.should == 'Kristian'
37
- User.in_role(:admin).first.name.should == 'Admin user'
38
- end
39
- end
40
-
41
- describe "Role API" do
42
- it "should have admin user role to :admin" do
43
- @admin_user.roles_list.first.should == :admin
44
- @admin_user.admin?.should be_true
45
-
46
- @admin_user.has_role?(:guest).should be_false
47
-
48
- @admin_user.has_role?(:admin).should be_true
49
- @admin_user.is?(:admin).should be_true
50
- @admin_user.has_roles?(:admin).should be_true
51
- @admin_user.has?(:admin).should be_true
52
- end
53
-
54
- it "should have user role to :guest" do
55
- @user.roles_list.first.should == :guest
56
- @user.admin?.should be_false
57
-
58
- @user.has_role?(:guest).should be_true
59
- @user.has_role?(:admin).should be_false
60
- @user.is?(:admin).should be_false
61
-
62
- @user.has_roles?(:admin).should be_false
63
- @user.has?(:admin).should be_false
64
- end
65
-
66
- it "should set user role to :admin using roles=" do
67
- @user.roles = :admin
68
- @user.roles_list.first.should == :admin
69
- @user.has_role?(:admin).should be_true
70
- end
71
- end
72
- end
73
- end
74
-
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :one_role
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :one_role, :default
9
- role_class :role
10
-
11
- valid_roles_are :admin, :guest
12
-
13
- field :name, :type => String
14
- end
15
-
16
- describe "Roles for Mongoid" do
17
-
18
- after :each do
19
- Database.teardown
20
- end
21
-
22
- context "default setup" do
23
-
24
- before do
25
- @user = User.create(:name => 'Kristian')
26
- @user.role = :guest
27
- @user.save
28
-
29
- @admin_user = User.create(:name => 'Admin user')
30
- @admin_user.role = Role.where(:name => :admin).to_a.first
31
- @admin_user.save
32
- end
33
-
34
- describe '#in_role' do
35
- it "should return first user matching role" do
36
- User.in_role(:guest).first.name.should == 'Kristian'
37
- User.in_role(:admin).first.name.should == 'Admin user'
38
- end
39
- end
40
-
41
- describe "Role API" do
42
- it "should have admin user role to :admin" do
43
- @admin_user.roles_list.first.should == :admin
44
- @admin_user.admin?.should be_true
45
-
46
- @admin_user.has_role?(:guest).should be_false
47
-
48
- @admin_user.has_role?(:admin).should be_true
49
- @admin_user.is?(:admin).should be_true
50
- @admin_user.has_roles?(:admin).should be_true
51
- @admin_user.has?(:admin).should be_true
52
- end
53
-
54
- it "should have user role to :guest" do
55
- @user.roles_list.first.should == :guest
56
- @user.admin?.should be_false
57
-
58
- @user.has_role?(:guest).should be_true
59
- @user.has_role?(:admin).should be_false
60
- @user.is?(:admin).should be_false
61
-
62
- @user.has_roles?(:admin).should be_false
63
- @user.has?(:admin).should be_false
64
- end
65
-
66
- it "should set user role to :admin using roles=" do
67
- @user.roles = :admin
68
- @user.roles_list.first.should == :admin
69
- @user.has_role?(:admin).should be_true
70
- end
71
- end
72
- end
73
- end
74
-
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :role_string
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :role_string, :default
9
-
10
- valid_roles_are :admin, :guest
11
-
12
- field :name, :type => String
13
- end
14
-
15
- describe "Roles for Mongoid" do
16
-
17
- after :each do
18
- Database.teardown
19
- end
20
-
21
- context "default setup" do
22
-
23
- before do
24
- @user = User.create(:name => 'Kristian')
25
- @user.role = :guest
26
- @user.save
27
-
28
- @admin_user = User.create(:name => 'Admin user')
29
- @admin_user.roles = :admin
30
- @admin_user.save
31
- end
32
-
33
- describe '#in_role' do
34
- it "should return first user matching role" do
35
- User.in_role(:guest).first.name.should == 'Kristian'
36
- User.in_role(:admin).first.name.should == 'Admin user'
37
- end
38
- end
39
-
40
- describe "Role API" do
41
- it "should have admin user role to :admin" do
42
- @admin_user.roles_list.first.should == :admin
43
- @admin_user.admin?.should be_true
44
-
45
- @admin_user.has_role?(:guest).should be_false
46
-
47
- @admin_user.has_role?(:admin).should be_true
48
- @admin_user.is?(:admin).should be_true
49
- @admin_user.has_roles?(:admin).should be_true
50
- @admin_user.has?(:admin).should be_true
51
- end
52
-
53
- it "should have user role to :guest" do
54
- @user.roles_list.first.should == :guest
55
- @user.admin?.should be_false
56
-
57
- @user.has_role?(:guest).should be_true
58
- @user.has_role?(:admin).should be_false
59
- @user.is?(:admin).should be_false
60
-
61
- @user.has_roles?(:admin).should be_false
62
- @user.has?(:admin).should be_false
63
- end
64
-
65
- it "should set user role to :admin using roles=" do
66
- @user.roles = :admin
67
- @user.roles_list.first.should == :admin
68
- @user.has_role?(:admin).should be_true
69
- end
70
- end
71
- end
72
- end
73
-
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :role_strings
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :role_strings, :default
9
-
10
- valid_roles_are :admin, :guest
11
-
12
- field :name, :type => String
13
- end
14
-
15
- describe "Roles for Mongoid" do
16
-
17
- after :each do
18
- Database.teardown
19
- end
20
-
21
- context "default setup" do
22
-
23
- before do
24
- @user = User.create(:name => 'Kristian')
25
- @user.role = :guest
26
- @user.save
27
-
28
- @admin_user = User.create(:name => 'Admin user')
29
- @admin_user.roles = :admin
30
- @admin_user.save
31
- end
32
-
33
- describe '#in_role' do
34
- it "should return first user matching role" do
35
- User.in_role(:guest).first.name.should == 'Kristian'
36
- User.in_role(:admin).first.name.should == 'Admin user'
37
- end
38
- end
39
-
40
- describe "Role API" do
41
- it "should have admin user role to :admin" do
42
- @admin_user.roles_list.first.should == :admin
43
- @admin_user.admin?.should be_true
44
-
45
- @admin_user.has_role?(:guest).should be_false
46
-
47
- @admin_user.has_role?(:admin).should be_true
48
- @admin_user.is?(:admin).should be_true
49
- @admin_user.has_roles?(:admin).should be_true
50
- @admin_user.has?(:admin).should be_true
51
- end
52
-
53
- it "should have user role to :guest" do
54
- @user.roles_list.first.should == :guest
55
- @user.admin?.should be_false
56
-
57
- @user.has_role?(:guest).should be_true
58
- @user.has_role?(:admin).should be_false
59
- @user.is?(:admin).should be_false
60
-
61
- @user.has_roles?(:admin).should be_false
62
- @user.has?(:admin).should be_false
63
- end
64
-
65
- it "should set user role to :admin using roles=" do
66
- @user.roles = :admin
67
- @user.roles_list.first.should == :admin
68
- @user.has_role?(:admin).should be_true
69
- end
70
- end
71
- end
72
- end
73
-
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :roles_mask
3
-
4
- class User
5
- include Mongoid::Document
6
- include Roles::Mongoid
7
-
8
- strategy :roles_mask, :default
9
-
10
- valid_roles_are :admin, :guest
11
-
12
- field :name, :type => String
13
- end
14
-
15
- describe "Roles for Mongoid" do
16
-
17
- after :each do
18
- Database.teardown
19
- end
20
-
21
- context "default setup" do
22
-
23
- before do
24
- @user = User.create(:name => 'Kristian')
25
- @user.role = :guest
26
- @user.save
27
-
28
- @admin_user = User.create(:name => 'Admin user')
29
- @admin_user.roles = :admin
30
- @admin_user.save
31
- end
32
-
33
- describe '#in_role' do
34
- it "should return first user matching role" do
35
- User.in_role(:guest).first.name.should == 'Kristian'
36
- User.in_role(:admin).first.name.should == 'Admin user'
37
- end
38
- end
39
-
40
- describe "Role API" do
41
- it "should have admin user role to :admin" do
42
- @admin_user.roles_list.first.should == :admin
43
- @admin_user.admin?.should be_true
44
-
45
- @admin_user.has_role?(:guest).should be_false
46
-
47
- @admin_user.has_role?(:admin).should be_true
48
- @admin_user.is?(:admin).should be_true
49
- @admin_user.has_roles?(:admin).should be_true
50
- @admin_user.has?(:admin).should be_true
51
- end
52
-
53
- it "should have user role to :guest" do
54
- @user.roles_list.first.should == :guest
55
- @user.admin?.should be_false
56
-
57
- @user.has_role?(:guest).should be_true
58
- @user.has_role?(:admin).should be_false
59
- @user.is?(:admin).should be_false
60
-
61
- @user.has_roles?(:admin).should be_false
62
- @user.has?(:admin).should be_false
63
- end
64
-
65
- it "should set user role to :admin using roles=" do
66
- @user.roles = :admin
67
- @user.roles_list.first.should == :admin
68
- @user.has_role?(:admin).should be_true
69
- end
70
- end
71
- end
72
- end
73
-