rolify 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.travis.yml +32 -16
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -2
  4. data/README.md +1 -1
  5. data/Rakefile +6 -6
  6. data/gemfiles/Gemfile.rails-3.2 +14 -15
  7. data/gemfiles/Gemfile.rails-4.0 +21 -22
  8. data/gemfiles/Gemfile.rails-4.1 +37 -0
  9. data/lib/generators/active_record/rolify_generator.rb +2 -2
  10. data/lib/rolify.rb +6 -0
  11. data/lib/rolify/adapters/active_record/resource_adapter.rb +25 -4
  12. data/lib/rolify/adapters/base.rb +4 -0
  13. data/lib/rolify/adapters/mongoid/resource_adapter.rb +18 -1
  14. data/lib/rolify/configure.rb +6 -2
  15. data/lib/rolify/resource.rb +12 -9
  16. data/lib/rolify/role.rb +8 -2
  17. data/lib/rolify/version.rb +1 -1
  18. data/rolify.gemspec +15 -15
  19. data/spec/rolify/config_spec.rb +6 -7
  20. data/spec/rolify/resource_spec.rb +22 -6
  21. data/spec/rolify/shared_contexts.rb +1 -0
  22. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +4 -4
  23. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +27 -27
  24. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +4 -0
  25. data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
  26. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +32 -32
  27. data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
  28. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +44 -44
  29. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +21 -15
  30. data/spec/spec_helper.rb +26 -3
  31. data/spec/support/adapters/active_record.rb +12 -4
  32. data/spec/support/adapters/mongoid.rb +8 -0
  33. data/spec/support/data.rb +4 -1
  34. data/spec/support/schema.rb +4 -0
  35. metadata +48 -33
  36. checksums.yaml +0 -7
data/lib/rolify/role.rb CHANGED
@@ -9,8 +9,8 @@ module Rolify
9
9
  end
10
10
 
11
11
  def add_role(role_name, resource = nil)
