rolify 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +2 -4
  3. data/CHANGELOG.rdoc +20 -0
  4. data/README.md +42 -6
  5. data/lib/generators/rolify/role/role_generator.rb +11 -3
  6. data/lib/generators/rolify/role/templates/initializer.rb +2 -1
  7. data/lib/generators/rolify/role/templates/role-active_record.rb +2 -0
  8. data/lib/generators/rolify/role/templates/role-mongoid.rb +11 -9
  9. data/lib/rolify/adapters/active_record/resource_adapter.rb +12 -4
  10. data/lib/rolify/adapters/active_record/role_adapter.rb +11 -4
  11. data/lib/rolify/adapters/active_record/scopes.rb +27 -0
  12. data/lib/rolify/adapters/base.rb +5 -0
  13. data/lib/rolify/adapters/mongoid/resource_adapter.rb +9 -5
  14. data/lib/rolify/adapters/mongoid/role_adapter.rb +14 -2
  15. data/lib/rolify/adapters/mongoid/scopes.rb +27 -0
  16. data/lib/rolify/finders.rb +39 -0
  17. data/lib/rolify/railtie.rb +1 -1
  18. data/lib/rolify/resource.rb +2 -1
  19. data/lib/rolify/role.rb +17 -2
  20. data/lib/rolify/version.rb +1 -1
  21. data/lib/rolify.rb +14 -5
  22. data/rolify.gemspec +7 -5
  23. data/spec/generators/rolify/role/role_generator_spec.rb +17 -61
  24. data/spec/rolify/custom_spec.rb +12 -0
  25. data/spec/rolify/resource_spec.rb +65 -17
  26. data/spec/rolify/role_spec.rb +12 -0
  27. data/spec/rolify/shared_contexts.rb +12 -0
  28. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +57 -0
  29. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +77 -0
  30. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +174 -0
  31. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +47 -25
  32. data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +38 -0
  33. data/spec/spec_helper.rb +13 -0
  34. data/spec/support/adapters/active_record.rb +5 -0
  35. data/spec/support/adapters/mongoid.rb +26 -2
  36. data/spec/support/adapters/mongoid.yml +6 -0
  37. metadata +63 -27
@@ -46,7 +46,7 @@ describe Rolify::Generators::RoleGenerator do
46
46
 
47
47
  describe 'app/models/user.rb' do
48
48
  subject { file('app/models/user.rb') }
49
- it { should contain "rolify" }
49
+ it { should contain /class User < ActiveRecord::Base\n rolify\n/ }
50
50
  end
51
51
 
52
52
  describe 'migration file' do
@@ -88,10 +88,10 @@ describe Rolify::Generators::RoleGenerator do
88
88
  it { should contain "belongs_to :resource, :polymorphic => true" }
89
89
  end
90
90
 
91
- describe 'app/models/client.rb' do
91
+ describe 'app/models/admin_user.rb' do
92
92
  subject { file('app/models/admin_user.rb') }
93
93
 
94
- it { should contain "rolify" }
94
+ it { should contain /class AdminUser < ActiveRecord::Base\n rolify :role_cname => 'AdminRole'\n/ }
95
95
  end
96
96
 
97
97
  describe 'migration file' do
@@ -103,61 +103,19 @@ describe Rolify::Generators::RoleGenerator do
103
103
  end
104
104
  end
105
105
 
106
- describe 'specifying dynamic shortcuts' do
107
- before(:all) { arguments [ "Role", "User", "--dynamic_shortcuts" ] }
108
-
109
- before {
110
- capture(:stdout) {
111
- generator.create_file "app/models/user.rb" do
112
- "class User < ActiveRecord::Base\nend"
113
- end
114
- }
115
- run_generator
116
- }
117
-
118
- describe 'config/initializers/rolify.rb' do
119
- subject { file('config/initializers/rolify.rb') }
120
- it { should exist }
121
- it { should contain "Rolify.configure do |config|"}
122
- it { should_not contain "# config.use_dynamic_shortcuts" }
123
- it { should contain "# config.use_mongoid" }
124
- end
125
-
126
- describe 'app/models/role.rb' do
127
- subject { file('app/models/role.rb') }
128
- it { should exist }
129
- it { should contain "class Role < ActiveRecord::Base" }
130
- it { should contain "has_and_belongs_to_many :users, :join_table => :users_roles" }
131
- it { should contain "belongs_to :resource, :polymorphic => true" }
132
- end
133
-
134
- describe 'app/models/user.rb' do
135
- subject { file('app/models/user.rb') }
136
- it { should contain "rolify" }
137
- end
138
-
139
- describe 'migration file' do
140
- subject { migration_file('db/migrate/rolify_create_roles.rb') }
141
-
142
- it { should be_a_migration }
143
- it { should contain "create_table(:roles) do" }
144
- it { should contain "create_table(:users_roles, :id => false) do" }
145
- end
146
- end
147
-
148
106
  describe 'specifying orm adapter' do
