roles_active_record 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
@@ -38,8 +38,7 @@ module Roles::ActiveRecord
|
|
38
38
|
|
39
39
|
# one_role reference
|
40
40
|
if strategy_name == :one_role
|
41
|
-
|
42
|
-
instance_eval "belongs_to :one_role, :class_name => '#{@role_class_name}'"
|
41
|
+
self.belongs_to :one_role, :foreign_key => 'role_id', :class_name => @role_class_name.to_s
|
43
42
|
end
|
44
43
|
|
45
44
|
# many_roles references
|
@@ -67,8 +66,7 @@ module Roles::ActiveRecord
|
|
67
66
|
end
|
68
67
|
|
69
68
|
def default_role_class strategy_name
|
70
|
-
if defined? ::Role
|
71
|
-
puts "require one_role"
|
69
|
+
if defined? ::Role
|
72
70
|
require "roles_active_record/#{strategy_name}"
|
73
71
|
return ::Role
|
74
72
|
end
|
data/roles_active_record.gemspec
CHANGED
@@ -22,192 +22,192 @@ describe "Roles for Active Record: #{api_name}" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
25
|
+
describe '#in_any_role' do
|
26
|
+
it "should return first user matching role" do
|
27
|
+
if User.respond_to? :in_roles
|
28
|
+
User.in_any_role(:guest, :user).first.name.should == 'Guest user'
|
29
|
+
User.in_any_role(:admin, :guest).should be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
|
35
|
+
# mutation API
|
36
|
+
[:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
|
37
|
+
@admin_user.respond_to?(api_method).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
# inspection API
|
41
|
+
[:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
|
42
|
+
@admin_user.respond_to?(api_method).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
# class method API
|
46
|
+
[:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
|
47
|
+
@admin_user.class.respond_to?(class_api_method).should be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#valid_role?' do
|
52
|
+
it "should be true that the admin user has a valid role of :guest" do
|
53
|
+
# @admin_user.valid_role?(:guest).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be true that the User class has a valid role of :guest" do
|
57
|
+
# User.valid_role?(:guest).should be_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#valid_roles' do
|
62
|
+
it "should be true that the admin user has a valid role of :guest" do
|
63
|
+
# @admin_user.valid_roles.should include(:guest, :admin)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be true that the User class has a valid role of :guest" do
|
67
|
+
User.valid_roles.should include(:guest, :admin)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#valid_roles?' do
|
72
|
+
it "should be true that the admin user has a valid role of :guest" do
|
73
|
+
@admin_user.valid_roles?(:guest, :admin).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be true that the User class has a valid role of :guest" do
|
77
|
+
User.valid_roles?(:guest, :admin).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#has_role?' do
|
82
|
+
it "should have admin user role to :admin and not to :user" do
|
83
|
+
@admin_user.has_role?(:user).should be_false
|
84
|
+
@admin_user.has_role?(:admin).should be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be true that guest user has role :guest and not :admin" do
|
88
|
+
puts "Guest user: #{@guest_user.roles_list}"
|
89
|
+
@guest_user.has_role?(:guest).should be_true
|
90
|
+
@guest_user.has_role?(:admin).should be_false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#has?' do
|
95
|
+
it "should be true that the admin_user has the :admin role" do
|
96
|
+
@admin_user.has?(:admin).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should NOT be true that the admin_user has the :admin role" do
|
100
|
+
@guest_user.has?(:admin).should be_false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#has_roles?' do
|
105
|
+
it "should be true that the admin_user has the roles :admin" do
|
106
|
+
# @admin_user.has_roles?(:admin).should be_true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should NOT be true that the user has the roles :admin" do
|
110
|
+
@guest_user.has_roles?(:admin).should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#roles_list' do
|
115
|
+
it "should be true that the first role of admin_user is the :admin role" do
|
116
|
+
@admin_user.roles_list.should include(:admin)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be true that the first role of admin_user is the :user role" do
|
120
|
+
case @normal_user.class.role_strategy.multiplicity
|
121
|
+
when :single
|
122
|
+
#if @normal_user.class.role_strategy.name == :admin_flag
|
123
|
+
@normal_user.roles_list.should include(:guest)
|
124
|
+
# else
|
125
|
+
# @normal_user.roles_list.should include(:user)
|
126
|
+
#end
|
127
|
+
when :multi
|
128
|
+
puts "Norm: #{@normal_user.roles}"
|
129
|
+
@normal_user.roles_list.should include(:user, :guest)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#roles' do
|
135
|
+
it "should be true that the roles of admin_user is an array with the role :admin" do
|
136
|
+
roles = @admin_user.roles
|
137
|
+
if defined?(Role) && roles.kind_of?(Role)
|
138
|
+
roles.name.to_sym.should == :admin
|
139
|
+
elsif roles.kind_of? Array
|
140
|
+
if @normal_user.class.role_strategy.type == :complex
|
141
|
+
roles.first.name.to_sym.should == :admin
|
142
|
+
end
|
143
|
+
if @normal_user.class.role_strategy.name == :admin_flag
|
144
|
+
roles.first.should == true
|
145
|
+
end
|
146
|
+
else
|
147
|
+
roles.to_sym.should == :admin
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#admin?' do
|
153
|
+
it "should be true that admin_user is in the :admin role" do
|
154
|
+
@admin_user.admin?.should be_true
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should NOT be true that the user is in the :admin role" do
|
158
|
+
@guest_user.admin?.should be_false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#is?' do
|
163
|
+
it "should be true that admin_user is in the :admin role" do
|
164
|
+
@admin_user.is?(:admin).should be_true
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should NOT be true that the user is in the :admin role" do
|
168
|
+
@guest_user.is?(:admin).should be_false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#roles=' do
|
173
|
+
it "should set user role to :admin" do
|
174
|
+
@guest_user.roles = :admin
|
175
|
+
@guest_user.has_role?(:admin).should be_true
|
176
|
+
@guest_user.roles = :guest
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#exchange_roles' do
|
181
|
+
it "should exchange user role :user with role :admin" do
|
182
|
+
@guest_user.exchange_role :guest, :with => :admin
|
183
|
+
@guest_user.has?(:guest).should be_false
|
184
|
+
@guest_user.has?(:admin).should be_true
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should exchange user role :admin with roles :user and :guest" do
|
188
|
+
case @admin_user.class.role_strategy.multiplicity
|
189
|
+
when :single
|
190
|
+
lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
|
191
|
+
when :multi
|
192
|
+
@admin_user.exchange_role :admin, :with => [:user, :guest]
|
193
|
+
@admin_user.has_role?(:user).should be_true
|
194
|
+
@admin_user.has_role?(:guest).should be_true
|
195
|
+
@admin_user.has?(:admin).should be_false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#remove_roles' do
|
201
|
+
it "should remove user role :admin using #remove_roles" do
|
202
|
+
@admin_user.remove_roles :admin
|
203
|
+
@admin_user.has_role?(:admin).should_not be_true
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should remove user role :admin using #remove_role" do
|
207
|
+
@guest_user.add_role :admin
|
208
|
+
@guest_user.has_role?(:admin).should be_true
|
209
|
+
@guest_user.remove_role :admin
|
210
|
+
@guest_user.has_role?(:admin).should_not be_true
|
211
|
+
end
|
212
|
+
end
|
213
213
|
end
|