12
- role = self.class.adapter.find_or_create_by(role_name.to_s,
13
- (resource.is_a?(Class) ? resource.to_s : resource.class.name if resource),
12
+ role = self.class.adapter.find_or_create_by(role_name.to_s,
13
+ (resource.is_a?(Class) ? resource.to_s : resource.class.name if resource),
14
14
  (resource.id if resource && !resource.is_a?(Class)))
15
15
 
16
16
  if !roles.include?(role)
@@ -23,6 +23,12 @@ module Rolify
23
23
  deprecate :has_role, :add_role
24
24
 
25
25
  def has_role?(role_name, resource = nil)
26
+ @r_map ||= {}
27
+ role_n_resource = role_name.to_s + resource.to_s
28
+ @r_map[role_n_resource].nil? ? @r_map[role_n_resource] = has_role_helper(role_name, resource) : @r_map[role_n_resource]
29
+ end
30
+
31
+ def has_role_helper(role_name, resource = nil)
26
32
  if new_record?
27
33
  self.roles.detect { |r| r.name == role_name.to_s && (r.resource == resource || resource.nil?) }.present?
28
34
  else
@@ -1,3 +1,3 @@
1
1
  module Rolify
2
- VERSION = "3.4.0"
2
+ VERSION = "3.4.1"
3
3
  end
data/rolify.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "rolify/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'rolify/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "rolify"
6
+ s.name = 'rolify'
7
7
  s.version = Rolify::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.license = "MIT"
10
- s.authors = ["Florent Monbillard"]
11
- s.email = ["f.monbillard@gmail.com"]
12
- s.homepage = "http://eppo.github.com/rolify/"
9
+ s.license = 'MIT'
10
+ s.authors = ['Florent Monbillard']
11
+ s.email = ['f.monbillard@gmail.com']
12
+ s.homepage = 'http://eppo.github.com/rolify/'
13
13
  s.summary = %q{Roles library with resource scoping}
14
14
  s.description = %q{Very simple Roles library without any authorization enforcement supporting scope on resource objects (instance or class). Supports ActiveRecord and Mongoid ORMs.}
15
15
 
@@ -18,12 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- spec/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ["lib"]
22
-
23
- s.add_development_dependency "ammeter"
24
- s.add_development_dependency "rake"
25
- s.add_development_dependency "rspec", ">= 2.0"
26
- s.add_development_dependency "rspec-rails", ">= 2.0"
27
- s.add_development_dependency "bundler"
28
- s.add_development_dependency "fuubar"
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_development_dependency 'ammeter', '~> 1.1.2'
24
+ s.add_development_dependency 'rake', '~> 10.3.2'
25
+ s.add_development_dependency 'rspec', '2.99.0'
26
+ s.add_development_dependency 'rspec-rails', '2.99.0'
27
+ s.add_development_dependency 'bundler', '~> 1.6.2'
28
+ s.add_development_dependency 'fuubar', '~> 1.3.3'
29
29
  end
@@ -20,7 +20,7 @@ describe Rolify do
20
20
  context "using defaults values" do
21
21
  subject { Rolify.dynamic_shortcuts }
22
22
 
23
- it { should be_false }
23
+ it { should be_falsey }
24
24
  end
25
25
 
26
26
  context "using custom values" do
@@ -30,7 +30,7 @@ describe Rolify do
30
30
 
31
31
  subject { Rolify.dynamic_shortcuts }
32
32
 
33
- it { should be_true }
33
+ it { should be_truthy }
34
34
  end
35
35
  end
36
36
 
@@ -127,7 +127,7 @@ describe Rolify do
127
127
  context "using defaults values" do
128
128
  subject { Rolify.dynamic_shortcuts }
129
129
 
130
- it { should be_false }
130
+ it { should be_falsey }
131
131
  end
132
132
 
133
133
  context "using custom values" do
@@ -138,7 +138,7 @@ describe Rolify do
138
138
 
139
139
  subject { Rolify.dynamic_shortcuts }
140
140
 
141
- it { should be_true }
141
+ it { should be_truthy }
142
142
  end
143
143
 
144
144
  context "using :use_dynamic_shortcuts method" do
@@ -148,7 +148,7 @@ describe Rolify do
148
148
 
149
149
  subject { Rolify.dynamic_shortcuts }
150
150
 
151
- it { should be_true }
151
+ it { should be_truthy }
152
152
  end
153
153
  end
154
154
  end
@@ -162,7 +162,7 @@ describe Rolify do
162
162
  end
163
163
  end
164
164
 
165
- its(:dynamic_shortcuts) { should be_true }
165
+ its(:dynamic_shortcuts) { should be_truthy }
166
166
  its(:orm) { should eq("mongoid") }
167
167
 
168
168
  context "on the User class", :if => ENV['ADAPTER'] == 'mongoid' do
@@ -183,7 +183,6 @@ describe Rolify do
183
183
  end
184
184
 
185
185
  subject { Forum }
186
-
187
186
  it { should satisfy { |u| u.include? Rolify::Resource }}
188
187
  its("adapter.class") { should be(Rolify::Adapter::ResourceAdapter) }
189
188
  end
@@ -3,10 +3,11 @@ require "spec_helper"
3
3
  describe Rolify::Resource do
4
4
  before(:all) do
5
5
  reset_defaults
6
- User.rolify
6
+ silence_warnings { User.rolify }
7
7
  Forum.resourcify
8
8
  Group.resourcify
9
9
  Team.resourcify
10
+ Organization.resourcify
10
11
  Role.destroy_all
11
12
  end
12
13
 
@@ -24,6 +25,7 @@ describe Rolify::Resource do
24
25
  let!(:sneaky_role) { tourist.add_role(:group, Forum.first) }
25
26
  let!(:captain_role) { captain.add_role(:captain, Team.first) }
26
27
  let!(:player_role) { captain.add_role(:player, Team.last) }
28
+ let!(:company_role) { admin.add_role(:owner, Company.first) }
27
29
 
28
30
  describe ".with_roles" do
29
31
  subject { Group }
@@ -38,11 +40,11 @@ describe Rolify::Resource do
38
40
  it "should include Forum instances with forum role" do
39
41
  subject.with_role(:forum).should =~ [ Forum.first, Forum.last ]
40
42
  end
41
-
43
+
42
44
  it "should include Forum instances with godfather role" do
43
45
  subject.with_role(:godfather).should =~ Forum.all.to_a
44
46
  end
45
-
47
+
46
48
  it "should be able to modify the resource", :if => ENV['ADAPTER'] == 'active_record' do
47
49
  forum_resource = subject.with_role(:forum).first
48
50
  forum_resource.name = "modified name"
@@ -138,14 +140,21 @@ describe Rolify::Resource do
138
140
 
139
141
  end
140
142
  end
141
-
143
+
142
144
  context "with a model not having ID column" do
143
145
  subject { Team }
144
-
146
+
145
147
  it "should find Team instance using team_code column" do
146
148
  subject.with_roles([:captain, :player], captain).should =~ [ Team.first, Team.last ]
147
149
  end
148
150
  end
151
+
152
+ context "with a resource using STI" do
153
+ subject { Organization }
154
+ it "should find instances of children classes" do
155
+ subject.with_roles(:owner, admin).should =~ [ Company.first ]
156
+ end
157
+ end
149
158
  end
150
159
 
151
160
  describe ".find_role" do
@@ -336,6 +345,13 @@ describe Rolify::Resource do
336
345
  end
337
346
  end
338
347
  end
348
+
349
+ context "with a resource using STI" do
350
+ subject{ Organization }
351
+ it "should find instances of children classes" do
352
+ subject.find_roles(:owner, admin).should =~ [company_role]
353
+ end
354
+ end
339
355
  end
340
356
 
341
357
  describe "#roles" do
@@ -387,4 +403,4 @@ describe Rolify::Resource do
387
403
  its(:applied_roles) { should_not include(forum_role, godfather_role, sneaky_role, tourist_role) }
388
404
  end
389
405
  end
390
- end
406
+ end
@@ -79,6 +79,7 @@ shared_context "mixed scoped roles", :scope => :mixed do
79
79
  let!(:root) { provision_user(user_class.first, [ :admin, :staff, [ :moderator, Group ], [ :visitor, Forum.last ] ]) }
80
80
  let!(:modo) { provision_user(user_class.where(:login => "moderator").first, [[ :moderator, Forum ], [ :manager, Group ], [ :visitor, Group.first ]])}
81
81
  let!(:visitor) { provision_user(user_class.last, [[ :visitor, Forum.last ]]) }
82
+ let!(:owner) { provision_user(user_class.first, [[:owner, Company.first]]) }
82
83
  end
83
84
 
84
85
  def create_other_roles
@@ -14,7 +14,7 @@ shared_examples_for "Rolify.callbacks" do
14
14
  it "should receive callback" do
15
15
  rolify_options = { :role_cname => role_class.to_s, :before_add => :role_callback }
16
16
  rolify_options[:role_join_table_name] = join_table if defined? join_table
17
- user_class.rolify rolify_options
17
+ silence_warnings { user_class.rolify rolify_options }
18
18
  @user = user_class.first
19
19
  @user.stub(:role_callback)
20
20
  @user.should_receive(:role_callback)
@@ -26,7 +26,7 @@ shared_examples_for "Rolify.callbacks" do
26
26
  it "should receive callback" do
27
27
  rolify_options = { :role_cname => role_class.to_s, :after_add => :role_callback }
28
28
  rolify_options[:role_join_table_name] = join_table if defined? join_table
29
- user_class.rolify rolify_options
29
+ silence_warnings { user_class.rolify rolify_options }
30
30
  @user = user_class.first
31
31
  @user.stub(:role_callback)
32
32
  @user.should_receive(:role_callback)
@@ -38,7 +38,7 @@ shared_examples_for "Rolify.callbacks" do
38
38
  it "should receive callback" do
39
39
  rolify_options = { :role_cname => role_class.to_s, :before_remove => :role_callback }
40
40
  rolify_options[:role_join_table_name] = join_table if defined? join_table
41
- user_class.rolify rolify_options
41
+ silence_warnings { user_class.rolify rolify_options }
42
42
  @user = user_class.first
43
43
  @user.add_role :admin
44
44
  @user.stub(:role_callback)
@@ -52,7 +52,7 @@ shared_examples_for "Rolify.callbacks" do
52
52
  it "should receive callback" do
53
53
  rolify_options = { :role_cname => role_class.to_s, :after_remove => :role_callback }
54
54
  rolify_options[:role_join_table_name] = join_table if defined? join_table
55
- user_class.rolify rolify_options
55
+ silence_warnings { user_class.rolify rolify_options }
56
56
  @user = user_class.first
57
57
  @user.add_role :admin
58
58
  @user.stub(:role_callback)
@@ -4,13 +4,13 @@ shared_examples_for Rolify::Dynamic do
4
4
  role_class.destroy_all
5
5
  rolify_options = { :role_cname => role_class.to_s }
6
6
  rolify_options[:role_join_table_name] = join_table if defined? join_table
7
- user_class.rolify rolify_options
7
+ silence_warnings { user_class.rolify rolify_options }
8
8
  Forum.resourcify :roles, :role_cname => role_class.to_s
9
9
  Group.resourcify :roles, :role_cname => role_class.to_s
10
10
  end
11
-
11
+
12
12
  context "using a global role" do
13
- subject do
13
+ subject do
14
14
  admin = user_class.first
15
15
  admin.add_role :admin
16
16
  admin.add_role :moderator, Forum.first
@@ -25,30 +25,30 @@ shared_examples_for Rolify::Dynamic do
25
25
  it { subject.is_admin?.should be(true) }
26
26
  it { subject.is_admin?.should be(true) }
27
27
  it { subject.is_admin?.should be(true) }
28
-
28
+
29
29
  context "removing the role on the last user having it" do
30
30
  before do
31
31
  subject.remove_role :solo
32
32
  end
33
-
33
+
34
34
  it { should_not respond_to(:is_solo?) }
35
35
  it { subject.is_solo?.should be(false) }
36
36
  end
37
37
  end
38
-
38
+
39
39
  context "using a resource scoped role" do
40
- subject do
40
+ subject do
41
41
  moderator = user_class.where(:login => "moderator").first
42
42
  moderator.add_role :moderator, Forum.first
43
43
  moderator.add_role :sole_mio, Forum.last
44
44
  moderator
45
45
  end
46
-
46
+
47
47
  it { should respond_to(:is_moderator?).with(0).arguments }
48
48
  it { should respond_to(:is_moderator_of?).with(1).arguments }
49
49
  it { should_not respond_to(:is_god?) }
50
50
  it { should_not respond_to(:is_god_of?) }
51
-
51
+
52
52
  it { subject.is_moderator?.should be(false) }
53
53
  it { subject.is_moderator_of?(Forum).should be(false) }
54
54
  it { subject.is_moderator_of?(Forum.first).should be(true) }
@@ -56,30 +56,30 @@ shared_examples_for Rolify::Dynamic do
56
56
  it { subject.is_moderator_of?(Group).should be(false) }
57
57
  it { subject.is_moderator_of?(Group.first).should be(false) }
58
58
  it { subject.is_moderator_of?(Group.last).should be(false) }
59
-
59
+
60
60
  context "removing the role on the last user having it" do
61
61
  before do
62
62
  subject.remove_role :sole_mio, Forum.last
63
63
  end
64
-
64
+
65
65
  it { should_not respond_to(:is_sole_mio?) }
66
66
  it { subject.is_sole_mio?.should be(false) }
67
67
  end
68
68
  end
69
-
69
+
70
70
  context "using a class scoped role" do
71
- subject do
71
+ subject do
72
72
  manager = user_class.where(:login => "god").first
73
73
  manager.add_role :manager, Forum
74
74
  manager.add_role :only_me, Forum
75
75
  manager
76
76
  end
77
-
77
+
78
78
  it { should respond_to(:is_manager?).with(0).arguments }
79
79
  it { should respond_to(:is_manager_of?).with(1).arguments }
80
80
  it { should_not respond_to(:is_god?) }
81
81
  it { should_not respond_to(:is_god_of?) }
82
-
82
+
83
83
  it { subject.is_manager?.should be(false) }
84
84
  it { subject.is_manager_of?(Forum).should be(true) }
85
85
  it { subject.is_manager_of?(Forum.first).should be(true) }
@@ -87,46 +87,46 @@ shared_examples_for Rolify::Dynamic do
87
87
  it { subject.is_manager_of?(Group).should be(false) }
88
88
  it { subject.is_manager_of?(Group.first).should be(false) }
89
89
  it { subject.is_manager_of?(Group.last).should be(false) }
90
-
90
+
91
91
  context "removing the role on the last user having it" do
92
92
  before do
93
93
  subject.remove_role :only_me, Forum
94
94
  end
95
-
95
+
96
96
  it { should_not respond_to(:is_only_me?) }
97
97
  it { subject.is_only_me?.should be(false) }
98
98
  end
99
99
  end
100
-
100
+
101
101
  context "if the role doesn't exist in the database" do
102
-
102
+
103
103
  subject { user_class.first }
104
-
104
+
105
105
  context "using a global role" do
106
106
  before(:all) do
107
107
  other_guy = user_class.last
108
108
  other_guy.add_role :superman
109
109
  end
110
-
110
+
111
111
  it { should respond_to(:is_superman?).with(0).arguments }
112
112
  it { should_not respond_to(:is_superman_of?) }
113
113
  it { should_not respond_to(:is_god?) }
114
-
114
+
115
115
  it { subject.is_superman?.should be(false) }
116
116
  it { subject.is_god?.should be(false) }
117
117
  end
118
-
118
+
119
119
  context "using a resource scope role" do
120
120
  before(:all) do
121
121
  other_guy = user_class.last
122
122
  other_guy.add_role :batman, Forum.first
123
123
  end
124
-
124
+
125
125
  it { should respond_to(:is_batman?).with(0).arguments }
126
126
  it { should respond_to(:is_batman_of?).with(1).arguments }
127
127
  it { should_not respond_to(:is_god?) }
128
128
  it { should_not respond_to(:is_god_of?) }
129
-
129
+
130
130
  it { subject.is_batman?.should be(false) }
131
131
  it { subject.is_batman_of?(Forum).should be(false) }
132
132
  it { subject.is_batman_of?(Forum.first).should be(false) }
@@ -134,7 +134,7 @@ shared_examples_for Rolify::Dynamic do
134
134
  it { subject.is_batman_of?(Group).should be(false) }
135
135
  it { subject.is_batman_of?(Group.first).should be(false) }
136
136
  it { subject.is_batman_of?(Group.last).should be(false) }
137
-
137
+
138
138
  it { subject.is_god?.should be(false) }
139
139
  it { subject.is_god_of?(Forum).should be(false) }
140
140
  it { subject.is_god_of?(Forum.first).should be(false) }
@@ -144,4 +144,4 @@ shared_examples_for Rolify::Dynamic do
144
144
  it { subject.is_god_of?(Group.last).should be(false) }
145
145
  end
146
146
  end
147
- end
147
+ end
@@ -42,6 +42,10 @@ shared_examples_for :finders do |param_name, param_method|
42
42
  it { subject.with_role("moderator".send(param_method), Group.first).should eq([ root ]) }
43
43
  it { subject.with_role("visitor".send(param_method), Group.first).should eq([ modo ]) }
44
44
  end
45
+
46
+ context "on Company.first_instance" do
47
+ it { subject.with_role("owner".send(param_method), Company.first).should eq([ owner ]) }
48
+ end
45
49
  end
46
50
  end
47
51
 
@@ -2,54 +2,54 @@ shared_examples_for "#has_all_roles?_examples" do |param_name, param_method|
2
2
  context "using #{param_name} as parameter" do
3
3
  context "with a global role", :scope => :global do
4
4
  context "on global roles only request" do
5
- it { subject.has_all_roles?("staff".send(param_method)).should be_true }
6
- it { subject.has_all_roles?("admin".send(param_method), "staff".send(param_method)).should be_true }
7
- it { subject.has_all_roles?("admin".send(param_method), "dummy".send(param_method)).should be_false }
8
- it { subject.has_all_roles?("dummy".send(param_method), "dumber".send(param_method)).should be_false }
5
+ it { subject.has_all_roles?("staff".send(param_method)).should be_truthy }
6
+ it { subject.has_all_roles?("admin".send(param_method), "staff".send(param_method)).should be_truthy }
7
+ it { subject.has_all_roles?("admin".send(param_method), "dummy".send(param_method)).should be_falsey }
8
+ it { subject.has_all_roles?("dummy".send(param_method), "dumber".send(param_method)).should be_falsey }
9
9
  end
10
10
 
11
11
  context "on mixed scoped roles" do
12
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "admin".send(param_method), :resource => Group }).should be_true }
13
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => :any }, { :name => "admin".send(param_method), :resource => Group }).should be_true }
14
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "staff".send(param_method), :resource => Group.last }).should be_true }
15
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "admin".send(param_method), :resource => Forum.last }).should be_true }
16
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_false }
17
- it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => :any }).should be_false}
12
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "admin".send(param_method), :resource => Group }).should be_truthy }
13
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => :any }, { :name => "admin".send(param_method), :resource => Group }).should be_truthy }
14
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "staff".send(param_method), :resource => Group.last }).should be_truthy }
15
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "admin".send(param_method), :resource => Forum.last }).should be_truthy }
16
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_falsey }
17
+ it { subject.has_all_roles?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => :any }).should be_falsey}
18
18
  end
