rolify 3.2.0.rc2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -2
- data/lib/rolify.rb +2 -1
- data/lib/rolify/adapters/active_record/resource_adapter.rb +2 -1
- data/lib/rolify/role.rb +5 -0
- data/lib/rolify/version.rb +1 -1
- data/rolify.gemspec +3 -1
- data/spec/rolify/resource_spec.rb +37 -20
- data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +174 -0
- data/spec/rolify/shared_examples/shared_examples_for_roles.rb +13 -3
- data/spec/support/adapters/active_record.rb +1 -0
- data/spec/support/adapters/mongoid.rb +4 -0
- metadata +40 -56
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
= 3.2 (
|
2
|
-
* <b>DEPRECATION NOTICE:</b>Ruby 1.8 support dropped ! Mongoid 3.0 only supports MRI 1.9.3, and HEAD, and JRuby 1.6.0+ in 1.9 mode
|
1
|
+
= 3.2 (Aug 7, 2012)
|
2
|
+
* <b>DEPRECATION NOTICE:</b> Ruby 1.8 support dropped ! Mongoid 3.0 only supports MRI 1.9.3, and HEAD, and JRuby 1.6.0+ in 1.9 mode
|
3
3
|
* removed <tt>dynamic_shortcuts</tt> arguments from the generator
|
4
4
|
* to use dynamic shortcuts feature when you're using ActiveRecord, you have to enable it _after_ running rake db:migrate as it relies on the roles table
|
5
5
|
* support for Mongoid 3.x (thanks to @Leonas)
|
@@ -10,9 +10,12 @@
|
|
10
10
|
* added association callbacks <tt>(before|after)_add</tt>, <tt>(before|after)_remove</tt> on <tt>rolify</tt> method (thanks to @shekibobo)
|
11
11
|
* added ability to pass an array of roles to <tt>Resource.with_role()</tt>, aliased by <tt>Resource.with_roles()</tt> (thanks to @lukes)
|
12
12
|
* added option to have roles be destroyed by default if parent resource is destroyed (thanks to @treydock)
|
13
|
+
* added new method <tt>only_has_role?</tt> to check if user has only a specific role (thanks to @jalcine)
|
13
14
|
* better edge cases covering in the specs
|
14
15
|
* fixed a bug regarding the loading order of the railtie when using Mongoid ORM and other gems using initializer files (thanks to @stigi)
|
15
16
|
* fixed double quote syntax when using MySQL
|
17
|
+
* fixed a nasty bug regarding class level queries (thanks to @kamrulhassan)
|
18
|
+
* fixed uninitialized constant error in scopify method
|
16
19
|
* documentation improvement
|
17
20
|
|
18
21
|
= 3.1 (Apr 6, 2012)
|
data/lib/rolify.rb
CHANGED
@@ -29,9 +29,10 @@ module Rolify
|
|
29
29
|
load_dynamic_methods if Rolify.dynamic_shortcuts
|
30
30
|
end
|
31
31
|
|
32
|
-
def resourcify(options = {
|
32
|
+
def resourcify(options = {})
|
33
33
|
include Resource
|
34
34
|
|
35
|
+
options.reverse_merge!({ :role_cname => 'Role', :dependent => :destroy })
|
35
36
|
resourcify_options = { :class_name => options[:role_cname].camelize, :as => :resource, :dependent => options[:dependent] }
|
36
37
|
has_many :roles, resourcify_options
|
37
38
|
|
@@ -4,7 +4,8 @@ module Rolify
|
|
4
4
|
module Adapter
|
5
5
|
class ResourceAdapter < ResourceAdapterBase
|
6
6
|
def resources_find(roles_table, relation, role_name)
|
7
|
-
resources = relation.joins("INNER JOIN #{quote(roles_table)} ON #{quote(roles_table)}.resource_type = '#{relation.to_s}'
|
7
|
+
resources = relation.joins("INNER JOIN #{quote(roles_table)} ON #{quote(roles_table)}.resource_type = '#{relation.to_s}' AND
|
8
|
+
(#{quote(roles_table)}.resource_id IS NULL OR #{quote(roles_table)}.resource_id = #{quote(relation.table_name)}.id)")
|
8
9
|
resources = resources.where("#{quote(roles_table)}.name IN (?) AND #{quote(roles_table)}.resource_type = ?", Array(role_name), relation.to_s)
|
9
10
|
resources
|
10
11
|
end
|
data/lib/rolify/role.rb
CHANGED
@@ -46,10 +46,15 @@ module Rolify
|
|
46
46
|
def has_any_role?(*args)
|
47
47
|
self.class.adapter.where(self.roles, *args).size > 0
|
48
48
|
end
|
49
|
+
|
50
|
+
def only_has_role?(role_name, resource = nil)
|
51
|
+
return self.has_role?(role_name,resource) && self.roles.count == 1
|
52
|
+
end
|
49
53
|
|
50
54
|
def remove_role(role_name, resource = nil)
|
51
55
|
self.class.adapter.remove(self, role_name, resource)
|
52
56
|
end
|
57
|
+
|
53
58
|
alias_method :revoke, :remove_role
|
54
59
|
deprecate :has_no_role, :remove_role
|
55
60
|
|
data/lib/rolify/version.rb
CHANGED
data/rolify.gemspec
CHANGED
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_development_dependency "mongoid", ">= 3.0"
|
30
30
|
s.add_development_dependency "ammeter"
|
31
31
|
s.add_development_dependency "rake"
|
32
|
-
s.add_development_dependency "rspec"
|
32
|
+
s.add_development_dependency "rspec", ">= 2.0"
|
33
|
+
s.add_development_dependency "rspec-rails", ">= 2.0"
|
34
|
+
s.add_development_dependency "mongoid-rspec", ">= 1.5"
|
33
35
|
s.add_development_dependency "bundler"
|
34
36
|
end
|
@@ -6,6 +6,7 @@ describe Rolify::Resource do
|
|
6
6
|
User.rolify :role_cname => "Role"
|
7
7
|
Forum.resourcify :role_cname => "Role"
|
8
8
|
Group.resourcify :role_cname => "Role"
|
9
|
+
Role.destroy_all
|
9
10
|
end
|
10
11
|
|
11
12
|
# Users
|
@@ -31,10 +32,10 @@ describe Rolify::Resource do
|
|
31
32
|
subject { Forum }
|
32
33
|
|
33
34
|
it "should include Forum instances with forum role" do
|
34
|
-
subject.with_role(:forum).should
|
35
|
+
subject.with_role(:forum).should =~ [ Forum.first, Forum.last ]
|
35
36
|
end
|
36
37
|
it "should include Forum instances with godfather role" do
|
37
|
-
subject.with_role(:godfather).should
|
38
|
+
subject.with_role(:godfather).should =~ Forum.all.to_a
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -42,7 +43,7 @@ describe Rolify::Resource do
|
|
42
43
|
subject { Group }
|
43
44
|
|
44
45
|
it "should include Group instances with group role" do
|
45
|
-
subject.with_role(:group).should
|
46
|
+
subject.with_role(:group).should =~ [ Group.last ]
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -51,8 +52,9 @@ describe Rolify::Resource do
|
|
51
52
|
context "with an array of role names as argument" do
|
52
53
|
context "on the Group class" do
|
53
54
|
subject { Group }
|
55
|
+
|
54
56
|
it "should include Group instances with both group and grouper roles" do
|
55
|
-
subject.with_roles([:group, :grouper]).should
|
57
|
+
subject.with_roles([:group, :grouper]).should =~ [ Group.first, Group.last ]
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -62,15 +64,15 @@ describe Rolify::Resource do
|
|
62
64
|
subject { Forum }
|
63
65
|
|
64
66
|
it "should get all Forum instances binded to the forum role and the admin user" do
|
65
|
-
subject.with_role(:forum, admin).should
|
67
|
+
subject.with_role(:forum, admin).should =~ [ Forum.first ]
|
66
68
|
end
|
67
69
|
|
68
70
|
it "should get all Forum instances binded to the forum role and the tourist user" do
|
69
|
-
subject.with_role(:forum, tourist).should
|
71
|
+
subject.with_role(:forum, tourist).should =~ [ Forum.last ]
|
70
72
|
end
|
71
73
|
|
72
74
|
it "should get all Forum instances binded to the godfather role and the admin user" do
|
73
|
-
subject.with_role(:godfather, admin).should
|
75
|
+
subject.with_role(:godfather, admin).should =~ Forum.all.to_a
|
74
76
|
end
|
75
77
|
|
76
78
|
it "should get all Forum instances binded to the godfather role and the tourist user" do
|
@@ -78,7 +80,7 @@ describe Rolify::Resource do
|
|
78
80
|
end
|
79
81
|
|
80
82
|
it "should get Forum instances binded to the group role and the tourist user" do
|
81
|
-
subject.with_role(:group, tourist).should
|
83
|
+
subject.with_role(:group, tourist).should =~ [ Forum.first ]
|
82
84
|
end
|
83
85
|
|
84
86
|
it "should not get Forum instances not binded to the group role and the tourist user" do
|
@@ -90,7 +92,7 @@ describe Rolify::Resource do
|
|
90
92
|
subject { Group }
|
91
93
|
|
92
94
|
it "should get all resources binded to the group role and the admin user" do
|
93
|
-
subject.with_role(:group, admin).should
|
95
|
+
subject.with_role(:group, admin).should =~ [ Group.last ]
|
94
96
|
end
|
95
97
|
|
96
98
|
it "should not get resources not binded to the group role and the admin user" do
|
@@ -104,7 +106,7 @@ describe Rolify::Resource do
|
|
104
106
|
subject { Forum }
|
105
107
|
|
106
108
|
it "should get Forum instances binded to the forum and group roles and the tourist user" do
|
107
|
-
subject.with_roles([:forum, :group], tourist).should
|
109
|
+
subject.with_roles([:forum, :group], tourist).should =~ [ Forum.first, Forum.last ]
|
108
110
|
end
|
109
111
|
|
110
112
|
end
|
@@ -113,7 +115,7 @@ describe Rolify::Resource do
|
|
113
115
|
subject { Group }
|
114
116
|
|
115
117
|
it "should get Group instances binded to the group and grouper roles and the admin user" do
|
116
|
-
subject.with_roles([:group, :grouper], admin).should
|
118
|
+
subject.with_roles([:group, :grouper], admin).should =~ [ Group.first, Group.last ]
|
117
119
|
end
|
118
120
|
|
119
121
|
end
|
@@ -129,7 +131,7 @@ describe Rolify::Resource do
|
|
129
131
|
subject { Forum }
|
130
132
|
|
131
133
|
it "should get all roles binded to a Forum class or instance" do
|
132
|
-
subject.find_roles.should
|
134
|
+
subject.find_roles.to_a.should =~ [ forum_role, godfather_role, tourist_role, sneaky_role ]
|
133
135
|
end
|
134
136
|
|
135
137
|
it "should not get roles not binded to a Forum class or instance" do
|
@@ -138,7 +140,7 @@ describe Rolify::Resource do
|
|
138
140
|
|
139
141
|
context "using :any parameter" do
|
140
142
|
it "should get all roles binded to any Forum class or instance" do
|
141
|
-
subject.find_roles(:any, :any).should
|
143
|
+
subject.find_roles(:any, :any).to_a.should =~ [ forum_role, godfather_role, tourist_role, sneaky_role ]
|
142
144
|
end
|
143
145
|
|
144
146
|
it "should not get roles not binded to a Forum class or instance" do
|
@@ -151,7 +153,7 @@ describe Rolify::Resource do
|
|
151
153
|
subject { Group }
|
152
154
|
|
153
155
|
it "should get all roles binded to a Group class or instance" do
|
154
|
-
subject.find_roles.should
|
156
|
+
subject.find_roles.to_a.should =~ [ group_role, grouper_role ]
|
155
157
|
end
|
156
158
|
|
157
159
|
it "should not get roles not binded to a Group class or instance" do
|
@@ -160,7 +162,7 @@ describe Rolify::Resource do
|
|
160
162
|
|
161
163
|
context "using :any parameter" do
|
162
164
|
it "should get all roles binded to Group class or instance" do
|
163
|
-
subject.find_roles(:any, :any).should
|
165
|
+
subject.find_roles(:any, :any).to_a.should =~ [ group_role, grouper_role ]
|
164
166
|
end
|
165
167
|
|
166
168
|
it "should not get roles not binded to a Group class or instance" do
|
@@ -186,7 +188,7 @@ describe Rolify::Resource do
|
|
186
188
|
|
187
189
|
context "using a user parameter" do
|
188
190
|
it "should get all roles binded to any resource" do
|
189
|
-
subject.find_roles(:forum, admin).should
|
191
|
+
subject.find_roles(:forum, admin).to_a.should =~ [ forum_role ]
|
190
192
|
end
|
191
193
|
|
192
194
|
it "should not get roles not binded to the admin user and forum role name" do
|
@@ -317,15 +319,30 @@ describe Rolify::Resource do
|
|
317
319
|
it { should respond_to :roles }
|
318
320
|
|
319
321
|
context "on a Forum instance" do
|
320
|
-
its(:roles) { should
|
322
|
+
its(:roles) { should eq([ forum_role, sneaky_role ]) }
|
321
323
|
its(:roles) { subject.should_not include(group_role, godfather_role, tourist_role) }
|
322
324
|
end
|
323
325
|
|
324
326
|
context "on a Group instance" do
|
325
327
|
subject { Group.last }
|
326
328
|
|
327
|
-
its(:roles) { should
|
329
|
+
its(:roles) { should eq([ group_role ]) }
|
328
330
|
its(:roles) { should_not include(forum_role, godfather_role, sneaky_role, tourist_role) }
|
331
|
+
|
332
|
+
context "when deleting a Group instance" do
|
333
|
+
subject do
|
334
|
+
Group.create(:name => "to delete")
|
335
|
+
end
|
336
|
+
|
337
|
+
before do
|
338
|
+
subject.roles.create :name => "group_role1"
|
339
|
+
subject.roles.create :name => "group_role2"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should remove the roles binded to this instance" do
|
343
|
+
expect { subject.destroy }.to change { Role.count }.by(-2)
|
344
|
+
end
|
345
|
+
end
|
329
346
|
end
|
330
347
|
end
|
331
348
|
|
@@ -333,14 +350,14 @@ describe Rolify::Resource do
|
|
333
350
|
context "on a Forum instance" do
|
334
351
|
subject { Forum.first }
|
335
352
|
|
336
|
-
its(:applied_roles) { should
|
353
|
+
its(:applied_roles) { should =~ [ forum_role, godfather_role, sneaky_role ] }
|
337
354
|
its(:applied_roles) { should_not include(group_role, tourist_role) }
|
338
355
|
end
|
339
356
|
|
340
357
|
context "on a Group instance" do
|
341
358
|
subject { Group.last }
|
342
359
|
|
343
|
-
its(:applied_roles) { should
|
360
|
+
its(:applied_roles) { should =~ [ group_role ] }
|
344
361
|
its(:applied_roles) { should_not include(forum_role, godfather_role, sneaky_role, tourist_role) }
|
345
362
|
end
|
346
363
|
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
|
2
|
+
context "using #{param_name} as parameter" do
|
3
|
+
context "with a global role", :scope => :global do
|
4
|
+
subject do
|
5
|
+
user = User.create(:login => "global_user")
|
6
|
+
user.add_role "global_role".send(param_method)
|
7
|
+
user
|
8
|
+
end
|
9
|
+
|
10
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_true }
|
11
|
+
|
12
|
+
context "on resource request" do
|
13
|
+
it { subject.only_has_role?("global_role".send(param_method), Forum.first).should be_true }
|
14
|
+
it { subject.only_has_role?("global_role".send(param_method), Forum).should be_true }
|
15
|
+
it { subject.only_has_role?("global_role".send(param_method), :any).should be_true }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with another global role" do
|
19
|
+
before(:all) { role_class.create(:name => "another_global_role") }
|
20
|
+
|
21
|
+
it { subject.only_has_role?("another_global_role".send(param_method)).should be_false }
|
22
|
+
it { subject.only_has_role?("another_global_role".send(param_method), :any).should be_false }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not get an instance scoped role" do
|
26
|
+
subject.only_has_role?("moderator".send(param_method), Group.first).should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not get a class scoped role" do
|
30
|
+
subject.only_has_role?("manager".send(param_method), Forum).should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
context "using inexisting role" do
|
34
|
+
it { subject.only_has_role?("dummy".send(param_method)).should be_false }
|
35
|
+
it { subject.only_has_role?("dumber".send(param_method), Forum.first).should be_false }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with multiple roles" do
|
39
|
+
before(:all) { subject.add_role "multiple_global_roles".send(param_method) }
|
40
|
+
|
41
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_false }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with a class scoped role", :scope => :class do
|
46
|
+
subject do
|
47
|
+
user = User.create(:login => "class_user")
|
48
|
+
user.add_role "class_role".send(param_method), Forum
|
49
|
+
user
|
50
|
+
end
|
51
|
+
|
52
|
+
context "on class scoped role request" do
|
53
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum).should be_true }
|
54
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_true }
|
55
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_true }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not get a scoped role when asking for a global" do
|
59
|
+
subject.only_has_role?("class_role".send(param_method)).should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not get a global role" do
|
63
|
+
role_class.create(:name => "global_role")
|
64
|
+
subject.only_has_role?("global_role".send(param_method)).should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with another class scoped role" do
|
68
|
+
context "on the same resource but with a different name" do
|
69
|
+
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Forum") }
|
70
|
+
|
71
|
+
it { subject.only_has_role?("another_class_role".send(param_method), Forum).should be_false }
|
72
|
+
it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_false }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "on another resource with the same name" do
|
76
|
+
before(:all) { role_class.create(:name => "class_role", :resource_type => "Group") }
|
77
|
+
|
78
|
+
it { subject.only_has_role?("class_role".send(param_method), Group).should be_false }
|
79
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_true }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "on another resource with another name" do
|
83
|
+
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Group") }
|
84
|
+
|
85
|
+
it { subject.only_has_role?("another_class_role".send(param_method), Group).should be_false }
|
86
|
+
it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_false }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "using inexisting role" do
|
91
|
+
it { subject.only_has_role?("dummy".send(param_method), Forum).should be_false }
|
92
|
+
it { subject.only_has_role?("dumber".send(param_method)).should be_false }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with multiple roles" do
|
96
|
+
before(:all) { subject.add_role "multiple_class_roles".send(param_method) }
|
97
|
+
|
98
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum).should be_false }
|
99
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_false }
|
100
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_false }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with a instance scoped role", :scope => :instance do
|
105
|
+
subject do
|
106
|
+
user = User.create(:login => "instance_user")
|
107
|
+
user.add_role "instance_role".send(param_method), Forum.first
|
108
|
+
user
|
109
|
+
end
|
110
|
+
|
111
|
+
context "on instance scoped role request" do
|
112
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should be_true }
|
113
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should not get an instance scoped role when asking for a global" do
|
117
|
+
subject.only_has_role?("instance_role".send(param_method)).should be_false
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should not get an instance scoped role when asking for a class scoped" do
|
121
|
+
subject.only_has_role?("instance_role".send(param_method), Forum).should be_false
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not get a global role" do
|
125
|
+
role_class.create(:name => "global_role")
|
126
|
+
subject.only_has_role?("global_role".send(param_method)).should be_false
|
127
|
+
end
|
128
|
+
|
129
|
+
context "with another instance scoped role" do
|
130
|
+
context "on the same resource but with a different role name" do
|
131
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.first) }
|
132
|
+
|
133
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.first).should be_false }
|
134
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
|
135
|
+
end
|
136
|
+
|
137
|
+
context "on another resource of the same type but with the same role name" do
|
138
|
+
before(:all) { role_class.create(:name => "moderator", :resource => Forum.last) }
|
139
|
+
|
140
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.last).should be_false }
|
141
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
|
142
|
+
end
|
143
|
+
|
144
|
+
context "on another resource of different type but with the same role name" do
|
145
|
+
before(:all) { role_class.create(:name => "moderator", :resource => Group.last) }
|
146
|
+
|
147
|
+
it { subject.only_has_role?("instance_role".send(param_method), Group.last).should be_false }
|
148
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
|
149
|
+
end
|
150
|
+
|
151
|
+
context "on another resource of the same type and with another role name" do
|
152
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.last) }
|
153
|
+
|
154
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.last).should be_false }
|
155
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
|
156
|
+
end
|
157
|
+
|
158
|
+
context "on another resource of different type and with another role name" do
|
159
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Group.first) }
|
160
|
+
|
161
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Group.first).should be_false }
|
162
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with multiple roles" do
|
167
|
+
before(:all) { subject.add_role "multiple_instance_roles".send(param_method), Forum.first }
|
168
|
+
|
169
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should be_false }
|
170
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_false }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rolify/shared_contexts"
|
2
2
|
require "rolify/shared_examples/shared_examples_for_add_role"
|
3
3
|
require "rolify/shared_examples/shared_examples_for_has_role"
|
4
|
+
require "rolify/shared_examples/shared_examples_for_only_has_role"
|
4
5
|
require "rolify/shared_examples/shared_examples_for_has_all_roles"
|
5
6
|
require "rolify/shared_examples/shared_examples_for_has_any_role"
|
6
7
|
require "rolify/shared_examples/shared_examples_for_remove_role"
|
@@ -56,6 +57,11 @@ shared_examples_for Rolify::Role do
|
|
56
57
|
it_should_behave_like "#has_role?_examples", "String", :to_s
|
57
58
|
it_should_behave_like "#has_role?_examples", "Symbol", :to_sym
|
58
59
|
end
|
60
|
+
|
61
|
+
describe "#only_has_role?" do
|
62
|
+
it_should_behave_like "#only_has_role?_examples", "String", :to_s
|
63
|
+
it_should_behave_like "#only_has_role?_examples", "Symbol", :to_sym
|
64
|
+
end
|
59
65
|
|
60
66
|
describe "#has_all_roles?" do
|
61
67
|
it_should_behave_like "#has_all_roles?_examples", "String", :to_s
|
@@ -72,17 +78,21 @@ shared_examples_for Rolify::Role do
|
|
72
78
|
it_should_behave_like "#remove_role_examples", "Symbol", :to_sym
|
73
79
|
end
|
74
80
|
end
|
75
|
-
|
81
|
+
|
82
|
+
context "with a new instance" do
|
76
83
|
let(:user) { user_class.new }
|
77
|
-
|
84
|
+
|
85
|
+
before(:all) do
|
78
86
|
user.add_role :admin
|
79
87
|
user.add_role :moderator, Forum.first
|
80
88
|
end
|
89
|
+
|
81
90
|
subject { user }
|
91
|
+
|
82
92
|
it { should have_role :admin }
|
83
93
|
it { should have_role :moderator, Forum.first }
|
84
|
-
|
85
94
|
end
|
95
|
+
|
86
96
|
context "on the Class level ", :scope => :mixed do
|
87
97
|
it_should_behave_like :finders, "String", :to_s
|
88
98
|
it_should_behave_like :finders, "Symbol", :to_sym
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rolify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.0
|
5
|
-
prerelease:
|
4
|
+
version: 3.2.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florent Monbillard
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70098036310660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *70098036310660
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: bson_ext
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70098036309620 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :development
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *70098036309620
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: activerecord
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70098036308480 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ! '>='
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: 3.1.0
|
54
44
|
type: :development
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.1.0
|
46
|
+
version_requirements: *70098036308480
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: mongoid
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70098036307720 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,15 +54,10 @@ dependencies:
|
|
69
54
|
version: '3.0'
|
70
55
|
type: :development
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '3.0'
|
57
|
+
version_requirements: *70098036307720
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
59
|
name: ammeter
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70098036307200 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
63
|
- - ! '>='
|
@@ -85,15 +65,10 @@ dependencies:
|
|
85
65
|
version: '0'
|
86
66
|
type: :development
|
87
67
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
68
|
+
version_requirements: *70098036307200
|
94
69
|
- !ruby/object:Gem::Dependency
|
95
70
|
name: rake
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirement: &70098036306500 !ruby/object:Gem::Requirement
|
97
72
|
none: false
|
98
73
|
requirements:
|
99
74
|
- - ! '>='
|
@@ -101,44 +76,51 @@ dependencies:
|
|
101
76
|
version: '0'
|
102
77
|
type: :development
|
103
78
|
prerelease: false
|
104
|
-
version_requirements:
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
79
|
+
version_requirements: *70098036306500
|
110
80
|
- !ruby/object:Gem::Dependency
|
111
81
|
name: rspec
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
82
|
+
requirement: &70098036305440 !ruby/object:Gem::Requirement
|
113
83
|
none: false
|
114
84
|
requirements:
|
115
85
|
- - ! '>='
|
116
86
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
87
|
+
version: '2.0'
|
118
88
|
type: :development
|
119
89
|
prerelease: false
|
120
|
-
version_requirements:
|
90
|
+
version_requirements: *70098036305440
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec-rails
|
93
|
+
requirement: &70098036304660 !ruby/object:Gem::Requirement
|
121
94
|
none: false
|
122
95
|
requirements:
|
123
96
|
- - ! '>='
|
124
97
|
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
98
|
+
version: '2.0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70098036304660
|
126
102
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
103
|
+
name: mongoid-rspec
|
104
|
+
requirement: &70098036303960 !ruby/object:Gem::Requirement
|
129
105
|
none: false
|
130
106
|
requirements:
|
131
107
|
- - ! '>='
|
132
108
|
- !ruby/object:Gem::Version
|
133
|
-
version: '
|
109
|
+
version: '1.5'
|
134
110
|
type: :development
|
135
111
|
prerelease: false
|
136
|
-
version_requirements:
|
112
|
+
version_requirements: *70098036303960
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: bundler
|
115
|
+
requirement: &70098036303500 !ruby/object:Gem::Requirement
|
137
116
|
none: false
|
138
117
|
requirements:
|
139
118
|
- - ! '>='
|
140
119
|
- !ruby/object:Gem::Version
|
141
120
|
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70098036303500
|
142
124
|
description: Very simple Roles library without any authorization enforcement supporting
|
143
125
|
scope on resource objects (instance or class). Supports ActiveRecord and Mongoid
|
144
126
|
ORMs.
|
@@ -194,6 +176,7 @@ files:
|
|
194
176
|
- spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
|
195
177
|
- spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
|
196
178
|
- spec/rolify/shared_examples/shared_examples_for_has_role.rb
|
179
|
+
- spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
|
197
180
|
- spec/rolify/shared_examples/shared_examples_for_remove_role.rb
|
198
181
|
- spec/rolify/shared_examples/shared_examples_for_roles.rb
|
199
182
|
- spec/rolify/shared_examples/shared_examples_for_scopes.rb
|
@@ -218,12 +201,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
202
|
none: false
|
220
203
|
requirements:
|
221
|
-
- - ! '
|
204
|
+
- - ! '>='
|
222
205
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
206
|
+
version: '0'
|
224
207
|
requirements: []
|
225
208
|
rubyforge_project: rolify
|
226
|
-
rubygems_version: 1.8.
|
209
|
+
rubygems_version: 1.8.17
|
227
210
|
signing_key:
|
228
211
|
specification_version: 3
|
229
212
|
summary: Roles library with resource scoping
|
@@ -241,6 +224,7 @@ test_files:
|
|
241
224
|
- spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
|
242
225
|
- spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
|
243
226
|
- spec/rolify/shared_examples/shared_examples_for_has_role.rb
|
227
|
+
- spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
|
244
228
|
- spec/rolify/shared_examples/shared_examples_for_remove_role.rb
|
245
229
|
- spec/rolify/shared_examples/shared_examples_for_roles.rb
|
246
230
|
- spec/rolify/shared_examples/shared_examples_for_scopes.rb
|