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.
- data/Gemfile +13 -5
- data/Rakefile +13 -14
- data/VERSION +1 -1
- data/development.sqlite3 +0 -0
- data/lib/roles_active_record/role.rb +3 -0
- data/lib/roles_active_record/strategy/multi/many_roles.rb +38 -41
- data/lib/roles_active_record/strategy/multi/roles_mask.rb +22 -23
- data/lib/roles_active_record/strategy/multi.rb +54 -0
- data/lib/roles_active_record/strategy/shared.rb +26 -0
- data/lib/roles_active_record/strategy/single/admin_flag.rb +19 -18
- data/lib/roles_active_record/strategy/single/one_role.rb +35 -26
- data/lib/roles_active_record/strategy/single/role_string.rb +24 -19
- data/lib/roles_active_record/strategy/single.rb +34 -0
- data/roles_active_record.gemspec +54 -49
- data/spec/fixtures/many_roles_setup.rb +1 -1
- data/spec/fixtures/one_role_setup.rb +1 -1
- data/spec/migrations/many_roles/002_create_roles.rb +0 -1
- data/spec/migrations/roles_mask/005_add_roles_mask_to_users.rb +1 -1
- data/spec/roles_active_record/strategy/api.rb +214 -0
- data/spec/roles_active_record/strategy/api_examples.rb +213 -0
- data/spec/roles_active_record/strategy/multi/many_roles_spec.rb +27 -0
- data/spec/roles_active_record/strategy/multi/roles_mask_spec.rb +23 -0
- data/spec/roles_active_record/strategy/single/admin_flag_spec.rb +27 -0
- data/spec/roles_active_record/strategy/single/one_role_spec.rb +19 -0
- data/spec/roles_active_record/strategy/single/role_string_spec.rb +23 -0
- data/spec/roles_active_record/strategy/user_setup.rb +20 -0
- data/spec/spec_helper.rb +6 -1
- metadata +49 -63
- data/roles_for_ar.gemspec +0 -165
- data/spec/roles_active_record/admin_flag_spec.rb +0 -71
- data/spec/roles_active_record/many_roles_spec.rb +0 -69
- data/spec/roles_active_record/one_role_spec.rb +0 -68
- data/spec/roles_active_record/role_string_spec.rb +0 -68
- 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
|
-
|