149
107
  before(:all) { arguments [ "Role", "User", "mongoid" ] }
150
108
 
151
109
  before {
152
110
  capture(:stdout) {
153
111
  generator.create_file "app/models/user.rb" do
154
- <<-CLASS
155
- class User
156
- include Mongoid::Document
112
+ <<-CLASS
113
+ class User
114
+ include Mongoid::Document
157
115
 
158
- field :login, :type => String
159
- end
160
- CLASS
116
+ field :login, :type => String
117
+ end
118
+ CLASS
161
119
  end
162
120
  }
163
121
  run_generator
@@ -178,20 +136,18 @@ describe Rolify::Generators::RoleGenerator do
178
136
  it { should contain "has_and_belongs_to_many :users\n" }
179
137
  it { should contain "belongs_to :resource, :polymorphic => true" }
180
138
  it { should contain "field :name, :type => String" }
181
- it { should contain "index :name, unique: true" }
182
- it { should contain " index(\n"
183
- " [\n"
184
- " [:name, Mongo::ASCENDING],\n"
185
- " [:resource_type, Mongo::ASCENDING],\n"
186
- " [:resource_id, Mongo::ASCENDING]\n"
187
- " ],\n"
188
- " unique: true\n"
189
- " )\n" }
139
+ it { should contain "index({ :name => 1 }, { :unique => true })" }
140
+ it { should contain " index({\n"
141
+ " { :name => 1 },\n"
142
+ " { :resource_type => 1 },\n"
143
+ " { :resource_id => 1 }\n"
144
+ " },\n"
145
+ " { unique => true })"}
190
146
  end
191
147
 
192
148
  describe 'app/models/user.rb' do
193
149
  subject { file('app/models/user.rb') }
194
- it { should contain "rolify" }
150
+ it { should contain /class User\n include Mongoid::Document\n rolify\n/ }
195
151
  end
196
152
  end
197
153
  end
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "rolify/shared_examples/shared_examples_for_roles"
3
3
  require "rolify/shared_examples/shared_examples_for_dynamic"
4
+ require "rolify/shared_examples/shared_examples_for_scopes"
5
+ require "rolify/shared_examples/shared_examples_for_callbacks"
4
6
 
5
7
  describe "Using Rolify with custom User and Role class names" do
6
8
  it_behaves_like Rolify::Role do
@@ -8,8 +10,18 @@ describe "Using Rolify with custom User and Role class names" do
8
10
  let(:role_class) { Privilege }
9
11
  end
10
12
 
13
+ it_behaves_like "Role.scopes" do
14
+ let(:user_class) { Customer }
15
+ let(:role_class) { Privilege }
16
+ end
17
+
11
18
  it_behaves_like Rolify::Dynamic do
12
19
  let(:user_class) { Customer }
13
20
  let(:role_class) { Privilege }
14
21
  end
22
+
23
+ it_behaves_like "Rolify.callbacks" do
24
+ let(:user_class) { Customer }
25
+ let(:role_class) { Privilege }
26
+ end
15
27
  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
@@ -16,6 +17,7 @@ describe Rolify::Resource do
16
17
  let!(:forum_role) { admin.add_role(:forum, Forum.first) }
17
18
  let!(:godfather_role) { admin.add_role(:godfather, Forum) }
18
19
  let!(:group_role) { admin.add_role(:group, Group.last) }
20
+ let!(:grouper_role) { admin.add_role(:grouper, Group.first) }
19
21
  let!(:tourist_role) { tourist.add_role(:forum, Forum.last) }
20
22
  let!(:sneaky_role) { tourist.add_role(:group, Forum.first) }
21
23
 
@@ -30,10 +32,10 @@ describe Rolify::Resource do
30
32
  subject { Forum }
31
33
 
32
34
  it "should include Forum instances with forum role" do
33
- subject.with_role(:forum).should include(Forum.first, Forum.last)
35
+ subject.with_role(:forum).should =~ [ Forum.first, Forum.last ]
34
36
  end
35
37
  it "should include Forum instances with godfather role" do
36
- subject.with_role(:godfather).should eq(Forum.all)
38
+ subject.with_role(:godfather).should =~ Forum.all.to_a
37
39
  end
38
40
  end
39
41
 
@@ -41,26 +43,36 @@ describe Rolify::Resource do
41
43
  subject { Group }
42
44
 
43
45
  it "should include Group instances with group role" do
44
- subject.with_role(:group).should include(Group.last)
46
+ subject.with_role(:group).should =~ [ Group.last ]
45
47
  end
46
48
  end
47
49
 
48
50
  end
49
51
 
52
+ context "with an array of role names as argument" do
53
+ context "on the Group class" do
54
+ subject { Group }
55
+
56
+ it "should include Group instances with both group and grouper roles" do
57
+ subject.with_roles([:group, :grouper]).should =~ [ Group.first, Group.last ]
58
+ end
59
+ end
60
+ end
61
+
50
62
  context "with a role name and a user as arguments" do
51
63
  context "on the Forum class" do
52
64
  subject { Forum }
53
65
 
54
66
  it "should get all Forum instances binded to the forum role and the admin user" do
55
- subject.with_role(:forum, admin).should include(Forum.first)
67
+ subject.with_role(:forum, admin).should =~ [ Forum.first ]
56
68
  end
57
69
 
58
70
  it "should get all Forum instances binded to the forum role and the tourist user" do
59
- subject.with_role(:forum, tourist).should include(Forum.last)
71
+ subject.with_role(:forum, tourist).should =~ [ Forum.last ]
60
72
  end
61
73
 
62
74
  it "should get all Forum instances binded to the godfather role and the admin user" do
63
- subject.with_role(:godfather, admin).should == Forum.all
75
+ subject.with_role(:godfather, admin).should =~ Forum.all.to_a
64
76
  end
65
77
 
66
78
  it "should get all Forum instances binded to the godfather role and the tourist user" do
@@ -68,7 +80,7 @@ describe Rolify::Resource do
68
80
  end
69
81
 
70
82
  it "should get Forum instances binded to the group role and the tourist user" do
71
- subject.with_role(:group, tourist).should include(Forum.first)
83
+ subject.with_role(:group, tourist).should =~ [ Forum.first ]
72
84
  end
73
85
 
74
86
  it "should not get Forum instances not binded to the group role and the tourist user" do
@@ -80,7 +92,7 @@ describe Rolify::Resource do
80
92
  subject { Group }
81
93
 
82
94
  it "should get all resources binded to the group role and the admin user" do
83
- subject.with_role(:group, admin).should include(Group.last)
95
+ subject.with_role(:group, admin).should =~ [ Group.last ]
84
96
  end
85
97
 
86
98
  it "should not get resources not binded to the group role and the admin user" do
@@ -88,6 +100,27 @@ describe Rolify::Resource do
88
100
  end
89
101
  end
90
102
  end
103
+
104
+ context "with an array of role names and a user as arguments" do
105
+ context "on the Forum class" do
106
+ subject { Forum }
107
+
108
+ it "should get Forum instances binded to the forum and group roles and the tourist user" do
109
+ subject.with_roles([:forum, :group], tourist).should =~ [ Forum.first, Forum.last ]
110
+ end
111
+
112
+ end
113
+
114
+ context "on the Group class" do
115
+ subject { Group }
116
+
117
+ it "should get Group instances binded to the group and grouper roles and the admin user" do
118
+ subject.with_roles([:group, :grouper], admin).should =~ [ Group.first, Group.last ]
119
+ end
120
+
121
+ end
122
+ end
123
+
91
124
  end
92
125
 
93
126
  describe ".find_role" do
@@ -98,7 +131,7 @@ describe Rolify::Resource do
98
131
  subject { Forum }
99
132
 
100
133
  it "should get all roles binded to a Forum class or instance" do
101
- subject.find_roles.should include(forum_role, godfather_role, tourist_role, sneaky_role)
134
+ subject.find_roles.to_a.should =~ [ forum_role, godfather_role, tourist_role, sneaky_role ]
102
135
  end
103
136
 
104
137
  it "should not get roles not binded to a Forum class or instance" do
@@ -107,7 +140,7 @@ describe Rolify::Resource do
107
140
 
108
141
  context "using :any parameter" do
109
142
  it "should get all roles binded to any Forum class or instance" do
110
- subject.find_roles(:any, :any).should include(forum_role, godfather_role, tourist_role, sneaky_role)
143
+ subject.find_roles(:any, :any).to_a.should =~ [ forum_role, godfather_role, tourist_role, sneaky_role ]
111
144
  end
112
145
 
113
146
  it "should not get roles not binded to a Forum class or instance" do
@@ -120,7 +153,7 @@ describe Rolify::Resource do
120
153
  subject { Group }
121
154
 
122
155
  it "should get all roles binded to a Group class or instance" do
123
- subject.find_roles.should include(group_role)
156
+ subject.find_roles.to_a.should =~ [ group_role, grouper_role ]
124
157
  end
125
158
 
126
159
  it "should not get roles not binded to a Group class or instance" do
@@ -129,7 +162,7 @@ describe Rolify::Resource do
129
162
 
130
163
  context "using :any parameter" do
131
164
  it "should get all roles binded to Group class or instance" do
132
- subject.find_roles(:any, :any).should include(group_role)
165
+ subject.find_roles(:any, :any).to_a.should =~ [ group_role, grouper_role ]
133
166
  end
134
167
 
135
168
  it "should not get roles not binded to a Group class or instance" do
@@ -155,7 +188,7 @@ describe Rolify::Resource do
155
188
 
156
189
  context "using a user parameter" do
157
190
  it "should get all roles binded to any resource" do
158
- subject.find_roles(:forum, admin).should include(forum_role)
191
+ subject.find_roles(:forum, admin).to_a.should =~ [ forum_role ]
159
192
  end
160
193
 
161
194
  it "should not get roles not binded to the admin user and forum role name" do
@@ -286,15 +319,30 @@ describe Rolify::Resource do
286
319
  it { should respond_to :roles }
287
320
 
288
321
  context "on a Forum instance" do
289
- its(:roles) { should include(forum_role, sneaky_role) }
322
+ its(:roles) { should eq([ forum_role, sneaky_role ]) }
290
323
  its(:roles) { subject.should_not include(group_role, godfather_role, tourist_role) }
291
324
  end
292
325
 
293
326
  context "on a Group instance" do
294
327
  subject { Group.last }
295
328
 
296
- its(:roles) { should include(group_role) }
329
+ its(:roles) { should eq([ group_role ]) }
297
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
298
346
  end
299
347
  end
300
348
 
@@ -302,14 +350,14 @@ describe Rolify::Resource do
302
350
  context "on a Forum instance" do
303
351
  subject { Forum.first }
304
352
 
305
- its(:applied_roles) { should include(forum_role, godfather_role, sneaky_role) }
353
+ its(:applied_roles) { should =~ [ forum_role, godfather_role, sneaky_role ] }
306
354
  its(:applied_roles) { should_not include(group_role, tourist_role) }
307
355
  end
308
356
 
309
357
  context "on a Group instance" do
310
358
  subject { Group.last }
311
359
 
312
- its(:applied_roles) { should include(group_role) }
360
+ its(:applied_roles) { should =~ [ group_role ] }
313
361
  its(:applied_roles) { should_not include(forum_role, godfather_role, sneaky_role, tourist_role) }
314
362
  end
315
363
  end
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "rolify/shared_examples/shared_examples_for_roles"
3
3
  require "rolify/shared_examples/shared_examples_for_dynamic"
4
+ require "rolify/shared_examples/shared_examples_for_scopes"
5
+ require "rolify/shared_examples/shared_examples_for_callbacks"
4
6
 
5
7
  describe Rolify do
6
8
  it_behaves_like Rolify::Role do
@@ -8,8 +10,18 @@ describe Rolify do
8
10
  let(:role_class) { Role }
9
11
  end
10
12
 
13
+ it_behaves_like "Role.scopes" do
14
+ let(:user_class) { User }
15
+ let(:role_class) { Role }
16
+ end
17
+
11
18
  it_behaves_like Rolify::Dynamic do
12
19
  let(:user_class) { User }
13
20
  let(:role_class) { Role }
14
21
  end
22
+
23
+ it_behaves_like "Rolify.callbacks" do
24
+ let(:user_class) { User }
25
+ let(:role_class) { Role }
26
+ end
15
27
  end
@@ -63,6 +63,18 @@ shared_context "instance scoped role", :scope => :instance do
63
63
  end
64
64
  end
65
65
 
66
+ shared_context "mixed scoped roles", :scope => :mixed do
67
+ subject { user_class }
68
+
69
+ before(:all) do
70
+ role_class.destroy_all
71
+ end
72
+
73
+ let!(:root) { provision_user(user_class.first, [ :admin, :staff, [ :moderator, Group ], [ :visitor, Forum.last ] ]) }
74
+ let!(:modo) { provision_user(user_class.where(:login => "moderator").first, [[ :moderator, Forum ], [ :manager, Group ], [ :visitor, Group.first ]])}
75
+ let!(:visitor) { provision_user(user_class.last, [[ :visitor, Forum.last ]]) }
76
+ end
77
+
66
78
  def create_other_roles
67
79
  role_class.create :name => "superhero"
68
80
  role_class.create :name => "admin", :resource_type => "Group"
@@ -0,0 +1,57 @@
1
+ shared_examples_for "Rolify.callbacks" do
2
+ before(:all) do
3
+ reset_defaults
4
+ Rolify.dynamic_shortcuts = false
5
+ role_class.destroy_all
6
+ end
7
+
8
+ after :each do
9
+ @user.roles.destroy_all
10
+ end
11
+
12
+ describe "rolify association callbacks", :if => (Rolify.orm == "active_record") do
13
+ describe "before_add" do
14
+ it "should receive callback" do
15
+ user_class.rolify :before_add => :role_callback, :role_cname => role_class.to_s
16
+ @user = user_class.first
17
+ @user.stub(:role_callback)
18
+ @user.should_receive(:role_callback)
19
+ @user.add_role :admin
20
+ end
21
+ end
22
+
23
+ describe "after_add" do
24
+ it "should receive callback" do
25
+ user_class.rolify :after_add => :role_callback, :role_cname => role_class.to_s
26
+ @user = user_class.first
27
+ @user.stub(:role_callback)
28
+ @user.should_receive(:role_callback)
29
+ @user.add_role :admin
30
+ end
31
+ end
32
+
33
+ describe "before_remove" do
34
+ it "should receive callback" do
35
+ user_class.rolify :before_remove => :role_callback, :role_cname => role_class.to_s
36
+ @user = user_class.first
37
+ @user.add_role :admin
38
+ @user.stub(:role_callback)
39
+
40
+ @user.should_receive(:role_callback)
41
+ @user.remove_role :admin
42
+ end
43
+ end
44
+
45
+ describe "after_remove" do
46
+ it "should receive callback" do
47
+ user_class.rolify :after_remove => :role_callback, :role_cname => role_class.to_s
48
+ @user = user_class.first
49
+ @user.add_role :admin
50
+ @user.stub(:role_callback)
51
+
52
+ @user.should_receive(:role_callback)
53
+ @user.remove_role :admin
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,77 @@
1
+ shared_examples_for :finders do |param_name, param_method|
2
+ context "using #{param_name} as parameter" do
3
+ describe ".with_role" do
4
+ it { should respond_to(:with_role).with(1).argument }
5
+ it { should respond_to(:with_role).with(2).arguments }
6
+
7
+ context "with a global role" do
8
+ it { subject.with_role("admin".send(param_method)).should eq([ root ]) }
9
+ it { subject.with_role("moderator".send(param_method)).should be_empty }
10
+ it { subject.with_role("visitor".send(param_method)).should be_empty }
11
+ end
12
+
13
+ context "with a class scoped role" do
14
+ context "on Forum class" do
15
+ it { subject.with_role("admin".send(param_method), Forum).should eq([ root ]) }
16
+ it { subject.with_role("moderator".send(param_method), Forum).should eq([ modo ]) }
17
+ it { subject.with_role("visitor".send(param_method), Forum).should be_empty }
18
+ end
19
+
20
+ context "on Group class" do
21
+ it { subject.with_role("admin".send(param_method), Group).should eq([ root ]) }
22
+ it { subject.with_role("moderator".send(param_method), Group).should eq([ root ]) }
23
+ it { subject.with_role("visitor".send(param_method), Group).should be_empty }
24
+ end
25
+ end
26
+
27
+ context "with an instance scoped role" do
28
+ context "on Forum.first instance" do
29
+ it { subject.with_role("admin".send(param_method), Forum.first).should eq([ root ]) }
30
+ it { subject.with_role("moderator".send(param_method), Forum.first).should eq([ modo ]) }
31
+ it { subject.with_role("visitor".send(param_method), Forum.first).should be_empty }
32
+ end
33
+
34
+ context "on Forum.last instance" do
35
+ it { subject.with_role("admin".send(param_method), Forum.last).should eq([ root ]) }
36
+ it { subject.with_role("moderator".send(param_method), Forum.last).should eq([ modo ]) }
37
+ it { subject.with_role("visitor".send(param_method), Forum.last).should include(root, visitor) } # =~ doesn't pass using mongoid, don't know why...
38
+ end
39
+
40
+ context "on Group.first instance" do
41
+ it { subject.with_role("admin".send(param_method), Group.first).should eq([ root ]) }
42
+ it { subject.with_role("moderator".send(param_method), Group.first).should eq([ root ]) }
43
+ it { subject.with_role("visitor".send(param_method), Group.first).should eq([ modo ]) }
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".with_all_roles" do
49
+ it { should respond_to(:with_all_roles) }
50
+
51
+ it { subject.with_all_roles("admin".send(param_method), :staff).should eq([ root ]) }
52
+ it { subject.with_all_roles("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
53
+ it { subject.with_all_roles("admin".send(param_method), "moderator".send(param_method)).should be_empty }
54
+ it { subject.with_all_roles("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Forum }).should be_empty }
55
+ it { subject.with_all_roles({ :name => "moderator".send(param_method), :resource => Forum }, { :name => :manager, :resource => Group }).should eq([ modo ]) }
56
+ it { subject.with_all_roles("moderator".send(param_method), :manager).should be_empty }
57
+ it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => Forum.last }, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
58
+ it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => Group.first }, { :name => "moderator".send(param_method), :resource => Forum }).should eq([ modo ]) }
59
+ it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo ] }
60
+ end
61
+
62
+ describe ".with_any_role" do
63
+ it { should respond_to(:with_any_role) }
64
+
65
+ it { subject.with_any_role("admin".send(param_method), :staff).should eq([ root ]) }
66
+ it { subject.with_any_role("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
67
+ it { subject.with_any_role("admin".send(param_method), "moderator".send(param_method)).should eq([ root ]) }
68
+ it { subject.with_any_role("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Forum }).should =~ [ root, modo ] }
69
+ it { subject.with_any_role({ :name => "moderator".send(param_method), :resource => Forum }, { :name => :manager, :resource => Group }).should eq([ modo ]) }
70
+ it { subject.with_any_role({ :name => "moderator".send(param_method), :resource => Group }, { :name => :manager, :resource => Group }).should =~ [ root, modo ] }
71
+ it { subject.with_any_role("moderator".send(param_method), :manager).should be_empty }
72
+ it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => Forum.last }, { :name => "moderator".send(param_method), :resource => Group }).should =~ [ root, visitor ] }
73
+ it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => Group.first }, { :name => "moderator".send(param_method), :resource => Forum }).should eq([ modo ]) }
74
+ it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo, visitor ] }
75
+ end
76
+ end
77
+ end