19
19
  end
20
20
 
21
21
  context "with a class scoped role", :scope => :class do
22
22
  context "on class scoped roles only" do
23
- it { subject.has_all_roles?({ :name => "player".send(param_method), :resource => Forum }).should be_true }
24
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => Forum }).should be_true }
25
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => Forum }).should be_true }
26
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => :any }).should be_true }
27
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => Forum }).should be_false }
28
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => :any }).should be_false }
29
- it { subject.has_all_roles?({ :name => "dummy".send(param_method), :resource => Forum }, { :name => "dumber".send(param_method), :resource => Group }).should be_false }
23
+ it { subject.has_all_roles?({ :name => "player".send(param_method), :resource => Forum }).should be_truthy }
24
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => Forum }).should be_truthy }
25
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => Forum }).should be_truthy }
26
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => :any }).should be_truthy }
27
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => Forum }).should be_falsey }
28
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => :any }).should be_falsey }
29
+ it { subject.has_all_roles?({ :name => "dummy".send(param_method), :resource => Forum }, { :name => "dumber".send(param_method), :resource => Group }).should be_falsey }
30
30
  end
31
31
 
32
32
  context "on mixed scoped roles" do
33
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "manager".send(param_method), :resource => Forum.last }).should be_true }
34
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Group }, { :name => "moderator".send(param_method), :resource => Forum.first }).should be_false }
35
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum }).should be_false }
36
- it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.last }, { :name => "warrior".send(param_method), :resource => Forum.last }).should be_true }
33
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "manager".send(param_method), :resource => Forum.last }).should be_truthy }
34
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Group }, { :name => "moderator".send(param_method), :resource => Forum.first }).should be_falsey }
35
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum }).should be_falsey }
36
+ it { subject.has_all_roles?({ :name => "manager".send(param_method), :resource => Forum.last }, { :name => "warrior".send(param_method), :resource => Forum.last }).should be_truthy }
37
37
  end
