effective_roles 1.4.4 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +7 -34
- data/app/controllers/admin/roles_controller.rb +2 -3
- data/app/helpers/effective_roles_helper.rb +21 -39
- data/app/views/effective/roles/_summary.html.haml +6 -8
- data/config/routes.rb +4 -4
- data/lib/effective_roles.rb +16 -6
- data/lib/effective_roles/version.rb +1 -1
- metadata +3 -192
- data/Rakefile +0 -23
- data/app/views/effective/roles/_fields.html.haml +0 -17
- data/lib/tasks/effective_roles_tasks.rake +0 -4
- data/spec/dummy/README.rdoc +0 -10
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/post.rb +0 -3
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -58
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -36
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/db/schema.rb +0 -46
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/effective_roles_spec.rb +0 -147
- data/spec/models/acts_as_role_restricted_spec.rb +0 -218
- data/spec/spec_helper.rb +0 -40
- data/spec/support/factories.rb +0 -1
data/spec/dummy/config/routes.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
Dummy::Application.routes.draw do
|
2
|
-
# The priority is based upon order of creation:
|
3
|
-
# first created -> highest priority.
|
4
|
-
|
5
|
-
# Sample of regular route:
|
6
|
-
# match 'products/:id' => 'catalog#view'
|
7
|
-
# Keep in mind you can assign values other than :controller and :action
|
8
|
-
|
9
|
-
# Sample of named route:
|
10
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
-
|
13
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
-
# resources :products
|
15
|
-
|
16
|
-
# Sample resource route with options:
|
17
|
-
# resources :products do
|
18
|
-
# member do
|
19
|
-
# get 'short'
|
20
|
-
# post 'toggle'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# collection do
|
24
|
-
# get 'sold'
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
|
28
|
-
# Sample resource route with sub-resources:
|
29
|
-
# resources :products do
|
30
|
-
# resources :comments, :sales
|
31
|
-
# resource :seller
|
32
|
-
# end
|
33
|
-
|
34
|
-
# Sample resource route with more complex sub-resources
|
35
|
-
# resources :products do
|
36
|
-
# resources :comments
|
37
|
-
# resources :sales do
|
38
|
-
# get 'recent', :on => :collection
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
|
42
|
-
# Sample resource route within a namespace:
|
43
|
-
# namespace :admin do
|
44
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
-
# # (app/controllers/admin/products_controller.rb)
|
46
|
-
# resources :products
|
47
|
-
# end
|
48
|
-
|
49
|
-
# You can have the root of your site routed with "root"
|
50
|
-
# just remember to delete public/index.html.
|
51
|
-
# root :to => 'welcome#index'
|
52
|
-
|
53
|
-
# See how all your routes lay out with "rake routes"
|
54
|
-
|
55
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
-
# match ':controller(/:action(/:id))(.:format)'
|
58
|
-
end
|
data/spec/dummy/db/schema.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended to check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(:version => 1) do
|
15
|
-
|
16
|
-
create_table "users", force: true do |t|
|
17
|
-
t.string "encrypted_password"
|
18
|
-
t.string "reset_password_token"
|
19
|
-
t.datetime "reset_password_sent_at"
|
20
|
-
t.datetime "remember_created_at"
|
21
|
-
t.datetime "confirmation_sent_at"
|
22
|
-
t.datetime "confirmed_at"
|
23
|
-
t.string "confirmation_token"
|
24
|
-
t.string "unconfirmed_email"
|
25
|
-
t.integer "sign_in_count", default: 0
|
26
|
-
t.datetime "current_sign_in_at"
|
27
|
-
t.datetime "last_sign_in_at"
|
28
|
-
t.string "current_sign_in_ip"
|
29
|
-
t.string "last_sign_in_ip"
|
30
|
-
t.string "email"
|
31
|
-
t.string "first_name"
|
32
|
-
t.string "last_name"
|
33
|
-
t.integer "roles_mask", default: 0
|
34
|
-
t.boolean "archived", default: false
|
35
|
-
t.datetime "updated_at"
|
36
|
-
t.datetime "created_at"
|
37
|
-
end
|
38
|
-
|
39
|
-
create_table "posts", force: true do |t|
|
40
|
-
t.string "title"
|
41
|
-
t.integer "roles_mask", default: 0
|
42
|
-
t.datetime "updated_at"
|
43
|
-
t.datetime "created_at"
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/spec/dummy/db/test.sqlite3
DELETED
Binary file
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EffectiveRoles do
|
4
|
-
let(:roles) { [:superadmin, :admin, :member] }
|
5
|
-
|
6
|
-
let(:post) { Post.new }
|
7
|
-
let(:user) { User.new.tap { |user| user.roles = [] } }
|
8
|
-
|
9
|
-
let(:member) { User.new.tap { |user| user.roles = [:member] } }
|
10
|
-
let(:admin) { User.new.tap { |user| user.roles = [:admin] } }
|
11
|
-
let(:superadmin) { User.new.tap { |user| user.roles = [:superadmin] } }
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
EffectiveRoles.setup { |config| config.roles = roles }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#roles_for_roles_mask' do
|
18
|
-
it 'computes the appropriate roles for the given mask' do
|
19
|
-
EffectiveRoles.roles_for(nil).should eq []
|
20
|
-
EffectiveRoles.roles_for(0).should eq []
|
21
|
-
EffectiveRoles.roles_for(1).should eq [:superadmin]
|
22
|
-
EffectiveRoles.roles_for(2).should eq [:admin]
|
23
|
-
EffectiveRoles.roles_for(3).should eq [:superadmin, :admin]
|
24
|
-
EffectiveRoles.roles_for(4).should eq [:member]
|
25
|
-
EffectiveRoles.roles_for(5).should eq [:superadmin, :member]
|
26
|
-
EffectiveRoles.roles_for(6).should eq [:admin, :member]
|
27
|
-
EffectiveRoles.roles_for(7).should eq [:superadmin, :admin, :member]
|
28
|
-
EffectiveRoles.roles_for(8).should eq []
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#assignable_roles' do
|
33
|
-
it 'uses the full Hash syntax to return the appropriate roles based on the passed User' do
|
34
|
-
EffectiveRoles.setup do |config|
|
35
|
-
config.assignable_roles = {
|
36
|
-
'User' => {
|
37
|
-
:superadmin => [:superadmin, :admin, :member], # Superadmins may assign all roles on a User#edit screen
|
38
|
-
:admin => [:admin, :member], # Admins may only assign :admin, :member on a User#edit screen
|
39
|
-
:member => [] # Members can assign no roles
|
40
|
-
},
|
41
|
-
'Post' => {
|
42
|
-
:superadmin => [:superadmin], # Superadmins may assign ony superadmin on a Post#edit screen
|
43
|
-
:admin => [:superadmin, :admin],
|
44
|
-
:member => [:admin, :member]
|
45
|
-
}
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
# On a User#edit screen
|
50
|
-
EffectiveRoles.assignable_roles_for(nil, user).should eq [:superadmin, :admin, :member]
|
51
|
-
EffectiveRoles.assignable_roles_for(superadmin, user).should eq [:superadmin, :admin, :member]
|
52
|
-
EffectiveRoles.assignable_roles_for(admin, user).should eq [:admin, :member]
|
53
|
-
EffectiveRoles.assignable_roles_for(member, user).should eq []
|
54
|
-
EffectiveRoles.assignable_roles_for(user, user).should eq []
|
55
|
-
|
56
|
-
# On a Post#edit screen
|
57
|
-
EffectiveRoles.assignable_roles_for(nil, post).should eq [:superadmin, :admin, :member]
|
58
|
-
EffectiveRoles.assignable_roles_for(superadmin, post).should eq [:superadmin]
|
59
|
-
EffectiveRoles.assignable_roles_for(admin, post).should eq [:superadmin, :admin]
|
60
|
-
EffectiveRoles.assignable_roles_for(member, post).should eq [:admin, :member]
|
61
|
-
EffectiveRoles.assignable_roles_for(user, post).should eq []
|
62
|
-
|
63
|
-
# On an unsupported object #edit screen
|
64
|
-
EffectiveRoles.assignable_roles_for(nil, nil).should eq [:superadmin, :admin, :member]
|
65
|
-
EffectiveRoles.assignable_roles_for(superadmin, nil).should eq []
|
66
|
-
EffectiveRoles.assignable_roles_for(admin, nil).should eq []
|
67
|
-
EffectiveRoles.assignable_roles_for(member, nil).should eq []
|
68
|
-
EffectiveRoles.assignable_roles_for(user, nil).should eq []
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'uses the simple Hash syntax to return the appropriate roles based on the passed User' do
|
72
|
-
EffectiveRoles.setup do |config|
|
73
|
-
config.assignable_roles = {
|
74
|
-
:superadmin => [:superadmin, :admin, :member], # Superadmins may assign any resource any role
|
75
|
-
:admin => [:admin, :member], # Admins may only assign the :admin or :member role
|
76
|
-
:member => [] # Members may not assign any roles
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
EffectiveRoles.assignable_roles_for(nil).should eq [:superadmin, :admin, :member]
|
81
|
-
|
82
|
-
EffectiveRoles.assignable_roles_for(superadmin).should eq [:superadmin, :admin, :member]
|
83
|
-
EffectiveRoles.assignable_roles_for(admin).should eq [:admin, :member]
|
84
|
-
EffectiveRoles.assignable_roles_for(member).should eq []
|
85
|
-
EffectiveRoles.assignable_roles_for(user).should eq []
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'uses the Array syntax to return the appropriate roles based on the passed User' do
|
89
|
-
EffectiveRoles.setup do |config|
|
90
|
-
config.assignable_roles = [:admin, :member]
|
91
|
-
end
|
92
|
-
|
93
|
-
EffectiveRoles.assignable_roles_for(nil).should eq [:admin, :member]
|
94
|
-
EffectiveRoles.assignable_roles_for(superadmin).should eq [:admin, :member]
|
95
|
-
EffectiveRoles.assignable_roles_for(admin).should eq [:admin, :member]
|
96
|
-
EffectiveRoles.assignable_roles_for(member).should eq [:admin, :member]
|
97
|
-
EffectiveRoles.assignable_roles_for(user).should eq [:admin, :member]
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'uses the Nil syntax to return all roles regardless of User' do
|
101
|
-
EffectiveRoles.setup do |config|
|
102
|
-
config.assignable_roles = nil
|
103
|
-
end
|
104
|
-
|
105
|
-
EffectiveRoles.assignable_roles_for(nil).should eq roles
|
106
|
-
EffectiveRoles.assignable_roles_for(superadmin).should eq roles
|
107
|
-
EffectiveRoles.assignable_roles_for(admin).should eq roles
|
108
|
-
EffectiveRoles.assignable_roles_for(member).should eq roles
|
109
|
-
EffectiveRoles.assignable_roles_for(user).should eq roles
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#disabled_roles' do
|
115
|
-
it 'uses the full Hash syntax to return the appropriate roles based on the passed User' do
|
116
|
-
EffectiveRoles.setup do |config|
|
117
|
-
config.disabled_roles = {
|
118
|
-
'User' => [:member],
|
119
|
-
'Post' => [:superadmin],
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
# On a User#edit screen
|
124
|
-
EffectiveRoles.disabled_roles_for(user).should eq [:member]
|
125
|
-
EffectiveRoles.disabled_roles_for(post).should eq [:superadmin]
|
126
|
-
EffectiveRoles.disabled_roles_for(nil).should eq []
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'uses the lazy Hash syntax to return the appropriate roles based on the passed User' do
|
130
|
-
EffectiveRoles.setup do |config|
|
131
|
-
config.disabled_roles = {
|
132
|
-
'User' => :member,
|
133
|
-
'Post' => :superadmin,
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
|
-
# On a User#edit screen
|
138
|
-
EffectiveRoles.disabled_roles_for(user).should eq [:member]
|
139
|
-
EffectiveRoles.disabled_roles_for(post).should eq [:superadmin]
|
140
|
-
EffectiveRoles.disabled_roles_for(nil).should eq []
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
@@ -1,218 +0,0 @@
|
|
1
|
-
describe 'Acts As Role Restricted' do
|
2
|
-
let(:roles) { [:superadmin, :admin, :member] }
|
3
|
-
|
4
|
-
let(:user) { User.new.tap { |user| user.roles = [] } }
|
5
|
-
let(:member) { User.new.tap { |user| user.roles = [:member] } }
|
6
|
-
let(:admin) { User.new.tap { |user| user.roles = [:admin] } }
|
7
|
-
let(:superadmin) { User.new.tap { |user| user.roles = [:superadmin] } }
|
8
|
-
let(:member_and_admin) { User.new.tap { |user| user.roles = [:member, :admin] } }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
EffectiveRoles.setup { |config| config.roles = roles }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#is_any?(roles)' do
|
15
|
-
context 'when subject has one of the roles in question' do
|
16
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
17
|
-
|
18
|
-
it 'is true' do
|
19
|
-
post.is_any?(:admin, :member).should be(true)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when subject does not have any of the roles in question' do
|
24
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
25
|
-
|
26
|
-
it 'is false' do
|
27
|
-
post.is_any?(:admin, :superadmin).should be(false)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when subject does not have any roles' do
|
32
|
-
let(:post) { Post.new }
|
33
|
-
|
34
|
-
it 'is false' do
|
35
|
-
post.is_any?(:member, :admin, :superadmin).should be(false)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#roles_permit?(obj)' do
|
41
|
-
describe 'when subject has no roles' do
|
42
|
-
let(:post) { Post.new }
|
43
|
-
|
44
|
-
it 'should be true when passed nil' do
|
45
|
-
post.roles_permit?(nil).should eq true
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should be true for any user' do
|
49
|
-
post.roles_permit?(user).should eq true
|
50
|
-
post.roles_permit?(member).should eq true
|
51
|
-
post.roles_permit?(admin).should eq true
|
52
|
-
post.roles_permit?(superadmin).should eq true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'when subject has one role' do
|
57
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
58
|
-
|
59
|
-
it 'should be false when passed nil' do
|
60
|
-
post.roles_permit?(nil).should eq false
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should be false when passed object doesnt share roles' do
|
64
|
-
post.roles_permit?(user).should eq false
|
65
|
-
post.roles_permit?(admin).should eq false
|
66
|
-
post.roles_permit?(superadmin).should eq false
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should be true for a user with all the same roles' do
|
70
|
-
post.roles_permit?(member).should eq true
|
71
|
-
post.roles_permit?(member_and_admin).should eq true
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'when subject has multiple roles' do
|
76
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
77
|
-
|
78
|
-
it 'should be false when passed nil' do
|
79
|
-
post.roles_permit?(nil).should eq false
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should be false when passed object doesnt share all roles' do
|
83
|
-
post.roles_permit?(user).should eq false
|
84
|
-
post.roles_permit?(superadmin).should eq false
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should be true for a user with overlapping roles' do
|
88
|
-
post.roles_permit?(member).should eq true
|
89
|
-
post.roles_permit?(admin).should eq true
|
90
|
-
post.roles_permit?(member_and_admin).should eq true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#roles_overlap?(obj)' do
|
96
|
-
describe 'when subject has no roles' do
|
97
|
-
let(:post) { Post.new }
|
98
|
-
|
99
|
-
it 'should be true when passed nil' do
|
100
|
-
post.roles_overlap?(nil).should eq true
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should be true when user has no roles either' do
|
104
|
-
post.roles_overlap?(user).should eq true
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should be false for any user with roles' do
|
108
|
-
post.roles_overlap?(member).should eq false
|
109
|
-
post.roles_overlap?(admin).should eq false
|
110
|
-
post.roles_overlap?(superadmin).should eq false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe 'when subject has one role' do
|
115
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
116
|
-
|
117
|
-
it 'should be false when passed nil' do
|
118
|
-
post.roles_overlap?(nil).should eq false
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should be false when passed object doesnt share roles' do
|
122
|
-
post.roles_overlap?(user).should eq false
|
123
|
-
post.roles_overlap?(admin).should eq false
|
124
|
-
post.roles_overlap?(superadmin).should eq false
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should be true for a user with all the same roles' do
|
128
|
-
post.roles_overlap?(member).should eq true
|
129
|
-
post.roles_overlap?(member_and_admin).should eq true
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'when subject has multiple roles' do
|
134
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
135
|
-
|
136
|
-
it 'should be false when passed nil' do
|
137
|
-
post.roles_overlap?(nil).should eq false
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should be false when passed object doesnt share all roles' do
|
141
|
-
post.roles_overlap?(user).should eq false
|
142
|
-
post.roles_overlap?(superadmin).should eq false
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should be true for a user with overlapping roles' do
|
146
|
-
post.roles_overlap?(member).should eq true
|
147
|
-
post.roles_overlap?(admin).should eq true
|
148
|
-
post.roles_overlap?(member_and_admin).should eq true
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
|
-
describe '#roles_match?(obj)' do
|
155
|
-
describe 'when subject has no roles' do
|
156
|
-
let(:post) { Post.new }
|
157
|
-
|
158
|
-
it 'should be true when passed nil' do
|
159
|
-
post.roles_match?(nil).should eq true
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should be true when user has no roles either' do
|
163
|
-
post.roles_match?(user).should eq true
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should be false for any user with roles' do
|
167
|
-
post.roles_match?(member).should eq false
|
168
|
-
post.roles_match?(admin).should eq false
|
169
|
-
post.roles_match?(superadmin).should eq false
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe 'when subject has one role' do
|
174
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member] } }
|
175
|
-
|
176
|
-
it 'should be false when passed nil' do
|
177
|
-
post.roles_match?(nil).should eq false
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'should be false when passed object doesnt share roles' do
|
181
|
-
post.roles_match?(user).should eq false
|
182
|
-
post.roles_match?(admin).should eq false
|
183
|
-
post.roles_match?(superadmin).should eq false
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should be true for a user with all the same roles' do
|
187
|
-
post.roles_match?(member).should eq true
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'should be false when the user has more roles' do
|
191
|
-
post.roles_match?(member_and_admin).should eq false
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe 'when subject has multiple roles' do
|
196
|
-
let(:post) { Post.new.tap { |post| post.roles = [:member, :admin] } }
|
197
|
-
|
198
|
-
it 'should be false when passed nil' do
|
199
|
-
post.roles_match?(nil).should eq false
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'should be false when passed object doesnt share all roles' do
|
203
|
-
post.roles_match?(user).should eq false
|
204
|
-
post.roles_match?(superadmin).should eq false
|
205
|
-
post.roles_match?(member).should eq false
|
206
|
-
post.roles_match?(admin).should eq false
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'should be true for a user with same roles' do
|
210
|
-
post.roles_match?(member_and_admin).should eq true
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
end
|