roles_active_record 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Gemfile +13 -5
  2. data/Rakefile +13 -14
  3. data/VERSION +1 -1
  4. data/development.sqlite3 +0 -0
  5. data/lib/roles_active_record/role.rb +3 -0
  6. data/lib/roles_active_record/strategy/multi/many_roles.rb +38 -41
  7. data/lib/roles_active_record/strategy/multi/roles_mask.rb +22 -23
  8. data/lib/roles_active_record/strategy/multi.rb +54 -0
  9. data/lib/roles_active_record/strategy/shared.rb +26 -0
  10. data/lib/roles_active_record/strategy/single/admin_flag.rb +19 -18
  11. data/lib/roles_active_record/strategy/single/one_role.rb +35 -26
  12. data/lib/roles_active_record/strategy/single/role_string.rb +24 -19
  13. data/lib/roles_active_record/strategy/single.rb +34 -0
  14. data/roles_active_record.gemspec +54 -49
  15. data/spec/fixtures/many_roles_setup.rb +1 -1
  16. data/spec/fixtures/one_role_setup.rb +1 -1
  17. data/spec/migrations/many_roles/002_create_roles.rb +0 -1
  18. data/spec/migrations/roles_mask/005_add_roles_mask_to_users.rb +1 -1
  19. data/spec/roles_active_record/strategy/api.rb +214 -0
  20. data/spec/roles_active_record/strategy/api_examples.rb +213 -0
  21. data/spec/roles_active_record/strategy/multi/many_roles_spec.rb +27 -0
  22. data/spec/roles_active_record/strategy/multi/roles_mask_spec.rb +23 -0
  23. data/spec/roles_active_record/strategy/single/admin_flag_spec.rb +27 -0
  24. data/spec/roles_active_record/strategy/single/one_role_spec.rb +19 -0
  25. data/spec/roles_active_record/strategy/single/role_string_spec.rb +23 -0
  26. data/spec/roles_active_record/strategy/user_setup.rb +20 -0
  27. data/spec/spec_helper.rb +6 -1
  28. metadata +49 -63
  29. data/roles_for_ar.gemspec +0 -165
  30. data/spec/roles_active_record/admin_flag_spec.rb +0 -71
  31. data/spec/roles_active_record/many_roles_spec.rb +0 -69
  32. data/spec/roles_active_record/one_role_spec.rb +0 -68
  33. data/spec/roles_active_record/role_string_spec.rb +0 -68
  34. data/spec/roles_active_record/roles_mask_spec.rb +0 -68
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :one_role
3
-
4
- migrate('one_role')
5
-
6
- describe "Roles for Active Record" do
7
- before do
8
- migrate('one_role')
9
- end
10
-
11
- context "default setup" do
12
-
13
- before :each do
14
- load 'fixtures/one_role_setup.rb'
15
-
16
- @user = User.create(:name => 'Kristian')
17
- @user.role = :guest
18
- @user.save
19
-
20
- puts "user: #{@user.one_role.inspect}"
21
- puts "role: #{Role.first.inspect}"
22
-
23
- @admin_user = User.create(:name => 'Admin user')
24
- @admin_user.role = :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,68 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :role_string
3
-
4
- class User < ActiveRecord::Base
5
- include Roles::ActiveRecord
6
-
7
- strategy :role_string, :default
8
- valid_roles_are :admin, :guest
9
- end
10
-
11
- describe "Roles for Active Record" do
12
- before do
13
- migrate('role_string')
14
- end
15
-
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,68 +0,0 @@
1
- require 'spec_helper'
2
- use_roles_strategy :roles_mask
3
-
4
- class User < ActiveRecord::Base
5
- include Roles::ActiveRecord
6
-
7
- strategy :roles_mask, :default
8
- valid_roles_are :admin, :guest
9
- end
10
-
11
- describe "Roles for Active Record" do
12
- before do
13
- migrate('roles_mask')
14
- end
15
-
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
-