38
38
  end
39
39
 
40
40
  context "with a instance scoped role", :scope => :instance do
41
41
  context "on instance scoped roles only" do
42
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => Forum.last }).should be_true }
43
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => :any }).should be_true }
44
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => Forum }).should be_false }
45
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "anonymous".send(param_method), :resource => Forum.last }).should be_true }
46
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum.last }).should be_false }
47
- it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_false }
48
- it { subject.has_all_roles?({ :name => "dummy".send(param_method), :resource => Forum.first }, { :name => "dumber".send(param_method), :resource => Forum.last }).should be_false }
42
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => Forum.last }).should be_truthy }
43
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => :any }).should be_truthy }
44
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => :any }, { :name => "anonymous".send(param_method), :resource => Forum }).should be_falsey }
45
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "anonymous".send(param_method), :resource => Forum.last }).should be_truthy }
46
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum.last }).should be_falsey }
47
+ it { subject.has_all_roles?({ :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_falsey }
48
+ it { subject.has_all_roles?({ :name => "dummy".send(param_method), :resource => Forum.first }, { :name => "dumber".send(param_method), :resource => Forum.last }).should be_falsey }
49
49
  end
50
50
 
51
51
  context "on mixed scoped roles" do
52
- it { subject.has_all_roles?({ :name => "visitor".send(param_method), :resource => Forum.last }).should be_true }
52
+ it { subject.has_all_roles?({ :name => "visitor".send(param_method), :resource => Forum.last }).should be_truthy }
53
53
  it { subject.has_all_roles?("soldier".send(param_method), { :name => "moderator".send(param_method), :resource => Forum.first }, { :name => "visitor".send(param_method), :resource => Forum }).should be(true) }
54
54
  it { subject.has_all_roles?("soldier".send(param_method), { :name => "moderator".send(param_method), :resource => Forum.last }, { :name => "visitor".send(param_method), :resource => Forum }).should be(false) }
55
55
  it { subject.has_all_roles?("soldier".send(param_method), { :name => "moderator".send(param_method), :resource => :any }, { :name => "visitor".send(param_method), :resource => Forum }).should be(true) }